1 // Copyright (C) 2006-2008 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.
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
21 #include "RuntimeSALOME.hxx"
23 #include "parsers.hxx"
30 YACS::YACSLoader::YACSLoader* loader;
32 class Obs_i : public POA_YACS_ORB::Observer,
33 public PortableServer::RefCountServantBase
36 inline Obs_i(YACS_ORB::Proc_ptr proc) {_server_proc=proc;}
38 void notifyObserver(CORBA::Long numid, const char* event);
40 YACS_ORB::Proc_ptr _server_proc;
43 void Obs_i::notifyObserver(CORBA::Long numid, const char* event)
45 std::cerr << "Obs_i::notifyObserver " << numid << event << std::endl;
46 std::cerr << "Obs_i::notifyObserver:state= " << _server_proc->getState(numid) << std::endl;
47 std::cerr << "Obs_i::notifyObserver:XMLstate= " << _server_proc->getXMLState(numid) << std::endl;
50 YACS_ORB::YACS_Gen_var yacsref;
51 YACS_ORB::Proc_ptr server_proc;
55 yacsref->Run(server_proc);
58 int main(int argc, char** argv)
60 YACS::ENGINE::RuntimeSALOME::setRuntime();
61 loader= new YACS::YACSLoader::YACSLoader();
65 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
66 CORBA::Object_var obj = orb->string_to_object("corbaname:rir:#test.my_context/Yacs.Object");
67 yacsref = YACS_ORB::YACS_Gen::_narrow(obj);
68 if( CORBA::is_nil(yacsref) )
70 std::cerr << "Can't narrow reference to type yacs (or it was nil)." << std::endl;
75 CORBA::Object_var poa = orb->resolve_initial_references("RootPOA");
76 PortableServer::POA_var root_poa = PortableServer::POA::_narrow(poa);
77 PortableServer::POAManager_var poa_man = root_poa->the_POAManager();
80 char* xmlFile="/local/chris/SALOME2/SUPERV/YACS/BR_CC/YACS_SRC/src/yacsloader/samples/aschema.xml";
81 //Load XML file in client
82 YACS::ENGINE::Proc* local_proc=loader->load(xmlFile);
83 //Load xml file in server
84 server_proc = yacsref->Load(xmlFile);
85 //Create an observer for server_proc
86 Obs_i* obs=new Obs_i(server_proc);
87 YACS_ORB::Observer_ptr obs_ptr = obs->_this();
89 YACS_ORB::stringArray_var names;
90 YACS_ORB::longArray_var ids;
91 server_proc->getIds(ids.out(),names.out());
93 int len=ids->length();
95 for(int i=0;i<len;i++)
98 yacsref->addObserver(obs_ptr,numid,"status");
100 //Execute Proc in thread ??
102 //pthread_create(&th,NULL,run,0);
103 yacsref->Run(server_proc);
108 catch(CORBA::COMM_FAILURE& ex) {
109 std::cerr << "Caught system exception COMM_FAILURE -- unable to contact the "
110 << "object." << std::endl;
112 catch(CORBA::SystemException&) {
113 std::cerr << "Caught a CORBA::SystemException." << std::endl;
115 catch(CORBA::Exception&) {
116 std::cerr << "Caught CORBA::Exception." << std::endl;
118 catch(omniORB::fatalException& fe) {
119 std::cerr << "Caught omniORB::fatalException:" << std::endl;
120 std::cerr << " file: " << fe.file() << std::endl;
121 std::cerr << " line: " << fe.line() << std::endl;
122 std::cerr << " mesg: " << fe.errmsg() << std::endl;
125 std::cerr << "Caught unknown exception." << std::endl;