2 #include "RuntimeSALOME.hxx"
11 YACS::YACSLoader::YACSLoader* loader;
13 class Obs_i : public POA_YACS_ORB::Observer,
14 public PortableServer::RefCountServantBase
17 inline Obs_i(YACS_ORB::Proc_ptr proc) {_server_proc=proc;}
19 void notifyObserver(CORBA::Long numid, const char* event);
21 YACS_ORB::Proc_ptr _server_proc;
24 void Obs_i::notifyObserver(CORBA::Long numid, const char* event)
26 std::cerr << "Obs_i::notifyObserver " << numid << event << std::endl;
27 std::cerr << "Obs_i::notifyObserver:state= " << _server_proc->getState(numid) << std::endl;
28 std::cerr << "Obs_i::notifyObserver:XMLstate= " << _server_proc->getXMLState(numid) << std::endl;
31 YACS_ORB::YACS_Gen_var yacsref;
32 YACS_ORB::Proc_ptr server_proc;
36 yacsref->Run(server_proc);
39 int main(int argc, char** argv)
41 YACS::ENGINE::RuntimeSALOME::setRuntime();
42 loader= new YACS::YACSLoader::YACSLoader();
46 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
47 CORBA::Object_var obj = orb->string_to_object("corbaname:rir:#test.my_context/Yacs.Object");
48 yacsref = YACS_ORB::YACS_Gen::_narrow(obj);
49 if( CORBA::is_nil(yacsref) )
51 std::cerr << "Can't narrow reference to type yacs (or it was nil)." << std::endl;
56 CORBA::Object_var poa = orb->resolve_initial_references("RootPOA");
57 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(poa);
58 PortableServer::POAManager_var poa_man = root_poa->the_POAManager();
61 char* xmlFile="/local/chris/SALOME2/SUPERV/YACS/BR_CC/YACS_SRC/src/yacsloader/samples/aschema.xml";
62 //Load XML file in client
63 YACS::ENGINE::Proc* local_proc=loader->load(xmlFile);
64 //Load xml file in server
65 server_proc = yacsref->Load(xmlFile);
66 //Create an observer for server_proc
67 Obs_i* obs=new Obs_i(server_proc);
68 YACS_ORB::Observer_ptr obs_ptr = obs->_this();
70 YACS_ORB::stringArray_var names;
71 YACS_ORB::longArray_var ids;
72 server_proc->getIds(ids.out(),names.out());
74 int len=ids->length();
76 for(int i=0;i<len;i++)
79 yacsref->addObserver(obs_ptr,numid,"status");
81 //Execute Proc in thread ??
83 //pthread_create(&th,NULL,run,0);
84 yacsref->Run(server_proc);
89 catch(CORBA::COMM_FAILURE& ex) {
90 std::cerr << "Caught system exception COMM_FAILURE -- unable to contact the "
91 << "object." << std::endl;
93 catch(CORBA::SystemException&) {
94 std::cerr << "Caught a CORBA::SystemException." << std::endl;
96 catch(CORBA::Exception&) {
97 std::cerr << "Caught CORBA::Exception." << std::endl;
99 catch(omniORB::fatalException& fe) {
100 std::cerr << "Caught omniORB::fatalException:" << std::endl;
101 std::cerr << " file: " << fe.file() << std::endl;
102 std::cerr << " line: " << fe.line() << std::endl;
103 std::cerr << " mesg: " << fe.errmsg() << std::endl;
106 std::cerr << "Caught unknown exception." << std::endl;