Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / yacsloader / debugger.cxx
1 #include "RuntimeSALOME.hxx"
2 #include "Proc.hxx"
3 #include "Exception.hxx"
4 #include "Executor.hxx"
5 #include "parsers.hxx"
6 #include "Thread.hxx"
7
8 #include <iostream>
9 #include <fstream>
10
11 using YACS::YACSLoader;
12 using YACS::ENGINE::RuntimeSALOME;
13 using YACS::ENGINE::Executor;
14 using YACS::ENGINE::Proc;
15 using YACS::BASES::Thread;
16 using namespace std;
17
18 //#define _DEVDEBUG_
19 #include "YacsTrace.hxx"
20
21 void *executorFunc(void *arg)
22 {
23   void **argT=(void **)arg;
24   Executor *myExec = (Executor *)argT[0];
25   Proc *myProc = (Proc *)argT[1];
26   myExec->RunB(myProc, 2);
27 }
28
29 int
30 main (int argc, char* argv[])
31 {
32   if (argc != 2)
33   {
34     cerr << "usage: " << argv[0] << " schema.xml" << endl;
35     return 1;
36   }
37
38   RuntimeSALOME::setRuntime();
39
40   YACSLoader loader;
41   Executor *executor = new Executor();
42  
43   try
44     {
45       Proc* p=loader.load(argv[1]);
46       std::ofstream f("toto");
47       p->writeDot(f);
48       f.close();
49
50       executor->setExecMode(YACS::STEPBYSTEP);
51       void **args=new void *[2];
52       args[0]=(void *)executor;
53       args[1]=(void *)p;
54       Thread* execThread = new Thread(executorFunc,args);
55       char com;
56       cerr << "enter a char to start" << endl;
57       cin >> com;
58       //executor->wakeUp();
59       while (executor->isNotFinished())
60         {
61           YACS::ExecutorState executorState = executor->getExecutorState();
62           cerr << "executorState: " << executorState << endl;
63           cerr << "command display=d step=s : ";
64           cin >> com;
65           switch (com)
66             {
67             case 's':
68               {
69                 executor->setExecMode(YACS::STEPBYSTEP);
70                 bool res = executor->resumeCurrentBreakPoint();
71                 cerr << "resumeCurrentBreakPoint(): " << res << endl;
72                 break;
73               }
74             case 'd':
75               {
76                 executor->displayDot(p);
77                 break;
78               }
79             default:
80               {
81                 cerr << "commande inconnue" << endl;
82               }
83             }
84         }
85       execThread->join();
86       std::ofstream g("titi");
87       p->writeDot(g);
88       g.close();
89       delete executor;
90       return 0;
91   }
92   catch (YACS::Exception& e)
93     {
94       DEBTRACE("exception YACS levee " << e.what());
95       return 1;
96     }
97   catch (const std::ios_base::failure&)
98     {
99       DEBTRACE("io failure");
100       return 1;
101     }
102   catch(CORBA::SystemException& ex)
103     {
104       DEBTRACE("...");
105       CORBA::Any tmp;
106       tmp <<= ex;
107       CORBA::TypeCode_var tc = tmp.type();
108       const char *p = tc->name();
109       if ( *p != '\0' )
110         {
111           DEBTRACE("Caught a CORBA::SystemException. " <<p);
112         }
113       else
114         {
115           DEBTRACE("Caught a CORBA::SystemException. " << tc->id());
116         }
117     return 1;
118     }
119   catch(omniORB::fatalException& fe)
120     {
121       DEBTRACE("Caught omniORB::fatalException: file: "<<fe.file()<<" line: "<<fe.line()<<" msg: "<<fe.errmsg());
122       return 1;
123     }
124   catch(...)
125     {
126       DEBTRACE("Caught unknown exception.");
127       return 1;
128     }
129 }
130