Salome HOME
08054e33504b3fc7b4e460026c4f52c3c31ed99b
[modules/yacs.git] / src / yacsloader / debugger.cxx
1 //  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
2 //
3 //  This library is free software; you can redistribute it and/or
4 //  modify it under the terms of the GNU Lesser General Public
5 //  License as published by the Free Software Foundation; either
6 //  version 2.1 of the License.
7 //
8 //  This library is distributed in the hope that it will be useful,
9 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 //  Lesser General Public License for more details.
12 //
13 //  You should have received a copy of the GNU Lesser General Public
14 //  License along with this library; if not, write to the Free Software
15 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 #include "RuntimeSALOME.hxx"
20 #include "Proc.hxx"
21 #include "Exception.hxx"
22 #include "Executor.hxx"
23 #include "parsers.hxx"
24 #include "Thread.hxx"
25
26 #include <iostream>
27 #include <fstream>
28
29 using YACS::YACSLoader;
30 using YACS::ENGINE::RuntimeSALOME;
31 using YACS::ENGINE::Executor;
32 using YACS::ENGINE::Proc;
33 using YACS::BASES::Thread;
34 using namespace std;
35
36 //#define _DEVDEBUG_
37 #include "YacsTrace.hxx"
38
39 void *executorFunc(void *arg)
40 {
41   void **argT=(void **)arg;
42   Executor *myExec = (Executor *)argT[0];
43   Proc *myProc = (Proc *)argT[1];
44   myExec->RunB(myProc, 2);
45 }
46
47 int
48 main (int argc, char* argv[])
49 {
50   if (argc != 2)
51   {
52     cerr << "usage: " << argv[0] << " schema.xml" << endl;
53     return 1;
54   }
55
56   RuntimeSALOME::setRuntime();
57
58   YACSLoader loader;
59   Executor *executor = new Executor();
60  
61   try
62     {
63       Proc* p=loader.load(argv[1]);
64       std::ofstream f("toto");
65       p->writeDot(f);
66       f.close();
67
68       executor->setExecMode(YACS::STEPBYSTEP);
69       void **args=new void *[2];
70       args[0]=(void *)executor;
71       args[1]=(void *)p;
72       Thread* execThread = new Thread(executorFunc,args);
73       char com;
74       cerr << "enter a char to start" << endl;
75       cin >> com;
76       //executor->wakeUp();
77       while (executor->isNotFinished())
78         {
79           YACS::ExecutorState executorState = executor->getExecutorState();
80           cerr << "executorState: " << executorState << endl;
81           cerr << "command display=d step=s : ";
82           cin >> com;
83           switch (com)
84             {
85             case 's':
86               {
87                 executor->setExecMode(YACS::STEPBYSTEP);
88                 bool res = executor->resumeCurrentBreakPoint();
89                 cerr << "resumeCurrentBreakPoint(): " << res << endl;
90                 break;
91               }
92             case 'd':
93               {
94                 executor->displayDot(p);
95                 break;
96               }
97             default:
98               {
99                 cerr << "commande inconnue" << endl;
100               }
101             }
102         }
103       execThread->join();
104       std::ofstream g("titi");
105       p->writeDot(g);
106       g.close();
107       delete executor;
108       return 0;
109   }
110   catch (YACS::Exception& e)
111     {
112       DEBTRACE("exception YACS levee " << e.what());
113       return 1;
114     }
115   catch (const std::ios_base::failure&)
116     {
117       DEBTRACE("io failure");
118       return 1;
119     }
120   catch(CORBA::SystemException& ex)
121     {
122       DEBTRACE("...");
123       CORBA::Any tmp;
124       tmp <<= ex;
125       CORBA::TypeCode_var tc = tmp.type();
126       const char *p = tc->name();
127       if ( *p != '\0' )
128         {
129           DEBTRACE("Caught a CORBA::SystemException. " <<p);
130         }
131       else
132         {
133           DEBTRACE("Caught a CORBA::SystemException. " << tc->id());
134         }
135     return 1;
136     }
137   catch(omniORB::fatalException& fe)
138     {
139       DEBTRACE("Caught omniORB::fatalException: file: "<<fe.file()<<" line: "<<fe.line()<<" msg: "<<fe.errmsg());
140       return 1;
141     }
142   catch(...)
143     {
144       DEBTRACE("Caught unknown exception.");
145       return 1;
146     }
147 }
148