void
VOmniORBHelper::nsRegisterObject(CORBA::Object_ptr obj,
				 const char* program, const char* object,
				 int telescopenumber)
  throw(CORBA::SystemException, 
	CosNaming::NamingContext::NotFound,
	CosNaming::NamingContext::CannotProceed,
	CosNaming::NamingContext::InvalidName,
	CosNaming::NamingContext::AlreadyBound)
{
  ZThread::Guard<ZThread::RecursiveMutex> guard(m_mutex);
  CosNaming::NamingContext_var root = nsRootContext();
  CosNaming::Name_var name = 
    nsPathToObjectName(program, object, telescopenumber);

  for(unsigned int n=0; n<name->length()-1; n++)
    {
      CosNaming::Name_var child_name = name;
      child_name->length(n+1);
      
      try
	{
	  CORBA::Object_var object = root->resolve(child_name);
	}
      catch(CosNaming::NamingContext::NotFound)
	{
	  CosNaming::NamingContext_var 
	    child = root->bind_new_context(child_name);
	}
    }

  root->rebind(name,obj);
}
Beispiel #2
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

    //Get reference to Root POA
    CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" );
    PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() );

    // Activate POA Manager
    PortableServer::POAManager_var mgr = poa->the_POAManager();
    mgr->activate();


    // Find the Naming Service
    obj = orb->resolve_initial_references("NameService");
    CosNaming::NamingContext_var root =
      CosNaming::NamingContext::_narrow(obj.in());
    if (CORBA::is_nil(root.in())) {
      std::cerr << "Nil Naming Context reference" << std::endl;
      return 1;
    }

    // Bind the example Naming Context, if necessary
    CosNaming::Name name;
    name.length( 1 );
    name[0].id = CORBA::string_dup("example");
    try {
      obj = root->resolve(name);
    }
    catch(const CosNaming::NamingContext::NotFound&) {
      CosNaming::NamingContext_var dummy = root->bind_new_context(name);
    }

    // Bind the Messenger object
    name.length(2);
    name[1].id = CORBA::string_dup("Messenger");

    // Create an object
    PortableServer::Servant_var<Messenger_i> servant = new Messenger_i;
    PortableServer::ObjectId_var oid = poa->activate_object(servant.in());
    obj = poa->id_to_reference(oid.in());
    Messenger_var messenger = Messenger::_narrow(obj.in());
    root->rebind(name, messenger.in());

    std::cout << "Messenger object bound in Naming Service" << std::endl;

    // Accept requests
    orb->run();
    orb->destroy();
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "server: Caught a CORBA::Exception: " << ex << std::endl;
    return 1;
  }

  return 0;
}
Beispiel #3
0
int main(int argc, char *argv[])
{
    CORBA::ORB_var orb = CORBA::ORB::_nil();
  
    try {

	orb = CORBA::ORB_init(argc, argv);
	
	CORBA::Object_var obj;
	
	obj = orb->resolve_initial_references("RootPOA");
	PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
	if(CORBA::is_nil(poa)){
	    throw std::string("error: failed to narrow root POA.");
	}
	
	PortableServer::POAManager_var poaManager = poa->the_POAManager();
	if(CORBA::is_nil(poaManager)){
	    throw std::string("error: failed to narrow root POA manager.");
	}
	
	OnlineViewer_impl* OnlineViewerImpl = new OnlineViewer_impl(orb, poa);
	poa->activate_object(OnlineViewerImpl);
	OnlineViewer_var OnlineViewer = OnlineViewerImpl->_this();
	OnlineViewerImpl->_remove_ref();

	obj = orb->resolve_initial_references("NameService");
	CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(obj);
	if(CORBA::is_nil(namingContext)){
	    throw std::string("error: failed to narrow naming context.");
	}
	
	CosNaming::Name name;
	name.length(1);
	name[0].id = CORBA::string_dup("OnlineViewer");
	name[0].kind = CORBA::string_dup("");
	namingContext->rebind(name, OnlineViewer);

	poaManager->activate();
	
        glmain(argc, argv);
    }
    catch (CORBA::SystemException& ex) {
        std::cerr << ex._rep_id() << std::endl;
    }
    catch (const std::string& error){
        std::cerr << error << std::endl;
    }

    try {
	orb->destroy();
    }
    catch(...){

    }
    
    return 0;
}
Beispiel #4
0
void
TAO_Hash_Naming_Context::rebind (const CosNaming::Name& n,
                                 CORBA::Object_ptr obj)
{
  // Check to make sure this object didn't have <destroy> method
  // invoked on it.
  if (this->destroyed_)
    throw CORBA::OBJECT_NOT_EXIST ();

  // Get the length of the name.
  CORBA::ULong const name_len = n.length ();

  // Check for invalid name.
  if (name_len == 0)
    throw CosNaming::NamingContext::InvalidName();

  // If we received compound name, resolve it to get the context in
  // which the rebinding should take place, then perform the rebinding
  // on target context.
  if (name_len > 1)
    {
      CosNaming::NamingContext_var context = this->get_context (n);

      CosNaming::Name simple_name;
      simple_name.length (1);
      simple_name[0] = n[name_len - 1];
      try
        {
          context->rebind (simple_name, obj);
        }
      catch (const CORBA::SystemException&)
        {
          throw CosNaming::NamingContext::CannotProceed(
            context.in (), simple_name);
        }
    }
  else
    // If we received a simple name, we need to rebind it in this
    // context.
    {
      ACE_WRITE_GUARD_THROW_EX (TAO_SYNCH_RW_MUTEX, ace_mon,
                                this->lock_,
                                CORBA::INTERNAL ());

      int result = this->context_->rebind (n[0].id,
                                           n[0].kind,
                                           obj,
                                           CosNaming::nobject);
      // Check for error conditions.
      if (result == -1)
        throw CORBA::INTERNAL ();

      else if (result == -2)
        throw CosNaming::NamingContext::NotFound(
          CosNaming::NamingContext::not_object, n);
    }
}
Beispiel #5
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv [])
{
  try
  {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    if (parse_args (argc, argv) != 0)
      return 1;

    // Find the Naming Service.
    CORBA::Object_var rootObj =  orb->resolve_initial_references("NameService");
    CosNaming::NamingContext_var rootNC =
      CosNaming::NamingContext::_narrow(rootObj.in());

    // Get the  Root POA.
    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());

    // Activate POA manager
    PortableServer::POAManager_var mgr = poa->the_POAManager();
    mgr->activate();

    // Create our Messenger servant.
    PortableServer::Servant_var<Messenger_i> messenger_servant =
      new Messenger_i(orb.in());

    // Register it with the RootPOA.
    PortableServer::ObjectId_var oid =
      poa->activate_object( messenger_servant.in() );
    CORBA::Object_var messenger_obj = poa->id_to_reference( oid.in() );

    // Bind it in the Naming Service.
    CosNaming::Name name;
    name.length (1);
    name[0].id = CORBA::string_dup("MessengerService");
    rootNC->rebind(name, messenger_obj.in());

    CORBA::String_var str = orb->object_to_string (messenger_obj.in());
    std::ofstream iorFile (ACE_TEXT_ALWAYS_CHAR(ior_output_file));
    iorFile << str.in () << std::endl;
    iorFile.close ();
    std::cout << "IOR written to file " << ior_output_file << std::endl;

    // Accept requests
    orb->run();
    orb->destroy();

  }
  catch(const CORBA::Exception& ex) {
    std::cerr << ex << std::endl;
    return 1;
  }
  return 0;

}
  /*!
   * @if jp
   * @brief 途中のコンテキストを bind しながら Object を rebind する
   * @else
   * @brief Bind intermediate context recursively and rebind object
   * @endif
   */
  void CorbaNaming::rebindRecursive(CosNaming::NamingContext_ptr context,
				    const CosNaming::Name& name,
				    CORBA::Object_ptr obj)
    throw (SystemException, CannotProceed, InvalidName)
  {
    CORBA::ULong len(name.length());
    CosNaming::NamingContext_var cxt;
    cxt = CosNaming::NamingContext::_duplicate(context);
    
    for (CORBA::ULong i = 0; i < len; ++i)
      {
	if (i == (len - 1))
	  {
	    cxt->rebind(subName(name, i, i), obj);
	    return;
	  }
	else
	  { // If the context is not a NamingContext, CannotProceed is thrown
	    if (isNamingContext(cxt))
	      {
		try
		  {
		    cxt = cxt->bind_new_context(subName(name, i, i));
		  }
		catch (AlreadyBound& e)
		  {
		    (void)(e);
		    cxt = CosNaming::
		      NamingContextExt::
		      _narrow(cxt->resolve(subName(name, i, i)));
		  }
	      }
	    else
	      throw CannotProceed(cxt, subName(name, i));
	  }
      }
    return;
  }
