From b507db3acb1114a2c900d0e2409cda73f54e02d7 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 23 Dec 2001 01:45:18 +0000 Subject: Big job on processus --- src/Main.cc | 102 ++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 69 insertions(+), 33 deletions(-) (limited to 'src/Main.cc') diff --git a/src/Main.cc b/src/Main.cc index 1436f84..caba9b6 100644 --- a/src/Main.cc +++ b/src/Main.cc @@ -21,45 +21,81 @@ InPipe * in; -class ad_t : public Action { +class ad_run : public Task { public: - ad_t() : Action("menu6") { } - virtual ~ad_t() { } - virtual String GetTitle() { return "Action dynamique"; } - virtual Task * Do(Variables * v, Variables * hds, Handle * h) { - String ut, un, shds; - - if (!fork()) { - execlp("uptime", "uptime", NULL); - } - (*in) >> ut; - wait(NULL); - - if (!fork()) { - execlp("uname", "uname", "-a", NULL); - } - (*in) >> un; - wait(NULL); - - for (int i = 0; i < hds->GetNb(); i++) { - shds += (*hds)[i] + "
\n"; - } - - Action * m = new Message("Action dynamique", - String("Vous avez choisi l'action dynamique. L'uptime de la machine est '") + - ut + "' et sa définition complète est '" + un + "'


Voici la liste des entêtes:

" + shds, ""); + ad_run(Variables * av, Variables * ahds, Handle * ah) : v(*av), hds(*ahds), h(ah) { + SetBurst(); + } + virtual ~ad_run() {} + virtual String GetName() { return "Action dynamique"; } + protected: + virtual int Do() throw (GeneralException) { + pid_t p; + + switch (current) { + case 0: + if (!(p = fork())) { + execlp("uptime", "uptime", NULL); + } + current = 1; + WaitFor(p); + Suspend(TASK_ON_HOLD); + + case 1: + (*in) >> ut; + if (!(p = fork())) { + execlp("uname", "uname", "-a", NULL); + } + current = 2; + WaitFor(p); + Suspend(TASK_ON_HOLD); - Task * t = m->Do(v, hds, h); + case 2: + (*in) >> un; + for (int i = 0; i < hds.GetNb(); i++) { + shds += hds[i] + "
\n"; + } - Image * testimg = new Image(100, 100); - testimg->Prepare(); + m = new Message("Action dynamique", + String("Vous avez choisi l'action dynamique. L'uptime de la machine est '") + + ut + "' et sa définition complète est '" + un + "'


Voici la liste des entêtes:

" + shds, ""); - Output * testoutput = new Output("TestImg.tga"); + current = 3; + WaitFor(m->Do(&v, &hds, h)); + Suspend(TASK_ON_HOLD); + + case 3: + delete m; + testimg = new Image(100, 100); + testimg->Prepare(); - new CopyJob(testimg, testoutput, -1, true, true); + testoutput = new Output("TestImg.tga"); - delete m; - return t; + current = 4; + WaitFor(new CopyJob(testimg, testoutput, -1, true, true)); + Suspend(TASK_ON_HOLD); + + case 4: + return TASK_DONE; + } + return TASK_DONE; + } + private: + Variables v, hds; + Handle * h; + String ut, un, shds; + Action * m; + Image * testimg; + Output * testoutput; +}; + +class ad_t : public Action { + public: + ad_t() : Action("menu6") { } + virtual ~ad_t() { } + virtual String GetTitle() { return "Action dynamique"; } + virtual Task * Do(Variables * v, Variables * hds, Handle * h) { + return new ad_run(v, hds, h); } }; Action * ad = new ad_t(); -- cgit v1.2.3