Version: 8.3.0
yacsSrv.cxx File Reference
#include <Python.h>
#include <yacs.hh>
#include "RuntimeSALOME.hxx"
#include "Proc.hxx"
#include "Exception.hxx"
#include "Executor.hxx"
#include "Dispatcher.hxx"
#include "parsers.hxx"
#include <iostream>
#include <sstream>
#include <set>
#include "YacsTrace.hxx"
Include dependency graph for yacsSrv.cxx:

Go to the source code of this file.

Classes

class  MyDispatcher
 
class  Yacs_i
 
class  Proc_i
 

Functions

static CORBA::Boolean bindObjectToName (CORBA::ORB_ptr, CORBA::Object_ptr, const char *)
 
static ostream & operator<< (ostream &os, const CORBA::Exception &e)
 
int main (int argc, char **argv)
 

Variables

YACS::YACSLoader::YACSLoaderloader
 
CORBA::ORB_ptr orb
 
YACS_ORB::YACS_Gen_var myyacsref
 

Function Documentation

static CORBA::Boolean bindObjectToName ( CORBA::ORB_ptr  orb,
CORBA::Object_ptr  objref,
const char *  name 
)
static

Definition at line 220 of file yacsSrv.cxx.

References DEBTRACE.

Referenced by main().

221 {
222  CosNaming::NamingContext_var rootContext;
223 
224  try {
225  // Obtain a reference to the root context of the Name service:
226  CORBA::Object_var obj;
227  obj = orb->resolve_initial_references("NameService");
228 
229  // Narrow the reference returned.
230  rootContext = CosNaming::NamingContext::_narrow(obj);
231  if( CORBA::is_nil(rootContext) ) {
232  DEBTRACE("Failed to narrow the root naming context.");
233  return 0;
234  }
235  }
236  catch(CORBA::ORB::InvalidName& ex) {
237  // This should not happen!
238  DEBTRACE("Service required is invalid [does not exist]." );
239  return 0;
240  }
241 
242  try {
243  // Bind a context called "test" to the root context:
244 
245  CosNaming::Name contextName;
246  contextName.length(1);
247  contextName[0].id = (const char*) "test"; // string copied
248  contextName[0].kind = (const char*) "my_context"; // string copied
249  // Note on kind: The kind field is used to indicate the type
250  // of the object. This is to avoid conventions such as that used
251  // by files (name.type -- e.g. test.ps = postscript etc.)
252 
253  CosNaming::NamingContext_var testContext;
254  try {
255  // Bind the context to root.
256  testContext = rootContext->bind_new_context(contextName);
257  }
258  catch(CosNaming::NamingContext::AlreadyBound& ex) {
259  // If the context already exists, this exception will be raised.
260  // In this case, just resolve the name and assign testContext
261  // to the object returned:
262  CORBA::Object_var obj;
263  obj = rootContext->resolve(contextName);
264  testContext = CosNaming::NamingContext::_narrow(obj);
265  if( CORBA::is_nil(testContext) ) {
266  DEBTRACE("Failed to narrow naming context.");
267  return 0;
268  }
269  }
270 
271  // Bind objref with name name to the testContext:
272  CosNaming::Name objectName;
273  objectName.length(1);
274  objectName[0].id = name; // string copied
275  objectName[0].kind = (const char*) "Object"; // string copied
276 
277  try {
278  testContext->bind(objectName, objref);
279  }
280  catch(CosNaming::NamingContext::AlreadyBound& ex) {
281  testContext->rebind(objectName, objref);
282  }
283  }
284  catch(CORBA::COMM_FAILURE& ex) {
285  DEBTRACE("Caught system exception COMM_FAILURE -- unable to contact the "
286  << "naming service.");
287  return 0;
288  }
289  catch(CORBA::SystemException&) {
290  DEBTRACE("Caught a CORBA::SystemException while using the naming service.");
291  return 0;
292  }
293 
294  return 1;
295 }
int main ( int  argc,
char **  argv 
)

Definition at line 161 of file yacsSrv.cxx.

References bindObjectToName(), DEBTRACE, loader, myyacsref, orb, YACS::ENGINE::Dispatcher::setDispatcher(), YACS::ENGINE::RuntimeSALOME::setRuntime(), and YACS::YACSLoader::YACSLoader().

162 {
165  MyDispatcher* disp=new MyDispatcher();
167 
168  try
169  {
170  orb = CORBA::ORB_init(argc, argv);
171 
172  {
173  CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
174  PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
175  // POA manager
176  PortableServer::POAManager_var poa_man = root_poa->the_POAManager();
177  poa_man->activate();
178 
179  // Create and activate servant
180  Yacs_i* myyacs = new Yacs_i();
181  // Obtain a reference to the object, and print it out as a
182  // stringified IOR.
183  obj = myyacs->_this();
184  CORBA::String_var sior(orb->object_to_string(obj));
185  DEBTRACE("'" << (char*)sior << "'");
186  myyacsref = YACS_ORB::YACS_Gen::_narrow(obj);
187 
188  if( !bindObjectToName(orb, myyacsref,"Yacs") ) return 1;
189 
190  // Decrement the reference count of the object implementation, so
191  // that it will be properly cleaned up when the POA has determined
192  // that it is no longer needed.
193  myyacs->_remove_ref();
194  }
195  orb->run();
196  }
197  catch(CORBA::SystemException&) {
198  DEBTRACE("Caught CORBA::SystemException.");
199  }
200  catch(CORBA::Exception& ex) {
201  DEBTRACE("Caught CORBA::Exception." << ex);
202  }
203  catch(omniORB::fatalException& fe) {
204  DEBTRACE("Caught omniORB::fatalException:");
205  DEBTRACE(" file: " << fe.file());
206  DEBTRACE(" line: " << fe.line());
207  DEBTRACE(" mesg: " << fe.errmsg());
208  }
209  catch(...) {
210  DEBTRACE("Caught unknown exception." );
211  }
212 
213  return 0;
214 }
static ostream & operator<< ( ostream &  os,
const CORBA::Exception &  e 
)
static

Definition at line 297 of file yacsSrv.cxx.

References p.

298 {
299  CORBA::Any tmp;
300  tmp<<= e;
301  CORBA::TypeCode_var tc = tmp.type();
302  const char *p = tc->name();
303  if ( *p != '\0' ) {
304  os<<p;
305  }
306  else {
307  os << tc->id();
308  }
309  return os;
310 }

Variable Documentation

Definition at line 38 of file yacsSrv.cxx.

YACS_ORB::YACS_Gen_var myyacsref

Definition at line 40 of file yacsSrv.cxx.

Referenced by main().