示例#1
0
int
Server_i::create_locator (PortableServer::POA_var second_poa)
{

  try
    {
      // An Servant Locator object is created which will activate
      // the servant on demand.
      ServantLocator *temp_servant_locator = 0;
      ACE_NEW_RETURN (temp_servant_locator,
                      ServantLocator (orb_.in (),
                                      ACE_TEXT ("Generic_Servant"),
                                      ACE_TEXT ("supply_servant"),
                                      ACE_TEXT ("destroy_servant")),
                      0);
      // Set ServantLocator object as the servant Manager of
      // secondPOA.
      this->servant_locator_ = temp_servant_locator;
      second_poa->set_servant_manager (this->servant_locator_);
      // For the code above, we're using the CORBA 3.0 servant manager
      // semantics supported by TAO.  For CORBA 2.x ORBs you'd need to
      // use the following code in place of the previous lines:
      //
      // this->servant_locator_ = temp_servant_locator->_this ();
      //
      // Set ServantLocator object as the servant Manager of
      // secondPOA.
      // second_poa->set_servant_manager (this->servant_locator_.in ()
      //);

      // Try to create a reference with user created ID in second_poa
      // which uses ServantLocator.
      PortableServer::ObjectId_var second_test_oid =
        PortableServer::string_to_ObjectId ("second test");

      second_test_ =
        second_poa->create_reference_with_id (second_test_oid.in (),
                                              "IDL:test:1.0");
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Server_i:create_locator ()");
      return 1;
    }

  return 0;
}
示例#2
0
int
Server_i::create_activator (PortableServer::POA_var first_poa)
{
  try
    {
      // An Servant Activator object is created which will activate
      // the servant on-demand.
      ACE_NEW_RETURN (servant_activator_impl_,
                      ServantActivator_i (orb_.in ()),
                      0);

      // Set ServantActivator_i object as the servant_manager of
      // firstPOA.
      first_poa->set_servant_manager (servant_activator_impl_);
      // For the code above, we're using the CORBA 3.0 servant manager
      // semantics supported by TAO.  For CORBA 2.x ORBs you'd need to
      // use the following code in place of the previous line:
      //
      // PortableServer::ServantManager_var servant_activator =
      //   servant_activator_impl_->_this ();
      //
      // first_poa->set_servant_manager (servant_activator.in (),
      //);

      // Create a reference with user created ID in firstPOA which
      // uses the ServantActivator. The servant dll name as well as
      // the factory function in the dll are used in creating the
      // objectId.

      PortableServer::ObjectId_var first_test_oid =
        servant_activator_impl_->create_dll_object_id ("Generic_Servant",
                                                       "create_test_i");

      first_test_ = first_poa->create_reference_with_id (first_test_oid.in (),
                                                        "IDL:test:1.0");
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Server_i:create_activator ()");
      return 1;
    }

  return 0;
}
示例#3
0
PortableServer::POA_ptr ossie::corba::createGCPOA(PortableServer::POA_ptr parent, const std::string& name)
{
    CORBA::PolicyList policy_list;
    policy_list.length(2);
    policy_list[0] = parent->create_servant_retention_policy(PortableServer::NON_RETAIN);
    policy_list[1] = parent->create_request_processing_policy(PortableServer::USE_SERVANT_MANAGER);

    PortableServer::POAManager_var poa_mgr = parent->the_POAManager();
    PortableServer::POA_var poa = parent->create_POA(name.c_str(), poa_mgr, policy_list);

    for (size_t ii = 0; ii < policy_list.length(); ++ii) {
        policy_list[ii]->destroy();
    }

    GCServantLocator* manager = new GCServantLocator();
    PortableServer::ServantManager_var manager_ref = manager->_this();
    poa->set_servant_manager(manager_ref);
    manager->_remove_ref();

    return poa._retn();
}
示例#4
0
int main(int argc, char* argv[]) {

//   // Signals staff
//   signal(SIGINT,  handler);
//   signal(SIGTERM, handler);
//   signal(SIGKILL, handler);
  
  // Print the welcome message
  printWelcome();
  
  //
  // Check TIDNaming arguments
  //
  /*
   * Note: this TIDNaming special arguments may be passed to ORB
   * initialization with no problems. Any unknown argument will be ignored
   * by ORB, so no change is needed for argv.
   */
  const char * persistence_dir = "";
  int max_binding_iterators = 40;
  const char * ior_file = "";

  for (int i = 1; i < argc; i++)
  {
    if (strcmp(argv[i], "--help") == 0)
    {
      printUsage(argv[0]);
      _exit(0);
    }

    if (strcmp(argv[i], "--version") == 0)
    {
      cerr << "TIDNaming C++ version " << TIDNaming::st_version << endl;
      _exit(0);
    }
    
    if (strcmp(argv[i], "--persistence-dir") == 0)
     {
       if (i == argc - 1)
       {
         cerr << "Error: --persistence-dir specified but no path given" << endl;
         printUsage(argv[0]);
         _exit(-1);
       }
       persistence_dir = argv[i+1];
     }

    if (strcmp(argv[i], "--max_binding_iterators") == 0) {
      char* ptr;
      long  laux;
      laux = strtol(argv[i+1], &ptr, 10);
      max_binding_iterators = laux;
    }

    if (strcmp(argv[i], "--ior") == 0) {
       if (i == argc - 1)
       {
         cerr << "Error: --ior specified but no file name given" << endl;
         printUsage(argv[0]);
         _exit(-1);
       }
       ior_file = argv[i+1];
    }

  }

  DMSG("Executing in debug mode, a lot of messages will be "\
       "printed to stderr");
  DMSG_P("Using '", persistence_dir, "' as persistence directory"); 
  DMSG_P("Using '", ior_file, "' as ior output file"); 

  char * port = strdup("2809");
  char * ssl_port = strdup("");
  bool port_given = false;
  bool ssl_port_given = false;
  bool ssl_config = false;

  try {
     
     //
     // Start TIDThread library
     //
     TIDThr::init();

     //
     // Check for -ORB_iiop_orb_port to set NameService default
     //
     int new_argc = argc + 2;
     char * new_argv[new_argc];
     for (int i = 1; i < argc; i++)
     {
       new_argv[i] = argv[i]; // No strdup is needed

       if (strcmp(argv[i], "-ORB_iiop_orb_port") == 0)
       {
         port_given = true;
         free(port);
         port = strdup(argv[i+1]);
       }

       if (strcmp(argv[i], "-ORB_ssl_port") == 0)
       {
         ssl_port_given = true; // util??
         free(ssl_port);
         ssl_port = strdup(argv[i+1]);
       }
       if (strcmp(argv[i], "-ORB_ssl_private_key") == 0)
       {
         for (int j = 1; j < argc; j++) {
           if (strcmp(argv[j], "-ORB_ssl_certificate") == 0) {
             ssl_config = true;
             break;
           }
         }
       }
     }
     new_argv[new_argc - 2] = "-ORB_iiop_orb_port";
     new_argv[new_argc - 1] = port;

     int orb_argc     = port_given ? argc : new_argc;
     char ** orb_argv = port_given ? argv : new_argv;

     //
     // ORB initialization
     //
     my_global_orb = CORBA::ORB_init(orb_argc, orb_argv);

     // Get internal ORB 
     TIDorb::core::TIDORB* m_orb = 
       dynamic_cast<TIDorb::core::TIDORB*> (CORBA::ORB::_duplicate(my_global_orb));

     //
     // Getting RootPOA & Manager references
     //
     CORBA::Object_var poa_obj = my_global_orb->resolve_initial_references("RootPOA");
     PortableServer::POA_ptr rootPOA = PortableServer::POA::_narrow(poa_obj);

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


     //
     // NamingContexts POA creation
     //
     CORBA::PolicyList policies;
     policies.length(4);

     policies[0] = rootPOA->create_servant_retention_policy(PortableServer::RETAIN);
     policies[1] = rootPOA->create_request_processing_policy(
                                                   PortableServer::USE_SERVANT_MANAGER);
     policies[2] = rootPOA->create_id_assignment_policy(PortableServer::USER_ID);
     policies[3] = rootPOA->create_lifespan_policy(PortableServer::PERSISTENT);

     PortableServer::POA_var namingContextsPOA = 
       rootPOA->create_POA("namingContextsPOA", manager, policies);

     PortableServer::POAManager_var namingContextsManager = 
       namingContextsPOA->the_POAManager();


     //
     // BindingIterators POA creation
     //
     CORBA::PolicyList bindingIterators_policies;
     bindingIterators_policies.length(2);

     bindingIterators_policies[0] = 
       rootPOA->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL); 
     bindingIterators_policies[1] = 
       rootPOA->create_id_assignment_policy(PortableServer::USER_ID);

     PortableServer::POA_var bindingIteratorsPOA = 
       namingContextsPOA->create_POA("bindingIteratorsPOA", namingContextsManager, 
                                     bindingIterators_policies);


     // 
     // Creates and sets a new ServantManager
     // 

     TIDNaming::ServantManagerNSImpl* servant_manager = 
       new TIDNaming::ServantManagerNSImpl(my_global_orb, bindingIteratorsPOA,
                                           max_binding_iterators);

     namingContextsPOA->set_servant_manager(servant_manager);


     // Creates the reference to the "root.ctx". Dont create it
     // This fragment of code is not needed anymore. It creates the
     // initial reference to root naming context, now created from
     // PersistenceManager class.
     /*
     PortableServer::ObjectId_var oid =
       PortableServer::string_to_ObjectId("root.ctx"); // Change to "NameService"

     CORBA::Object_var obj = 
       namingContextsPOA->create_reference_with_id(oid,"IDL:omg.org/CosNaming/NamingContextExt:1.0");  
     */

     // Manager activation (ORB/POA staff)
     manager->activate();
     namingContextsManager->activate();


     //
     // Check if has persistence 
     //
     if (strcmp(persistence_dir, "") != 0) {

       if (m_orb->trace != NULL){
         TIDorb::util::StringBuffer msg;
         msg << "Using '" << persistence_dir << "' as persistence directory";
         m_orb->print_trace(TIDorb::util::TR_USER, msg.str().data());
       }

       //
       // Recover the persistent data 
       //
       try {
         TIDNaming::NamingContextFileIOFactory::init(persistence_dir);
       }
       catch (TIDNaming::NamingContextFileIOFactory::InvalidPathException & e) {
         if (m_orb->trace != NULL) {
           TIDorb::util::StringBuffer msg;
           msg << "Error: cannot initialize persistence directory '";
           msg << e.path << "'";
           m_orb->print_trace(TIDorb::util::TR_ERROR, msg.str().data());
         }
         printUsage(argv[0]);
         _exit(-1);
       }

       loadPersistence(namingContextsPOA.inout(), 
                       bindingIteratorsPOA.inout(),
                       ior_file);


     } else {

       //
       // Start without persistent data 
       //     
       try {
         TIDNaming::NamingContextNullIOFactory::init();
       }
       catch (...) {
         printUsage(argv[0]);
         _exit(-1);
       }
       
       if (m_orb->trace != NULL)
         m_orb->print_trace(TIDorb::util::TR_USER, 
                            "No root context found. Initializing a new one... ");

       CosNaming::NamingContext_var root_nc = 
         createNamingContextReference(namingContextsPOA, 
                                      NamingInternals::RootNamingContextOID);

       // Get ssl system assigned port
       if (ssl_config && (!ssl_port_given)) {
         TIDorb::portable::Stub* stub_obj = 
           dynamic_cast<TIDorb::portable::Stub*> ((CORBA::Object*)root_nc);
         TIDorb::core::ObjectDelegateImpl* obj_delegate = 
           dynamic_cast<TIDorb::core::ObjectDelegateImpl*> (stub_obj->_get_delegate());
         TIDorb::core::iop::IOR* ior = obj_delegate->getReference();
         SSLIOP::SSL* _ssl = ior->get_SSL();
         free(ssl_port);
         ssl_port = (char*)malloc(6);
         sprintf(ssl_port, "%d", _ssl->port);         
       }
       registerNameService(my_global_orb, root_nc, ior_file);

       if (m_orb->trace != NULL)
         m_orb->print_trace(TIDorb::util::TR_DEBUG, "Done");
       
       
     }

     //
     // Run the ORB loop forever
     //
     TIDorb::util::StringBuffer msg;
     msg << "Serving at port " << port << "... " << endl;
     if (ssl_config) {
       msg.seekp(0, ios::beg);
       msg << "Serving at SSL port " << ssl_port << "... " << endl;
     }
     if (m_orb->trace != NULL)
       m_orb->print_trace(TIDorb::util::TR_USER,  msg.str().data());
     cerr << msg.str().data();

     my_global_orb->run();

     my_global_orb->destroy();

  }
  catch (const CORBA::INITIALIZE & ex) {
    cerr << "ERROR: cannot initialize Naming Service at port ";
    if (ssl_config) 
      cerr << ssl_port;
    else
      cerr << port;
    cerr << " due to: " << ex << endl;
  }
  catch (const CORBA::Exception& ex) {
    cerr << "ERROR: Naming Server Exception: " << ex << endl << flush;
    exit (1);
  }
  catch (...) {
    cerr << "ERROR: unexpected exception raised" << endl << flush;
    exit (1);
  }

  free(port);
  free(ssl_port);

}