3 #include "RuntimeSALOME.hxx"
12 YACS::YACSLoader::YACSLoader* loader;
14 class Obs_i : public POA_YACS_ORB::Observer,
15 public PortableServer::RefCountServantBase
18 inline Obs_i(YACS_ORB::Proc_ptr proc) {_server_proc=proc;}
20 void notifyObserver(CORBA::Long numid, const char* event);
22 YACS_ORB::Proc_ptr _server_proc;
25 void Obs_i::notifyObserver(CORBA::Long numid, const char* event)
27 std::cerr << "Obs_i::notifyObserver " << numid << event << std::endl;
28 std::cerr << "Obs_i::notifyObserver:state= " << _server_proc->getState(numid) << std::endl;
29 std::cerr << "Obs_i::notifyObserver:XMLstate= " << _server_proc->getXMLState(numid) << std::endl;
32 YACS_ORB::YACS_Gen_var yacsref;
33 YACS_ORB::Proc_ptr server_proc;
37 yacsref->Run(server_proc);
40 int main(int argc, char** argv)
42 YACS::ENGINE::RuntimeSALOME::setRuntime();
43 loader= new YACS::YACSLoader::YACSLoader();
47 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
48 CORBA::Object_var obj = orb->string_to_object("corbaname:rir:#test.my_context/Yacs.Object");
49 yacsref = YACS_ORB::YACS_Gen::_narrow(obj);
50 if( CORBA::is_nil(yacsref) )
52 std::cerr << "Can't narrow reference to type yacs (or it was nil)." << std::endl;
57 CORBA::Object_var poa = orb->resolve_initial_references("RootPOA");
58 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(poa);
59 PortableServer::POAManager_var poa_man = root_poa->the_POAManager();
62 char* xmlFile="/local/chris/SALOME2/SUPERV/YACS/BR_CC/YACS_SRC/src/yacsloader/samples/aschema.xml";
63 //Load XML file in client
64 YACS::ENGINE::Proc* local_proc=loader->load(xmlFile);
65 //Load xml file in server
66 server_proc = yacsref->Load(xmlFile);
67 //Create an observer for server_proc
68 Obs_i* obs=new Obs_i(server_proc);
69 YACS_ORB::Observer_ptr obs_ptr = obs->_this();
71 YACS_ORB::stringArray_var names;
72 YACS_ORB::longArray_var ids;
73 server_proc->getIds(ids.out(),names.out());
75 int len=ids->length();
77 for(int i=0;i<len;i++)
80 yacsref->addObserver(obs_ptr,numid,"status");
82 //Execute Proc in thread ??
84 //pthread_create(&th,NULL,run,0);
85 yacsref->Run(server_proc);
90 catch(CORBA::COMM_FAILURE& ex) {
91 std::cerr << "Caught system exception COMM_FAILURE -- unable to contact the "
92 << "object." << std::endl;
94 catch(CORBA::SystemException&) {
95 std::cerr << "Caught a CORBA::SystemException." << std::endl;
97 catch(CORBA::Exception&) {
98 std::cerr << "Caught CORBA::Exception." << std::endl;
100 catch(omniORB::fatalException& fe) {
101 std::cerr << "Caught omniORB::fatalException:" << std::endl;
102 std::cerr << " file: " << fe.file() << std::endl;
103 std::cerr << " line: " << fe.line() << std::endl;
104 std::cerr << " mesg: " << fe.errmsg() << std::endl;
107 std::cerr << "Caught unknown exception." << std::endl;