Beispiel #1
0
void CNamingTreeCtrl::OnContextPopupBindContext()
{
  // TODO: Add your command handler code here
  CBindDialog Dialog(true, m_pORB);
  if(Dialog.DoModal() != IDOK)
  {
    return;
  }
  try
  {
    CNamingObject* pObject = GetTreeObject();
    CosNaming::NamingContext_var Context = pObject->NamingContext();
    if(CORBA::is_nil(Context.in ()))
    {
      return;
    }
    CosNaming::NamingContext_var NewContext = CosNaming::NamingContext::_narrow(Dialog.GetObject());
    if(CORBA::is_nil(NewContext.in ()))
    {
      AfxMessageBox(ACE_TEXT ("Object is not a CosNaming::NamingContext"));
      return;
    }
    Context->bind_context(Dialog.GetName(), NewContext);
    OnContextPopupRefresh();
  }
  catch(CORBA::Exception& ex)
  {
    MessageBox(ACE_TEXT_CHAR_TO_TCHAR (ex._rep_id()), ACE_TEXT ("CORBA::Exception"));
  }
}
Beispiel #2
0
CosNaming::NamingContext_ptr
TAO_Hash_Naming_Context::bind_new_context (const CosNaming::Name& n)
{
  // 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 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 binding should take place, then perform the operation 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];
      return context->bind_new_context (simple_name);
    }

  // If we received a simple name, we need to bind it in this context.

  // Stores our new Naming Context.
  CosNaming::NamingContext_var result = CosNaming::NamingContext::_nil ();

  // Create new context.
  result = this->new_context ();

  // Bind the new context to the name.
  try
    {
      this->bind_context (n, result.in ());
    }
  catch (const CORBA::Exception&)
    {
      // If the bind() operation fails we must destroy the recently
      // created context, should any exceptions be raised by the
      // destroy() operation we want to ignore them.
      {
        try
          {
            result->destroy ();
          }
        catch (const CORBA::Exception&)
          {
          }
      }
      // Re-raise the exception in bind_context()
      throw;
    }
  return result._retn ();
}
Beispiel #3
0
void CNamingTreeCtrl::OnContextpopupBindnewcontext()
{
  // TODO: Add your command handler code here
  HTREEITEM hItem = GetSelectedItem();
  CNamingObject* pObject = GetTreeObject(hItem);
  CosNaming::NamingContext_var Context = pObject->NamingContext();
  if(CORBA::is_nil(Context.in ()))
  {
    return;
  }
  CBindNewContext Dialog;
  if(Dialog.DoModal() != IDOK)
  {
    return;
  }
  try
  {
    CosNaming::NamingContext_var NewContext = Context->new_context();
    Context->bind_context(Dialog.GetName(), NewContext);
    OnContextPopupRefresh();
  }
  catch(CORBA::Exception& ex)
  {
    MessageBox(ACE_TEXT_CHAR_TO_TCHAR (ex._rep_id()), ACE_TEXT ("CORBA::Exception"));
  }
}
Beispiel #4
0
void
TAO_Hash_Naming_Context::bind_context (const CosNaming::Name &n,
                                       CosNaming::NamingContext_ptr nc)
{
  // Check to make sure this object didn't have <destroy> method
  // invoked on it.
  if (this->destroyed_)
    throw CORBA::OBJECT_NOT_EXIST ();

  // Do not allow binding of nil context reference.
  if (CORBA::is_nil (nc))
    throw CORBA::BAD_PARAM ();

  // 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 binding should take place, then perform the binding 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->bind_context (simple_name, nc);
        }
      catch (const CORBA::SystemException&)
        {
          throw CosNaming::NamingContext::CannotProceed(
            context.in (), simple_name);
        }
    }
  // If we received a simple name, we need to bind it in this context.
  else
    {
      ACE_WRITE_GUARD_THROW_EX (TAO_SYNCH_RW_MUTEX, ace_mon,
                                this->lock_,
                                CORBA::INTERNAL ());

      // Try binding the name.
      int result = this->context_->bind (n[0].id,
                                        n[0].kind,
                                        nc,
                                        CosNaming::ncontext);
      if (result == 1)
        throw CosNaming::NamingContext::AlreadyBound();

      // Something went wrong with the internal structure
      else if (result == -1)
        throw CORBA::INTERNAL ();
    }
}
Beispiel #5
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 #6
0
void
TAO_Hash_Naming_Context::rebind_context (const CosNaming::Name &n,
                                         CosNaming::NamingContext_ptr nc)
{
  // 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_context (simple_name, nc);
        }
      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,
                                           nc,
                                           CosNaming::ncontext);
      // Check for error conditions.
      if (result == -1)
        throw CORBA::INTERNAL ();

      else if (result == -2)
        throw CosNaming::NamingContext::NotFound(
          CosNaming::NamingContext::not_context,
          n);
    }
}
Beispiel #7
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;
}
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."));
			}
		}
	}
}
Beispiel #9
0
int
MT_Test::execute (TAO_Naming_Client &root_context)
{
  if (CORBA::is_nil (this->orb_.in ()))
    return -1;

  // Create data which will be used by all threads.

  // Dummy object instantiation.
  My_Test_Object *test_obj_impl =
    new My_Test_Object (CosNaming_Client::OBJ1_ID);

  try
    {
      test_ref_ =
        test_obj_impl->_this ();

      test_obj_impl->_remove_ref ();

      // Get the IOR for the Naming Service.  Each thread can use it
      // in <string_to_object> to create its own stub for the Naming
      // Service.  This 'trick' is necessary, because multiple threads
      // cannot be using the same stub - bad things happen...  This is
      // just a way to give each thread its own stub.

      CosNaming::NamingContext_var context =
        root_context.get_context ();

      name_service_ior_ =
        orb_->object_to_string (context.in ());

    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        "Unexpected exception while instantiating dummy");
      return -1;
    }

  // Create a name for dummy.
  test_name_.length (1);
  test_name_[0].id = CORBA::string_dup ("Foo");

  // Spawn threads, each of which will be executing svc ().
  int status = this->activate (THR_NEW_LWP | THR_JOINABLE,
                               size_);

  if (status == -1)
    return -1;

  status = this->wait ();
  return status;
}
Beispiel #10
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());
}
Beispiel #11
0
CosNaming::NamingContext_ptr
TAO_Hash_Naming_Context::get_context (const CosNaming::Name &name)
{
  CosNaming::NamingContext_var result =
    CosNaming::NamingContext::_nil ();

  // Create compound name to be resolved, i.e.,
  // (<name> - last component).  To avoid copying, we can just reuse
  // <name>'s buffer, since we will not be modifying it.
  CORBA::ULong name_len = name.length ();
  CosNaming::Name comp_name (name.maximum (),
                             name_len - 1,
                             const_cast<CosNaming::NameComponent*> (name.get_buffer ()));
  try
    {
      CORBA::Object_var context = this->resolve (comp_name);

      // Try narrowing object reference to the NamingContext type.
      result = CosNaming::NamingContext::_narrow (context.in ());
    }
  catch (CosNaming::NamingContext::NotFound& ex)
    {
      // Add the last component of the name, which was stripped before
      // the call to resolve.
      CORBA::ULong const rest_len = ex.rest_of_name.length () + 1;
      ex.rest_of_name.length (rest_len);
      ex.rest_of_name[rest_len - 1] = name[name_len - 1];

      throw;
    }

  if (CORBA::is_nil (result.in ()))
    {
      CosNaming::Name rest;
      rest.length (2);
      rest[0] = name[name_len - 2];
      rest[1] = name[name_len - 1];
      throw CosNaming::NamingContext::NotFound(
        CosNaming::NamingContext::not_context,
        rest);
    }
  // Finally, if everything went smoothly, just return the resolved
  // context.
  return result._retn ();
}
Beispiel #12
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      ClientInitializer* temp_initializer = new ClientInitializer;

      PortableInterceptor::ORBInitializer_var orb_initializer =
        temp_initializer;

      PortableInterceptor::register_orb_initializer (orb_initializer.in ());

      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "Client ORB");

      // Now that the ORB is initialized (and subsequently the
      // PICurrent), we can set the slot data on the PICurrent for our
      // interceptor initializer.
      temp_initializer->set_slot_data ();

      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() ) ) {
        std::cerr << "Couldn't find Naming Service." << std::endl;
        return 1;
      }

      // get Messenger
      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;
        return 1;
      }

      CORBA::String_var message = CORBA::string_dup( "Hello!" );
      messenger->send_message( "TAO User", "TAO Test", message.inout() );

    }

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

  return 0;
}
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();
	}

}
Beispiel #14
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 #15
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;
}
Beispiel #16
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 #17
0
int
FactoryDriver::start (int argc, ACE_TCHAR *argv [])
{
  try
    {
      orb_ = CORBA::ORB_init (argc, argv);

      if (this->parse_args (argc, argv) == -1)
        return -1;

      // Ref counted servants are on the heap..
      ACE_NEW_RETURN (factory_servant_,
                      TAO_CosEventChannelFactory_i (),
                      -1);

      CORBA::Object_var poa_object  =
        orb_->resolve_initial_references("RootPOA");

      if (CORBA::is_nil (poa_object.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to initialize the POA.\n"),
                          -1);

      root_poa_ =
        PortableServer::POA::_narrow (poa_object.in ());

      PortableServer::POAManager_var poa_manager =
        root_poa_->the_POAManager ();


      poa_manager->activate ();


      // Initialization of the naming service.
      if (naming_client_.init (orb_.in ()) != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "(%P|%t) Unable to initialize "
                           "the TAO_Naming_Client.\n"),
                          1);

      CosNaming::NamingContext_var context =
        naming_client_.get_context ();

      if (factory_servant_->init (root_poa_.in (),
                                  child_poa_name_,
                                  context.in ()) != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "(%P|%t) Unable to initialize "
                           "the factory.\n"),
                          1);

      // activate the factory in the root poa.
      factory_ = factory_servant_->_this ();

      // Give the ownership to the POA.
      factory_servant_->_remove_ref ();

      CORBA::String_var
        str = orb_->object_to_string (factory_.in ());

      ACE_DEBUG ((LM_DEBUG,
                  "CosEvent_Service: The Cos Event Channel Factory IOR is <%s>\n",
                  str.in ()));

      CosNaming::Name name (1);
      name.length (1);
      name[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(factoryName_));
      naming_client_->rebind (name,
                              factory_.in ());

      ACE_DEBUG ((LM_DEBUG,
                  "Registered with the naming service as %s\n", factoryName_));

      orb_->run ();
    }
  catch (const CORBA::UserException& ue)
    {
      ue._tao_print_exception ("cosecfactory: ");
      return 1;
    }
  catch (const CORBA::SystemException& se)
    {
      se._tao_print_exception ("cosecfactory: ");
      return 1;
    }

  return 0;
}
Beispiel #18
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 #19
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 #20
0
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;
}
Beispiel #21
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
    CORBA::ULong i = 0;

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

        // Check arguments
        if (argc != 1) {
            std::cerr << "Usage: client" << std::endl;
            throw 0;
        }

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

        // Look for controller in the Naming Service.
        CosNaming::Name n;
        n.length(2);
        n[0].id = CORBA::string_dup("CCS");
        n[1].id = CORBA::string_dup("Controller");
        CCS::Controller_var ctrl;
        try {
            ctrl = resolve_name<CCS::Controller>(inc.in(), n);
        } catch (const CosNaming::NamingContext::NotFound &) {
            std::cerr << "No controller in Naming Service" << std::endl;
            throw 0;
        }

        // Get list of devices
        CCS::Controller::ThermometerSeq_var list = ctrl->list();

        // Show number of devices.
        CORBA::ULong len = list->length();
        std::cout << "Controller has " << len << " device";
        if (len != 1)
            std::cout << "s";
        std::cout << "." << std::endl;

        CCS::Thermometer_var t = ctrl->create_thermometer(27, "Room 1");
        CCS::Thermostat_var ts = ctrl->create_thermostat(28, "Room 2", 48);
        CCS::Thermostat_var ts2 = ctrl->create_thermostat(30, "Room 3", 48);
        CCS::Thermostat_var ts3 = ctrl->create_thermostat(32, "Room 3", 68);
        CCS::Thermostat_var ts4 = ctrl->create_thermostat(34, "Room 3", 68);
        CCS::Thermostat_var ts5 = ctrl->create_thermostat(36, "Room 3", 48);
        std::cout << t->location() << std::endl;
        std::cout << ts->location() << std::endl;
        std::cout << ts2->location() << std::endl;
        t->remove();

        list = ctrl->list();
        // Show details for each device.
        for ( i = 0; i < list->length(); i++)
          {
            CCS::Thermometer_ptr ti = list[i];
            std::cout << ti;
          }
        std::cout << std::endl;

        // Change the location of first device in the list
        CCS::AssetType anum = list[0u]->asset_num();
        std::cout << "Changing location of device "
             << anum << "." << std::endl;
        list[0u]->location("Earth");
        // Check that the location was updated
        std::cout << "New details for device "
             << anum << " are:" << std::endl;
        CCS::Thermometer_ptr tx = list[0u];
        std::cout << tx << std::endl;

        // Find first thermostat in list.
        CCS::Thermostat_var tmstat;
        for (   i = 0;
                i < list->length() && CORBA::is_nil(tmstat.in());
                i++) {
            tmstat = CCS::Thermostat::_narrow(list[i]);
        }

        // Check that we found a thermostat on the list.
        if (CORBA::is_nil(tmstat.in())) {
            std::cout << "No thermostat devices in list." << std::endl;
        } else {
            // Set temperature of thermostat to
            // 50 degrees (should work).
            set_temp(tmstat.inout(), 50);
            std::cout << std::endl;

            // Set temperature of thermostat to
            // -10 degrees (should fail).
            set_temp(tmstat.inout(), -10);
        }

        // Look for device in Rooms Earth and HAL. This must
        // locate at least one device because we earlier changed
        // the location of the first device to Room Earth.
        std::cout << "Looking for devices in Earth and HAL." << std::endl;
        CCS::Controller::SearchSeq ss;
        ss.length(2);
        ss[0].key.loc(CORBA::string_dup("Earth"));
        ss[1].key.loc(CORBA::string_dup("HAL"));
        ctrl->find(ss);

        // Show the devices found in that room.
        for ( i = 0; i < ss.length(); i++)
            std::cout << ss[i].device.in();          // Overloaded <<
        std::cout << std::endl;

        // Increase the temperature of all thermostats
        // by 40 degrees. First, make a new list (tss)
        // containing only thermostats.
        std::cout << "Increasing thermostats by 40 degrees." << std::endl;
        CCS::Controller::ThermostatSeq tss;
        for ( i = 0; i < list->length(); i++) {
            tmstat = CCS::Thermostat::_narrow(list[i]);
            if (CORBA::is_nil(tmstat.in()))
                continue;                   // Skip thermometers
            len = tss.length();
            tss.length(len + 1);
            tss[len] = tmstat;
        }

        // Try to change all thermostats.
        try {
            ctrl->change(tss, 40);
        } catch (const CCS::Controller::EChange &ec) {
            std::cerr << ec;                     // Overloaded <<
        }
    } catch (const CORBA::Exception & e) {
        std::cerr << "Uncaught CORBA exception: "
                  << e
                  << std::endl;
        return 1;
    } catch (...) {
        return 1;
    }
    return 0;
}
Beispiel #22
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 #23
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  if (parse_args (argc, argv) != 0)
  {
    return 1;
  }

  // create initial data for supplier and consumer operations
  const int operation_count = 8;
  ACE_Scheduler_Factory::POD_RT_Info config_infos[operation_count] = {
                  // good supplier (no unresolved dependencies)
                  { "good_supplier",    // entry point
                    0,                  // handle
                    5000,               // worst case execution time
                    5000,               // typical execution time (unused)
                    5000,               // cached execution time
                    500000,             // period (100 ns)
                    RtecScheduler::HIGH_CRITICALITY,   // criticality
                    RtecScheduler::LOW_IMPORTANCE,     // importance
                    0,                  // quantum (unused)
                    1,                  // threads
                    0,                  // OS priority
                    0,                  // Preemption subpriority
                    0,                  // Preemption priority
                    RtecScheduler::OPERATION           // info type
                  },
                  // good consumer (no unresolved dependencies)
                  { "good_consumer",    // entry point
                    1,                  // handle
                    5000,               // worst case execution time
                    5000,               // typical execution time (unused)
                    5000,               // cached execution time
                    0,                  // period (100 ns)
                    RtecScheduler::HIGH_CRITICALITY,   // criticality
                    RtecScheduler::LOW_IMPORTANCE,     // importance
                    0,                  // quantum (unused)
                    0,                  // threads
                    0,                  // OS priority
                    0,                  // Preemption subpriority
                    0,                  // Preemption priority
                    RtecScheduler::OPERATION           // info type
                  },
                  // supplier with unresolved remote dependencies
                  { "unresolved_remote_supplier",    // entry point
                    2,                  // handle
                    5000,               // worst case execution time
                    5000,               // typical execution time (unused)
                    5000,               // cached execution time
                    0,                  // period (100 ns)
                    RtecScheduler::HIGH_CRITICALITY,   // criticality
                    RtecScheduler::LOW_IMPORTANCE,     // importance
                    0,                  // quantum (unused)
                    0,                  // threads
                    0,                  // OS priority
                    0,                  // Preemption subpriority
                    0,                  // Preemption priority
                    RtecScheduler::REMOTE_DEPENDANT    // info type
                  },
                  // consumer with unresolved remote dependencies
                  { "unresolved_remote_consumer",    // entry point
                    3,                  // handle
                    5000,               // worst case execution time
                    5000,               // typical execution time (unused)
                    5000,               // cached execution time
                    0,                  // period (100 ns)
                    RtecScheduler::HIGH_CRITICALITY,   // criticality
                    RtecScheduler::LOW_IMPORTANCE,     // importance
                    0,                  // quantum (unused)
                    0,                  // threads
                    0,                  // OS priority
                    0,                  // Preemption subpriority
                    0,                  // Preemption priority
                    RtecScheduler::OPERATION           // info type
                  },
                  // supplier with unresolved local dependencies
                  { "unresolved_local_supplier",    // entry point
                    4,                  // handle
                    5000,               // worst case execution time
                    5000,               // typical execution time (unused)
                    5000,               // cached execution time
                    0,                  // period (100 ns)
                    RtecScheduler::HIGH_CRITICALITY,   // criticality
                    RtecScheduler::LOW_IMPORTANCE,     // importance
                    0,                  // quantum (unused)
                    0,                  // threads
                    0,                  // OS priority
                    0,                  // Preemption subpriority
                    0,                  // Preemption priority
                    RtecScheduler::OPERATION           // info type
                  },
                  // consumer with unresolved local dependencies
                  { "unresolved_local_consumer",    // entry point
                    5,                  // handle
                    5000,               // worst case execution time
                    5000,               // typical execution time (unused)
                    5000,               // cached execution time
                    0,                  // period (100 ns)
                    RtecScheduler::HIGH_CRITICALITY,   // criticality
                    RtecScheduler::LOW_IMPORTANCE,     // importance
                    0,                  // quantum (unused)
                    0,                  // threads
                    0,                  // OS priority
                    0,                  // Preemption subpriority
                    0,                  // Preemption priority
                    RtecScheduler::OPERATION           // info type
                  },
                  // consumer with unresolved local and remote dependencies
                  { "both_unresolved_consumer_1",    // entry point
                    6,                  // handle
                    5000,               // worst case execution time
                    5000,               // typical execution time (unused)
                    5000,               // cached execution time
                    0,                  // period (100 ns)
                    RtecScheduler::HIGH_CRITICALITY,   // criticality
                    RtecScheduler::LOW_IMPORTANCE,     // importance
                    0,                  // quantum (unused)
                    0,                  // threads
                    0,                  // OS priority
                    0,                  // Preemption subpriority
                    0,                  // Preemption priority
                    RtecScheduler::OPERATION           // info type
                  },
                  // another consumer with unresolved
                  // local and remote dependencies
                  { "both_unresolved_consumer_2",    // entry point
                    7,                  // handle
                    5000,               // worst case execution time
                    5000,               // typical execution time (unused)
                    5000,               // cached execution time
                    0,                  // period (100 ns)
                    RtecScheduler::HIGH_CRITICALITY,   // criticality
                    RtecScheduler::LOW_IMPORTANCE,     // importance
                    0,                  // quantum (unused)
                    0,                  // threads
                    0,                  // OS priority
                    0,                  // Preemption subpriority
                    0,                  // Preemption priority
                    RtecScheduler::OPERATION           // info type
                  }
  };

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

      CORBA::Object_var poa_object =
        orb->resolve_initial_references("RootPOA");

      if (CORBA::is_nil(poa_object.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to initialize the POA.\n"),
                          1);

      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in());

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();

      // Initialize the naming services
      TAO_Naming_Client my_name_client;
      if (my_name_client.init (orb.in ()) != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to initialize "
                           "the TAO_Naming_Client.\n"),
                          -1);

      CosNaming::NamingContext_var context =
        my_name_client.get_context ();

      if (ACE_Scheduler_Factory::use_config (context.in (),
                                             service_name) < 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to bind to the scheduling service.\n"),
                          1);

      // create and initialize RT_Infos in the scheduler,
      // make second half of array depend on first half.
      for (int i = 0; i < operation_count; ++i)
        {
          // create the RT_Info
          config_infos[i].handle =
            ACE_Scheduler_Factory::server ()->create (config_infos[i].entry_point);

          // initialize the RT_Info
          ACE_Scheduler_Factory::server ()->
            set (config_infos[i].handle,
                 static_cast<RtecScheduler::Criticality_t> (config_infos[i].criticality),
                 config_infos[i].worst_case_execution_time,
                 config_infos[i].typical_execution_time,
                 config_infos[i].cached_execution_time,
                 config_infos[i].period,
                 static_cast<RtecScheduler::Importance_t> (config_infos[i].importance),
                 config_infos[i].quantum,
                 config_infos[i].threads,
                 static_cast<RtecScheduler::Info_Type_t> (config_infos[i].info_type));
        }


      // register dependency of good consumer on good supplier
      ACE_Scheduler_Factory::server ()->
        add_dependency (config_infos[1].handle,
                        config_infos[0].handle,
                        1,                            // number of calls
                        RtecBase::ONE_WAY_CALL  // type of dependency
                        );

      // register dependency of consumer that will have unresolved remote
      // dependencies on supplier with unresolved remote dependencies
      ACE_Scheduler_Factory::server ()->
        add_dependency (config_infos[3].handle,
                        config_infos[2].handle,
                        1,                            // number of calls
                        RtecBase::ONE_WAY_CALL  // type of dependency
                        );


      // register dependency of consumer that will have unresolved local
      // dependencies on supplier with unresolved local dependencies
      ACE_Scheduler_Factory::server ()->
        add_dependency (config_infos[5].handle,
                        config_infos[4].handle,
                        1,                            // number of calls
                        RtecBase::ONE_WAY_CALL  // type of dependency
                        );


      // register dependencies on each supplier of first consumer that will
      // have both unresolved local and unresolved remote dependencies.
      ACE_Scheduler_Factory::server ()->
        add_dependency (config_infos[6].handle,
                        config_infos[0].handle,
                        1,                            // number of calls
                        RtecBase::ONE_WAY_CALL  // type of dependency
                        );

      ACE_Scheduler_Factory::server ()->
        add_dependency (config_infos[6].handle,
                        config_infos[2].handle,
                        1,                            // number of calls
                        RtecBase::ONE_WAY_CALL  // type of dependency
                        );

      ACE_Scheduler_Factory::server ()->
        add_dependency (config_infos[6].handle,
                        config_infos[4].handle,
                        1,                            // number of calls
                        RtecBase::ONE_WAY_CALL  // type of dependency
                        );

      // Register dependencies on each of the other consumers by second
      // consumer that will have both unresolved local and unresolved remote
      // dependencies.
      ACE_Scheduler_Factory::server ()->
        add_dependency (config_infos[7].handle,
                        config_infos[1].handle,
                        1,                            // number of calls
                        RtecBase::ONE_WAY_CALL  // type of dependency
                        );

      ACE_Scheduler_Factory::server ()->
        add_dependency (config_infos[7].handle,
                        config_infos[3].handle,
                        1,                            // number of calls
                        RtecBase::ONE_WAY_CALL  // type of dependency
                        );

      ACE_Scheduler_Factory::server ()->
        add_dependency (config_infos[7].handle,
                        config_infos[5].handle,
                        1,                            // number of calls
                        RtecBase::ONE_WAY_CALL  // type of dependency
                        );

      ACE_Scheduler_Factory::server ()->
        add_dependency (config_infos[7].handle,
                        config_infos[6].handle,
                        1,                            // number of calls
                        RtecBase::ONE_WAY_CALL  // type of dependency
                        );

      RtecScheduler::RT_Info_Set_var infos;
      RtecScheduler::Dependency_Set_var deps;
      RtecScheduler::Config_Info_Set_var configs;
      RtecScheduler::Scheduling_Anomaly_Set_var anomalies;

      ACE_Scheduler_Factory::server ()->compute_scheduling
        (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO,
                                         ACE_SCOPE_THREAD),
         ACE_Sched_Params::priority_max (ACE_SCHED_FIFO,
                                         ACE_SCOPE_THREAD),
         infos.out (), deps.out (),
         configs.out (), anomalies.out ());

      ACE_Scheduler_Factory::dump_schedule (infos.in (),
                                            deps.in (),
                                            configs.in (),
                                            anomalies.in (),
                                            "Sched_Conf_Anomalies_Runtime.h",
                                            format_string);
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("SYS_EX");
    }

  return 0;
}
Beispiel #24
0
CORBA::Object_ptr
TAO_Hash_Naming_Context::resolve (const CosNaming::Name& n)
{
  // 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();

  // Resolve the first component of the name.

  // Stores the binding type for the first name component.
  CosNaming::BindingType type;

  // Stores the object reference bound to the first name component.
  CORBA::Object_var result;

  {
    ACE_READ_GUARD_THROW_EX (TAO_SYNCH_RW_MUTEX, ace_mon, this->lock_,
                             CORBA::INTERNAL ());
    if (this->context_->find (n[0].id,
                              n[0].kind,
                              result.out (),
                              type) == -1)
      throw CosNaming::NamingContext::NotFound
        (CosNaming::NamingContext::missing_node, n);
  }
  // If the name we have to resolve is a compound name, we need to
  // resolve it recursively.
  if (name_len > 1)
    {
      CosNaming::NamingContext_var context =
        CosNaming::NamingContext::_nil ();

      if (type == CosNaming::ncontext)
        {
          // Narrow to NamingContext.
          context = CosNaming::NamingContext::_narrow (result.in ());
        }
      else
        // The first name component wasn't bound to a NamingContext.
        throw CosNaming::NamingContext::NotFound(
          CosNaming::NamingContext::not_context,
          n);

      // If narrow failed...
      if (CORBA::is_nil (context.in ()))
        throw CosNaming::NamingContext::NotFound(
          CosNaming::NamingContext::not_context,
          n);
      else
        {
          // Successfully resolved the first name component, need to
          // recursively call resolve on <n> without the first component.

          // We need a name just like <n> but without the first
          // component.  Instead of copying data we can reuse <n>'s
          // buffer since we will only be using it for 'in' parameters
          // (no modifications).
          CosNaming::Name rest_of_name
            (n.maximum () - 1,
             n.length () - 1,
             const_cast<CosNaming::NameComponent*> (n.get_buffer ())
             + 1);

          // If there are any exceptions, they will propagate up.
          try
            {
              CORBA::Object_ptr resolved_ref;
              resolved_ref = context->resolve (rest_of_name);
              return resolved_ref;
            }
          catch (const CORBA::SystemException&)
            {
              throw CosNaming::NamingContext::CannotProceed
                (context.in (), rest_of_name);
            }
        }
    }
  else
    {
      ACE_READ_GUARD_THROW_EX (TAO_SYNCH_RW_MUTEX, ace_mon,
                               this->lock_,
                               CORBA::INTERNAL ());

      if (this->context_->find (n[0].id,
                                n[0].kind,
                                result.out (),
                                type) == -1)
        throw CosNaming::NamingContext::NotFound
          (CosNaming::NamingContext::missing_node, n);
    }

  // If the name we had to resolve was simple, we just need to return
  // the result.
  return result._retn ();
}
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();
}
Beispiel #26
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;
			
		}
		
	}