Beispiel #7
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
    CORBA::ORB_var orb;

    try {
        // Initialize orb
        orb = CORBA::ORB_init (argc, argv);

        // Get reference to Root POA.
        CORBA::Object_var obj
            = orb->resolve_initial_references ("RootPOA");
        PortableServer::POA_var poa
            = PortableServer::POA::_narrow (obj.in ());

        // Get POA manager
        PortableServer::POAManager_var poa_mgr = poa->the_POAManager ();

        // Create a policy list. We use persistent objects with
        // user-assigned IDs, and explicit activation.
        CORBA::PolicyList policy_list;
        policy_list.length (6);
        policy_list[0] = poa->create_lifespan_policy (
                             PortableServer::TRANSIENT   // REVISIT
                         );
        policy_list[1] = poa->create_id_assignment_policy (
                             PortableServer::USER_ID
                         );
        policy_list[2] = poa->create_implicit_activation_policy (
                             PortableServer::NO_IMPLICIT_ACTIVATION
                         );
        policy_list[3] = poa->create_request_processing_policy (
                             PortableServer::USE_SERVANT_MANAGER
                         );
        policy_list[4] = poa->create_servant_retention_policy (
                             PortableServer::NON_RETAIN
                         );
        policy_list[5] = poa->create_thread_policy (
                             PortableServer::SINGLE_THREAD_MODEL
                         );

        // Create a POA for all CCS elements.
        PortableServer::POA_var ccs_poa
            = poa->create_POA ("CCS_POA", poa_mgr.in (), policy_list);

        // Create a controller and set static m_ctrl member
        // for thermostats and thermometers.
        Controller_impl ctrl_servant (ccs_poa.in (), "/tmp/CCS_assets");
        Thermometer_impl::m_ctrl = &ctrl_servant;

        // Create a reference for the controller and
        // create the corresponding CORBA object.
        PortableServer::ObjectId_var oid
            = PortableServer::string_to_ObjectId (Controller_oid);
        CORBA::Object_var ctrl
            = ccs_poa->create_reference_with_id (
                  oid.in (), "IDL:acme.com/CCS/Controller:1.0"
              );

        // Get reference to initial naming context.
        CosNaming::NamingContext_var inc
            = resolve_init<CosNaming::NamingContext> (
                  orb.in (), "NameService"
              );

        // Attempt to create CCS context.
        CosNaming::Name n;
        n.length (1);
        n[0].id = CORBA::string_dup ("CCS");
        try {
            CosNaming::NamingContext_var nc
                = inc->bind_new_context (n);
        } catch (const CosNaming::NamingContext::AlreadyBound &) {
            // Fine, CCS context already exists.
        }

        // Force binding of controller reference to make
        // sure it is always up-to-date.
        n.length (2);
        n[1].id = CORBA::string_dup ("Controller");
        inc->rebind (n, ctrl.in ());

        // Instantiate the servant locator for devices.
        PortableServer::ServantManager_var locator =
            new DeviceLocator_impl (&ctrl_servant);

        // Set servant locator.
        ccs_poa->set_servant_manager (locator.in ());

        // Activate the POA manager.
        poa_mgr->activate ();

        // Accept requests
        orb->run ();
    }
    catch (const CORBA::Exception & e) {
        std::cerr << "Uncaught CORBA exception: "
                  << e
                  << std::endl;
        return 1;
    }
    catch (...) {
        assert (0);  // Uncaught exception, dump core
    }
    return 0;
}
Beispiel #8
0
int main(int argc, char** argv)
{


  try{
    // 1. init ORB
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    // 2. get reference to root POA, in order to be available for the client
    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var _poa = PortableServer::POA::_narrow(obj.in());
 
    // 3. bind to name service
    // Invoke operations defined in object interface, via object reference
    // Instance of CRequestSocketStream_i servant is initialized
    CServiceA_i* myRequestServiceA = new CServiceA_i();
    PortableServer::ObjectId_var myRequestServiceA_oid = _poa->activate_object(myRequestServiceA);
    CORBA::Object_var SA_obj = myRequestServiceA->_this();
    CORBA::String_var sior(orb->object_to_string(SA_obj.in()));
    fprintf(stderr, "\'%s\'\n", static_cast< char* >(sior)); // TODO check - std::string??

    // (re)bind object (orb) to the name (SA_obj) via name service
    CORBA::Object_var obj1 = orb->resolve_initial_references("OmniNameService");
    assert(!CORBA::is_nil(obj1.in()));

    // narrow to naming context
    CosNaming::NamingContext_var nc = CosNaming::NamingContext::_narrow(obj1.in());
    assert(!CORBA::is_nil(nc.in()));

    // bind to CORBA name service
    CosNaming::Name name;
    name.length(1);
    name[0].id = CORBA::string_dup("DataServiceName1"); // string_dup does malloc()
    nc->rebind(name, SA_obj.in());
    myRequestServiceA->_remove_ref();

    // 4. init servant object
    PortableServer::POAManager_var pmgr = _poa->the_POAManager();
    pmgr->activate();

    // accept requests from clients
    orb->run();

    // 5. cleanup
    orb->destroy();

    // TODO check memory management(!!!)
    free(name[0].id); // string_dup() / malloc() - no nulling possible without explicitly defined operator=() !

  }catch(CORBA::SystemException&){
    fprintf(stderr, "server: caught CORBA::SystemException. - every idl function can throw a CORBA::SystemException.\n");

  }catch(CORBA::Exception&){
    fprintf(stderr, "server: caught CORBA::Exception.\n");

  }catch(omniORB::fatalException& fe){
    fprintf(stderr, "server: omniORB::fatalException:\n");
    fprintf(stderr, "\tfile: %s\n", fe.file());
    fprintf(stderr, "\tline: %s\n", fe.line());
    fprintf(stderr, "\tmesg: %s\n", fe.errmsg());

  }catch(...){
    fprintf(stderr, "server: caught unknown exception.\n");
  }
}
Beispiel #9
0
int TestTask::svc()
{

  try {
    // Get reference to Root POA
    CORBA::Object_var obj = orb_->resolve_initial_references ("RootPOA");

    PortableServer::POA_var poa = PortableServer::POA::_narrow (obj.in ());

    // Activate POA Manager
    PortableServer::POAManager_var mgr = poa->the_POAManager ();
    mgr->activate ();

    // Find the Naming Service
    obj = orb_->string_to_object (
      "corbaloc:iiop:1.2@localhost:9932/NameService");

    CosNaming::NamingContext_var rootB =
      CosNaming::NamingContext::_narrow (obj.in ());

    if (CORBA::is_nil (rootB.in ())) {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Error, Nil Naming Context reference\n")));
      return 1;
    }
    // Bind the example Naming Context, if necessary
    CosNaming::NamingContext_var example_nc;
    CosNaming::Name name;
    name.length(1);
    name[0].id = CORBA::string_dup( "example");
    try
    {
      obj = rootB->resolve (name);
      example_nc =
        CosNaming::NamingContext::_narrow (obj.in ());
    }
    catch (const CosNaming::NamingContext::NotFound&)
    {
      example_nc = rootB->bind_new_context (name);
    }

    // Bind the Test object
    name.length (2);
    name[1].id = CORBA::string_dup ("Hello");

    // Create an object
    Hello servant (orb_.in ());
    PortableServer::ObjectId_var oid = poa->activate_object (&servant);
    obj = poa->id_to_reference (oid.in ());
    rootB->rebind (name, obj.in ());

    ACE_DEBUG ((LM_INFO,
                ACE_TEXT ("Hello object bound in Naming Service B\n")));

    name.length (1);
    name[0].id = CORBA::string_dup ("nsB");

    obj = orb_->string_to_object (
      "corbaloc:iiop:1.2@localhost:9931/NameService");

    CosNaming::NamingContext_var rootA =
      CosNaming::NamingContext::_narrow (obj.in ());

    rootA->bind_context (name, rootB.in ());

    ACE_DEBUG ((LM_INFO,
                ACE_TEXT ("Root context of NS B bound in Naming Service A ")
                ACE_TEXT ("under name 'nsB'\n")));

    CORBA::String_var ior =
      orb_->object_to_string (obj.in ());

    // Output the IOR to the <ior_output_file>
    FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
    if (output_file == 0)
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Cannot open output file %s for writing ")
                         ACE_TEXT ("IOR: %C\n"),
                         ior_output_file,
                         ior.in ()),
                         1);
    ACE_OS::fprintf (output_file, ACE_TEXT ("%s"), ior.in ());
    ACE_OS::fclose (output_file);

    ACE_DEBUG ((LM_INFO,
                ACE_TEXT ("Wrote IOR file\n")));

    // Normally we run the orb and the orb is shutdown by
    // calling TestTask::end().
    // Accept requests
    orb_->run();
    orb_->destroy();

    return 0;
  }
  catch (CORBA::Exception& ex)
  {
    ex._tao_print_exception (ACE_TEXT ("CORBA exception: "));
  }

  return -1;
}
Beispiel #10
0
static CORBA::Boolean
bindObjectToName(CORBA::ORB_ptr orb, CORBA::Object_ptr objref)
{
  CosNaming::NamingContext_var rootContext;

  try {
    // Obtain a reference to the root context of the Name service:
    CORBA::Object_var obj;
    obj = orb->resolve_initial_references("NameService");

    // Narrow the reference returned.
    rootContext = CosNaming::NamingContext::_narrow(obj);
    if( CORBA::is_nil(rootContext) ) {
      cerr << "Failed to narrow the root naming context." << endl;
      return 0;
    }
  }
  catch (CORBA::NO_RESOURCES&) {
    cerr << "Caught NO_RESOURCES exception. You must configure omniORB "
	 << "with the location" << endl
	 << "of the naming service." << endl;
    return 0;
  }
  catch (CORBA::ORB::InvalidName&) {
    // This should not happen!
    cerr << "Service required is invalid [does not exist]." << endl;
    return 0;
  }

  try {
    // Bind a context called "test" to the root context:

    CosNaming::Name contextName;
    contextName.length(1);
    contextName[0].id   = (const char*) "test";       // string copied
    contextName[0].kind = (const char*) "my_context"; // string copied
    // Note on kind: The kind field is used to indicate the type
    // of the object. This is to avoid conventions such as that used
    // by files (name.type -- e.g. test.ps = postscript etc.)

    CosNaming::NamingContext_var testContext;
    try {
      // Bind the context to root.
      testContext = rootContext->bind_new_context(contextName);
    }
    catch(CosNaming::NamingContext::AlreadyBound& ex) {
      // If the context already exists, this exception will be raised.
      // In this case, just resolve the name and assign testContext
      // to the object returned:
      CORBA::Object_var obj;
      obj = rootContext->resolve(contextName);
      testContext = CosNaming::NamingContext::_narrow(obj);
      if( CORBA::is_nil(testContext) ) {
        cerr << "Failed to narrow naming context." << endl;
        return 0;
      }
    }

    // Bind objref with name Echo to the testContext:
    CosNaming::Name objectName;
    objectName.length(1);
    objectName[0].id   = (const char*) "Echo";   // string copied
    objectName[0].kind = (const char*) "Object"; // string copied

    try {
      testContext->bind(objectName, objref);
    }
    catch(CosNaming::NamingContext::AlreadyBound& ex) {
      testContext->rebind(objectName, objref);
    }
    // Note: Using rebind() will overwrite any Object previously bound
    //       to /test/Echo with obj.
    //       Alternatively, bind() can be used, which will raise a
    //       CosNaming::NamingContext::AlreadyBound exception if the name
    //       supplied is already bound to an object.

    // Amendment: When using OrbixNames, it is necessary to first try bind
    // and then rebind, as rebind on it's own will throw a NotFoundexception if
    // the Name has not already been bound. [This is incorrect behaviour -
    // it should just bind].
  }
  catch(CORBA::TRANSIENT& ex) {
    cerr << "Caught system exception TRANSIENT -- unable to contact the "
         << "naming service." << endl
	 << "Make sure the naming server is running and that omniORB is "
	 << "configured correctly." << endl;

    return 0;
  }
  catch(CORBA::SystemException& ex) {
    cerr << "Caught a CORBA::" << ex._name()
	 << " while using the naming service." << endl;
    return 0;
  }
  return 1;
}
void
ServerActivatorImpl::initialize()
{
	try
	{
		CORBA::Object_var root_poa_obj = orb_->resolve_initial_references ("RootPOA");
		root_poa_ = PortableServer::POA::_narrow (root_poa_obj);
	}
	catch (CORBA::ORB::InvalidName&)
	{
		std::cerr << "ServerActivatorImpl: Fatal error - no root POA available." << std::endl;
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: Fatal error - cannot narrow root POA." << std::endl;
		throw CannotInitialize();
	}

	root_poa_manager_ = root_poa_->the_POAManager();

	root_poa_manager_->activate();

	CosNaming::NamingContext_var ns;

	// Now try to bind with the Name Service
	try
	{
		CORBA::Object_var ns_obj = orb_->resolve_initial_references ("NameService");
		ns = CosNaming::NamingContext::_narrow (ns_obj);
	}
	catch (CORBA::ORB::InvalidName&)
	{
		std::cerr << "ServerActivatorImpl: Name Service not found" << std::endl;
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: Cannot narrow object reference of Name Service" << std::endl;
		throw CannotInitialize();
	}

	if (CORBA::is_nil (ns))
	{
		std::cerr << "ServerActivatorImpl: Name Service is nil" << std::endl;
		throw CannotInitialize();
	}

	// Create the Qedo and Activators naming context
	CosNaming::Name current_name;
	current_name.length (1);
	current_name[0].id = CORBA::string_dup ("Qedo");
	current_name[0].kind = CORBA::string_dup ("");
	try
	{
		ns->bind_new_context (current_name);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		// Ignore this exception
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: CORBA system exception during binding context 'Qedo'" << std::endl;
		throw CannotInitialize();
	}

	current_name.length(2);
	current_name[1].id = CORBA::string_dup ("Activators");
	current_name[1].kind = CORBA::string_dup ("");

	try
	{
		ns->bind_new_context (current_name);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		// Ignore this exception
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: CORBA system exception during binding context 'Activators'" << std::endl;
		throw CannotInitialize();
	}

	// Now bind this Component Server Activator with the Name Service, use the name Qedo/Activators/<hostname>
	char hostname[256];
	if (gethostname (hostname, 256))
	{
		std::cerr << "ServerActivatorImpl: Cannot determine my hostname" << std::endl;
		throw CannotInitialize();
	}

	std::cout << "ServerActivatorImpl: Binding Component Server Activator under Qedo/Activators/" << hostname << std::endl;

	current_name.length (3);
	current_name[2].id = CORBA::string_dup (hostname);
	current_name[2].kind = CORBA::string_dup ("");

	CORBA::Object_var my_ref = this->_this();

	try
	{
		ns->bind (current_name, my_ref);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		try
		{
			ns->rebind (current_name, my_ref);
		}
		catch (CosNaming::NamingContext::InvalidName&)
		{
			std::cerr << "ServerActivatorImpl: Name Service complains about an invalid name" << std::endl;
			throw CannotInitialize();
		}
		catch (CORBA::SystemException&)
		{
			std::cerr << "ServerActivatorImpl: CORBA system exception in rebind()" << std::endl;
			throw CannotInitialize();
		}
	}
	catch (CosNaming::NamingContext::InvalidName&)
	{
		std::cerr << "ServerActivatorImpl: Name Service complains about an invalid name" << std::endl;
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: CORBA system exception during bind()" << std::endl;
		throw CannotInitialize();
	}



}
Beispiel #12
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{

  try
    {
      // Initialize orb
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      // Get reference to Root POA.
      CORBA::Object_var obj =
        orb->resolve_initial_references ("RootPOA");

      PortableServer::POA_var rootpoa =
        PortableServer::POA::_narrow (obj.in ());

      // Activate POA manager
      PortableServer::POAManager_var mgr =
        rootpoa->the_POAManager ();

      mgr->activate ();

      PortableServer::POA_var poa;

      TAO::Utils::PolicyList_Destroyer PolicyList (3);
      PolicyList.length (3);

      PolicyList [0] =
        rootpoa->create_lifespan_policy (PortableServer::PERSISTENT);

      PolicyList [1] =
        rootpoa->create_id_assignment_policy (PortableServer::USER_ID);

      CORBA::Any CallbackPolicy;
      CallbackPolicy <<= BiDirPolicy::BOTH;
      const char* sServerPoaName = "TelemetryServer";

      PolicyList [2] =
        orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE,
                            CallbackPolicy);

      poa = rootpoa->create_POA (sServerPoaName,
                                 mgr.in(),
                                 PolicyList);


      PortableServer::ObjectId_var ServerId =
        PortableServer::string_to_ObjectId ("TimeServer");

      // Create an object
      Time_impl *time_servant = new Time_impl;
      PortableServer::ServantBase_var self_manage (time_servant);

      poa->activate_object_with_id (ServerId.in (),
                                    time_servant);

      // Get a reference after activating the object
      CORBA::Object_var object = poa->id_to_reference (ServerId.in ());
      TimeModule::Time_var tm = TimeModule::Time::_narrow (object.in ());

      // Get reference to initial naming context
      CORBA::Object_var name_obj =
        orb->resolve_initial_references ("NameService");

      CosNaming::NamingContext_var inc =
        CosNaming::NamingContext::_narrow (name_obj.in ());

      if (CORBA::is_nil (inc.in ()))
        {
          ACE_ERROR ((LM_ERROR,
                      "(%P|%t) Error fetching naming context\n"));
        }

      CosNaming::Name service_name;
      service_name.length(1);
      service_name[0].id   =
        CORBA::string_dup ("Time");

      inc->rebind (service_name,
                   tm.in ());

      // Run the event loop for fun
      ACE_Time_Value tv (3, 0);

      // Accept requests
      orb->run (&tv);

      rootpoa->destroy (0 , 0);

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught an exception\n");

      return -1;
    }

  return 0;
}
Beispiel #13
0
int main (int argc, char** argv) {

    if (!init (argc, argv))
        return 1;

    // --------------------------------------------------------------------------
    // Start HTTP server:
    // --------------------------------------------------------------------------
    for (size_t i = 1; i < argc; ++i) {
    	std::stringstream key;
    	key << "arg_" << i;
    	wspace.p[key.str()] = argv[i];
    }
    wspace.p["http_port"] = port;
    using namespace codeare::service;
    MongooseService& mg = MongooseService::Instance();

    // --------------------------------------------------------------------------
    // Start CORBA server:
    // --------------------------------------------------------------------------
    try {
        
        streambuf* out;
        streambuf* err;
        ofstream   log (logfile);
        
        if (log.is_open()) {
            out = cout.rdbuf(log.rdbuf());
            err = cerr.rdbuf(log.rdbuf());
        } else {
            cout << "Could not open logfile " << logfile << "." << endl;
            cout << "Exiting :(" << endl << endl;
            return 1;
        }
        
        // Initialise ORB
        const char*    options[][2] = { { (char*)"traceLevel", debug}, /*{ (char*)"traceFile", logfile}, */{ 0, 0 } };
        CORBA::ORB_var orb          = CORBA::ORB_init(argc, argv, "omniORB4", options);
        
        // Get reference to the RootPOA.
        CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
        PortableServer::POA_var _poa = PortableServer::POA::_narrow(obj.in());
        
        // Initialise servant
        ReconServant* myReconServant = new ReconServant();

        // Activate in RootPDA
        PortableServer::ObjectId_var myReconServant_oid
            = _poa->activate_object(myReconServant);
        
        // Obtain object reference from servant and register in naming service
        CORBA::Object_var SA_obj = myReconServant->_this();
        
        // Obtain a reference to the object, and print it out as string IOR.
        CORBA::String_var sior(orb->object_to_string(SA_obj.in()));
        
        // Bind to the name server and lookup 
        CORBA::Object_var obj1=orb->resolve_initial_references("NameService");
        assert(!CORBA::is_nil(obj1.in()));
        
        // Get context
        CosNaming::NamingContext_var nc = CosNaming::NamingContext::_narrow(obj1.in());
        assert(!CORBA::is_nil(nc.in()));
        
        // Resolve name
        CosNaming::Name m_name;
        m_name.length(1);
        m_name[0].id=CORBA::string_dup(name);
        nc->rebind (m_name,SA_obj.in());
        
        // Activate POA manager
        PortableServer::POAManager_var pmgr = _poa->the_POAManager();
        pmgr->activate();
        
        // Accept requests from clients
        orb->run();
                                                                                
        orb->destroy();
        
        free(m_name[0].id); // str_dup does a malloc internally
        
        cout.rdbuf(out);
        cerr.rdbuf(err);
        
    } catch(CORBA::SystemException&) {
        cerr << "Caught CORBA::SystemException." << endl;
        throw DS_SystemException();
    } catch(CORBA::Exception&) {
        cerr << "Caught CORBA::Exception." << endl;
        throw DS_Exception();
    } catch(omniORB::fatalException& fe) {
        cerr << "Caught omniORB::fatalException:" << endl;
        cerr << "  file: " << fe.file() << endl;
        cerr << "  line: " << fe.line() << endl;
        cerr << "  mesg: " << fe.errmsg() << endl;
        throw DS_FatalException();
    } catch(...) {
        cerr << "Caught unknown exception." << endl;
        throw DS_Exception();
    }
    
    return 0;
    
}
Beispiel #14
0
int TestTask::svc()
{

  try {
    // Start the Naming Service tasks
    namingServiceA_.activate();
    // Wait for the Naming Service initialized.
    namingServiceA_.waitInit();

    namingServiceB_.activate();
    // Wait for the Naming Service initialized.
    namingServiceB_.waitInit();

    FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
    if (output_file == 0)
      ACE_ERROR_RETURN ((LM_ERROR,
                          "Cannot open output file for writing IOR: ns.ior\n"),
                          1);
    ACE_OS::fprintf (output_file, "%s", namingServiceA_.ior ());
    ACE_OS::fclose (output_file);

    // Get reference to Root POA
    CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA");
    PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());

    // Activate POA Manager
    PortableServer::POAManager_var mgr = poa->the_POAManager();
    mgr->activate();

    // Find the Naming Service
    obj = orb_->string_to_object (namingServiceB_.ior ());
    CosNaming::NamingContext_var root =
      CosNaming::NamingContext::_narrow(obj.in());

    if (CORBA::is_nil(root.in())) {
      ACE_ERROR ((LM_ERROR, "Error, Nil Naming Context reference\n"));
      return 1;
    }
    // Bind the example Naming Context, if necessary
    CosNaming::NamingContext_var example_nc;
    CosNaming::Name name;
    name.length(1);
    name[0].id = CORBA::string_dup("example");
    try
    {
      obj = root->resolve(name);
      example_nc = CosNaming::NamingContext::_narrow(obj.in());
    }
    catch (const CosNaming::NamingContext::NotFound&)
    {
      example_nc = root->bind_new_context(name);
    }

    // Bind the Test object
    name.length(2);
    name[1].id = CORBA::string_dup("Hello");

    // Create an object
    Hello servant(orb_.in ());
    PortableServer::ObjectId_var oid = poa->activate_object(&servant);
    obj = poa->id_to_reference(oid.in());
    root->rebind(name, obj.in());

    ACE_DEBUG ((LM_INFO, "Hello object bound in Naming Service B\n"));

    name.length(1);
    obj = orb_->string_to_object (namingServiceA_.ior ());
    root = CosNaming::NamingContext::_narrow(obj.in());
    root->bind_context (name, example_nc.in ());

    ACE_DEBUG ((LM_INFO, "'example' context of NS B bound in Naming Service A\n"));

    if (shutdown_ns_)
    {
      namingServiceB_.end();

      ACE_DEBUG ((LM_INFO, "Naming Service B shut down\n"));
    }

    // Create shutdown server
    NsShutdown shutdown_servant(orb_.in ());
    PortableServer::ObjectId_var shutdown_oid = poa->activate_object(&shutdown_servant);
    obj = poa->id_to_reference(shutdown_oid.in());
    CORBA::String_var ior = orb_->object_to_string (obj.in ());

    output_file= ACE_OS::fopen (ior_shutdown_file, "w");
    if (output_file == 0)
      ACE_ERROR_RETURN ((LM_ERROR,
                          "Cannot open output file %s for writing IOR: %C\n",
                          ior_shutdown_file,
                          ior.in ()),
                          1);
    ACE_OS::fprintf (output_file, "%s", ior.in ());
    ACE_OS::fclose (output_file);

    // Normally we run the orb and the orb is shutdown by
    // calling TestTask::end().
    // Accept requests
    orb_->run();
    orb_->destroy();

    // Shutdown the Naming Services.
    namingServiceA_.end();
    if (!shutdown_ns_)
      {
        namingServiceB_.end();
      }

    return 0;
  }
  catch (CORBA::Exception& ex)
  {
    ex._tao_print_exception ("CORBA exception: ");
  }

  return -1;
}
bool
NameServiceBase::registerName(std::string name, CORBA::Object_ptr obj, bool rebind)
{
    if (name.empty())
    {
        return false;
    }
    
    // extract name without contexts
    std::string pure_name = name;
    std::string contexts = "";
    std::string::size_type delimiter_pos = name.find_last_of("/");
    if (delimiter_pos != std::string::npos)
    {
        pure_name = pure_name.replace(0, delimiter_pos + 1, "");
        contexts = name.replace(delimiter_pos, std::string::npos, "");
    }

    CosNaming::Name aName;
    aName.length(1);
    aName[0].id = CORBA::string_dup(pure_name.c_str());
    aName[0].kind = CORBA::string_dup("");

    // make sure each context is bound
    CosNaming::NamingContext_var context = nameService_;
    while (contexts.length())
    {
        std::string ctx = contexts;
        delimiter_pos = contexts.find_first_of("/");
        if (delimiter_pos != std::string::npos)
        {
            ctx = ctx.replace(delimiter_pos, std::string::npos, "");
            contexts = contexts.replace(0, delimiter_pos + 1, "");
        }
        else
        {
            contexts = "";
        }

	    CosNaming::Name contextName;
        contextName.length(1);
        contextName[0].id = CORBA::string_dup(ctx.c_str());
        contextName[0].kind = CORBA::string_dup("");

        try
        {
            context = context->bind_new_context(contextName);
	    }
	    catch (const CosNaming::NamingContext::AlreadyBound&)
        {
            try
            {
		        // already bound -> take it
                CORBA::Object_var dummy;
                context = CosNaming::NamingContext::_narrow(dummy = context->resolve(contextName));
            }
            catch (...)
            {
                std::cerr << ctx << " is probably no context?" << std::endl;
                return false;
            }
        }
	    catch (const CosNaming::NamingContext::NotFound&)
        {
            std::cerr << "Got a `NotFound' exception : " << std::endl;
    		return false;
        }
        catch (const CosNaming::NamingContext::CannotProceed&)
        {
            std::cerr << "Got a `CannotProceed' exception : " << std::endl;
    		return false;
        }
        catch (const CosNaming::NamingContext::InvalidName&)
        {
            std::cerr << "Got a `InvalidName' exception : " << std::endl;
		    return false;
        }
    }

    //  bind the name
    try
	{
        context->bind(aName, obj);
	}
	catch(const CosNaming::NamingContext::AlreadyBound&)
    {
		// rebind the name if intended
        if (rebind)
        {
		    try
		    {
			    context->rebind(aName, obj);
		    }
		    catch (const CosNaming::NamingContext::NotFound&)
	        {
	            std::cerr << "Got a `NotFound' exception : " << std::endl;
			    return false;
	        }
	        catch (const CosNaming::NamingContext::CannotProceed&)
		    {
		        std::cerr << "Got a `CannotProceed' exception : " << std::endl;
			    return false;
		    }
		    catch (const CosNaming::NamingContext::InvalidName&)
	        {
			    std::cerr << "Got a `InvalidName' exception : " << std::endl;
			    return false;
		    }
        }
        else
        {
            std::cerr << "Got a `InvalidName' exception" << std::endl;
            return false;
        }
    }
	catch (const CosNaming::NamingContext::NotFound&)
    {
        std::cerr << "Got a `NotFound' exception : " << std::endl;
		return false;
    }
    catch (const CosNaming::NamingContext::CannotProceed&)
    {
        std::cerr << "Got a `CannotProceed' exception : " << std::endl;
		return false;
    }
    catch (const CosNaming::NamingContext::InvalidName&)
    {
        std::cerr << "Got a `InvalidName' exception : " << std::endl;
		return false;
    }

    return true;
}
Beispiel #16
0
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
	std::cout << __FILE__ << " build " << __DATE__ << " " << __TIME__ <<std::endl;

	int ret = 0;
	CORBA::ORB_var orb;
	CORBA::Object_var distrio_manager_obj, root_poa, naming_service;
	PortableServer::POA_var poa;
	PortableServer::POAManager_var poa_mgr;
	CosNaming::NamingContext_var nc;
	CosNaming::Name name;

	Distrio_Manager_i *distrio_manager;
	PortableServer::ObjectId_var distrio_manager_oid;

	distrio_manager = new Distrio_Manager_i ();

	try {
		std::cout << "initialize CORBA orb" << std::endl;
		orb = CORBA::ORB_init (argc, argv);
		root_poa = orb->resolve_initial_references ("RootPOA");
		poa = PortableServer::POA::_narrow (root_poa.in ());
		distrio_manager_oid = poa->activate_object (distrio_manager);
		distrio_manager_obj = distrio_manager->_this ();

		std::cout << "get context of NameService" << std::endl;
		naming_service = orb->resolve_initial_references ("NameService");
		if (CORBA::is_nil (naming_service)) {
			std::cerr << "can't resolve NameService" << std::endl;
			ret = -EINVAL;
			goto out;
		}
		nc = CosNaming::NamingContext::_narrow (naming_service.in ());
		if (CORBA::is_nil (nc)) {
			std::cerr << "resolved invalid NameService object" << std::endl;
			ret = -EINVAL;
			goto out;
		}

		std::cout << "bind manager object at NameService" << std::endl;
		/* TODO: find out how to build a tree @ the nameservice "distrio/manager" */
		name.length (1);
		name[0].id = CORBA::string_dup ("distrio_manager");
		nc->rebind (name, distrio_manager_obj.in ());

		std::cout << "activate POA Manager" << std::endl;
		poa_mgr = poa->the_POAManager ();
		poa_mgr->activate ();

		std::cout << "distrio_manager ready" << std::endl;
		orb->run ();
		orb->destroy ();
	} catch (CORBA::SystemException &e) {
		std::cerr << "CORBA initialization failed: " << e << std::endl;
		ret = -EINVAL;
		goto out;
	} catch(CORBA::Exception &e) {
		std::cerr << "CORBA initialization failed: " << e << std::endl;
		ret = -EINVAL;
		goto out;
	}

