示例#1
0
Web_Server::Iterator_Factory_ptr
get_iterator (CORBA::ORB_ptr o)
{
  CORBA::ORB_var orb = CORBA::ORB::_duplicate (o);

  // Get a reference to the Name Service.
  CORBA::Object_var obj =
    orb->resolve_initial_references ("NameService");

  // Narrow to a Naming Context
  CosNaming::NamingContext_var nc =
    CosNaming::NamingContext::_narrow (obj.in ());

  if (CORBA::is_nil (obj.in ()))
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("Nil reference to Name Service\n")));
      return Web_Server::Iterator_Factory::_nil ();
    }

  // Create a name.
  CosNaming::Name name;
  name.length (1);
  name[0].id = CORBA::string_dup ("Iterator_Factory");
  name[0].kind = CORBA::string_dup ("");

  obj = nc->resolve (name);

  Web_Server::Iterator_Factory_ptr factory =
    Web_Server::Iterator_Factory::_narrow (obj.in ());

  return factory;
}
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);
}
OnlineViewer_var getOnlineViewer(CosNaming::NamingContext_var cxt)
{  
    CosNaming::Name ncName;
    ncName.length(1);
    ncName[0].id = CORBA::string_dup("OnlineViewer");
    ncName[0].kind = CORBA::string_dup("");
    OnlineViewer_var onlineViewer = NULL;
    try {
        onlineViewer = OnlineViewer::_narrow(cxt->resolve(ncName));
    } catch(const CosNaming::NamingContext::NotFound &exc) {
        std::cerr << "OnlineViewer not found: ";
        switch(exc.why) {
        case CosNaming::NamingContext::missing_node:
            std::cerr << "Missing Node" << std::endl;
        case CosNaming::NamingContext::not_context:
            std::cerr << "Not Context" << std::endl;
            break;
        case CosNaming::NamingContext::not_object:
            std::cerr << "Not Object" << std::endl;
            break;
        }
        return 0;
    } catch(CosNaming::NamingContext::CannotProceed &exc) {
        std::cerr << "Resolve OnlineViewer CannotProceed" << std::endl;
        return 0;
    } catch(CosNaming::NamingContext::AlreadyBound &exc) {
        std::cerr << "Resolve OnlineViewer InvalidName" << std::endl;
        return 0;
    }
    return onlineViewer;
}
X_ptr checkCorbaServer(std::string n, CosNaming::NamingContext_var &cxt)
{
  CosNaming::Name ncName;
  ncName.length(1);
  ncName[0].id = CORBA::string_dup(n.c_str());
  ncName[0].kind = CORBA::string_dup("");
  X_ptr srv = NULL;
  try {
    srv = X::_narrow(cxt->resolve(ncName));
  } catch(const CosNaming::NamingContext::NotFound &exc) {
    std::cerr << n << " not found: ";
    switch(exc.why) {
    case CosNaming::NamingContext::missing_node:
      std::cerr << "Missing Node" << std::endl;
    case CosNaming::NamingContext::not_context:
      std::cerr << "Not Context" << std::endl;
      break;
    case CosNaming::NamingContext::not_object:
      std::cerr << "Not Object" << std::endl;
      break;
    }
    return (X_ptr)NULL;
  } catch(CosNaming::NamingContext::CannotProceed &exc) {
    std::cerr << "Resolve " << n << " CannotProceed" << std::endl;
  } catch(CosNaming::NamingContext::AlreadyBound &exc) {
    std::cerr << "Resolve " << n << " InvalidName" << std::endl;
  }
  return srv;
}
ModelLoader_var hrp::getModelLoader(CosNaming::NamingContext_var cxt)
{
    CosNaming::Name ncName;
    ncName.length(1);
    ncName[0].id = CORBA::string_dup("ModelLoader");
    ncName[0].kind = CORBA::string_dup("");
    ModelLoader_var modelLoader = NULL;
    try {
        modelLoader = ModelLoader::_narrow(cxt->resolve(ncName));
        modelLoader->_non_existent();
    } catch(const CosNaming::NamingContext::NotFound &exc) {
        std::cerr << "ModelLoader not found: ";
        switch(exc.why) {
        case CosNaming::NamingContext::missing_node:
            std::cerr << "Missing Node" << std::endl;
        case CosNaming::NamingContext::not_context:
            std::cerr << "Not Context" << std::endl;
            break;
        case CosNaming::NamingContext::not_object:
            std::cerr << "Not Object" << std::endl;
            break;
        }
        modelLoader = ModelLoader::_nil();
    } catch(CosNaming::NamingContext::CannotProceed &exc) {
        std::cerr << "Resolve ModelLoader CannotProceed" << std::endl;
        modelLoader = ModelLoader::_nil();
    } catch(CosNaming::NamingContext::AlreadyBound &exc) {
        std::cerr << "Resolve ModelLoader InvalidName" << std::endl;
        modelLoader = ModelLoader::_nil();
    } catch(...){
        modelLoader = ModelLoader::_nil();
    }
    return modelLoader;
}
示例#6
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;
}
示例#7
0
static CORBA::Object_ptr getObjectReference(CORBA::ORB_ptr orb) {
  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 CORBA::Object::_nil();
    }
  } 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& ex) {
    // This should not happen!
    cerr << "Service required is invalid [does not exist]." << endl;
    return CORBA::Object::_nil();
  }

  // Create a name object, containing the name test/context:
  CosNaming::Name name;
  name.length(2);

  name[0].id   = (const char*) "test";       // string copied
  name[0].kind = (const char*) "my_context"; // string copied
  name[1].id   = (const char*) "IdServer";
  name[1].kind = (const char*) "Object";
  // 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.)

  try {
    // Resolve the name to an object reference.
    return rootContext->resolve(name);
  } catch(CosNaming::NamingContext::NotFound& ex) {
    // This exception is thrown if any of the components of the
    // path [contexts or the object] aren't found:
    cerr << "Context not found." << endl;
  } 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;

  } catch(CORBA::SystemException& ex) {
    cerr << "Caught a CORBA::" << ex._name()
	 << " while using the naming service." << endl;
    return 0;
  }

  return CORBA::Object::_nil();
}
int ACE_TMAIN(int argc, ACE_TCHAR * argv[])
{
    try
    {
        // Initialize orb
        CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

        CORBA::Object_var rootObj =
            orb->resolve_initial_references("NameService");

        CosNaming::NamingContext_var rootContext =
            CosNaming::NamingContext::_narrow(rootObj.in());

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

        CORBA::Object_var messengerObj = rootContext->resolve(name);

        if (CORBA::is_nil(messengerObj.in())) {
            std::cerr << "Nil Messenger reference" << std::endl;
            return 1;
        }

        // Narrow
        Messenger_var messenger = Messenger::_narrow(messengerObj.in());
        if (CORBA::is_nil(messenger.in ())) {
            std::cerr << "Argument is not a Messenger reference" << std::endl;
            return 1;
        }

        CORBA::String_var message = CORBA::string_dup(
                                        "We are experiencing network problems.");
        messenger->send_message ("*****@*****.**",
                                 "urgent",
                                 message.inout());

        message = CORBA::string_dup("Where can I get TAO?");
        messenger->send_message ("*****@*****.**",
                                 "OCI's Distribution of TAO",
                                 message.inout());

        message = CORBA::string_dup(
                      "Please contact [email protected] regarding your request.");
        messenger->send_message ("*****@*****.**",
                                 "OCI's Distribution of TAO",
                                 message.inout());

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

    std::cout << "MessengerClient: success" << std::endl;
    return 0;
}
示例#9
0
int main( int argc, char *argv[] )
{
  try 
  {
    // Initialize the CORBA Object Request Broker
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

	// Find the CORBA Services Naming Service
	CORBA::Object_var naming_obj = orb->resolve_initial_references("NameService");
	CosNaming::NamingContext_var root = CosNaming::NamingContext::_narrow(naming_obj.in());
	if(CORBA::is_nil(root.in()))
	{
		cerr << "Could not narrow NameService to NamingContext!" << endl;
		throw 0;
	}

    // Resolve the desired object (ExampleInterfaces.IAdder).
	// The module and interface bindings need to be the same here in the client as they
	// are in the server.
    CosNaming::Name name;
    name.length(2);
    name[0].id = CORBA::string_dup( "ExampleInterfaces" );	// IDL-defined Module (namespace)
    name[1].id = CORBA::string_dup( "IAdder" );				// IDL-defined Interface (interface class)
    CORBA::Object_var obj = root->resolve(name);

    // Narrow to confirm that we have the interface we want.
	ExampleInterfaces::IAdder_var iAdder = ExampleInterfaces::IAdder::_narrow(obj.in());
    if (CORBA::is_nil(iAdder.in())) 
	{
      cerr << "Could not narrow to an iAdder reference" << endl;
      return 1;
    }

	// Now use the remote object...
	cout << "Using a remote object that implements the IAdder interface..." << endl;
	cout << endl;
	double number1 = 0;
	double number2 = 0;
	double sum = 0;
	while (true)
	{
		cout << "Enter the first number: ";
		cin >> number1;
		cout << "Enter the second number: ";
		cin >> number2;
		sum = iAdder->add(number1, number2);
		cout << "The sum is: " << sum << endl;
		cout << "------------------" << endl;
	}
  }
  catch ( CORBA::Exception& ex ) {
    cerr << "Caught a CORBA::Exception: " << ex << endl;
    return 1;
  }
  
  return 0;
}
示例#10
0
static void checkLogging(ACSDaemonContext * context, short instance)
{
	if (!loggingSystemInitialized)
	{
		// we need msg_callback to get LoggingProxy
		if (ACE_LOG_MSG->msg_callback () != 0 &&
				context->hasConfigurationReference(instance, acsServices[NAMING_SERVICE].xmltag))
		{
			try
			{
				// we get via NS and not a manager (to support logging when manager is not running)
				std::string nsReference = context->getConfigurationReference(instance, acsServices[NAMING_SERVICE].xmltag);
				CORBA::Object_var nc_obj = context->getORB()->string_to_object(nsReference.c_str());
				if (nc_obj.ptr() != CORBA::Object::_nil())
				{
					CosNaming::NamingContext_var nc = CosNaming::NamingContext::_narrow(nc_obj.in());
					if (nc.ptr() != CosNaming::NamingContext::_nil())
					{
						CosNaming::Name name;
						name.length(1);
						name[0].id = CORBA::string_dup("Log");

						CORBA::Object_var obj = nc->resolve(name);
						if (!CORBA::is_nil(obj.in()))
                    	{
							Logging::AcsLogService_var logger = Logging::AcsLogService::_narrow(obj.in());

							LoggingProxy* lp = static_cast<LoggingProxy*>(ACE_LOG_MSG->msg_callback());
							lp->setCentralizedLogger(logger.in());
							lp->setNamingContext(nc.in());
                            loggingSystemInitialized = true;
                            ACS_SHORT_LOG((LM_DEBUG, "Remote logging system initialized."));
                        }
						else
						{
							ACS_SHORT_LOG((LM_DEBUG, "Unable to resolve Log from the naming service."));
						}
					}
					else
					{
						ACS_SHORT_LOG((LM_DEBUG, "Unable to narrow NamingContext."));
					}
				}
				else
				{
					ACS_SHORT_LOG((LM_ERROR, "Unable to resolve naming service, invalid corbaloc reference: '%s'.", nsReference.c_str()));
				}
			}
			catch (...)
			{
				ACS_SHORT_LOG((LM_DEBUG, "Unable to initialize logging sytem, unexpected exception caught."));
			}
		}
	}
}
示例#11
0
CORBA::Object_ptr 
VOmniORBHelper::nsGetObject(const char* program, const char* object,
			    int telescopenumber)
  throw(CORBA::SystemException, 
	CosNaming::NamingContext::NotFound,
	CosNaming::NamingContext::CannotProceed,
	CosNaming::NamingContext::InvalidName)
{
  CosNaming::NamingContext_var root = nsRootContext();
  CosNaming::Name_var name = 
    nsPathToObjectName(program,object,telescopenumber);
  CORBA::Object_ptr obj = root->resolve(name);
  return obj;
}
示例#12
0
CORBA::Object_ptr getObjectReference(CORBA::ORB_ptr orb, const char serviceName[])
{  
   CosNaming::NamingContext_var rootContext;

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

      // Narrow the object returned by resolve_initial_references() to a CosNaming::NamingContext 
      // object
      rootContext = CosNaming::NamingContext::_narrow(initServ);
      if (CORBA::is_nil(rootContext))
      {  
         cerr << "Failed to narrow naming context." << endl;
         return CORBA::Object::_nil();
      }
   }
   catch (CORBA::ORB::InvalidName&)
   {  
      cerr << "Name service does not exist." << endl;
      return CORBA::Object::_nil();
   }

   // Create a name object, containing the name corejava/SysProp:
   CosNaming::Name name;
   name.length(1);

   name[0].id   = serviceName;
   name[0].kind = "Object";

   CORBA::Object_ptr obj;
   try
   {  
      // Resolve the name to an object reference, and assign the returned reference to a 
      // CORBA::Object:
      obj = rootContext->resolve(name);
   }
   catch (CosNaming::NamingContext::NotFound&)
   {  
      // This exception is thrown if any of the components of the path [contexts or the object] 
      // aren't found:
      cerr << "Context not found." << endl;
      return CORBA::Object::_nil();
   }
   return obj;
}
示例#13
0
void
ClientInitializer::post_init (PortableInterceptor::ORBInitInfo_ptr info)
{
  // Find the Naming Service
  CORBA::Object_var naming_obj =
    info->resolve_initial_references("NameService");
  CosNaming::NamingContext_var root =
    CosNaming::NamingContext::_narrow(naming_obj.in());
  if( CORBA::is_nil(root.in())) {
    std::cerr << "Nil Naming Context reference" << std::endl;
    ACE_ASSERT(false);
  }

  // Resolve the Messenger object
  CosNaming::Name name;
  name.length( 1 );
  name[0].id = CORBA::string_dup( "Messenger" );
  CORBA::Object_var obj = CORBA::Object::_nil();
  while ( CORBA::is_nil( obj.in() ) ) {
    try {
      obj = root->resolve( name );
    } catch (const CosNaming::NamingContext::NotFound&) {
      // Sleep for a second and try again
      ACE_OS::sleep(1);
    }
   }

  Messenger_var messenger = Messenger::_narrow( obj.in() );
  if( CORBA::is_nil( messenger.in() ) ) {
    std::cerr << "Not a Messenger reference" << std::endl;
    ACE_ASSERT(false);
  }

  // allocate slot
  slot_ = info->allocate_slot_id();

  // get PICurrent
  CORBA::Object_var current_obj = info->resolve_initial_references("PICurrent");

  current_ =
    PortableInterceptor::Current::_narrow(current_obj.in());

  // Create and register the request interceptors.
  PortableInterceptor::ClientRequestInterceptor_var ci =
      new ClientInterceptor(messenger, current_.in(), slot_);
  info->add_client_request_interceptor (ci.in());
}
/** Bind a context to the corba root, with a given name.
 */
