1 // Copyright (C) 2006-2015 CEA/DEN, EDF R&D
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, or (at your option) any later version.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "RuntimeSALOME.hxx"
24 #include "parsers.hxx"
31 YACS::YACSLoader::YACSLoader* loader;
33 class Obs_i : public POA_YACS_ORB::Observer,
34 public PortableServer::RefCountServantBase
37 inline Obs_i(YACS_ORB::Proc_ptr proc) {_server_proc=proc;}
39 void notifyObserver(CORBA::Long numid, const char* event);
41 YACS_ORB::Proc_ptr _server_proc;
44 void Obs_i::notifyObserver(CORBA::Long numid, const char* event)
46 std::cerr << "Obs_i::notifyObserver " << numid << event << std::endl;
47 std::cerr << "Obs_i::notifyObserver:state= " << _server_proc->getState(numid) << std::endl;
48 std::cerr << "Obs_i::notifyObserver:XMLstate= " << _server_proc->getXMLState(numid) << std::endl;
51 YACS_ORB::YACS_Gen_var yacsref;
52 YACS_ORB::Proc_ptr server_proc;
56 yacsref->Run(server_proc);
59 int main(int argc, char** argv)
61 YACS::ENGINE::RuntimeSALOME::setRuntime();
62 loader= new YACS::YACSLoader::YACSLoader();
66 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
67 CORBA::Object_var obj = orb->string_to_object("corbaname:rir:#test.my_context/Yacs.Object");
68 yacsref = YACS_ORB::YACS_Gen::_narrow(obj);
69 if( CORBA::is_nil(yacsref) )
71 std::cerr << "Can't narrow reference to type yacs (or it was nil)." << std::endl;
76 CORBA::Object_var poa = orb->resolve_initial_references("RootPOA");
77 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(poa);
78 PortableServer::POAManager_var poa_man = root_poa->the_POAManager();
81 char* xmlFile="/local/chris/SALOME2/SUPERV/YACS/BR_CC/YACS_SRC/src/yacsloader/samples/aschema.xml";
82 //Load XML file in client
83 YACS::ENGINE::Proc* local_proc=loader->load(xmlFile);
84 //Load xml file in server
85 server_proc = yacsref->Load(xmlFile);
86 //Create an observer for server_proc
87 Obs_i* obs=new Obs_i(server_proc);
88 YACS_ORB::Observer_ptr obs_ptr = obs->_this();
90 YACS_ORB::stringArray_var names;
91 YACS_ORB::longArray_var ids;
92 server_proc->getIds(ids.out(),names.out());
94 int len=ids->length();
96 for(int i=0;i<len;i++)
99 yacsref->addObserver(obs_ptr,numid,"status");
101 //Execute Proc in thread ??
103 //pthread_create(&th,NULL,run,0);
104 yacsref->Run(server_proc);
109 catch(CORBA::COMM_FAILURE& ex) {
110 std::cerr << "Caught system exception COMM_FAILURE -- unable to contact the "
111 << "object." << std::endl;
113 catch(CORBA::SystemException&) {
114 std::cerr << "Caught a CORBA::SystemException." << std::endl;
116 catch(CORBA::Exception&) {
117 std::cerr << "Caught CORBA::Exception." << std::endl;
119 catch(omniORB::fatalException& fe) {
120 std::cerr << "Caught omniORB::fatalException:" << std::endl;
121 std::cerr << " file: " << fe.file() << std::endl;
122 std::cerr << " line: " << fe.line() << std::endl;
123 std::cerr << " mesg: " << fe.errmsg() << std::endl;
126 std::cerr << "Caught unknown exception." << std::endl;