out:
	free (distrio_manager);
	return ret;
}
Beispiel #17
0
int MessengerTask::svc()
{

  try {
    // Get reference to Root POA
    CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA");
    PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());

    // Activate POA Manager
    PortableServer::POAManager_var mgr = poa->the_POAManager();
    mgr->activate();

    // Find the Naming Service
    obj = orb_->resolve_initial_references("NameService");
    CosNaming::NamingContext_var root =
      CosNaming::NamingContext::_narrow(obj.in());

    if (CORBA::is_nil(root.in())) {
      std::cerr << "Nil Naming Context reference" << std::endl;
      return 1;
    }
    // Bind the example Naming Context, if necessary
    CosNaming::Name name;
    name.length(1);
    name[0].id = CORBA::string_dup("example");
    try {
      root->resolve(name);
    }
    catch(const CosNaming::NamingContext::NotFound&) {
      root->bind_new_context(name);
    }

    // Bind the Messenger object
    name.length(2);
    name[1].id = CORBA::string_dup("Messenger");

    // Create an object
    PortableServer::Servant_var<Messenger_i> servant = new Messenger_i;
    PortableServer::ObjectId_var oid = poa->activate_object(servant.in());
    obj = poa->id_to_reference(oid.in());
    root->rebind(name, obj.in());

    std::cout << "Messenger object bound in Naming Service" << std::endl;

    // Normally we run the orb and the orb is shutdown by
    // calling MessengerTask::end(). To simplify the coordination
    // between the main thread and this Messenger thread, specify
    // the time period to let the Messenger thread finish by itself.
    // Accept requests
    ACE_Time_Value tv(1);
    orb_->run(tv);
    orb_->destroy();

    return 0;
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "CORBA exception: " << ex << std::endl;
  }

  return -1;
}
Beispiel #18
0
int ACE_TMAIN(int argc, ACE_TCHAR * argv[])
{
  try
  {
     CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
     CORBA::Object_var rootObj = orb->resolve_initial_references("NameService");
     CosNaming::NamingContext_var rootNC =
       CosNaming::NamingContext::_narrow(rootObj.in());

     // Get reference to Root POA.
     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
     PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());

     // Activate POA manager
     PortableServer::POAManager_var mgr = poa->the_POAManager();
     mgr->activate();

     // Create an Event Channel factory.
     CosNotifyChannelAdmin::EventChannelFactory_var notify_factory =
       TAO_Notify_EventChannelFactory_i::create(poa.in());
     ACE_ASSERT (!CORBA::is_nil (notify_factory.in ()));

     // Create an Event Channel.
     CosNotifyChannelAdmin::ChannelID id;
     CosNotification::QoSProperties initial_qos;
     CosNotification::AdminProperties initial_admin;
     CosNotifyChannelAdmin::EventChannel_var ec =
       notify_factory->create_channel (initial_qos, initial_admin, id);

     // Bind it in the Naming Service.
     CosNaming::Name name(1);
     name.length(1);
     name[0].id = CORBA::string_dup("MyEventChannel");
     rootNC->rebind(name, ec.in());

     // Become a structured push supplier.
     CosNotifyChannelAdmin::AdminID adminid;
     CosNotifyChannelAdmin::InterFilterGroupOperator ifgop =
       CosNotifyChannelAdmin::AND_OP;
     CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin =
       ec->new_for_suppliers (ifgop, adminid);

     CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id;
     CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer =
     supplier_admin->obtain_notification_push_consumer(
       CosNotifyChannelAdmin::STRUCTURED_EVENT,
       supplieradmin_proxy_id);

     StructuredEventSupplier_i *servant =
       new StructuredEventSupplier_i(orb.in());
     CosNotifyComm::StructuredPushSupplier_var supplier = servant->_this();

     CosNotifyChannelAdmin::StructuredProxyPushConsumer_var consumer_proxy =
       CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow(
         proxy_consumer.in());
     consumer_proxy->connect_structured_push_supplier(supplier.in());

     // Set up events to push.
     CosNotification::StructuredEvent event;
     event.header.fixed_header.event_type.domain_name =
     CORBA::string_dup("OCI_TAO");

    event.header.fixed_header.event_type.type_name =
      CORBA::string_dup("examples");
    event.header.fixed_header.event_name = CORBA::string_dup("myevent");
    event.filterable_data.length (1);
    event.filterable_data[0].name = CORBA::string_dup("Message from:");
    event.filterable_data[0].value <<= (const char *)user_name;
    event.filterable_data.length (2);
    event.filterable_data[1].name = CORBA::string_dup("Subject:");
    event.filterable_data[1].value <<= (const char *)subject;
    event.filterable_data.length (3);
    event.filterable_data[2].name = CORBA::string_dup("Message:");
    event.filterable_data[2].value <<= (const char *)message;

    // Push events.
    while (1) {
      std::cout << "pushing " << std::endl;
      consumer_proxy->push_structured_event (event);
      ACE_OS::sleep (1);
    }
  }
  catch(const CORBA::Exception& ex) {
    return 1;
  }

  return 0;
}
Beispiel #19
0
bool ServiceOptions::bindServiceObject(CORBA::ORB_ptr orb, 
                                       CORBA::Object_ptr object,
                                       PortableServer::Servant p_servant,
                                       const char* objName,
                                       bool rebind)
{
 if(is_set("with-naming")) {
     CosNaming::Name name;
     name.length(1);
     name[0].id=CORBA::string_dup(objName);
     name[0].kind=CORBA::string_dup("");
     CORBA::Object_var obj ;
     try {
        obj = orb->resolve_initial_references("NameService");
     }catch(const CORBA::ORB::InvalidName& ex){
        std::cerr << argv()[0] << ": can't resolve `NameService'" << std::endl;
        return false;
     }
     CosNaming::NamingContext_var nc;
     try {
        nc = CosNaming::NamingContext::_narrow(obj.in());
     }catch(const CORBA::SystemException& ex){
        std::cerr << argv()[0] << ": can't narrow naming service" << std::endl;
        return false;
     }
     try {
        if(rebind){
          nc->rebind(name,object);
        }else{
          try{
            nc->bind(name,object);
          }catch(const CosNaming::NamingContext::AlreadyBound&){
            std::cerr<<argv()[0]<<":can't bind "<<objName<<" (AlreadyBound)"<< std::endl;
            return false;
          }
        }
     }catch(const CosNaming::NamingContext::CannotProceed&){
        std::cerr<<argv()[0]<<": can't bind "<<objName<<" (CannotProceed)"<< std::endl;
        return false;
     }catch(const CosNaming::NamingContext::InvalidName&){
        std::cerr<<argv()[0]<<":can't bind "<<objName<<" (InvalidName)"<< std::endl;
        return false;
     }
     std::cout<<argv()[0]<<": binding completed successfully"<<std::endl;
 }
 CORBA::String_var ior ;
 try {
   ior = orb->object_to_string(object);
 }catch(const CORBA::SystemException& ex){
#ifdef CORBA_SYSTEM_EXCEPTION_IS_STREAMBLE
   std::cerr << ex << std::endl;
#else
   std::cerr << "CORBA::SystemException" << std::endl; 
#endif
   return false;
 }
 const char* fname = get_ior_fname(objName);
 if (fname!=NULL && strcmp(fname,"")!=0) {
    std::ofstream ofs (fname);
    if (ofs.bad()) {
       std::cerr << argv()[0] << ": can't open file " << fname <<  std::endl;
       perror(argv()[0]);
       return false;
    }
    ofs << ior.in();
    ofs.close();
 }
 if (is_set("ior-stdout")) {
    std::cout << ior << std::flush;
 }
#ifdef ORBACUS
 CORBA::Object_var bmgrObj = orb->resolve_initial_references("BootManager");
 OB::BootManager_var bootManager = OB::BootManager::_narrow(bmgrObj);
 PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId(objName);
 bootManager -> add_binding(oid.in(),object);
#elif defined(OMNIORB)
 PortableServer::POA_var objPOA = p_servant->_default_POA();
 CORBA::String_var objPOAName = objPOA->the_name();
 if (strcmp(objPOAName.in(),"omniINSPOA")!=0) {
   CORBA::Object_var insPOAObj = orb->resolve_initial_references("omniINSPOA");
   PortableServer::POA_var insPOA = PortableServer::POA::_narrow(insPOAObj);
   PortableServer::POAManager_var insPOAManager=insPOA->the_POAManager();
   insPOAManager->activate();
   PortableServer::ObjectId_var oid = 
                          PortableServer::string_to_ObjectId(objName);
   insPOA->activate_object_with_id(oid.in(),p_servant);
 }
#elif defined(RSSH_TAO)
#ifdef TAO_HAVE_IORTABLE_ADAPTER
 CORBA::Object_var table = orb->resolve_initial_references ("IORTable");
 IORTable::Table_var adapter = IORTable::Table::_narrow (table.in());
 if (CORBA::is_nil(adapter.in())) {
   cerr<<argv()[0]<<": nil IORTable reference"<<endl;
 } else {
   adapter->bind (objName, ior.in ());
 }
#else
 ACE_CString ins(objName);
 if (orb->_tao_add_to_IOR_table(ins,object)!=0) {
   return false;
 }
#endif
#elif defined(MICO)
  // create persistent POA with name as service name if we have no one.
 PortableServer::POA_var objPOA = p_servant->_default_POA();
 CORBA::String_var objPOAName = objPOA->the_name();
 std::cerr << "existent OBJPOAName=" << objPOAName.in() << std::endl;
 std::cerr << "objName=" << objName << std::endl;
 if (strcmp(objPOAName.in(),objName)!=0) {
   CORBA::Object_var rootPOAObj = orb->resolve_initial_references ("RootPOA");
   PortableServer::POA_var rootPOA = PortableServer::POA::_narrow(rootPOAObj);
   CORBA::PolicyList pl;
   pl.length (2);                              
   pl[0] = rootPOA->create_lifespan_policy (PortableServer::PERSISTENT);
   pl[1] = rootPOA->create_id_assignment_policy (PortableServer::USER_ID);
   PortableServer::POA_var objPOA = rootPOA->create_POA(objName,
			                  PortableServer::POAManager::_nil (),
			                  pl);
   PortableServer::POAManager_var objPOAManager = objPOA->the_POAManager ();   
   PortableServer::ObjectId_var objId =
                           PortableServer::string_to_ObjectId (objName);
   objPOA->activate_object_with_id (objId.in(), p_servant);
   objPOAManager->activate();
 }else{
   //PortbaobjPOA
 }  
#endif
 return true;
}
void
ServerActivatorImpl::initialize()
{
	try
	{
		CORBA::Object_var root_poa_obj = orb_->resolve_initial_references ("RootPOA");
		root_poa_ = PortableServer::POA::_narrow (root_poa_obj);
	}
	catch (CORBA::ORB::InvalidName&)
	{
		std::cerr << "ServerActivatorImpl: Fatal error - no root POA available." << std::endl;
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: Fatal error - cannot narrow root POA." << std::endl;
		throw CannotInitialize();
	}

	root_poa_manager_ = root_poa_->the_POAManager();

	root_poa_manager_->activate();

	//
	// register in name service
	//

	CosNaming::NamingContext_var nameService;

	//
	// try to get naming service from config values
	//
	CORBA::Object_var obj;
	std::string ns = Qedo::ConfigurationReader::instance()->lookup_config_value( "/General/NameService" );
	if( !ns.empty() )
	{
		try
		{
			obj = orb_->string_to_object( ns.c_str() );
		}
		catch(...)
		{
			std::cerr << "ServerActivatorImpl: can't resolve NameService " << ns << std::endl;
			throw CannotInitialize();
		}

		std::cout <<  "ServerActivatorImpl: NameService is " <<  ns << std::endl;
	}
	//
	// try to get naming service from orb
	//
	else
	{
		try
		{
			obj = orb_->resolve_initial_references( "NameService" );
		}
		catch (const CORBA::ORB::InvalidName&)
		{
			std::cerr << "ServerActivatorImpl: can't resolve NameService" << std::endl;
			throw CannotInitialize();
		}

		if (CORBA::is_nil(obj.in()))
		{
			std::cerr << "ServerActivatorImpl: NameService is a nil object reference" << std::endl;
			throw CannotInitialize();
		}
	}

	try
	{
		nameService = CosNaming::NamingContext::_narrow( obj.in() );
	}
	catch (const CORBA::Exception&)
	{
		std::cerr << "ServerActivatorImpl: NameService is not running" << std::endl;
		throw CannotInitialize();
	}

	if( CORBA::is_nil(nameService.in()) )
	{
		std::cerr << "NameService is not a NamingContext object reference" << std::endl;
		throw CannotInitialize();
	}

	CORBA::ULong context_offset;
	if (global_context_used_)
	{
		context_offset = 1;
	} else 
	{
		context_offset= 0;
	};


	// Create the Qedo and Activators naming context
	CosNaming::Name current_name;

	current_name.length (1);
	if (global_context_used_)
	{
		current_name[0].id = CORBA::string_dup(global_context_.c_str());
		current_name[0].kind = CORBA::string_dup("");
		try 
		{
			nameService->bind_new_context (current_name);
		}
		catch (CosNaming::NamingContext::AlreadyBound&)
		{
			// ignore this exception
		}
		catch (CORBA::SystemException&)
		{
			std::cerr << "ServerActivatorImpl: CORBA system exception during binding context 'Qedo'" << std::endl;
			throw CannotInitialize();
		}

	} 
	current_name.length (1 + context_offset);
	current_name[0 + context_offset].id = CORBA::string_dup ("Qedo");
	current_name[0 + context_offset].kind = CORBA::string_dup ("");
	try
	{
		nameService->bind_new_context (current_name);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		// Ignore this exception
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: CORBA system exception during binding context 'Qedo'" << std::endl;
		throw CannotInitialize();
	}

	current_name.length(2 + context_offset);
	current_name[1+context_offset].id = CORBA::string_dup ("Activators");
	current_name[1+context_offset].kind = CORBA::string_dup ("");

	try
	{
		nameService->bind_new_context (current_name);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		// Ignore this exception
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: CORBA system exception during binding context 'Activators'" << std::endl;
		throw CannotInitialize();
	}

	// Now bind this Component Server Activator with the Name Service, use the name Qedo/Activators/<hostname>
	char hostname[256];
	if (gethostname (hostname, 256))
	{
		std::cerr << "ServerActivatorImpl: Cannot determine my hostname" << std::endl;
		throw CannotInitialize();
	}

	std::cout << "ServerActivatorImpl: Binding Component Server Activator under Qedo/Activators/" << hostname << std::endl;

	current_name.length (3 + context_offset);
	current_name[2+context_offset].id = CORBA::string_dup (hostname);
	current_name[2+context_offset].kind = CORBA::string_dup ("");

	CORBA::Object_var my_ref = this->_this();

	try
	{
		nameService->bind (current_name, my_ref);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		try
		{
			nameService->rebind (current_name, my_ref);
		}
		catch (CosNaming::NamingContext::InvalidName&)
		{
			std::cerr << "ServerActivatorImpl: Name Service complains about an invalid name" << std::endl;
			throw CannotInitialize();
		}
		catch (CORBA::SystemException&)
		{
			std::cerr << "ServerActivatorImpl: CORBA system exception in rebind()" << std::endl;
			throw CannotInitialize();
		}
	}
	catch (CosNaming::NamingContext::InvalidName&)
	{
		std::cerr << "ServerActivatorImpl: Name Service complains about an invalid name" << std::endl;
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		std::cerr << "ServerActivatorImpl: CORBA system exception during bind()" << std::endl;
		throw CannotInitialize();
	}

}
void
ServerActivatorImpl::initialize()
{
	try
	{
		CORBA::Object_var root_poa_obj = orb_->resolve_initial_references ("RootPOA");
		root_poa_ = PortableServer::POA::_narrow (root_poa_obj);
	}
	catch (CORBA::ORB::InvalidName&)
	{
		cerr << "ServerActivatorImpl: Fatal error - no root POA available." << endl;
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		cerr << "ServerActivatorImpl: Fatal error - cannot narrow root POA." << endl;
		throw CannotInitialize();
	}

	root_poa_manager_ = root_poa_->the_POAManager();

	root_poa_manager_->activate();

	CosNaming::NamingContext_var ns;

	// Now try to bind with the Name Service
	try
	{
		CORBA::Object_var ns_obj = orb_->resolve_initial_references ("NameService");
		ns = CosNaming::NamingContext::_narrow (ns_obj);
	}
	catch (CORBA::ORB::InvalidName&)
	{
		cerr << "ServerActivatorImpl: Name Service not found" << endl;
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		cerr << "ServerActivatorImpl: Cannot narrow object reference of Name Service" << endl;
		throw CannotInitialize();
	}

	if (CORBA::is_nil (ns))
	{
		cerr << "ServerActivatorImpl: Name Service is nil" << endl;
		throw CannotInitialize();
	}

	// Create the Qedo and Activators naming context
	CosNaming::Name current_name;
	current_name.length (1);
	current_name[0].id = CORBA::string_dup ("Qedo");
	current_name[0].kind = CORBA::string_dup ("");
	try
	{
		ns->bind_new_context (current_name);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		// Ignore this exception
	}
	catch (CORBA::SystemException&)
	{
		cerr << "ServerActivatorImpl: CORBA system exception during binding context 'Qedo'" << endl;
		throw CannotInitialize();
	}

	current_name.length(2);
	current_name[1].id = CORBA::string_dup ("Activators");
	current_name[1].kind = CORBA::string_dup ("");

	try
	{
		ns->bind_new_context (current_name);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		// Ignore this exception
	}
	catch (CORBA::SystemException&)
	{
		cerr << "ServerActivatorImpl: CORBA system exception during binding context 'Activators'" << endl;
		throw CannotInitialize();
	}

	// Now bind this Component Server Activator with the Name Service, use the name Qedo/Activators/<hostname>
	char hostname[256];
	if (gethostname (hostname, 256))
	{
		cerr << "ServerActivatorImpl: Cannot determine my hostname" << endl;
		throw CannotInitialize();
	}

	cout << "ServerActivatorImpl: Binding Component Server Activator under Qedo/Activators/" << hostname << endl;

	current_name.length (3);
	current_name[2].id = CORBA::string_dup (hostname);
	current_name[2].kind = CORBA::string_dup ("");

	CORBA::Object_var my_ref = this->_this();

	try
	{
		ns->bind (current_name, my_ref);
	}
	catch (CosNaming::NamingContext::AlreadyBound&)
	{
		try
		{
			ns->rebind (current_name, my_ref);
		}
		catch (CosNaming::NamingContext::InvalidName&)
		{
			cerr << "ServerActivatorImpl: Name Service complains about an invalid name" << endl;
			throw CannotInitialize();
		}
		catch (CORBA::SystemException&)
		{
			cerr << "ServerActivatorImpl: CORBA system exception in rebind()" << endl;
			throw CannotInitialize();
		}
	}
	catch (CosNaming::NamingContext::InvalidName&)
	{
		cerr << "ServerActivatorImpl: Name Service complains about an invalid name" << endl;
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		cerr << "ServerActivatorImpl: CORBA system exception during bind()" << endl;
		throw CannotInitialize();
	}

#ifdef HAVE_JTC
#else
#if _WIN32
	// Create an event handle to be used for the notification from the created component server
	event_handle_ = CreateEvent (NULL, TRUE /*auto-reset*/, FALSE /*initial: non-signaled*/, "QEDO_NOTIFY_EVENT");
	    
	if (event_handle_ == NULL)
	{
		cerr << "ServerActivatorImpl: ServerActivatorImpl: Cannot create event object for notify_component_server() operation"<< endl;
		throw CannotInitialize();
	}
#endif
#endif
}
Beispiel #22
0
int main(int argc, char *argv[])
{
    int wsize=0;
    double maxEdgeLen=0.0;
    bool useDefaultLights=true;
    float bgColor[3]={0,0,0};
    
    for (int i=1; i<argc; i++){
        if (strcmp(argv[i], "-size")==0){
            wsize = atoi(argv[++i]);
        }else if(strcmp(argv[i], "-max-edge-length")==0){
            maxEdgeLen = atof(argv[++i]);
        }else if(strcmp(argv[i], "-no-default-lights")==0){
            useDefaultLights=false;
        }else if(strcmp(argv[i], "-bg")==0){
            bgColor[0] = atof(argv[++i]);
            bgColor[1] = atof(argv[++i]);
            bgColor[2] = atof(argv[++i]);
        }else if(strcmp(argv[i], "-h")==0 || strcmp(argv[i], "--help")==0){
            print_usage(argv[0]);
            return 1;
        }
    }
    
    CORBA::ORB_var orb = CORBA::ORB::_nil();
    
    try {
        
        orb = CORBA::ORB_init(argc, argv);
        
        CORBA::Object_var obj;
        
        obj = orb->resolve_initial_references("RootPOA");
        PortableServer::POA_var poa = PortableServer::POA::_narrow(obj);
        if(CORBA::is_nil(poa)){
            throw std::string("error: failed to narrow root POA.");
        }
        
        PortableServer::POAManager_var poaManager = poa->the_POAManager();
        if(CORBA::is_nil(poaManager)){
            throw std::string("error: failed to narrow root POA manager.");
        }
        
        LogManager<OpenHRP::WorldState> log;
        GLscene scene(&log);
        scene.setBackGroundColor(bgColor);
        scene.maxEdgeLen(maxEdgeLen);
        
        OnlineViewer_impl* OnlineViewerImpl 
            = new OnlineViewer_impl(orb, poa, &scene, &log);
        poa->activate_object(OnlineViewerImpl);
        OnlineViewer_var OnlineViewer = OnlineViewerImpl->_this();
        OnlineViewerImpl->_remove_ref();
        
        obj = orb->resolve_initial_references("NameService");
        CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(obj);
        if(CORBA::is_nil(namingContext)){
            throw std::string("error: failed to narrow naming context.");
        }
        
        CosNaming::Name name;
        name.length(1);
        name[0].id = CORBA::string_dup("OnlineViewer");
        name[0].kind = CORBA::string_dup("");
        namingContext->rebind(name, OnlineViewer);

        poaManager->activate();
        
        if (argc >= 2 && argv[1][0] != '-'){
            OpenHRP::ModelLoader_var ml = hrp::getModelLoader(namingContext);
            if (CORBA::is_nil(ml)){
                std::cerr << "openhrp-model-loader is not running" << std::endl;
                return 1;
            }
            OpenHRP::ModelLoader::ModelLoadOption opt;
            opt.readImage = true;
            opt.AABBdata.length(0);
            opt.AABBtype = OpenHRP::ModelLoader::AABB_NUM;
            GLbody *glbody = new GLbody();
            std::string url = argv[1];
            if (argv[1][0] != '/'){
                char buf[MAXPATHLEN];
                std::string cwd = getcwd(buf, MAXPATHLEN);
                url = cwd + '/' + url;
            }
            hrp::BodyPtr body(glbody);
            body->setName("model");
            OpenHRP::BodyInfo_var binfo = ml->getBodyInfoEx(url.c_str(), opt);
            hrp::loadBodyFromBodyInfo(body, binfo, false, GLlinkFactory);
            loadShapeFromBodyInfo(glbody, binfo);
            scene.addBody(body);
        }
        
        GLlink::useAbsTransformToDraw();
        GLbody::useAbsTransformToDraw();

        SDLwindow window(&scene, &log);
        window.init(wsize, wsize);
        if (!useDefaultLights) scene.defaultLights(false);
        
        while(window.oneStep());
        
    }
    catch(OpenHRP::ModelLoader::ModelLoaderException ex){
        std::cerr << ex.description << std::endl;
    }
    catch (CORBA::SystemException& ex) {
        std::cerr << ex._rep_id() << std::endl;
    }
    catch (const std::string& error){
        std::cerr << error << std::endl;
    }
    
    try {
        orb->destroy();
    }
    catch(...){
        
    }
    
    return 0;
}
Beispiel #23
0
static void bindObjectToName(CORBA::ORB_ptr orb, const char name[], CORBA::Object_ptr objref)
{
   CosNaming::NamingContext_var rootContext;

   try 
   {
      // Obtain a reference to the root context of the name service:
      CORBA::Object_var obj;
      obj = orb->resolve_initial_references("NameService");
      
      // Narrow the reference returned.
      rootContext = CosNaming::NamingContext::_narrow(obj);
      if(CORBA::is_nil(rootContext)) 
      {
         cerr << "Failed to narrow the root naming context." << endl;
         return;
      }
   }
   catch (CORBA::ORB::InvalidName& ex) 
   {
      // This should not happen!
      cerr << "Service required is invalid [does not exist]." << endl;
      return;
   }

   try 
   {
      CosNaming::Name contextName;
      contextName.length(1);
      contextName[0].id   = (const char*) "corejava"; 
      contextName[0].kind = (const char*) "Context"; 

      CosNaming::NamingContext_var corejavaContext;
      try 
      {
         // Bind the context to root.
         corejavaContext = rootContext->bind_new_context(contextName);
      }
      catch (CosNaming::NamingContext::AlreadyBound& ex) 
      {
         // If the context already exists, this exception will be raised. In this case, just 
         // resolve the name and assign the context to the object returned:
         CORBA::Object_var obj;
         obj = rootContext->resolve(contextName);
         corejavaContext = CosNaming::NamingContext::_narrow(obj);
         if( CORBA::is_nil(corejavaContext) ) 
         {
            cerr << "Failed to narrow naming context." << endl;
            return;
         }
      }

      // Bind objref with given name to the context:
      CosNaming::Name objectName;
      objectName.length(1);
      objectName[0].id = name;
      objectName[0].kind = (const char*) "Object"; 

      try 
      {      
         corejavaContext->bind(objectName, objref);
      }
      catch (CosNaming::NamingContext::AlreadyBound& ex) 
      {
         corejavaContext->rebind(objectName, objref);
      }
   }
   catch (CORBA::COMM_FAILURE& ex) 
   {
      cerr << "Caught system exception COMM_FAILURE--unable to contact the naming service." 
         << endl;
   }
   catch (CORBA::SystemException&) 
   {
      cerr << "Caught a CORBA::SystemException while using the naming service." << endl;
   }
}