Exemplo n.º 1
0
void
handle_sigint
( int signal )
{
	std::cout << "\nGot Crtl-C" << std::endl;
	std::cerr << "..... unbind in NameService" << std::endl;

	//
	// unbind in naming service
	//
    CORBA::Object_var obj;
	CosNaming::NamingContext_var nameService;
	char hostname[256];
	gethostname(hostname, 256);
	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("ComponentInstallation");
    name[1].kind = CORBA::string_dup("");
	name[2].id = CORBA::string_dup(hostname);
    name[2].kind = CORBA::string_dup("");
    try
    {
        obj = orb->resolve_initial_references("NameService");
		nameService = CosNaming::NamingContext::_narrow(obj.in());
		nameService->unbind(name);
    }
	catch (const CORBA::Exception&)
	{
		std::cerr << "..... could not unbind" << std::endl;
	}
	
	exit(1);
}
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;
}
NotifyLogPlayer::~NotifyLogPlayer()
{
  DBG(cout << "Destructing NotifyLogPlayer." << endl);

  delete pPushSupplier;

  try {
    if (own_) {
      CosNaming::Name n;
      n.length(1);
      n[0].id = CORBA::string_dup("EventChannel");
      namingContext->unbind(n);
    }
    if (colocated_)
      initialNamingContext->unbind(channelFactoryName);

  }
  catch (const CORBA::Exception& e) {
    cerr << "Caught CORBA exception on unbind: " << e << endl;
    cerr << "Porbably the NameSevice went down while we run." << endl;
  }

  DBG(cout << "unbound objects from Name Sevice" << endl);

  if (colocated_)
    ec_->destroy();
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
0
RTT::TaskContext* CorbaNameService::getTaskContext(const std::string& taskName)
{
    if(CORBA::is_nil(orb))
    {
        throw std::runtime_error("CorbaNameService::Error, called getTaskContext() without connection " );
    }

    CosNaming::Name serverName;
    serverName.length(2);
    serverName[0].id = CORBA::string_dup("TaskContexts");
    serverName[1].id = CORBA::string_dup( taskName.c_str() );

    // Get object reference
    CORBA::Object_var task_object = rootContext->resolve(serverName);
    CORBA::String_var s = orb->object_to_string(task_object);

    RTT::TaskContext *ret = nullptr;
        
    try
    {
        ret = RTT::corba::TaskContextProxy::Create(s.in(), true);;
    }
    catch (...)
    {
        std::cout << "Ghost " << taskName << std::endl;
    }
    
    return ret;
}
Exemplo n.º 7
0
void
Connection_Manager::add_to_receivers (CosNaming::BindingList &binding_list)
{
  for (CORBA::ULong i = 0;
       i < binding_list.length ();
       i++)
    {
      // Get the receiver name from the binding list.
      ACE_CString receiver_name =
        binding_list [i].binding_name [0].id.in ();

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

      // Resolve the reference of the receiver from the receiver
      // context.
      CORBA::Object_var obj =
        this->receiver_context_->resolve (name);

      AVStreams::MMDevice_var receiver_device =
        AVStreams::MMDevice::_narrow (obj.in ());

      // Add this receiver to the receiver map.
      ACE_CString flowname =
        this->sender_name_ +
        "_" +
        receiver_name;
      this->receivers_.bind (flowname,
                             receiver_device);
    }
}
Exemplo n.º 8
0
void
Connection_Manager::unbind_sender (const ACE_CString &sender_name,
                                   AVStreams::MMDevice_ptr sender_mmdevice_obj)
{
  if (TAO_debug_level > 0)
    ACE_DEBUG ((LM_DEBUG,
                "Connection_Manager::unbind_sender\n"));

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

  // Try binding the sender context in the NS
  name [0].id =
    CORBA::string_dup (sender_name.c_str ());

  try
    {
      CORBA::Object_var object =
        this->naming_client_->resolve (name);

      CosNaming::NamingContext_var sender_context =
        CosNaming::NamingContext::_narrow (object.in ());

      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG,
                    "Sender Context Found\n"));

      try
        {
          object =
            sender_context->resolve (name);

          AVStreams::MMDevice_var mmdevice =
            AVStreams::MMDevice::_narrow (object.in ());

          if (mmdevice->_is_equivalent (sender_mmdevice_obj))
          {
            sender_context->unbind (name);

            if (TAO_debug_level > 0)
              ACE_DEBUG ((LM_DEBUG,
                          "Sender Unbound\n"));
          }
        }
      catch (const CosNaming::NamingContext::NotFound&)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "Sender object not found\n"));
          // Do not have to unbind.
        }

    }
  catch (const CosNaming::NamingContext::NotFound&)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Sender Context Not Found\n"));
      // Do not have to unbind.
    }

}
Exemplo n.º 9
0
bool CorbaNameService::isRegistered(const std::string& taskName)
{
    if(CORBA::is_nil(orb))
    {
       throw std::runtime_error("CorbaNameService::Error, called getTaskContext() without connection " );
    }

    CosNaming::Name serverName;
    serverName.length(2);
    serverName[0].id = CORBA::string_dup("TaskContexts");
    serverName[1].id = CORBA::string_dup( taskName.c_str() );

    try {
        // Get object reference
        CORBA::Object_var task_object = rootContext->resolve(serverName);
        if(CORBA::is_nil(task_object))
            return false;

        RTT::corba::CTaskContext_var mtask = RTT::corba::CTaskContext::_narrow (task_object.in ());
        if ( CORBA::is_nil( mtask ) ) {
            return false;
        }
        
        // force connect to object.
        //this needs to be done. If not, we may return a ghost task
        CORBA::String_var nm = mtask->getName(); 
    } catch (...)
    {
        return false;
    }
    
    return true;
}
Exemplo n.º 10
0
CosNaming::Name* 
VOmniORBHelper::nsPathToObjectName(const char* program, const char* object,
				   int telescopenumber)
  throw(CORBA::SystemException)
{
  std::ostringstream program_stream;
  if(telescopenumber!=-1)
    program_stream << program << telescopenumber;
  else 
    program_stream << program;
  
  CosNaming::Name* name = new CosNaming::Name;
  name->length(3);
  
  (*name)[0].id   = CORBA::string_dup(m_project.c_str());
  (*name)[0].kind = CORBA::string_dup("");

  (*name)[1].id   = CORBA::string_dup(program_stream.str().c_str());
  (*name)[1].kind = CORBA::string_dup("Program");

  (*name)[2].id   = CORBA::string_dup(object);
  (*name)[2].kind = CORBA::string_dup("Object");

  return name;
}
ImageServer::~ImageServer()
{
  CosNaming::Name n;
  n.length(1);
  n[0].id = CORBA::string_dup("Image");
  namingContext->unbind(n);
}
void
ApplicationWindow::resolveFactory(QString const& _name)
{
  try {
    CosNaming::Name name;
    
    name.length(1);
    name[0].id = CORBA::string_dup(_name.latin1());
    CosNotifyChannelAdmin::EventChannelFactory_ptr factory =
      server_.resolveName<CosNotifyChannelAdmin::EventChannelFactory>(name);
    
    EventChannelFactory * f = 
      new EventChannelFactory(factory, listView_, this, _name);

    connect(timer_, SIGNAL(timeout()), f, SLOT(updateFactory()));
  }
  catch(CORBA::Exception& e) {
    std::ostringstream sstr;
    sstr << "CORBA exception: " << e << std::flush;

    QString error = sstr.str().c_str();
    QMessageBox::warning(this, 
			 "Resolve EventChannelFactory", 
			 "Error resolving factory " + _name + ".\n" + error);

  }
}
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;
}
Speech::~Speech()
{
#ifdef DEBUG
  cout << "Destructing Speech." << endl;
#endif
  //  pConsumer->disconnect_push_consumer();

  try {
    CosNaming::Name n;
     
    n.length(1);
    n[0].id = CORBA::string_dup("Speech");
    namingContext->unbind(n);
    //    n[0].id = CORBA::string_dup("SpeechEC");
    //    namingContext->unbind(n);

#ifdef DEBUG
    cout << "Unbound objects from NamingSevice." << endl;
#endif
  }
  catch (const CORBA::Exception& e) {
    cerr << "Caught CORBA exception on unbind: " << e << endl;
    cerr << "Porbably the NameSevice went down while we ran." << endl;
  }
}
Exemplo n.º 15
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;
}
Exemplo n.º 16
0
int main(int argc, char *argv[])
{
    CORBA::ORB_var orb = CORBA::ORB::_nil();
  
    try {

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

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

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

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

    }
    
    return 0;
}
Exemplo n.º 17
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();
}
Exemplo n.º 18
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;
}
Exemplo n.º 19
0
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;
}
Exemplo n.º 20
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv [])
{
  try
  {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

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

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

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

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

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

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

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

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

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

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

}
Exemplo n.º 21
0
void NamingContextHelper::unbind(const std::string& name)
{
    if(isAlive()){
        CosNaming::Name nc;
        nc.length(1);
        nc[0].id   = CORBA::string_dup(name.c_str());
        nc[0].kind = CORBA::string_dup("");
        namingContext->unbind(nc);
    }
}
Exemplo n.º 22
0
RecordingDevice::ReturnCode RecordingDevice::ResolveDevice()
{
    ReturnCode result = OK;
    if(mName.empty())
    {
        result = NO_DEVICE;
    }
    mTrackCount = 0;

    CosNaming::Name name;
    name.length(3); 
    name[0].id = CORBA::string_dup("ProductionAutomation");
    name[1].id = CORBA::string_dup("RecordingDevices");
    name[2].id = CORBA::string_dup(mName.c_str());

    CORBA::Object_var obj;
    if(OK == result)
    {
        obj = CorbaUtil::Instance()->ResolveObject(name);
    }

    if(CORBA::is_nil(obj))
    {
        result = NO_DEVICE;
    }

    if(OK == result)
    {
        try
        {
            mRecorder = ProdAuto::Recorder::_narrow(obj);
        }
        catch(const CORBA::Exception &)
        {
            result = NO_DEVICE;
        }
    }

    // Find out how many recording tracks there are
    ProdAuto::TrackList_var track_list;
    if(OK == result)
    {
        try
        {
            track_list = mRecorder->Tracks();
            mTrackCount = track_list->length();
        }
        catch(const CORBA::Exception &)
        {
            result = NO_DEVICE;
        }
    }

    return result;
}
Exemplo n.º 23
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."));
			}
		}
	}
}
Exemplo n.º 24
0
std::vector< std::string > CorbaNameService::getRegisteredTasks()
{
    if(CORBA::is_nil(orb))
    {
        throw std::runtime_error("CorbaNameService::Error, called getRegisteredTasks() without connection " );
    }
    CosNaming::Name server_name;
    server_name.length(1);
    server_name[0].id = CORBA::string_dup("TaskContexts");
    std::vector<std::string> task_names;
    CosNaming::BindingList_var binding_list;
    CosNaming::BindingIterator_var binding_it;

    // get all available task names from the name server
    CORBA::Object_var control_tasks_var = rootContext->resolve(server_name);
    CosNaming::NamingContext_var control_tasks = CosNaming::NamingContext::_narrow (control_tasks_var);
    if (CORBA::is_nil(control_tasks))
        return task_names;

    control_tasks->list(0, binding_list, binding_it);
    if (CORBA::is_nil(binding_it))
        return task_names;

    // iterate over all task names
    while(binding_it->next_n(10, binding_list))
    {
        CosNaming::BindingList list = binding_list.in();
        for (unsigned int i = 0; i < list.length(); ++i)
        {
            std::string name = list[i].binding_name[0].id.in();
            CosNaming::Name serverName;
            serverName.length(2);
            serverName[0].id = CORBA::string_dup("TaskContexts");
            serverName[1].id = CORBA::string_dup( name.c_str() );

            try {
                //verify that the object really exists, and is not just some leftover from a crash
                
                // Get object reference
                CORBA::Object_var task_object = rootContext->resolve(serverName);
                RTT::corba::CTaskContext_var mtask = RTT::corba::CTaskContext::_narrow (task_object.in ());
                
                std::cout << "Connection test to " << name << std::endl;
                
                // force connect to object.
                CORBA::String_var nm = mtask->getName(); 
                task_names.push_back(name);
                }
            catch (...)
            {
            }
        }
    }
    return task_names;
}
Exemplo n.º 25
0
int
Server_Task::svc (void)
{
    try
    {
        CORBA::Object_var poa_object =
            this->sorb_->resolve_initial_references("RootPOA");

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

        if (CORBA::is_nil (root_poa.in ()))
            ACE_ERROR_RETURN ((LM_ERROR,
                               " (%P|%t) Panic: nil RootPOA\n"),
                              1);

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

        Hello *hello_impl = 0;
        ACE_NEW_RETURN (hello_impl,
                        Hello (this->sorb_.in (),
                               ACE_Thread::self ()),
                        1);

        PortableServer::ServantBase_var owner_transfer(hello_impl);

        Test::Hello_var hello =
            hello_impl->_this ();

        CosNaming::NamingContext_var example_nc;
        CosNaming::Name name;
        name.length(1);
        name[0].id = CORBA::string_dup("Hello");
        root_context_->rebind(name, hello.in());

        poa_manager->activate ();

        // Signal the main thread before we call orb->run ();
        this->me_.signal ();

        ACE_Time_Value runtime (10);
        this->sorb_->run (runtime);

        ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
    }
    catch (const CORBA::Exception& ex)
    {
        ex._tao_print_exception ("Exception caught:");
        return 1;
    }

    return 0;
}
Exemplo n.º 26
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try {
    // Initialize orb
    CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );

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

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

    // Narrow the Messenger object reference
    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!");

    // Send a message
    messenger->send_message("TAO User", "TAO Test", message.inout());

    std::cout << "Message was sent" << std::endl;

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

  return 0;
}
Exemplo n.º 27
0
CORBA::Object_ptr
TAO_Notify_Tests_LookupManager::resolve_object (const char* obj_name)
{
  CosNaming::Name name (1);
  name.length (1);
  name[0].id = CORBA::string_dup (obj_name);

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

  return obj._retn ();
}
Exemplo n.º 28
0
int
IOR_corbaloc_Client_i::run (void)
{

  try
    {
      CosNaming::Name name (1);

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

      // Resolve the name
      CORBA::Object_var factory_object =
        this->naming_context_->resolve (name);

      // Narrow
      corbaloc::Status_var factory =
        corbaloc::Status::_narrow (factory_object.in ());

      if (CORBA::is_nil (factory.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Object reference is nil for: %s\n",
                             corbaloc_url_.c_str() ),
                            1);
        }

      // Invoke a request on the server
      CORBA::Boolean ret_value =
        factory->print_status ();

      if (ret_value != 0)
        {
        ACE_DEBUG ((LM_DEBUG,
                    "The server has not been contacted. Error!!\n",
                    0));
        }
    }
  catch (const CosNaming::NamingContext::NotFound& ex)
    {
      ex._tao_print_exception ("CosNaming::NamingContext::NotFound");
    }
  catch (const CORBA::SystemException& ex)
    {
      ex._tao_print_exception ("A system exception on client side");
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("client");
    }

  return 0;
}
Exemplo n.º 29
0
bool NamingContextHelper::bindObject(CORBA::Object_ptr object, const std::string& name)
{
    if(isAlive()){
        CosNaming::Name nc;
        nc.length(1);
        nc[0].id   = CORBA::string_dup(name.c_str());
        nc[0].kind = CORBA::string_dup("");
        namingContext->rebind(nc, object);
        return true;
    }
    return false;
}
Exemplo n.º 30
0
void NamingContextHelper::unbind(std::vector<ObjectPath> pathList)
{
    if(isAlive()){
        CosNaming::Name ncName;
        ncName.length(pathList.size());
        for (int index = 0; index < pathList.size(); index++) {
            ncName[index].id = CORBA::string_dup(pathList[index].id.c_str());
            ncName[index].kind = CORBA::string_dup(pathList[index].kind.c_str());
        }
        namingContext->unbind(ncName);
    }
}