Exemplo n.º 1
0
SignalObserver::Observer_ptr 
Task::getObserver()
{
	PortableServer::POA_var poa = singleton::tofSession_i::instance()->poa();
  
	if ( ! pObserver_ ) {
		acewrapper::scoped_mutex_t<> lock( mutex_ );
		if ( ! pObserver_ )
			pObserver_.reset( new tofObserver_i( *this ) );

        // add Traces
		SignalObserver::Description desc;
        desc.axis_x_decimals = 3;
        desc.axis_y_decimals = 2;
		desc.trace_display_name = CORBA::wstring_dup( L"TIC" );
		desc.trace_id = CORBA::wstring_dup( L"MS.TIC" );
		desc.trace_method = SignalObserver::eTRACE_TRACE;

		boost::shared_ptr< traceObserver_i > p( new traceObserver_i( *this ) );
		p->setDescription( desc );
        pTraceObserverVec_.push_back( p );
		do {
			CORBA::Object_ptr obj = poa->servant_to_reference( p.get() );
			pObserver_->addSibling( SignalObserver::Observer::_narrow( obj ) );
		} while(0);
#if 0
		// add mass chromatograms
		std::wstring trace_id = L"MS.CHROMATOGRAM.";
		for ( int i = 0; i < 3; ++i ) {
			boost::shared_ptr< traceObserver_i > p( new traceObserver_i( *this ) );
			desc.trace_display_name = CORBA::wstring_dup( L"Chromatogram.%1%" );
			desc.trace_id = CORBA::wstring_dup( (trace_id + boost::lexical_cast<std::wstring>(i + 1)).c_str() );
			p->setDescription( desc );
			pTraceObserverVec_.push_back( p );
			do {
				CORBA::Object_ptr obj = poa->servant_to_reference( p.get() );
				pObserver_->addSibling( SignalObserver::Observer::_narrow( obj ) );
			} while(0);
		}
#endif
	}
	CORBA::Object_ptr obj = poa->servant_to_reference( pObserver_.get() );
	return SignalObserver::Observer::_narrow( obj );
}
CORBA::Object* PortSupplier_impl::getPort (const char* name) throw (CORBA::SystemException, CF::PortSupplier::UnknownPort)
{
    PortServantMap::iterator port = _portServants.find(name);
    if (port != _portServants.end()) {
        PortBase* servant = port->second;
        PortableServer::POA_var poa = servant->_default_POA();
        return poa->servant_to_reference(port->second);
    }
    throw CF::PortSupplier::UnknownPort();
}
Exemplo n.º 3
0
SignalObserver::Observer_ptr
iTask::getObserver()
{
    PortableServer::POA_var poa = adcontroller::manager_i::instance()->poa();
    if ( ! pMasterObserver_ ) {
        std::lock_guard< std::mutex > lock( mutex_ );
        if ( ! pMasterObserver_ )
            pMasterObserver_.reset( new observer_i() );
    }
    CORBA::Object_ptr obj = poa->servant_to_reference( pMasterObserver_.get() );
    try {
        return SignalObserver::Observer::_narrow( obj );
    } catch ( CORBA::Exception& ) {
    }
    return 0;
}
Exemplo n.º 4
0
ControlServer::Session_ptr
manager_i::getSession( const CORBA::WChar * token )
{
    PortableServer::POA_var poa = manager_i::instance()->poa(); // getServantManager()->root_poa();

    if ( CORBA::is_nil( poa ) )
        return 0;

    if ( session_list_.empty() )
        adcontroller::iTaskManager::instance()->manager_initialize();

    session_map_type::iterator it = session_list_.find( token );
    if ( it == session_list_.end() ) 
        session_list_[ token ].reset( new adcontroller::session_i() );

    CORBA::Object_ptr obj = poa->servant_to_reference( session_list_[ token ].get() );
    return ControlServer::Session::_narrow( obj );
}
Exemplo n.º 5
0
int
main( int argc, char *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() );

      PortableServer::POAManager_var mgr = poa->the_POAManager();

      // Activate POA Manager
      mgr->activate();

      // Create an object
      GoodDay_i servant;

      // Register the servant with the RootPOA, obtain its object
      // reference, stringify it, and write it to a file.
      obj = poa->servant_to_reference( &servant );

      CORBA::String_var str = orb->object_to_string( obj.in() );
      ofstream iorFile( "IOR" );
      iorFile << str.in() << endl;
      iorFile.close();

      cout << "IOR written to file IOR" << endl;

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

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

  return 0;
}
Exemplo n.º 6
0
Broker::Session_ptr
manager_i::getSession( const CORBA::WChar * token )
{
    PortableServer::POA_var poa = ::adbroker::manager_i::instance()->poa();

    if ( CORBA::is_nil( poa ) )
        return 0;

    session_map_type::iterator it = session_list_.find( token );
    if ( it == session_list_.end() )
        session_list_[ token ].reset( new adbroker::session_i( token ) );

    CORBA::Object_ptr obj = poa->servant_to_reference( session_list_[ token ].get() );
    try {
        return Broker::Session::_narrow( obj ); // return new object, refcount should be 1
    } catch ( CORBA::Exception& ) {
        return 0;
    }
}
Exemplo n.º 7
0
void
TAO_ECG_UDP_Sender::reconnect (const RtecEventChannelAdmin::ConsumerQOS& sub)
{
  // Obtain our object reference from the POA.
  RtecEventComm::PushConsumer_var consumer_ref;
  PortableServer::POA_var poa = this->_default_POA ();

  CORBA::Object_var obj = poa->servant_to_reference (this);
  consumer_ref =
    RtecEventComm::PushConsumer::_narrow (obj.in ());

  if (CORBA::is_nil (consumer_ref.in ()))
    {
      throw CORBA::INTERNAL ();
    }

  // Reconnect.
  this->supplier_proxy_->connect_push_consumer (consumer_ref.in (),
                                                sub);
}
Exemplo n.º 8
0
Broker::Logger_ptr
manager_i::getLogger()
{
    PortableServer::POA_var poa = ::adbroker::manager_i::instance()->poa();
    if ( CORBA::is_nil( poa ) )
        return 0;

    if ( ! logger_i_ ) {
        logger_i_.reset( new broker::logger_i( poa ) );
        PortableServer::ObjectId * oid = poa->activate_object( logger_i_.get() );
        logger_i_->oid( *oid );
    }

    CORBA::Object_var obj = poa->servant_to_reference( logger_i_.get() );
    try {
        return Broker::Logger::_narrow( obj );
    } catch ( CORBA::Exception& ) {
        return 0;
    }
}
int main(int argc, char **argv)
{
    // Removes ORB related arguments
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    // Program options
    std::string register_servant;
    std::string proxy_reference;

    _po::options_description _desc("Proxy Server options");
    _desc.add_options()
        ("help,h", "produce help message")
        ("register-servant,r", _po::value< std::string >(&register_servant),
         "register the servant into the name service")
        ("proxy-reference,p", _po::value< std::string >(&proxy_reference),
         "forward received calls to another servant");

    _po::variables_map _vm;
    _po::store(_po::parse_command_line(argc, argv, _desc), _vm);
    _po::notify(_vm);

    if (_vm.count("help"))
    {
        std::cout << _desc << std::endl;
        return 0;
    }

    bool reference_is_ns_entry = false;
    // TODO

    // Name Service
    CosNaming::NamingContextExt_var nc;

    if (reference_is_ns_entry || !register_servant.empty())
    {
        try {
            CORBA::Object_var ncObj = orb->resolve_initial_references("NameService");

            nc = CosNaming::NamingContextExt::_narrow(ncObj);
        } catch(...) {
        }

        if (CORBA::is_nil(nc))
            std::cerr << "Name service unavailable!" << std::endl;
    }

    // Proxy reference
    prueba::Iface_var reference;

    if (!proxy_reference.empty())
    {
        CORBA::Object_var refObj;

        if (reference_is_ns_entry && !CORBA::is_nil(nc))
            refObj = nc->resolve_str(proxy_reference.c_str());
        else
            refObj = orb->string_to_object(proxy_reference.c_str());

        reference = prueba::Iface::_narrow(refObj);
    }

    // Servant
    prueba_Iface_impl _impl(reference.in());

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

    PortableServer::POA_var rootPOA =
            PortableServer::POA::_narrow(rootPOAObj.in());

    PortableServer::POAManager_var manager = rootPOA->the_POAManager();

    PortableServer::ObjectId_var myObjID =
                rootPOA->activate_object(&_impl);

    CORBA::Object_var obj = rootPOA->servant_to_reference(&_impl);

    // Displaying reference
    CORBA::String_var ref = orb->object_to_string(obj);
    std::cout << ref << std::endl;

    // Registring servant
    CosNaming::Name_var name;

    if (!register_servant.empty() && !CORBA::is_nil(nc))
    {
        name = nc->to_name(register_servant.c_str());

        nc->rebind(name, obj);
    }

    /*PROTECTED REGION ID(prueba_Iface_impl_server::___main) ENABLED START*/
    /*PROTECTED REGION END*/

    // Running
    manager->activate();
    orb->run();

    // Unbinding servant
    if (!CORBA::is_nil(nc) && name)
        nc->unbind(name);

    return 0;
}
Exemplo n.º 10
0
int FT_ReplicaFactory_i::init (CORBA::ORB_ptr orb)
{
  int result = 0;

  this->orb_ = CORBA::ORB::_duplicate (orb);

  // Use the ROOT POA for now
  CORBA::Object_var poa_object =
    this->orb_->resolve_initial_references (TAO_OBJID_ROOTPOA);

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

  // Get the POA object.
  this->poa_ =
    PortableServer::POA::_narrow (poa_object.in ());

  if (CORBA::is_nil(this->poa_.in ()))
  {
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" (%P|%t) Unable to narrow the POA.\n")),
                      -1);
  }

  PortableServer::POAManager_var poa_manager =
    this->poa_->the_POAManager ();

  poa_manager->activate ();

  // Register with the POA.

  this->object_id_ = this->poa_->activate_object (this);

  CORBA::Object_var this_obj =
    this->poa_->id_to_reference (object_id_.in ());

  this->ior_ = this->orb_->object_to_string (this_obj.in ());

  if (this->factory_registry_ior_ != 0)
  {
    if (ACE_OS::strcmp (this->factory_registry_ior_, ACE_TEXT("none")) != 0)
    {
      CORBA::Object_var reg_obj = this->orb_->string_to_object(factory_registry_ior_);
      this->factory_registry_ = ::PortableGroup::FactoryRegistry::_narrow(reg_obj.in ());
      if (CORBA::is_nil(this->factory_registry_.in ()))
      {
        ACE_ERROR (( LM_ERROR,
           "Can't resolve Factory Registry IOR %s\n",
           this->factory_registry_ior_
           ));
        result = -1;
      }
    }
  }
  else // no -f option.  Try RIR(RM)
  {
    ///////////////////////////////
    // Find the ReplicationManager
    try
    {
      CORBA::Object_var rm_obj = orb->resolve_initial_references("ReplicationManager");
      this->replication_manager_ = ::FT::ReplicationManager::_narrow(rm_obj.in());
      if (!CORBA::is_nil (replication_manager_.in ()))
      {
        this->have_replication_manager_ = 1;
        // empty criteria
        ::PortableGroup::Criteria criteria;
        this->factory_registry_ = this->replication_manager_->get_factory_registry(criteria);
        if (CORBA::is_nil (this->factory_registry_.in ()))
        {
          ACE_ERROR ((LM_ERROR,"ReplicaFactory: ReplicationManager failed to return FactoryRegistry.  Factory will not be registered.\n" ));
        }
      }
      else
      {
        this->factory_registry_ =  ::PortableGroup::FactoryRegistry::_narrow(rm_obj.in());
        if (!CORBA::is_nil(this->factory_registry_.in ()))
        {
          ACE_DEBUG ((LM_DEBUG,"Found a FactoryRegistry DBA ReplicationManager\n" ));
        }
        else
        {
          ACE_ERROR ((LM_ERROR,"ReplicaFactory: Can't resolve ReplicationManager.\n" ));
        }
      }
    }
    catch (const CORBA::Exception& ex)
    {
      if (this->test_output_file_ == 0) // ignore if this is a test run
      {
        ex._tao_print_exception (
          "ReplicaFactory: Exception resolving ReplicationManager. Factory will not be registered.\n");
      }
    }

  }

  if ( ! CORBA::is_nil (this->factory_registry_.in ()))
  {
    size_t roleCount = roles_.size();
    for (size_t nRole = 0; nRole < roleCount; ++nRole)
    {
      const char * roleName = this->roles_[nRole].c_str();

      PortableGroup::FactoryInfo info;
      info.the_factory = ::PortableGroup::GenericFactory::_narrow(this_obj.in ());
      info.the_location.length(1);
      info.the_location[0].id = CORBA::string_dup(this->location_.c_str ());
      info.the_criteria.length(1);
      info.the_criteria[0].nam.length(1);
      info.the_criteria[0].nam[0].id = CORBA::string_dup(PortableGroup::role_criterion);
      info.the_criteria[0].val <<= CORBA::string_dup(roleName);

      ACE_ERROR (( LM_INFO,
         "Factory: %s@%C registering with factory registry\n",
         roleName,
         location_.c_str ()
         ));

      char const * replica_repository_id =
        FT_TEST::_tc_TestReplica->id ();

      this->factory_registry_->register_factory(
        roleName,
        replica_repository_id,
        info);
    }
    this->registered_ = 1;
  }

  int identified = 0; // bool

  if (this->roles_.size() > 0)
  {
    this->identity_ = ACE_TEXT("Factory");
    if (this->location_.length () != 0)
    {
      this->identity_ += ACE_TEXT("@");
      this->identity_ += ACE_TEXT_CHAR_TO_TCHAR(this->location_.c_str ());
    }
    identified = 1;
  }

  if (this->ior_output_file_ != 0)
  {
    if (!identified)
    {
      this->identity_ = ACE_TEXT("file:");
      this->identity_ += this->ior_output_file_;
      // note: don't set identified--ns identity overrides file identitiy
    }
    result = write_ior (this->ior_output_file_, this->ior_. in ());
  }
  else
  {
    if (this->registered_)
    {
      // if we didn't register with a FactoryRegistry
      // and no IOR file specified,
      // then always try to register with name service
      this->ns_name_ = "FT_ReplicaFactory";
    }
  }

  if (this->ns_name_.length () != 0)
  {
    if (!identified)
    {
      this->identity_ = ACE_TEXT("name:");
      this->identity_ += ACE_TEXT_CHAR_TO_TCHAR(this->ns_name_.c_str ());
    }

    CORBA::Object_var naming_obj =
      this->orb_->resolve_initial_references ("NameService");

    if (CORBA::is_nil(naming_obj.in ())){
      ACE_ERROR_RETURN ((LM_ERROR,
                         "%T %n (%P|%t) Unable to find the Naming Service\n"),
                        1);
    }

    this->naming_context_ =
      CosNaming::NamingContext::_narrow (naming_obj.in ());

    this->this_name_.length (1);
    this->this_name_[0].id = CORBA::string_dup (this->ns_name_.c_str ());

    this->naming_context_->rebind (this->this_name_, this_obj.in());
  }

  // if we're testing.  Create a replica at startup time
  if (this->test_output_file_ != 0)
  {
    // shouldn't be necessary, but create_replica assumes this
    ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, this->internals_, 1);
    FT_TestReplica_i * replica = create_replica ("test");

    PortableServer::POA_var poa = replica->_default_POA ();
    ::CORBA::Object_var replica_obj = poa->servant_to_reference(replica);
    ::CORBA::String_var replicaIOR = this->orb_->object_to_string(replica_obj.in ());
    write_ior (this->test_output_file_, replicaIOR.in ());
  }

  return result;
}
Exemplo n.º 11
0
int main (int argc, char *argv[])
{
  const int domainId = 411;
  const char *topicName = "Stock Quotes";

  try {
    DDS::DomainParticipantFactory_var dpf;
    DDS::DomainParticipant_var participant;

    dpf = TheParticipantFactoryWithArgs(argc, argv);

    // To Do: Create the participant
    participant =
      dpf->create_participant(domainId,
                              PARTICIPANT_QOS_DEFAULT,
                              DDS::DomainParticipantListener::_nil());
    if (CORBA::is_nil (participant.in ())) {
      cerr << "create_participant failed." << endl;
      return 1 ;
    }
    // End: Create the participant

    QuoterTypeSupportImpl* servant = new QuoterTypeSupportImpl();
    PortableServer::ServantBase_var safe_servant = servant;

    // To Do: Register the type
    if (DDS::RETCODE_OK != servant->register_type(participant.in (),
                                                      "")) {
      cerr << "Failed to register the QuoterTypeTypeSupport." << endl;
      exit(1);
    }
    // End: Register the type

    CORBA::String_var type_name = servant->get_type_name ();

    // To Do: Get the (default) topic QoS and create the topic
    DDS::TopicQos topic_qos;
    participant->get_default_topic_qos(topic_qos);
    DDS::Topic_var topic =
      participant->create_topic(topicName,
                                type_name.in (),
                                topic_qos,
                                DDS::TopicListener::_nil());
    if (CORBA::is_nil (topic.in ())) {
      cerr << "Failed to create_topic." << endl;
      exit(1);
    }
    // End: Get the (default) topic QoS and create the topic
    
    // To Do: Create the subscriber
    DDS::Subscriber_var sub =
      participant->create_subscriber(SUBSCRIBER_QOS_DEFAULT,
                                     DDS::SubscriberListener::_nil());
    if (CORBA::is_nil (sub.in ())) {
      cerr << "Failed to create_subscriber." << endl;
      exit(1);
    }
    // End: Create the subscriber

    // jhoffert
    // There seem to be problems using auto configurations with an application
    // distributed across different nodes. Take this out for now.

    // Initialize the transport
    TAO::DCPS::TransportImpl_rch tcp_impl =
      TheTransportFactory->create_transport_impl (TCP_IMPL_ID,
                                                  //::TAO::DCPS::AUTO_CONFIG);
                                                  ::TAO::DCPS::DONT_AUTO_CONFIG);
    TAO::DCPS::TransportConfiguration_rch reader_config =
      //TheTransportFactory->get_configuration (SUB_TRAFFIC);
      TheTransportFactory->get_configuration (TCP_IMPL_ID);

    TAO::DCPS::SimpleTcpConfiguration* reader_tcp_config =
      static_cast <TAO::DCPS::SimpleTcpConfiguration*> (reader_config.in ());

    if (0 != ACE_OS::strcmp ("default", reader_address_str)) {
      ACE_INET_Addr reader_address (reader_address_str);
      reader_tcp_config->local_address_ = reader_address;
    }

    if (0 != tcp_impl->configure (reader_config.in ())) {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT("(%P|%t) ::main: ")
                  ACE_TEXT("Failed to configure the transport.\n")));
      exit(1);
    }
    // jhoffert - End of transport configuration changes

    // Attach the subscriber to the transport.
    TAO::DCPS::SubscriberImpl* sub_impl =
      ::TAO::DCPS::reference_to_servant< TAO::DCPS::SubscriberImpl,
                                         DDS::Subscriber_ptr> (sub.in ());
    if (0 == sub_impl) {
      cerr << "Failed to obtain subscriber servant\n" << endl;
      exit(1);
    }

    TAO::DCPS::AttachStatus status = sub_impl->attach_transport(tcp_impl.in());
    if (status != TAO::DCPS::ATTACH_OK) {
      std::string status_str;
      switch (status) {
        case TAO::DCPS::ATTACH_BAD_TRANSPORT:
          status_str = "ATTACH_BAD_TRANSPORT";
          break;
        case TAO::DCPS::ATTACH_ERROR:
          status_str = "ATTACH_ERROR";
          break;
        case TAO::DCPS::ATTACH_INCOMPATIBLE_QOS:
          status_str = "ATTACH_INCOMPATIBLE_QOS";
          break;
        default:
          status_str = "Unknown Status";
          break;
      }
      cerr << "Failed to attach to the transport. Status == "
           << status_str.c_str() << endl;
      exit(1);
    }

    // activate the listener
    DataReaderListenerImpl        listener_servant;
    PortableServer::POA_var poa = TheServiceParticipant->the_poa ();
    CORBA::Object_var obj = poa->servant_to_reference(&listener_servant);
    DDS::DataReaderListener_var listener =
      DDS::DataReaderListener::_narrow (obj.in ());
    if (CORBA::is_nil (listener.in ())) {
      cerr << "listener is nil." << endl;
      exit(1);
    }

    // To Do: Get default data reader QoS and create the data reader.
    DDS::DataReaderQos dr_qos;
    sub->get_default_datareader_qos (dr_qos);
    DDS::DataReader_var dr = sub->create_datareader(topic.in (),
                                                    dr_qos,
                                                    listener.in ());
    if (CORBA::is_nil (dr.in ())) {
      cerr << "create_datareader failed." << endl;
      exit(1);
    }
    // End: Get default data reader QoS and create the data reader.

    // To Do: Set up the constraints for when the subscriber is done
    // receiving updates.
    int expected = 10;
    while ( listener_servant.num_reads() < expected) {
      ACE_OS::sleep (1);
    }
    // End: Set up the constraints for how long the subscriber should
    // receive updates.

    // To Do: Delete the participant's contained entities
    if (!CORBA::is_nil (participant.in ())) {
      participant->delete_contained_entities();
    }
    // End: Delete the participant's contained entities
    if (!CORBA::is_nil (dpf.in ())) {
      dpf->delete_participant(participant.in ());
    }

    ::DDS::InstanceHandleSeq handles;
    while (1)
    {
      ACE_OS::sleep(1);
      dr->get_matched_publications(handles);
      if (handles.length() == 0)
        break;
    }

    ACE_OS::sleep(2);

    TheTransportFactory->release();
    TheServiceParticipant->shutdown ();

  } catch (CORBA::Exception& e) {
    cerr << "Exception caught in main ():" << endl << e << endl;
    return 1;
  }

  return 0;
}