void CorbaServerGeneric::
createContext( const std::string & contextStrName )
{

  try {

    /* Obtains a reference to the root context of the Name service
     * and narrows the reference returned. */
    CosNaming::NamingContext_var rootContext = CosNaming::NamingContext::
      _narrow(orb->resolve_initial_references("NameService"));
    if( CORBA::is_nil(rootContext) )
      {
        std::cerr << "Failed to narrow the root naming context." << std::endl;
        throw "TODO";
      }

    /* Create the name of the context. */
    CosNaming::Name contextName;
    contextName.length(1);
    contextName[0].id   = CORBA::string_dup(contextStrName.c_str());
    contextName[0].kind = CORBA::string_dup("context");
    /* 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. hpp.ps = postscript etc.). */

    /* Bind a context called <contextName> to the root context. */
    try{ hppContext = 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 hppContext
         * to the object returned. */
        hppContext = CosNaming::NamingContext::
          _narrow(rootContext->resolve(contextName));
        if( CORBA::is_nil(hppContext) )
          {
            std::cerr << "Failed to narrow naming context." << std::endl;
            throw "TODO";
          }
      }
  } HPP_RETHROW("Creating context");

  return;
}
int loadBodyFromModelLoader(::World* world, const char* name, const char *url, CosNaming::NamingContext_var cxt)
{
    CosNaming::Name ncName;
    ncName.length(1);
    ncName[0].id = CORBA::string_dup("ModelLoader");
    ncName[0].kind = CORBA::string_dup("");
    ModelLoader_var modelLoader = NULL;
    try {
        modelLoader = ModelLoader::_narrow(cxt->resolve(ncName));
    } catch(const CosNaming::NamingContext::NotFound &exc) {
        std::cerr << "ModelLoader not found: ";
        switch(exc.why) {
        case CosNaming::NamingContext::missing_node:
            std::cerr << "Missing Node" << std::endl;
        case CosNaming::NamingContext::not_context:
            std::cerr << "Not Context" << std::endl;
            break;
        case CosNaming::NamingContext::not_object:
            std::cerr << "Not Object" << std::endl;
            break;
        }
        return 0;
    } catch(CosNaming::NamingContext::CannotProceed &exc) {
        std::cerr << "Resolve ModelLoader CannotProceed" << std::endl;
    } catch(CosNaming::NamingContext::AlreadyBound &exc) {
        std::cerr << "Resolve ModelLoader InvalidName" << std::endl;
    }

	BodyInfo_var bodyInfo;
	try {
		bodyInfo = modelLoader->getBodyInfo(url);
	} catch(CORBA::SystemException& ex) {
		std::cerr << "CORBA::SystemException raised by ModelLoader: " << ex._rep_id() << std::endl;
		return 0;
	} catch(ModelLoader::ModelLoaderException& ex){
		std::cerr << "ModelLoaderException ( " << ex.description << ") : " << ex.description << std::endl;
	}

	if(CORBA::is_nil(bodyInfo)){
		return 0;
	}

	return loadBodyFromBodyInfo(world, name, bodyInfo);
}
示例#16
0
static CORBA::Object_ptr
get_distributor_reference (CORBA::ORB_ptr orb)
{
  if (use_naming)
    {
      CORBA::Object_var tmp =
        orb->resolve_initial_references ("NameService");

      CosNaming::NamingContext_var pns =
        CosNaming::NamingContext::_narrow (tmp.in ());

      CosNaming::Name name (1);
      name.length (1);
      name[0].id = distributor_name.c_str ();

      return pns->resolve (name);
    }
  else
    // Read and destringify the Stock_Distributor object's IOR.
    return orb->string_to_object (ior.c_str ());
}
示例#17
0
void
IdAssignment::init (int argc,
                    ACE_TCHAR *argv[])
{
  CORBA::ORB_var orb = CORBA::ORB_init (argc,
                                        argv);

  CORBA::Object_var rootObj =
    orb->resolve_initial_references ("NameService");

  if (CORBA::is_nil (rootObj.in ()))
    {
      ACE_ERROR ((LM_ERROR,
                  " (%P|%t) Unable to resolve naming service !\n"));
      return;

    }
  CosNaming::NamingContext_var rootNC =
    CosNaming::NamingContext::_narrow (rootObj.in ());

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

  CORBA::Object_var obj = rootNC->resolve (name);

  if (CORBA::is_nil (obj.in ()))
    {
      ACE_ERROR ((LM_ERROR,
                  " (%P|%t) Unable to locate Notify_Service\n"));
      return;
    }

  this->notify_factory_ =
    CosNotifyChannelAdmin::EventChannelFactory::_narrow (
        obj.in()
      );

}
  /*!
   * @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;
  }
示例#19
0
	RemoteConnector::RemoteConnector          (const std::string& service_id, const std::string& debug_level, const std::string& client_id) {
		
		try {

            if (!client_id.empty()) {
                m_client_id = client_id;
            } else {
                std::stringstream ss;
                ss << (size_t)this;
                m_client_id = ss.str();
            }
			
			// Initialise ORB
			int         i            = 0;
			char**      c            = 0;
			const char* options[][2] = { { (char*)"traceLevel", debug_level.c_str()}, { 0, 0 } };
			
			m_orb = CORBA::ORB_init(i, c, "omniORB4", options);
			
			// Bind ORB object to name service object
			CORBA::Object_var obj = m_orb->resolve_initial_references("NameService");
			assert (!CORBA::is_nil(obj.in()));
			
			// Narrow this to the naming context
			CosNaming::NamingContext_var context  = CosNaming::NamingContext::_narrow(obj.in());
			assert (!CORBA::is_nil(context.in()));
			
			// Bind to the name server and lookup 
			CosNaming::Name m_name;
			m_name.length(1);
			m_name[0].id = CORBA::string_dup(service_id.c_str());
			
			// Resolve object reference.
			CORBA::Object_var orid = context->resolve(m_name);
			assert(!CORBA::is_nil(orid.in()));
			
			m_rrsi       = RRSInterface::_narrow(orid.in());
			if (CORBA::is_nil(m_rrsi.in()))
				std::cerr << "IOR is not an SA object reference." << std::endl;
			
		} catch (CORBA::COMM_FAILURE&)        {
			
			std::cerr << "Caught system exception COMM_FAILURE -- unable to contact the object.\n" << std::endl;
			throw DS_ServerConnectionException();
			return;
			
		} catch (CORBA::SystemException&)     {
            
			std::cerr << "Caught a CORBA::SystemException." << std::endl;
			throw DS_SystemException();
			return;
			
		} catch (CORBA::Exception&)           {
			
			std::cerr << "Caught CORBA::Exception." << std::endl;
			throw DS_Exception();
			return;
			
		} catch (omniORB::fatalException& fe) {
			
			std::cerr << "Caught omniORB::fatalException:" << std::endl;
			std::cerr << "  file: " << fe.file() << std::endl;
			std::cerr << "  line: " << fe.line() << std::endl;
			std::cerr << "  mesg: " << fe.errmsg() << std::endl;
			throw DS_FatalException();
			return;
			
		} catch(...) {
			
			std::cerr << "Caught unknown exception." << std::endl;
			throw DS_Exception();
			return;
			
		}
		
	}
示例#20
0
void COSBindingNode::walkBranches(CosNaming::NamingContext_var& nodeContext)
{
	CosNaming::NamingContext_var newNodeContext;
	CosNaming::Binding_var binding( new CosNaming::Binding );

	CosNaming::BindingIterator_var biIterVar( new CosNaming::_objref_BindingIterator );
	CosNaming::BindingIterator_out biIter( biIterVar );

	CosNaming::BindingList_var biListVar( new CosNaming::BindingList );
	CosNaming::BindingList_out biList( biListVar );
	
	CORBA::Object_var obj;

	unsigned i = 0;
	
	if(CORBA::is_nil(nodeContext))
	{
		_isLeaf = true;
		
		//No need to iterate through the tree; this is a leaf.
		return;
	}
	
	try {
		nodeContext->list(0, biList, biIter);
	}
	catch(CORBA::TRANSIENT&) {
		_isDead = true;
	}
	catch(CORBA::INV_OBJREF&) {
		_isLeaf = true;
	}
	catch(CORBA::Exception&) {
	}
	catch(...)  {
		std::cerr << "Other list exception." << std::endl;
	}

	if( isLeaf() )
	{
		//No need to iterate through the tree; this is a leaf.
		return;
	}

	bool deadServantFound = false;

	while(biIter->next_one(binding))
	{
		i++;
		//get the context for this branch and add a new node
		obj = nodeContext->resolve( binding->binding_name );

		try {
			obj->_non_existent();
		}
		catch(CORBA::TRANSIENT&)
		{
			//This is a dead servant. 
			deadServantFound = true;

			addBranch(std::string(omni::omniURI::nameToString(binding->binding_name)));

			//_branches.push_back( 
			//	new COSBindingNode(
			//	omni::omniURI::nameToString( binding->binding_name ), true) );
		}
		catch(CORBA::COMM_FAILURE)
		{
			//This is a dead servant. 
			deadServantFound = true;

			addBranch(std::string(omni::omniURI::nameToString(binding->binding_name)));
			//_branches.push_back(
			//	new COSBindingNode(
			//	omni::omniURI::nameToString( binding->binding_name ), true) );
		}

		if( !deadServantFound )
		{
			try {
				newNodeContext = CosNaming::NamingContext::
					_narrow( obj );
			}
			catch(...)
			{
				std::cerr << "Branch list exception: _narrow" << std::endl;
			}

			try {
				addBranch(std::string(omni::omniURI::nameToString(binding->binding_name)), newNodeContext);
				
				//_branches.push_back( 
				//	new COSBindingNode(
				//	omni::omniURI::nameToString( binding->binding_name ), newNodeContext)
				//	);
			}
			catch(CORBA::INV_OBJREF&)
			{
				std::cerr << "Branch list exception: push_back" << std::endl;
			}
		}
	}

}
void
ComponentDeployment::init()
throw (DeploymentFailure)
{
	int dummy = 0;
	CORBA::ORB_var orb = CORBA::ORB_init (dummy, 0);

    //
	// get NameService
	//
    if (! initNameService(orb))
    {
        throw DeploymentFailure();
    }

	//
	// try to get a local AssemblyFactory
	//
	char hostname[256];
	gethostname(hostname, 256);
	CORBA::Object_var obj = resolveName(std::string("Qedo/AssemblyFactory/") + hostname);
	assemblyFactory_ = Components::Deployment::AssemblyFactory::_narrow( obj.in() );
    if( !CORBA::is_nil( assemblyFactory_.in() ) && 
		!assemblyFactory_->_non_existent() )
	{
		std::cerr << "..... take assembly factory on " << hostname << std::endl;
		return;
	}

	//
	// try to get another one
	//
	std::cerr << "..... no local assembly factory, try to get another one" << std::endl;

	obj = resolveName(std::string("Qedo/AssemblyFactory"));
	CosNaming::NamingContext_var ctx = CosNaming::NamingContext::_narrow( obj.in() );
	if( !CORBA::is_nil( ctx.in() ) )
	{
		CosNaming::BindingList_var list;
		CosNaming::BindingIterator_var iter;
		try
		{
			ctx->list(10, list.out(), iter.out());
		}
		catch (...)
		{
		}

		for(CORBA::ULong i = 0; i < list->length(); i++)
		{
			try
			{
				obj = ctx->resolve(list[i].binding_name);
			}
			catch (...)
			{
				continue;
			}
			assemblyFactory_ = Components::Deployment::AssemblyFactory::_narrow( obj.in() );
			if( !CORBA::is_nil( assemblyFactory_.in() ) &&
				!assemblyFactory_->_non_existent() )
			{
				std::cerr << "..... take assembly factory on " << list[i].binding_name[0].id << std::endl;
				return;
			}
		}
	}

	//
	// use our own assembly
	//
	// todo


	std::cerr << "!!!!! no assembly factory found" << std::endl;
	throw DeploymentFailure();
}
示例#22
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;
}
示例#23
0
::ComponentServerActivatorInfoList* Explore_impl::explore_qedo()
{	
	
	
	//CORBA::ORB_var e_orb=CORBA::ORB_init(e_argc,e_argv);

	// get name services reference
	CORBA::Object_var nsobj = e_orb->resolve_initial_references("NameService");
	CosNaming::NamingContext_var nc = CosNaming::NamingContext::_narrow(nsobj);
	CORBA::Object_var saobj = e_orb ->resolve_initial_references("NameService");
		
	/*
	if (CORBA::is_nil(nc)) {

		cerr << "Kann den Naming Service nicht finden!" << endl;
		cin >> t;
		exit(1);

	}
	
	if (CORBA::is_nil(saobj)) {
		cout << "ServerActivator kann nicht gefunden werden" << endl;
		cin >>  t;
		exit(1);
	} */



	// get server activator reference
	char hostname[256];
	//int gethostname;
	 gethostname (hostname, 256);
	if (gethostname (hostname, 256))
	{
		std::cout<< "Kann Hostname nicht finden"<<endl;
		e_orb->destroy();
		exit(1);
	}
	
	
	CosNaming::Name cname;
	cname.length(2);
	cname[0].id=CORBA::string_dup("Qedo");
	cname[0].kind=CORBA::string_dup("");
	cname[1].id=CORBA::string_dup("Activators");
	cname[1].kind=CORBA::string_dup("");
	
		
	CosNaming::NamingContext_var ncQA = CosNaming::NamingContext::_nil();
	CORBA::Object_var obj = nc->resolve(cname);
	ncQA = CosNaming::NamingContext::_narrow (obj);

	
	CORBA::Object_var server_activator_obj;
		server_activator_obj=nc->resolve(cname);
		CosNaming::BindingList *test;
		CosNaming::BindingIterator *test2;
		ncQA->list(100,test,test2);



		CosNaming::BindingList_var bl = test;
		CosNaming::BindingIterator_var bi = test2;
		std::cout<< bl->length() << " ServerActivator gefunden" << endl;
		

	ComponentServerActivatorInfoList_var Activatorlist=new ComponentServerActivatorInfoList;
	for (int as=0;as<bl->length();as++) {

			
			CosNaming::Binding b=bl->operator [](as);
			

			CosNaming::Name name;
			name.length(3);
			name[0].id=CORBA::string_dup("Qedo");
			name[0].kind=CORBA::string_dup("");
			name[1].id=CORBA::string_dup("Activators");
			name[1].kind=CORBA::string_dup("");
			name[2].id=CORBA::string_dup(b.binding_name[0].id);
			name[2].kind=CORBA::string_dup("");

	

	try {
		std::cout<< "ServerActivator: " << b.binding_name[0].id << endl;
		server_activator_obj=nc->resolve(name);

	}
	catch (CosNaming::NamingContext::NotFound_catch &exec) {
		std::cerr << "Notfound" << endl;
	}
	catch (CosNaming::NamingContext::CannotProceed_catch &exec) {
		std::cerr << "CannotProceed" <<endl;
	}
	catch (CosNaming::NamingContext::InvalidName_catch &exec) {
		std::cout << "InvalidName exception"<<endl;
	}

	
	Components::Deployment::ServerActivator_var server_activator ;
	try {
		server_activator= Components::Deployment::ServerActivator::_narrow(server_activator_obj);
	} 
	catch (CORBA::SystemException&) 
	{
		std::cout<<"Cannon narrow"<<endl;
		e_orb->destroy();
		exit(1);
	}
	

	
	// get Component Servers
	
	Components::Deployment::ComponentServers *component_servers = 
	server_activator -> get_component_servers();
	

	std::cout << "ServerActivator liefert " << component_servers->length() << " Component Server"<< endl;

	
	ComponentServerActivatorInfo ComponentServerActivator;
	const char* host="schlepptop";
	ComponentServerActivator.host_name=(const char*)hostname;
	ComponentServerActivator.component_server_activator_ref=server_activator;
	
	ComponentServerInfoList ComponentServerList;
	ComponentServerList.length(component_servers->length());
	

	for (int i=1; i<=component_servers->length(); i++) {
		
	std::cout<<"ComponentServer " << i-1 << endl;	


		Components::Deployment::ComponentServer_var comp_server = 
			Components::Deployment::ComponentServer::_duplicate((*component_servers)[i-1]);

		ComponentServerInfo ComponentServer;

		// Der Hostname muss noch gefunden werden

		const char* host="schlepptop";
		ComponentServer.host_name=(const char*)hostname;
		ComponentServer.component_server_ref=comp_server;

		Components::Deployment::Containers *comp_containers = 
			comp_server->get_containers();
		ContainerInstanceInfoList ContainerList;
		ContainerList.length(comp_containers->length());

		std::cout<< " ->" << comp_containers->length() << " Container"<<endl;



		for (int y=1; y<=comp_containers->length(); y++) {
			std::cout<<"    " << y-1 << " Container" << endl;
			
			
			Components::Deployment::Container_var container = 
				Components::Deployment::Container::_duplicate((*comp_containers)[y-1]);
			
			ContainerInstanceInfo ContainerInfo;
			const char* egal="SESSION";
			
			ContainerInfo.short_name=egal;
			ContainerInfo.container_ref=container;
		   // Components::Deployment::ComponentServer_var test = container->get_component_server();
            Components::CCMHomes *homes = container->get_homes();
			
			HomeInstanceInfoList HomeList;
			HomeList.length(homes->length());
			std::cout<< "  ->" << homes->length() << " Homes" << endl;

			for (int z=1; z<=homes->length(); z++) {

				std::cout<<"     " << z-1 << " Home" << endl;

				Components::CCMHome_var home = 
					Components::CCMHome::_duplicate((*homes)[z-1]);

				HomeInstanceInfo HomeInfo;
				HomeInfo.full_scoped_name=home->get_home_rep_id();
				//std::cout << z << " " << home->get_home_rep_id() << endl;
				std::cout << "    " <<  z-1 << get_short_name(HomeInfo.full_scoped_name)<<endl;
				
				HomeInfo.short_name=get_short_name(HomeInfo.full_scoped_name).c_str();
				//std::cout << "HomeInfo" << HomeInfo.short_name << " " <<  endl;
				HomeInfo.home_ref=home;
				Components::CCMObjects *homeinstances = home->get_instances();
				
				ComponentInstanceInfoList ComponentList;
				ComponentList.length(homeinstances->length());


				for (int a=1; a<=homeinstances->length(); a++) {
				
					Components::CCMObject_var inst=
						Components::CCMObject::_duplicate((*homeinstances)[a-1]);

					ComponentInstanceInfo ComponentInfo;
					//std::cout<<a-1<<endl;
					ComponentInfo.full_scoped_name=home->get_component_rep_id();
					//std::cout<< a-1 << ":" << home->get_component_rep_id()<<endl;
					std::cout<< "        " << a-1 << get_short_name(home->get_component_rep_id()).c_str() << endl;;
					ComponentInfo.short_name=get_short_name(home->get_component_rep_id()).c_str();	
					ComponentInfo.compont_ref=inst;
					ComponentList[a-1]=ComponentInfo;

                } // Ende Components
				
				HomeInfo.my_components=ComponentList;
				HomeList[z-1]=HomeInfo;

			} // Ende Homes
			ContainerInfo.my_homes=HomeList;
			ContainerList[y-1]=ContainerInfo;
		
		} // Ende Container

		ComponentServer.my_containers=ContainerList;
		ComponentServerList[i-1]=ComponentServer;

	} // Ende ComponentServers
	ComponentServerActivator.my_component_servers=ComponentServerList;
	
	
	Activatorlist->length(bl->length());
		
	Activatorlist.inout()[as]=ComponentServerActivator;
	
}
	