void
handle_sigint
( int sig )
{
#ifdef HAVE_SIGACTION
	 struct sigaction act;

    /* Assign sig_chld as our SIGINT handler */
    act.sa_handler = SIG_IGN;

    /* We don't want to block any other signals in this example */
    sigemptyset(&act.sa_mask);

	 sigaction(SIGINT,&act,0);
#else
	signal(sig, SIG_IGN);
#endif
	std::cout << "\nGot Crtl-C" << std::endl;
	std::cerr << "..... unbind in NameService" << std::endl;

	//
	// build name for name service
	//
    CORBA::Object_var obj;
	CosNaming::NamingContext_var nameService;
	CosNaming::Name name;
    name.length(2);
    name[0].id = CORBA::string_dup("Qedo");
    name[0].kind = CORBA::string_dup("");
	name[1].id = CORBA::string_dup("HomeFinder");
    name[1].kind = CORBA::string_dup("");
    
	//
	// unbind name in name service
	//
	try
	{
		//
		// try to get name service from config values
		//
		std::string ns = Qedo::ConfigurationReader::instance()->lookup_config_value( "/General/NameService" );
		if( !ns.empty() )
		{
			try
			{
				obj = orb->string_to_object( ns.c_str() );
			}
			catch(...)
			{
				NORMAL_ERR2( "qassf: can't resolve NameService ", ns );
			}

			NORMAL_OUT2( "qassf: NameService is ", ns );
		}
		//
		// try to get naming service from orb
		//
		else
		{
			try
			{
				obj = orb->resolve_initial_references( "NameService" );
			}
			catch (const CORBA::ORB::InvalidName&)
			{
				NORMAL_ERR( "qassf: can't resolve NameService from ORB" );
			}

			if (CORBA::is_nil(obj.in()))
			{
				NORMAL_ERR( "qassf: NameService is a nil object reference" );
			}
		}

		try
		{
			nameService = CosNaming::NamingContext::_narrow( obj.in() );
		}
		catch (const CORBA::Exception&)
		{
			NORMAL_ERR( "qassf: NameService is not running" );
		}

		if( CORBA::is_nil(nameService.in()) )
		{
			NORMAL_ERR( "qassf: NameService is not a NamingContext object reference" );
		}

		if (!CORBA::is_nil(nameService.in()))
		{
 			nameService->unbind(name);
		}
	}
	catch (const CORBA::Exception&)
	{
		std::cerr << "..... could not unbind" << std::endl;
	}
	catch(...)
	{
		std::cerr << "..... error in signal handler" << std::endl;
	}

	orb->shutdown(false);
}
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 nameService;

	try
	{
		//
		// 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() )
		{
			obj = orb_->string_to_object( ns.c_str() );
			DEBUG_OUT2( "ComponentServerImpl:: NameService is ", ns );
		}
		//
		// try to get naming service from orb
		//
		else
		{
			obj = orb_->resolve_initial_references( "NameService" );
		}
		nameService = CosNaming::NamingContext::_narrow( obj.in() );

		if( CORBA::is_nil(nameService.in()) )
		{
        		NORMAL_ERR( "NameService is not a NamingContext object reference" );
		}
	}
	catch (CORBA::ORB::InvalidName&)
	{
		NORMAL_ERR ("ComponentServerImpl: Name Service not found");
		csa_ref_->notify_component_server_create (Qedo_Components::Deployment::ComponentServer::_nil());
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		NORMAL_ERR ("ComponentServerImpl: Cannot narrow object reference of Name Service");
		csa_ref_->notify_component_server_create (Qedo_Components::Deployment::ComponentServer::_nil());
		throw CannotInitialize();
	}

	if (CORBA::is_nil (nameService))
	{
		NORMAL_ERR ("ComponentServerImpl: Name Service is nil");
		csa_ref_->notify_component_server_create (Qedo_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_create (Qedo_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 = nameService->resolve (installer_name);
	}
	catch (CosNaming::NamingContext::NotFound&)
	{
		NORMAL_ERR ("ComponentServerImpl: Component Installer not found in Name Service");
		csa_ref_->notify_component_server_create (Qedo_Components::Deployment::ComponentServer::_nil());
		throw CannotInitialize();
	}
	catch (CORBA::SystemException&)
	{
		NORMAL_ERR ("ComponentServerImpl: CORBA system exception during resolve()");
		csa_ref_->notify_component_server_create (Qedo_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_create (Qedo_Components::Deployment::ComponentServer::_nil());
		throw CannotInitialize();
	}

	if (CORBA::is_nil (component_installer_))
	{
		NORMAL_ERR ("ComponentServerImpl: Component Installer is nil");
		csa_ref_->notify_component_server_create (Qedo_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);

	Qedo_Components::Deployment::ComponentServer_var component_server = this->_this();
	csa_ref_->notify_component_server_create (component_server.in());

	// create a handle of connector
	pConn_ = new ConnectorImpl("");
}