summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Main.cc102
1 files changed, 69 insertions, 33 deletions
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] + "<BR>\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 + "'<BR><BR><BR>Voici la liste des entêtes:<BR><BR>" + 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] + "<BR>\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 + "'<BR><BR><BR>Voici la liste des entêtes:<BR><BR>" + 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();