//	ComponentServerActivatorInfoList* wert = Activatorlist;
	 
   return Activatorlist._retn() ;


}
ContainerInterfaceImpl::ContainerInterfaceImpl (CORBA::ORB_ptr orb, 
												PortableServer::POA_ptr root_poa, 
												ContainerType container_type,
												ComponentServerImpl* component_server,
												Components::Deployment::ComponentInstallation_ptr component_installer)
: orb_ (CORBA::ORB::_duplicate (orb)),
  root_poa_ (PortableServer::POA::_duplicate (root_poa)),
  container_type_ (container_type),
  component_server_ (component_server),
  component_installer_ (Components::Deployment::ComponentInstallation::_duplicate (component_installer))
{
	component_server_->_add_ref();

	// Retrieve config values
	if (! strcmp (Qedo::ConfigurationReader::instance()->lookup_config_value ("/Events/EventDispatchingStrategy"), "asynchronous"))
	{
		event_communication_mode_ = EVENT_COMMUNICATION_ASYNCHRONOUS;
	}
	else
	{
		event_communication_mode_ = EVENT_COMMUNICATION_SYNCHRONOUS;
	}

	//
	// get home finder
	//
	home_finder_ = Qedo_Components::HomeFinder::_nil();
	CORBA::Object_var obj;

    try
    {
        obj = orb->resolve_initial_references("ComponentHomeFinder");
    }
    catch (const CORBA::ORB::InvalidName&)
    {
        DEBUG_OUT("ContainerInterfaceImpl: No HomeFinder");
		/* Since problem with MICO Initializer a new try directly over the name service*/
		//return;
	
		CosNaming::NamingContext_var nameService;
		
		try
		{
			obj = orb->resolve_initial_references("NameService");
		}
		catch (const CORBA::ORB::InvalidName&)
		{
			std::cerr << "ContainerInterfaceImpl: Can't resolve NameService" << std::endl;
		}

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

		try
		{
			nameService = CosNaming::NamingContext::_narrow(obj.in());
		}
		catch (CORBA::SystemException&)
		{
			std::cerr << "ContainerInterfaceImpl: ORB knows NameService, but I cannot contact it" << std::endl;
		}

		//
		// Resolve the HomeFinder
		//
		CosNaming::Name aName;
	    aName.length(2);
		aName[0].id = CORBA::string_dup("Qedo");
		aName[0].kind = CORBA::string_dup("");
		aName[1].id = CORBA::string_dup("HomeFinder");
		aName[1].kind = CORBA::string_dup("");

		try
		{
			obj = nameService->resolve(aName);
		}
		catch (CosNaming::NamingContext::InvalidName&)
		{
			obj = CORBA::Object::_nil();
		}
		catch (CosNaming::NamingContext::NotFound&)
		{
			obj = CORBA::Object::_nil();
		}
		catch (CORBA::SystemException&)
		{
			obj = CORBA::Object::_nil();
		}
    }
    if (CORBA::is_nil(obj.in())) {
        DEBUG_OUT("ContainerInterfaceImpl: No HomeFinder");
    }

	try
	{
		home_finder_ = Qedo_Components::HomeFinder::_narrow(obj.in());
	}
	catch (const CORBA::SystemException&)
	{
		DEBUG_OUT("ContainerInterfaceImpl: No HomeFinder");
	}
    if (CORBA::is_nil(home_finder_.in())) {
        DEBUG_OUT("ContainerInterfaceImpl: No HomeFinder");
    }

	// Start global event dispatcher thread
	if (event_communication_mode_ == EVENT_COMMUNICATION_ASYNCHRONOUS)
		qedo_startDetachedThread (event_dispatcher_thread, this);
}
void
ComponentServerImpl::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&)
	{
		NORMAL_ERR ("ComponentServerImpl: Fatal error - no root POA available.");
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		NORMAL_ERR ("ComponentServerImpl: Fatal error - cannot narrow root POA.");
		throw CannotInitialize();
	}

	root_poa_manager_ = root_poa_->the_POAManager();

	root_poa_manager_->activate();

	// Convert the stringified object reference from the command line into a usable ComponentServerActivator reference
	CORBA::Object_var csa_obj;
	
	try
	{
		csa_obj = orb_->string_to_object (csa_string_ref_);
	}
	catch (CORBA::BAD_PARAM&)
	{
		NORMAL_ERR ("ComponentServerImpl: Cannot get Component Server Activator object reference from string");
		throw CannotInitialize();
	}


	if (CORBA::is_nil (csa_obj))
	{
		NORMAL_ERR ("ComponentServerImpl: Component Server Activator object reference is nil");
		throw CannotInitialize();
	}

	try
	{
		csa_ref_ = Qedo_Components::Deployment::ServerActivator::_narrow (csa_obj);
	}
	catch (CORBA::SystemException&)
	{
		NORMAL_ERR ("ComponentServerImpl: Cannot narrow Component Server Activator object reference");
		throw CannotInitialize();
	}

	// Now retrieve the Component Installer to be used for containers created by this Component Server
	// From now, we also inform the Component Server Activator to return a nil reference in case of any failure
	// First get the Name Service
	CosNaming::NamingContext_var ns;

	try
	{
		CORBA::Object_var ns_obj = orb_->resolve_initial_references ("NameService");
		ns = CosNaming::NamingContext::_narrow (ns_obj);
	}
	catch (CORBA::ORB::InvalidName&)
	{
		NORMAL_ERR ("ComponentServerImpl: Name Service not found");
		csa_ref_->notify_component_server (Components::Deployment::ComponentServer::_nil());
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		NORMAL_ERR ("ComponentServerImpl: Cannot narrow object reference of Name Service");
		csa_ref_->notify_component_server (Components::Deployment::ComponentServer::_nil());
		throw CannotInitialize();
	}

	if (CORBA::is_nil (ns))
	{
		NORMAL_ERR ("ComponentServerImpl: Name Service is nil");
		csa_ref_->notify_component_server (Components::Deployment::ComponentServer::_nil());
		throw CannotInitialize();
	}

	// Determine the hostname of the host on which I run
	char hostname[256];
	if (gethostname (hostname, 256))
	{
		NORMAL_ERR ("ComponentServerImpl: Cannot determine my hostname");
		csa_ref_->notify_component_server (Components::Deployment::ComponentServer::_nil());
		throw CannotInitialize();
	}

	// Finally resolve the Component Installer
	CosNaming::Name installer_name;
	installer_name.length (3);
	installer_name[0].id = CORBA::string_dup ("Qedo");
	installer_name[0].kind = CORBA::string_dup ("");
	installer_name[1].id = CORBA::string_dup ("ComponentInstallation");
	installer_name[1].kind = CORBA::string_dup ("");
	installer_name[2].id = CORBA::string_dup (hostname);
	installer_name[2].kind = CORBA::string_dup ("");

	CORBA::Object_var component_installer_obj;

	try
	{
		component_installer_obj = ns->resolve (installer_name);
	}
	catch (CosNaming::NamingContext::NotFound&)
	{
		NORMAL_ERR ("ComponentServerImpl: Component Installer not found in Name Service");
		csa_ref_->notify_component_server (Components::Deployment::ComponentServer::_nil());
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		NORMAL_ERR ("ComponentServerImpl: CORBA system exception during resolve()");
		csa_ref_->notify_component_server (Components::Deployment::ComponentServer::_nil());
		throw CannotInitialize();
	}
		
	try
	{
		component_installer_ = Components::Deployment::ComponentInstallation::_narrow (component_installer_obj);
	}
	catch (CORBA::SystemException&)
	{
		NORMAL_ERR ("ComponentServerImpl: Cannot narrow Component Installer");
		csa_ref_->notify_component_server (Components::Deployment::ComponentServer::_nil());
		throw CannotInitialize();
	}

	if (CORBA::is_nil (component_installer_))
	{
		NORMAL_ERR ("ComponentServerImpl: Component Installer is nil");
		csa_ref_->notify_component_server (Components::Deployment::ComponentServer::_nil());
		throw CannotInitialize();
	}

	// Register valuetype factories
	CORBA::ValueFactoryBase* factory;
	factory = new Qedo::ConfigValueFactory_impl();
    orb_->register_value_factory ("IDL:omg.org/Components/ConfigValue:1.0", factory);
	factory = new Qedo::CookieFactory_impl();
    orb_->register_value_factory ("IDL:omg.org/Components/Cookie:1.0", factory);

	Components::Deployment::ComponentServer_var component_server = this->_this();
	csa_ref_->notify_component_server (component_server.in());
	
}
示例#26
0
文件: nsmain.cpp 项目: asdlei00/ACE
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;
}
示例#27
0
void Robot::connect(void)
{
  char buf[ARGNUM][128], *argv[ARGNUM];
  for(int i=0; i<ARGNUM; i++) argv[i]=buf[i];
  std::strcpy(argv[0], ARGV[0]);
  std::sprintf(argv[1], "NameService=corbaloc:iiop:%s:2809/NameService", 
	       this->ipaddr.c_str());
  std::strcpy(argv[2], ARGV[2]);
  std::strcpy(argv[3], ARGV[3]);
  
  int argc=ARGNUM;
  try {
    ::CORBA::ORB_var orb = ::CORBA::ORB_init(argc, argv);
    ::CORBA::Object_var obj = orb->resolve_initial_references("NameService");
    CosNaming::NamingContext_var nsref =CosNaming::NamingContext::_narrow(obj);
  
    CORBA::Object_ptr ref;
  
    CosNaming::Name ncName;
    ncName.length(1);
    ncName[0].kind = "";

    ncName[0].id = "sysCom";
    ref = nsref->resolve(ncName);
    this->sysCom = systemCommand::_narrow(ref);

    ncName[0].id = "armServer";
    ref = nsref->resolve(ncName);
    this->arm = armServer::_narrow(ref);

    ncName[0].id = "coordServer";
    ref = nsref->resolve(ncName);
    this->coord = coordServer::_narrow(ref);

    ncName[0].id = "dio";
    ref = nsref->resolve(ncName);
    this->dio = dioPlugin::_narrow(ref);

  } catch(CORBA::SystemException& e) {
    // [TODO] change message properly
    char mesg[128];
    this->emesg("connect(): Caught CORBA::SystemException.");
    std::sprintf(mesg, "connect():   Exception name = %s", e._name());
    this->emesg(mesg);
    throw;

  } catch(CORBA::Exception&) {
    // [TODO] check message properly
    this->emesg("connect(): Caught CORBA::Exception.");
    throw;

  } catch(omniORB::fatalException& fe) {
    // [TODO] check message properly
    char mesg[128];
    this->emesg("connect(): Caught omniORB::fatalException:" );
    std::sprintf(mesg, "connect():   file: %s", fe.file());
    this->emesg(mesg);
    std::sprintf(mesg, "connect():   line: %d", fe.line());
    this->emesg(mesg);
    std::sprintf(mesg, "connect():   mesg: %s", fe.errmsg());
    this->emesg(mesg);
    throw;

  } catch(...) {
    this->emesg("connect(): Caught unknown exception.");
    throw;
  }
  
  this->rarm.connect(this->arm);
  this->larm.connect(this->arm);
  this->rhand.connect(this->arm, this->coord);
  this->lhand.connect(this->arm, this->coord);
}
示例#28
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;
}
示例#29
0
文件: server.cpp 项目: OspreyHub/ATCD
CORBA::Object_ptr
join_object_group (CORBA::ORB_ptr orb,
                   CosLoadBalancing::LoadManager_ptr lm,
                   const PortableGroup::Location & location)
{
  CORBA::Object_var ns_object =
    orb->resolve_initial_references ("NameService");

  CosNaming::NamingContext_var nc =
    CosNaming::NamingContext::_narrow (ns_object.in ());

  CosNaming::Name name (1);
  name.length (1);

  name[0].id = "RoundtripObjectGroup";
  name[0].kind = "Object Group";

  CORBA::Object_var group;

  try
    {
      group = nc->resolve (name);
    }
  catch (const CosNaming::NamingContext::NotFound& )
    {
      // Object group not created.  Create one.
      const char repository_id[] = "IDL:Test/Roundtrip:1.0";

      PortableGroup::Criteria criteria (1);
      criteria.length (1);

      PortableGroup::Property & property = criteria[0];
      property.nam.length (1);

      property.nam[0].id =
        CORBA::string_dup ("org.omg.PortableGroup.MembershipStyle");

      PortableGroup::MembershipStyleValue msv =
        PortableGroup::MEMB_APP_CTRL;
      property.val <<= msv;

      PortableGroup::GenericFactory::FactoryCreationId_var fcid;

      group = lm->create_object (repository_id,
                                 criteria,
                                 fcid.out ());

      try
        {
          nc->bind (name,
                    group.in ());

          PortableGroup::Properties props (1);
          props.length (1);
          props[0].nam.length (1);
          props[0].nam[0].id =
            CORBA::string_dup ("org.omg.CosLoadBalancing.StrategyInfo");

          CosLoadBalancing::StrategyInfo strategy_info;

          strategy_info.name = CORBA::string_dup (strategy);

          if (ACE_OS::strcasecmp (strategy, "LeastLoaded") == 0
              && (reject_threshold != 0
                  || critical_threshold != 0
                  || dampening != 0))
            {
              CORBA::ULong len = 1;

              PortableGroup::Properties & props =
                strategy_info.props;

              if (reject_threshold != 0)
                {
                  const CORBA::ULong i = len - 1;

                  props.length (len++);

                  props[i].nam.length (1);
                  props[i].nam[0].id =
                    CORBA::string_dup ("org.omg.CosLoadBalancing.Strategy.LeastLoaded.RejectThreshold");
                  props[i].val <<= reject_threshold;
                }

              if (critical_threshold != 0)
                {
                  const CORBA::ULong i = len - 1;

                  props.length (len++);

                  props[i].nam.length (1);
                  props[i].nam[0].id =
                    CORBA::string_dup ("org.omg.CosLoadBalancing.Strategy.LeastLoaded.CriticalThreshold");
                  props[i].val <<= critical_threshold;
                }

              if (dampening != 0)
                {
                  const CORBA::ULong i = len - 1;

                  props.length (len++);

                  props[i].nam.length (1);
                  props[i].nam[0].id =
                    CORBA::string_dup ("org.omg.CosLoadBalancing.Strategy.LeastLoaded.Dampening");
                  props[i].val <<= dampening;
                }

            }

          props[0].val <<= strategy_info;

          lm->set_default_properties (props);
        }
      catch (const CosNaming::NamingContext::AlreadyBound& )
        {
          // Somebody beat us to creating the object group.  Clean up
          // the one we created.
          lm->delete_object (fcid.in ());

          group = nc->resolve (name);
        }
    }

  Roundtrip * roundtrip_impl;
  ACE_NEW_THROW_EX (roundtrip_impl,
                    Roundtrip (orb),
                    CORBA::NO_MEMORY ());

  PortableServer::ServantBase_var owner_transfer (roundtrip_impl);

  Test::Roundtrip_var roundtrip =
    roundtrip_impl->_this ();

  group = lm->add_member (group.in (),
                          location,
                          roundtrip.in ());

  return group._retn ();
}
示例#30
0
文件: client.cpp 项目: CCJY/ATCD
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

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

      CORBA::Object_var tmp =
        orb->string_to_object("corbaloc:iiop:1.2@localhost:9931/NameService");

      CosNaming::NamingContext_var root =
        CosNaming::NamingContext::_narrow(tmp.in());

      if (CORBA::is_nil (root.in ()))
        {
          ACE_ERROR_RETURN ((LM_DEBUG,
                             "Nil NamingService reference\n"),
                            1);
        }

      ACE_DEBUG ((LM_INFO, "**** Narrowed root NamingContext\n"));

      CosNaming::Name name;
      name.length(2);
      name[0].id = CORBA::string_dup("example");
      name[1].id = CORBA::string_dup("Hello");

      try
        {
          tmp = root->resolve (name);
          ACE_DEBUG ((LM_INFO, "**** Resolved #example/Hello\n"));

          Test::Hello_var hello =
            Test::Hello::_narrow(tmp.in ());

          if (CORBA::is_nil (hello.in ()))
            {
              ACE_ERROR_RETURN ((LM_DEBUG,
                                 "Nil Test::Hello reference\n"),
                                1);
            }

          CORBA::String_var the_string = hello->get_string ();

          ACE_DEBUG ((LM_DEBUG, "(%P|%t) - string returned <%C>\n",
                      the_string.in ()));

          hello->shutdown ();
        }
      catch (const CosNaming::NamingContext::CannotProceed&)
        {
          ACE_DEBUG ((LM_DEBUG, "Caught correct exception\n"));
        }

      if (shutdown_nsmain)
        {
          CORBA::Object_var shutdowntmp = orb->string_to_object(ior);

          Test::NsShutdown_var shutdown =
            Test::NsShutdown::_narrow(shutdowntmp.in ());

          ACE_DEBUG ((LM_DEBUG, "Shutdown nsmain\n"));
          shutdown->shutdown ();
        }

      orb->shutdown ();
      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;
}