예제 #1
1
파일: server2.cpp 프로젝트: CCJY/ATCD
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      Server_ORBInitializer2 *temp_initializer = 0;
      ACE_NEW_RETURN (temp_initializer,
                      Server_ORBInitializer2,
                      -1);  // No exceptions yet!
      PortableInterceptor::ORBInitializer_var orb_initializer =
        temp_initializer;

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

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

      CORBA::Object_var poa_object =
        orb->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 ();

      CORBA::PolicyList policies (2);
      policies.length (2);

      policies[0] =
        root_poa->create_id_assignment_policy (PortableServer::USER_ID);

      policies[1] =
        root_poa->create_lifespan_policy (PortableServer::PERSISTENT);

      PortableServer::POA_var my_poa =
        root_poa->create_POA ("my_poa",
                              poa_manager.in (),
                              policies);

      // Creation of the new POA is over, so destroy the Policy_ptr's.
      for (CORBA::ULong i = 0; i < policies.length (); ++i)
        {
          CORBA::Policy_ptr policy = policies[i];
          policy->destroy ();
        }


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

      Hello *hello_impl = 0;
      ACE_NEW_RETURN (hello_impl,
                      Hello (orb.in (), Test::Hello::_nil (), my_id_number),
                      -1);
      PortableServer::ServantBase_var owner (hello_impl);

      PortableServer::ObjectId_var server_id =
        PortableServer::string_to_ObjectId ("server_id");

      my_poa->activate_object_with_id (server_id.in (),
                                       hello_impl);

      CORBA::Object_var hello =
        my_poa->id_to_reference (server_id.in ());

      CORBA::String_var ior =
        orb->object_to_string (hello.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,
                           "Cannot open output file for writing IOR: %s\n",
                           ior_output_file),
                           -1);
      ACE_OS::fprintf (output_file, "%s", ior.in ());
      ACE_OS::fclose (output_file);

      poa_manager->activate ();

      orb->run ();

      root_poa->destroy (1, 1);

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

  return 0;
}
예제 #2
0
CORBA::Boolean
ImR_Adapter::unknown_adapter (PortableServer::POA_ptr parent,
                              const char *name)
{
  ACE_ASSERT (! CORBA::is_nil(parent));
  ACE_ASSERT (name != 0);
  CORBA::PolicyList policies (3);

  const char *exception_message = "Null Message";
  policies.length (3);
  try
    {
      // Servant Retention Policy
      exception_message = "While PortableServer::POA::create_servant_retention_policy";
      policies[0] =
        parent->create_servant_retention_policy (PortableServer::NON_RETAIN);

      // Request Processing Policy
      exception_message = "While PortableServer::POA::create_request_processing_policy";

      policies[1] =
        parent->create_request_processing_policy (PortableServer::USE_DEFAULT_SERVANT);
      policies[2] =
        parent->create_id_uniqueness_policy (PortableServer::MULTIPLE_ID);

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

      exception_message = "While create_POA";
      PortableServer::POA_var child =
        parent->create_POA (name,
                            poa_manager.in (),
                            policies);

      exception_message = "While policy->destroy";
      for (CORBA::ULong i = 0; i < policies.length (); ++i)
        {
          CORBA::Policy_ptr policy = policies[i];
          policy->destroy ();
        }

      exception_message = "While child->the_activator";
      child->the_activator (this);

      exception_message = "While set_servant";
      child->set_servant (this->default_servant_);
    }
  catch (const CORBA::Exception& ex)
    {
      ORBSVCS_ERROR ((LM_ERROR,
                  "IMR_Adapter_Activator::unknown_adapter - %s\n",
                  exception_message));
      ex._tao_print_exception ("System Exception");
      return 0;
    }

  // Finally, now everything is fine
  return 1;
}
예제 #3
0
파일: Manager.cpp 프로젝트: asdlei00/ACE
int
Manager::init (int argc, ACE_TCHAR *argv[])
{
  this->orb_ = CORBA::ORB_init (argc, argv);

  // Obtain the RootPOA.
  CORBA::Object_var obj_var =
    this->orb_->resolve_initial_references ("RootPOA");

  // Get the POA_var object from Object_var.
  PortableServer::POA_var root_poa_var =
    PortableServer::POA::_narrow (obj_var.in ());

  // Get the POAManager of the RootPOA.
  PortableServer::POAManager_var poa_manager_var =
    root_poa_var->the_POAManager ();

  poa_manager_var->activate ();

  // Policies for the childPOA to be created.
  CORBA::PolicyList policies (4);
  policies.length (4);

  // The next two policies are common to both
  // Id Assignment Policy
  policies[0] =
    root_poa_var->create_id_assignment_policy (PortableServer::USER_ID);

  // Lifespan policy
  policies[1] =
    root_poa_var->create_lifespan_policy (PortableServer::PERSISTENT);

  // Tell the POA to use a servant manager
  policies[2] =
    root_poa_var->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER);

  // Servant Retention Policy -> Use a locator
  policies[3] =
    root_poa_var->create_servant_retention_policy (PortableServer::NON_RETAIN);

  ACE_CString name = "newPOA";

  this->new_poa_var_ =
    root_poa_var->create_POA (name.c_str (),
                              poa_manager_var.in (),
                              policies);

  // Creation of childPOAs is over. Destroy the Policy objects.
  for (CORBA::ULong i = 0;
       i < policies.length ();
       ++i)
    {
      CORBA::Policy_ptr policy = policies[i];
      policy->destroy ();
    }

  return 0;
}
TAO_BEGIN_VERSIONED_NAMESPACE_DECL

TAO::Utils::PolicyList_Destroyer::~PolicyList_Destroyer() throw ()
{
  for (CORBA::ULong i = 0; i != length(); ++i)
    {
      CORBA::Policy_ptr policy = (*this)[i];
      if (!CORBA::is_nil (policy))
        {
          try
            {
              policy->destroy ();
              (*this)[i] = CORBA::Policy::_nil();
            }
          catch (...)
            {
            }
        }
    }
}
예제 #5
0
파일: server.cpp 프로젝트: OspreyHub/ATCD
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
  {
    CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
    if (parse_args (argc, argv) != 0)
    {
      return 1;
    }

    CORBA::Object_var object =
      orb->resolve_initial_references ("RootPOA");
    PortableServer::POA_var rootPOA =
      PortableServer::POA::_narrow (object.in ());
    PortableServer::POAManager_var poa_manager =
      rootPOA->the_POAManager ();

    CORBA::PolicyList policies (5);
    policies.length (5);

    // Lifespan policy
    policies[0] =
      rootPOA->create_lifespan_policy (PortableServer::PERSISTENT);

    // Servant Retention Policy
    policies[1] =
      rootPOA->create_servant_retention_policy (PortableServer::RETAIN );

    // ID Assignment Policy
    policies[2] =
      rootPOA->create_id_assignment_policy (PortableServer::USER_ID );

    // Request Processing Policy
    policies[3] =
      rootPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY );

    // Threading policy
    policies[4] =
      rootPOA->create_thread_policy (PortableServer::ORB_CTRL_MODEL);

    PortableServer::POA_var poa_a = rootPOA->create_POA ("poaA",
        poa_manager.in (),
        policies
        );
    PortableServer::POA_var poa_c = rootPOA->create_POA ("poaC",
        poa_manager.in (),
        policies
        );

    for (CORBA::ULong i = 0;
      i < policies.length ();
      ++i)
    {
      CORBA::Policy_ptr policy = policies[i];
      policy->destroy ();
    }

    Test_Time_i* time = new Test_Time_i();

    PortableServer::ObjectId_var oid =
      PortableServer::string_to_ObjectId ("Server_A");
    poa_a->activate_object_with_id (oid.in (), time);
    CORBA::Object_var time_obj = poa_a->id_to_reference(oid.in());
    CORBA::String_var ior =
      orb->object_to_string (time_obj.in ());

    poa_manager->activate ();

    FILE *output_file = ACE_OS::fopen (pid_file, ACE_TEXT ("w"));
    if (output_file == 0)
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("Cannot open output file for writing IOR: %s\n"),
                         pid_file),
                        1);
    int pid = static_cast<int> (ACE_OS::getpid ());
    ACE_OS::fprintf (output_file, "%d\n", pid);
    ACE_OS::fclose (output_file);

    orb->run ();

    rootPOA->destroy (1, 1);
    orb->destroy ();
  }
  catch (const CORBA::Exception &ex)
  {
    ex._tao_print_exception (ACE_TEXT ("server:"));
    return 1;
  }

  return 0;
}
예제 #6
0
int
Airplane_Server_i::init (int argc, ACE_TCHAR** argv)
{
  try
    {
      // Initialize the ORB
      this->orb_ = CORBA::ORB_init (argc, argv);

      // Save pointers to the command line arguments
      this->argc_ = argc;
      this->argv_ = argv;

      // Now check the arguments for our options
      int retval = this->parse_args ();

      if (retval != 0)
        return retval;

      // Get the POA from the ORB.
      CORBA::Object_var obj =
        this->orb_->resolve_initial_references ("RootPOA");
      ACE_ASSERT(! CORBA::is_nil (obj.in ()));

      // Narrow the object to a POA.
      root_poa_ = PortableServer::POA::_narrow (obj.in ());

      // Get the POA_Manager.
      this->poa_manager_ = this->root_poa_->the_POAManager ();

      // We now need to create a POA with the persistent and user_id policies,
      // since they are need for use with the Implementation Repository.

      CORBA::PolicyList policies (2);
      policies.length (2);

      policies[0] =
        this->root_poa_->create_id_assignment_policy (PortableServer::USER_ID);

      policies[1] =
        this->root_poa_->create_lifespan_policy (PortableServer::PERSISTENT);

      // Since the Implementation Repository keys off of the POA name, we need
      // to use the server_name_ as the POA's name.
      this->airplane_poa_ =
        this->root_poa_->create_POA (this->server_name_.c_str(),
                                     this->poa_manager_.in (),
                                     policies);

      // Creation of the new POA is over, so destroy the Policy_ptr's.
      for (CORBA::ULong i = 0; i < policies.length (); ++i)
        {
          CORBA::Policy_ptr policy = policies[i];
          policy->destroy ();
        }

      ACE_NEW_RETURN (this->server_impl_, Airplane_i, -1);

      PortableServer::ObjectId_var server_id =
        PortableServer::string_to_ObjectId ("server");

      this->airplane_poa_->activate_object_with_id (server_id.in (),
                                                    this->server_impl_);

      obj = this->airplane_poa_->id_to_reference (server_id.in ());
      CORBA::String_var ior =
        this->orb_->object_to_string (obj.in ());
      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG, "The ImRified IOR is: <%C>\n", ior.in ()));

      TAO_Root_POA* tmp_poa = dynamic_cast<TAO_Root_POA*>(airplane_poa_.in());
      obj = tmp_poa->id_to_reference_i (server_id.in (), false);
      CORBA::String_var plain_ior =
        this->orb_->object_to_string (obj.in ());
      if (TAO_debug_level > 0)
        ACE_DEBUG ((LM_DEBUG, "The plain IOR is: <%C>\n", plain_ior.in ()));

      // Note : The IORTable will only be used for those clients who try to
      // invoke indirectly using a simple object_key reference
      // like "corbaloc::localhost:8888/airplane_server".
      obj = this->orb_->resolve_initial_references ("IORTable");

      IORTable::Table_var adapter =
        IORTable::Table::_narrow (obj.in ());
      ACE_ASSERT(! CORBA::is_nil (adapter.in ()));
      adapter->bind (this->server_name_.c_str(), plain_ior.in ());

      this->poa_manager_->activate ();

      if (this->ior_output_file_)
        {
          ACE_OS::fprintf (this->ior_output_file_, "%s", ior.in ());
          ACE_OS::fclose (this->ior_output_file_);
        }

      if (this->pid_output_file_)
        {
          int pid = static_cast<int> (ACE_OS::getpid ());
          ACE_OS::fprintf (this->pid_output_file_, "%d\n", pid);
          ACE_OS::fclose (this->pid_output_file_);
        }
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Airplane_Server_i::init");
      throw;
    }

  return 0;
}
예제 #7
0
파일: serverB.cpp 프로젝트: OspreyHub/ATCD
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
  {
    CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

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

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

    ORB_Task worker (orb.in ());
    worker.activate (THR_NEW_LWP | THR_JOINABLE,
                      1);

    PortableServer::POA_var rootPOA =
      PortableServer::POA::_narrow (object.in ());
    PortableServer::POAManager_var poa_manager =
      rootPOA->the_POAManager ();

    CORBA::PolicyList policies (5);
    policies.length (5);

    // Lifespan policy
    policies[0] =
      rootPOA->create_lifespan_policy (PortableServer::PERSISTENT);

    // Servant Retention Policy
    policies[1] =
      rootPOA->create_servant_retention_policy (PortableServer::RETAIN );

    // ID Assignment Policy
    policies[2] =
      rootPOA->create_id_assignment_policy (PortableServer::USER_ID );

    // Request Processing Policy
    policies[3] =
      rootPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY );

    // Threading policy
    policies[4] =
      rootPOA->create_thread_policy (PortableServer::ORB_CTRL_MODEL);

    if (server_notify_delay > 0)
    {
      ACE_OS::sleep (server_notify_delay);
      ACE_DEBUG ((LM_DEBUG, "(%P|%t)ServerB Now register with IMR \n"));
    }

    PortableServer::POA_var poa_a = rootPOA->create_POA ("poaB",
        poa_manager.in (),
        policies
        );

    for (CORBA::ULong i = 0;
      i < policies.length ();
      ++i)
    {
      CORBA::Policy_ptr policy = policies[i];
      policy->destroy ();
    }

    Test_Dummy_i* dummy = new Test_Dummy_i();

    PortableServer::ObjectId_var oid =
      PortableServer::string_to_ObjectId ("Server_B");
    poa_a->activate_object_with_id (oid.in (), dummy);
    CORBA::Object_var dummy_obj = poa_a->id_to_reference(oid.in());
    CORBA::String_var ior =
      orb->object_to_string (dummy_obj.in ());

    poa_manager->activate ();

    // 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,
      "Cannot open output file for writing IOR: %s",
      ior_output_file),
      1);
    ACE_OS::fprintf (output_file, "%s", ior.in ());
    ACE_OS::fclose (output_file);

    worker.wait ();

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

  return 0;
}
예제 #8
0
파일: Naming_Server.cpp 프로젝트: CCJY/ATCD
int
TAO_Naming_Server::init_with_orb (int argc,
                                  ACE_TCHAR *argv [],
                                  CORBA::ORB_ptr orb)
{
  int result;

  try
    {
      // Duplicate the ORB
      this->orb_ = CORBA::ORB::_duplicate (orb);

      // Get the POA from the ORB.
      CORBA::Object_var poa_object =
        orb->resolve_initial_references ("RootPOA");

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

      // Check the non-ORB arguments.  this needs to come before we
      // initialize my_naming_server so that we can pass on some of
      // the command-line arguments.
      result = this->parse_args (argc, argv);

      if (result < 0)
        return result;

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

      // Get the POA_Manager.
      PortableServer::POAManager_var poa_manager =
        this->root_poa_->the_POAManager ();

#if defined (CORBA_E_MICRO)
      this->ns_poa_ = PortableServer::POA::_duplicate (this->root_poa_);
#else
      int numPolicies = 2;
# if (TAO_HAS_MINIMUM_POA == 0)
      if (this->use_storable_context_)
        {
          this->use_servant_activator_ = true;
        }

      if (this->use_servant_activator_) {
        numPolicies += 2;
      }
# endif /* TAO_HAS_MINIMUM_POA */

      CORBA::PolicyList policies (numPolicies);
      policies.length (numPolicies);

      // Id Assignment policy
      policies[0] =
        this->root_poa_->create_id_assignment_policy (PortableServer::USER_ID);

      // Lifespan policy
      policies[1] =
        this->root_poa_->create_lifespan_policy (PortableServer::PERSISTENT);

# if (TAO_HAS_MINIMUM_POA == 0) && !defined (CORBA_E_COMPACT)
      if (this->use_servant_activator_)
        {
          // Request Processing Policy
          policies[2] =
            this->root_poa_->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER);

          // Servant Retention Policy
          policies[3] =
            this->root_poa_->create_servant_retention_policy (PortableServer::RETAIN);
        }
# endif /* TAO_HAS_MINIMUM_POA */

      // We use a different POA, otherwise the user would have to change
      // the object key each time it invokes the server.
      this->ns_poa_ = this->root_poa_->create_POA ("NameService",
                                                   poa_manager.in (),
                                                   policies);
      // Warning!  If create_POA fails, then the policies won't be
      // destroyed and there will be hell to pay in memory leaks!

      // Creation of the new POAs over, so destroy the Policy_ptr's.
      for (CORBA::ULong i = 0;
           i < policies.length ();
           ++i)
        {
          CORBA::Policy_ptr policy = policies[i];
          policy->destroy ();
        }
#endif /* CORBA_E_MICRO */

      poa_manager->activate ();

#if defined (CORBA_E_MICRO)
      result = this->init (orb,
                           this->ns_poa_.in (),
                           this->context_size_,
                           0,
                           0,
                           0,
                           0,
                           this->multicast_,
                           false,
                           this->round_trip_timeout_,
                           this->use_round_trip_timeout_);
#else
      result = this->init (orb,
                           this->ns_poa_.in (),
                           this->context_size_,
                           0,
                           0,
                           this->persistence_file_name_,
                           this->base_address_,
                           this->multicast_,
                           this->use_storable_context_,
                           this->round_trip_timeout_,
                           this->use_round_trip_timeout_);
#endif /* CORBA_E_MICRO */

      if (result == -1)
        return result;
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        "TAO_Naming_Server::init_with_orb");
      return -1;
    }

  // If an ior file name was provided on command line
  if (this->ior_file_name_ != 0)
    {
      CORBA::String_var ns_ior = this->naming_service_ior ();
      if (this->write_ior_to_file (
            ns_ior.in (),
            ACE_TEXT_ALWAYS_CHAR (this->ior_file_name_)) != 0)
        {
          ORBSVCS_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT("Unable to open %C for writing:(%u) %p\n"),
                             this->ior_file_name_,
                             ACE_ERRNO_GET,
                             ACE_TEXT("TAO_Naming_Server::init_with_orb")),
                            -1);
        }
    }

  if (this->pid_file_name_ != 0)
    {
      FILE *pidf = ACE_OS::fopen (this->pid_file_name_, ACE_TEXT("w"));
      if (pidf != 0)
        {
          ACE_OS::fprintf (pidf,
                           "%ld\n",
                           static_cast<long> (ACE_OS::getpid ()));
          ACE_OS::fclose (pidf);
        }
    }

  return 0;
}
예제 #9
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{

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

      // Obtain the RootPOA.
      CORBA::Object_var object =
        orb->resolve_initial_references ("RootPOA");

      // Narrow to POA.
      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (object.in ());

      // Get the POAManager of the RootPOA.
      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();

      // Policies for the new POA.
      CORBA::PolicyList policies (3);
      policies.length (3);

      // Request Processing Policy.
      policies[0] =
        root_poa->create_request_processing_policy (PortableServer::USE_DEFAULT_SERVANT);

      // Id Uniqueness Policy.
      policies[1] =
        root_poa->create_id_uniqueness_policy (PortableServer::MULTIPLE_ID);

      // Servant Retention Policy.
      policies[2] =
        root_poa->create_servant_retention_policy (PortableServer::NON_RETAIN);

      // Create POA to host default servant.
      ACE_CString name = "Default Servant";
      PortableServer::POA_var default_servant_poa =
        root_poa->create_POA (name.c_str (),
                              poa_manager.in (),
                              policies);

      // Destroy policies.
      for (CORBA::ULong i = 0;
           i < policies.length ();
           ++i)
        {
          CORBA::Policy_ptr policy = policies[i];
          policy->destroy ();
        }

      // Activate POA manager.
      poa_manager->activate ();

      test_reference_to_servant_active_object(root_poa.in ());

      // Test servant.
      test_i test;
      CORBA::ULong expected_refcount = 1;

      (void) test_get_servant_with_no_set (default_servant_poa.in());

      (void) test_get_servant_manager (default_servant_poa.in());

      (void) test_set_servant_manager (default_servant_poa.in());

      // Register default servant.
      default_servant_poa->set_servant (&test);
      expected_refcount++;

      // Create dummy id.
      PortableServer::ObjectId_var id =
        PortableServer::string_to_ObjectId ("id");

      // Create dummy object.
      object =
        default_servant_poa->create_reference ("IDL:test:1.0");

      // Invoke id_to_servant(). Should retrieve default servant.
      PortableServer::ServantBase_var servant =
        default_servant_poa->id_to_servant (id.in ());
      expected_refcount++;

      // Assert correctness.
      ACE_ASSERT (&test == servant.in());

      // Invoke reference_to_servant(). Should retrieve default servant.
      servant =
        default_servant_poa->reference_to_servant (object.in ());
      expected_refcount++;

      // Assert correctness.
      ACE_ASSERT (&test == servant.in());

      // Report success.
      ACE_DEBUG ((LM_DEBUG,
                  "Default_Servant test successful\n"));

      CORBA::ULong refcount =
        test._refcount_value ();

      ACE_UNUSED_ARG (refcount);
      ACE_UNUSED_ARG (expected_refcount);
      ACE_ASSERT (expected_refcount == refcount);

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

  return 0;
}
예제 #10
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{

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

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

      // Obtain the RootPOA.
      CORBA::Object_var obj =
        orb->resolve_initial_references ("RootPOA");

      // Narrow the Object reference to a POA reference
      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (obj.in ());

      // Get the POAManager of RootPOA

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


      CORBA::PolicyList policies (4);
      policies.length (4);

      // ID Assignment Policy
      policies[0] =
        root_poa->create_id_assignment_policy (PortableServer::USER_ID);

      // Lifespan Policy
      policies[1] =
        root_poa->create_lifespan_policy (PortableServer::PERSISTENT);

      // Request Processing Policy
      policies[2] =
        root_poa->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER);

      PortableServer::POA_var first_poa;
      {
        // Servant Retention Policy
        policies[3] =
          root_poa->create_servant_retention_policy (PortableServer::RETAIN);

        ACE_CString name = "firstPOA";

        // Create firstPOA as the child of RootPOA with the above policies
        // firstPOA will use SERVANT_ACTIVATOR because of RETAIN policy.
        first_poa = root_poa->create_POA (name.c_str (),
                                          poa_manager.in (),
                                          policies);

      }

      PortableServer::POA_var second_poa;
      {
        // Servant Retention Policy
        policies[3] =
          root_poa->create_servant_retention_policy (PortableServer::NON_RETAIN);

        ACE_CString name = "secondPOA";

        // Create secondPOA as child of RootPOA with the above policies
        // secondPOA will use a SERVANT_LOCATOR because of NON_RETAIN
        // policy.
        second_poa = root_poa->create_POA (name.c_str (),
                                           poa_manager.in (),
                                           policies);

      }

      // Destroy the policy objects as they have been passed to
      // create_POA and no longer needed.
      for (CORBA::ULong i = 0;
           i < policies.length ();
           ++i)
        {
          CORBA::Policy_ptr policy = policies[i];
          policy->destroy ();
        }

      // Allocate the servant activator.
      ServantActivator activator (orb.in ());

      // Set ServantActivator object as the servant_manager of
      // firstPOA.
      first_poa->set_servant_manager (&activator);
      // 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 =
      //   activator->_this ();
      //
      // first_poa->set_servant_manager (servant_activator.in (),
      //);

      // Create a reference with user created ID in firstPOA which uses
      // the ServantActivator.

      PortableServer::ObjectId_var first_test_oid =
        PortableServer::string_to_ObjectId ("first test");

      CORBA::Object_var first_test =
        first_poa->create_reference_with_id (first_test_oid.in (), "IDL:test:1.0");

      // Allocate the servant locator.
      ServantLocator locator (orb.in ());

      // Set ServantLocator object as the servant Manager of
      // secondPOA.
      second_poa->set_servant_manager (&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 line:
      //
      // PortableServer::ServantManager_var servant_locator =
      //   locator->_this ();
      //
      // second_poa->set_servant_manager (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");

      CORBA::Object_var second_test =
        second_poa->create_reference_with_id (second_test_oid.in (),
                                              "IDL:test:1.0");

      // Invoke object_to_string on the references created in firstPOA and
      // secondPOA.

      CORBA::String_var first_test_ior =
        orb->object_to_string (first_test.in ());


      CORBA::String_var second_test_ior =
        orb->object_to_string (second_test.in ());

      // Print the ior's of first_test and second_test.

      ACE_DEBUG((LM_DEBUG,"Cs\n%C\n",
                 first_test_ior.in (),
                 second_test_ior.in ()));

      int write_result = write_iors_to_file (first_test_ior.in (),
                                             second_test_ior.in ());
      if (write_result != 0)
        return write_result;

      // Set the poa_manager state to active, ready to process requests.
      poa_manager->activate ();

      // Run the ORB.
      orb->run ();

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

  return 0;
}
예제 #11
0
파일: acsLogSvc.cpp 프로젝트: jantogni/ACS
int main(int argc, char *argv[])
{

    CosNaming::NamingContext_var naming_context;
    int  nargc=0;
    char **nargv=0;
    const char *hn=ACSPorts::getIP();
    ACE_CString iorFile;

    if (argc>=2 && !ACE_OS_String::strcmp(argv[1], "-?")) {
        ACE_OS::printf ("USAGE: acsLogSvc  [-ORBInitRef NameService=iiop://yyy:xxxx/NameService] [-ORBEndpoint iiop://ip:port] [-o iorfile] [-silent]\n");
        return -1;
    }

// here we have to unset ACS_LOG_CENTRAL that we prevent filtering of log messages
    char *logCent=getenv("ACS_LOG_CENTRAL");
    if (logCent)
    {
        unsetenv("ACS_LOG_CENTRAL");
        printf("Unset ACS_LOG_CENTRAL which was previously set to %s\n", logCent);
    }//if

// create logging proxy
    LoggingProxy::ProcessName(argv[0]);
    ACE_Log_Msg::instance()->local_host(hn);
    LoggingProxy m_logger (0, 0, 31, 0);
    LoggingProxy::init (&m_logger);
    ACS_SHORT_LOG((LM_INFO, "Logging proxy successfully created !"));

    ACE_CString argStr;

    for(int i=1; i<argc; i++)
    {
        argStr += argv[i];
        argStr += " ";

        if (!ACE_OS_String::strcmp(argv[i], "-o") && (i+1)<argc)
        {
            iorFile = argv[i+1];
        }//if
    }//for

    if (argStr.find ("-ORBEndpoint")==ACE_CString::npos)
    {
        argStr = argStr + "-ORBEndpoint iiop://" + hn + ":" + ACSPorts::getLogPort().c_str();
    }

    ACS_SHORT_LOG((LM_INFO, "New command line is: %s", argStr.c_str()));

    ACE_OS::string_to_argv ((ACE_TCHAR*)argStr.c_str(), nargc, nargv);

    ACE_OS::signal(SIGINT,  TerminationSignalHandler);  // Ctrl+C
    ACE_OS::signal(SIGTERM, TerminationSignalHandler);  // termination request

    try
    {
        // Initialize the ORB
        ACE_OS::printf ("Initialising ORB ... \n");
        orb = CORBA::ORB_init (nargc, nargv, 0);
        ACE_OS::printf ("ORB initialsed !\n");
    }
    catch( CORBA::Exception &ex )
    {
        ex._tao_print_exception("Failed to initalise ORB");
        return -1;
    }


    if (!ACSError::init(orb.in()))
    {
        ACS_SHORT_LOG ((LM_ERROR, "Failed to initalise the ACS Error System"));
        return -1;
    }

// resolve naming service
    try
    {
        ACS_SHORT_LOG((LM_INFO, "Trying to connect to the Naming Service ...."));
        CORBA::Object_var naming_obj = orb->resolve_initial_references ("NameService");

        if (!CORBA::is_nil (naming_obj.in ()))
        {
            naming_context = CosNaming::NamingContext::_narrow (naming_obj.in ());
            ACS_SHORT_LOG((LM_INFO, "Connected to the Name Service"));
        }
        else
        {
            ACS_SHORT_LOG((LM_ERROR, "Could not connect the Name Service!"));
            return -1;
        }//if-else
    }
    catch( CORBA::Exception &_ex )
    {
        ACS_SHORT_LOG((LM_ERROR, "Could not connect the Name Service!"));
        return -1;
    }


    // logging service
    try
    {
        CORBA::Object_var log_obj;
        /*
              if (argStr.find ("-ORBInitRef NameService=")!=ACE_CString::npos)
        	{
        	// Initialize the ORB
        	ACE_OS::printf ("Initialising ORB ... \n");
        	orb = CORBA::ORB_init (nargc, nargv, 0);
        	ACE_OS::printf ("ORB initialsed !\n");
                //Naming Service
        	ACE_OS::printf ("Resolving  Naming service ... \n");
        	CORBA::Object_var naming_obj =
        	  orb->resolve_initial_references ("NameService");
        	if (!CORBA::is_nil (naming_obj.in ()))
        	  {
        	    CosNaming::NamingContext_var naming_context =
        	      CosNaming::NamingContext::_narrow (naming_obj.in ());
        	    ACE_OS::printf ( "Naming Service resolved !\n");
        */

        ACE_OS::printf ( "Resolving Logging Service from Naming service ...\n");
        CosNaming::Name name;
        name.length(1);
        name[0].id = CORBA::string_dup("Log");
        log_obj = naming_context->resolve(name);
        /*
          }
        	else
        	  {
        	    ACS_LOG(LM_SOURCE_INFO, "main", (LM_ERROR,  "Failed to initialise the Name Service!"));
        	  }
        	}//if naming Service

              else
        	{
        	ACE_OS::printf ("Getting Log from the Manager... \n");
        	CORBA::ULong status;
        	maci::Manager_ptr manager = maci::MACIHelper::resolveManager (orb.in(), nargc, nargv, 0, 0);


        	log_obj = manager->get_COB(0, "Log", true,  status);
        	}
        */
        if (!CORBA::is_nil (log_obj.in()))
        {
            Logging::AcsLogService_var logger = Logging::AcsLogService::_narrow(log_obj.in());
            ACE_OS::printf ( "Logging Service resolved !\n");

            m_logger.setCentralizedLogger(logger.in());
        }
        else
        {
            ACS_LOG(LM_SOURCE_INFO, "main", (LM_ERROR, "Failed to initialise the Logging Service!"));
            return -1;
        }//if-else
    }
    catch( CORBA::Exception &__ex )
    {
        __ex._tao_print_exception("Failed to get and set the centralized logger");
        return -1;
    }


    try
    {
        //Get a reference to the RootPOA
        ACE_OS::printf("Creating POA ... \n");
        CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");

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


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


        CORBA::PolicyList policy_list;
        policy_list.length(5);
        policy_list[0] = root_poa->create_request_processing_policy (PortableServer::USE_DEFAULT_SERVANT);

        policy_list[1] =  root_poa->create_id_uniqueness_policy (PortableServer::MULTIPLE_ID);

        policy_list[2] = root_poa->create_id_assignment_policy(PortableServer::USER_ID);

        policy_list[3] = root_poa->create_servant_retention_policy(PortableServer::NON_RETAIN);

        policy_list[4] =  root_poa->create_lifespan_policy (PortableServer::PERSISTENT);

        printf("policies are created !\n");

        PortableServer::POA_var poa = root_poa->create_POA("ACSLogSvc", poa_manager.in(), policy_list);

        ACE_OS::printf("POA created !\n");

        for (CORBA::ULong i = 0; i < policy_list.length (); ++i) {
            CORBA::Policy_ptr policy = policy_list[i];
            policy->destroy ();

        }
        printf("Policies are destroyed !\n");

        ACSLogImpl acsLogSvc (m_logger);
        poa->set_servant (&acsLogSvc);


        PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId ("ACSLogSvc");
        obj = poa->create_reference_with_id (oid.in(),  acsLogSvc._interface_repository_id());


        CORBA::String_var ior = orb->object_to_string (obj.in());


        // if ther is file name write ior in it
        if (iorFile.length()!=0)
        {
            FILE *output_file = ACE_OS::fopen (iorFile.c_str(), "w");
            if (output_file == 0)
            {
                ACS_SHORT_LOG ((LM_ERROR,
                                "Cannot open output files for writing IOR: ior.ior"));
                return  -1;
            }//if

            int result = ACE_OS::fprintf (output_file, "%s", ior.in());
            if (result < 0)
            {
                ACS_SHORT_LOG ((LM_ERROR,
                                "ACE_OS::fprintf failed while writing %s to ior.ior", ior.in()));
                return  -1;
            }//if
            ACE_OS::fclose (output_file);
            ACS_SHORT_LOG((LM_INFO, "ACSLogSvc's IOR has been written into: %s", iorFile.c_str()));
        }//if


// adding ACSLog to NamingService
        if (!CORBA::is_nil (naming_context.in ()))
        {
            // register cdb server in Naming service
            CosNaming::Name name (1);
            name.length (1);
            name[0].id = CORBA::string_dup ("ACSLogSvc");
            naming_context->rebind (name, obj.in ());
            ACS_SHORT_LOG((LM_INFO, "ACSLogSvc service registered with Naming Services"));
        }//if

        CORBA::Object_var table_object =
            orb->resolve_initial_references ("IORTable");

        IORTable::Table_var adapter =
            IORTable::Table::_narrow (table_object.in ());

        if (CORBA::is_nil (adapter.in ()))
        {
            ACS_SHORT_LOG ((LM_ERROR, "Nil IORTable"));
        }
        else
        {
            adapter->bind ("ACSLogSvc", ior.in ());
        }

        poa_manager->activate ();


        ACS_SHORT_LOG((LM_INFO, "ACSLogSvc is waiting for incoming log messages ..."));
        if (argStr.find ("-ORBEndpoint")!=ACE_CString::npos)
            m_logger.setStdio(31);
        orb->run ();

        ACSError::done();
        LoggingProxy::done();
    }
    catch( CORBA::Exception &ex )
    {
        ex. _tao_print_exception("EXCEPTION CAUGHT");
        return -1;
    }

    return 0;
}
예제 #12
0
파일: server.cpp 프로젝트: OspreyHub/ATCD
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try {
    // First initialize the ORB, that will remove some arguments...
    CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "TestORB");

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

    CORBA::Object_var poa_object = orb->resolve_initial_references ("RootPOA");
    PortableServer::POA_var root_poa = PortableServer::POA::_narrow (poa_object.in());
    PortableServer::POAManager_var poa_manager = root_poa->the_POAManager ();
    poa_manager->activate ();

    // Make policies for child POA
    CORBA::PolicyList policies(2) ;
    policies.length(2) ;
    policies[0] = root_poa->create_lifespan_policy ( PortableServer::PERSISTENT ) ;
    policies[1] = root_poa->create_id_assignment_policy ( PortableServer::USER_ID ) ;

    PortableServer::POA_var poa = root_poa->create_POA ( "MyPOA", poa_manager.in(), policies );

    // Creation of the new POAs over, so destroy the Policy_ptr's.
    for ( CORBA::ULong i = 0 ; i < policies.length (); ++i ) {
      CORBA::Policy_ptr policy = policies[i];
      policy->destroy ();
    }

    // use this poa for making system objects
    Quoter_Stock_i::set_default_POA ( poa.in() ) ;

    // Create the servant
    Quoter_Stock_Factory_i *stock_factory_i = 0;
    ACE_NEW_RETURN (stock_factory_i,
                    Quoter_Stock_Factory_i,
                    -1);
    PortableServer::ServantBase_var safe (stock_factory_i);

    // Activate it to obtain the object reference
    PortableServer::ObjectId_var id =
      root_poa->activate_object (stock_factory_i);

    CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());

    Quoter::Stock_Factory_var stock_factory =
      Quoter::Stock_Factory::_narrow (object_act.in ());

    // Put the object reference as an IOR string
    CORBA::String_var ior = orb->object_to_string (stock_factory.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,
                          "Cannot open output file for writing IOR: %s\n",
                          ior_output_file),
                          1);
    ACE_OS::fprintf (output_file, "%s", ior.in ());
    ACE_OS::fclose (output_file);

    ACE_Time_Value timeout (15);
    orb->run (timeout);

    // Destroy the POA, waiting until the destruction terminates
    root_poa->destroy (1, 1);
    orb->destroy ();
  }
  catch (const CORBA::Exception & e) {
    cerr << "CORBA exception raised: " << e << endl;
  }
  return 0;
}
예제 #13
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 ();


     CORBA::PolicyList policies (4);
     policies.length (4);

     // ID Assignment Policy
     policies[0] =
       root_poa->create_id_assignment_policy (PortableServer::USER_ID);

     // Lifespan Policy
     policies[1] =
       root_poa->create_lifespan_policy (PortableServer::PERSISTENT);

     // Request Processing Policy
     policies[2] =
       root_poa->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER);

     PortableServer::POA_var first_poa;
     {
       // Servant Retention Policy
       policies[3] =
         root_poa->create_servant_retention_policy (PortableServer::RETAIN);

       ACE_CString name = "firstPOA";

       // Create firstPOA as the child of RootPOA with the above policies
       // firstPOA will use SERVANT_ACTIVATOR because of RETAIN policy.
       first_poa = root_poa->create_POA (name.c_str (),
                                         poa_manager.in (),
                                         policies);

     }

     // Destroy the policy objects as they have been passed to
     // create_POA and no longer needed.
     for (CORBA::ULong i = 0;
          i < policies.length ();
          ++i)
       {
         CORBA::Policy_ptr policy = policies[i];
         policy->destroy ();
       }
     // Allocate the servant activator.
     ServantActivator activator (this->sorb_.in (),  ACE_Thread::self ());
     // Set ServantActivator object as the servant_manager of
     // firstPOA.

     first_poa->set_servant_manager (&activator);
     // Create a reference with user created ID in firstPOA which uses
     // the ServantActivator.

     PortableServer::ObjectId_var first_test_oid =
         PortableServer::string_to_ObjectId ("first test");

     CORBA::Object_var first_test =
         first_poa->create_reference_with_id (first_test_oid.in (), "IDL:test:1.0");
        // Invoke object_to_string on the references created in firstPOA

     CORBA::String_var first_test_ior =
         this->sorb_->object_to_string (first_test.in ());

     // Print the ior's of first_test.
     ACE_DEBUG((LM_DEBUG,"<%C>\n",
                  first_test_ior.in ()));

     int write_result = write_iors_to_file (first_test_ior.in ());
     if (write_result != 0)
        return write_result;

     // Set the poa_manager state to active, ready to process requests.
     poa_manager->activate ();
     this->me_.signal ();
     // Run the ORB.
     this->sorb_->run ();

     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;
}
예제 #14
0
int main(int argc, char *argv[])
{
    int c, instance = -1;
    ACE_CString daemonRef;
    ACE_CString hostName;
    ACE_CString additional;
    for (;;) {
	int option_index = 0;
	c = getopt_long(argc, argv, "hi:d:H:a:",
			long_options, &option_index);
	if (c == -1)
	    break;
	switch (c) {
	case 'h':
	    usage(argv[0]);
	    return 0;
	case 'i':
	    instance = ACE_OS::atoi(optarg);
	    break;
	case 'd':
	    daemonRef = optarg;
	    break;
	case 'H':
	    hostName = optarg;
	    break;
	case 'a':
	    additional = optarg;
	    break;
	}
    }
    if (instance == -1) {
	ACE_OS::printf("Error: instance is a mandatory option try %s -h\n",
		       argv[0]);
	return -1;
    }

	#define DEFAULT_LOG_FILE_NAME "acs_local_log"
	ACE_CString daemonsLogFileName = getTempFileName(0, DEFAULT_LOG_FILE_NAME);

	// replace "ACS_INSTANCE.x" with "acsdaemonStartAcs_" + <timestamp>
	ACE_CString daemonsDir = "acsdaemonStartAcs_" + getStringifiedTimeStamp();

	ACE_CString instancePart("ACS_INSTANCE.");
	ACE_CString::size_type pos = daemonsLogFileName.find(instancePart);
	daemonsLogFileName =
			daemonsLogFileName.substring(0, pos) +
			daemonsDir +
			daemonsLogFileName.substring(pos + instancePart.length() + 1);	// +1 for skipping instance number

	ACE_OS::setenv("ACS_LOG_FILE", daemonsLogFileName.c_str(), 1);

	LoggingProxy *logger = new LoggingProxy(0, 0, 31);
    if (logger) {
	LoggingProxy::init(logger);
	LoggingProxy::ProcessName(argv[0]);
	LoggingProxy::ThreadName("main");
    } else
	ACS_SHORT_LOG((LM_INFO, "Failed to initialize logging."));

    StartCallback* sc = new StartCallback();

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

	// get a reference to the RootPOA
	CORBA::Object_var pobj = orb->resolve_initial_references("RootPOA");
	PortableServer::POA_var root_poa = PortableServer::POA::_narrow(pobj.in());
	PortableServer::POAManager_var poa_manager = root_poa->the_POAManager();
      
	// create policies
	CORBA::PolicyList policy_list;
	policy_list.length(5);
	policy_list[0] = root_poa->create_request_processing_policy(PortableServer::USE_DEFAULT_SERVANT);
	policy_list[1] = root_poa->create_id_uniqueness_policy(PortableServer::MULTIPLE_ID);
	policy_list[2] = root_poa->create_id_assignment_policy(PortableServer::USER_ID); 
	policy_list[3] = root_poa->create_servant_retention_policy(PortableServer::NON_RETAIN); 
	policy_list[4] = root_poa->create_lifespan_policy(PortableServer::PERSISTENT);
      
	// create a ACSDaemon POA with policies 
	PortableServer::POA_var poa = root_poa->create_POA("DaemonCallback", poa_manager.in(), policy_list);

	// destroy policies
	for (CORBA::ULong i = 0; i < policy_list.length(); ++i)
	    {
	    CORBA::Policy_ptr policy = policy_list[i];
	    policy->destroy();
	    }

	// set as default servant
	poa->set_servant(sc);

	// create reference
	PortableServer::ObjectId_var oid = PortableServer::string_to_ObjectId("DaemonCallback");
	pobj = poa->create_reference_with_id (oid.in(), sc->_interface_repository_id());
	CORBA::String_var m_ior = orb->object_to_string(pobj.in());

	// bind to IOR table
      	CORBA::Object_var table_object = orb->resolve_initial_references("IORTable");
	IORTable::Table_var adapter = IORTable::Table::_narrow(table_object.in());
      
	if (CORBA::is_nil(adapter.in()))
	    {
	    ACS_SHORT_LOG ((LM_ERROR, "Nil IORTable"));
	    return -1;
	    }
	else
	    {
	    adapter->bind("DaemonCallback", m_ior.in());
	    }

	// activate POA
	poa_manager->activate();

	ACS_SHORT_LOG((LM_INFO, "%s is waiting for incoming requests.", "DaemonCallback"));


	// construct default one
	if (daemonRef.length() == 0) {
	    if (hostName.length() == 0) {
		hostName = ACSPorts::getIP();
	    }
	    daemonRef = "corbaloc::";
	    daemonRef =
		daemonRef + hostName + ":" +
		ACSPorts::getServicesDaemonPort().c_str() +
		"/" + ::acsdaemon::servicesDaemonServiceName;
	    ACS_SHORT_LOG((LM_INFO,
			   "Using local ACS Services Daemon reference: '%s'",
			   daemonRef.c_str()));

	} else {
	    ACS_SHORT_LOG((LM_INFO,
			   "ACS Services Daemon reference obtained via command line: '%s'",
			   daemonRef.c_str()));
	}

	CORBA::Object_var obj = orb->string_to_object(daemonRef.c_str());
	if (CORBA::is_nil(obj.in())) {
	    ACS_SHORT_LOG((LM_INFO, "Failed to resolve reference '%s'.",
			   daemonRef.c_str()));
	    return -1;
	}

	acsdaemon::ServicesDaemon_var daemon =
	    acsdaemon::ServicesDaemon::_narrow(obj.in());
	if (CORBA::is_nil(daemon.in())) {
	    ACS_SHORT_LOG((LM_INFO, "Failed to narrow reference '%s'.",
			   daemonRef.c_str()));
	    return -1;
	}

	// @todo implement support for callback and wait for completion call
	acsdaemon::DaemonSequenceCallback_var dummyCallback = sc->_this();
	ACS_SHORT_LOG((LM_INFO, "Calling start_acs(%d, %s, dummyCallback).", instance,
		       additional.c_str()));
	daemon->start_acs(dummyCallback.in(), instance, additional.c_str());
	ACS_SHORT_LOG((LM_INFO, "ACS start message issued."));

	while(!sc->isComplete())
	{
	    if (orb->work_pending())
	        orb->perform_work();
	}
    }
    catch(ACSErrTypeCommon::BadParameterEx & ex) {
	ACSErrTypeCommon::BadParameterExImpl exImpl(ex);
	exImpl.log();
	return -1;
    }
    catch(CORBA::Exception & ex) {

	ACS_SHORT_LOG((LM_INFO, "Failed."));
	ex._tao_print_exception("Caught unexpected exception:");
	return -1;
    }

    return 0;
}
예제 #15
0
int
TAO_Repository_i::create_servants_and_poas (void)
{
  CORBA::PolicyList policies (5);
  policies.length (5);

  // ID Assignment Policy.
  policies[0] =
    this->root_poa_->create_id_assignment_policy (PortableServer::USER_ID);

  // Lifespan Policy.
  policies[1] =
    this->root_poa_->create_lifespan_policy (PortableServer::PERSISTENT);

  // Request Processing Policy.
  policies[2] =
    this->root_poa_->create_request_processing_policy (
        PortableServer::USE_DEFAULT_SERVANT
      );

  // Servant Retention Policy.
  policies[3] =
    this->root_poa_->create_servant_retention_policy (
        PortableServer::NON_RETAIN
      );

  // Id Uniqueness Policy.
  policies[4] =
    this->root_poa_->create_id_uniqueness_policy (
        PortableServer::MULTIPLE_ID
      );

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

#define GEN_IR_OBJECT(name) \
  this-> name ## _poa_ = \
    this->root_poa_->create_POA (#name "_poa", \
                                 poa_manager.in (), \
                                 policies); \
\
  TAO_ ## name ## _i * name ## _impl = 0; \
  ACE_NEW_RETURN (name ## _impl, \
                  TAO_ ## name ## _i (this), \
                  -1); \
  ACE_NEW_RETURN (this-> name ## _servant_, \
                  POA_CORBA:: name ## _tie<TAO_ ## name ## _i> ( \
                      name ## _impl, \
                      this-> name ## _poa_.in (), \
                      1 \
                    ), \
                  -1); \
  PortableServer::ServantBase_var name ## _safety ( \
      this-> name ## _servant_ \
    ); \
  this-> name ## _poa_->set_servant (this-> name ## _servant_);

  CONCRETE_IR_OBJECT_TYPES

#undef GEN_IR_OBJECT
#undef CONCRETE_IR_OBJECT_TYPES

  CORBA::ULong length = policies.length ();

  for (CORBA::ULong i = 0; i < length; ++i)
    {
      CORBA::Policy_ptr policy = policies[i];
      policy->destroy ();
    }

  return 0;
}
예제 #16
0
파일: server.cpp 프로젝트: manut/TAO
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 poa_object =  orb->resolve_initial_references ("RootPOA");
    PortableServer::POA_var rootPOA =  PortableServer::POA::_narrow (poa_object.in ());
    PortableServer::POAManager_var poa_manager =  rootPOA->the_POAManager ();

    // Policies for the firstPOA to be created.
    CORBA::PolicyList policies (5);
    policies.length (5);
    // Lifespan policy
    policies[0] =
      rootPOA->create_lifespan_policy (PortableServer::PERSISTENT );

    // Servant Retention Policy
    policies[1] =
      rootPOA->create_servant_retention_policy (PortableServer::RETAIN );


    // ID Assignment Policy
    policies[2] =
      rootPOA->create_id_assignment_policy (PortableServer::USER_ID );

    // Request Processing Policy
    policies[3] =
      rootPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY );

    // Threading policy
    policies[4] =
      rootPOA->create_thread_policy (PortableServer::ORB_CTRL_MODEL  );

    PortableServer::POA_var demoPOA
      = rootPOA->create_POA ("HelloWorldServer",
                              poa_manager.in (),
                              policies
                              );

    for (CORBA::ULong i = 0;
        i < policies.length ();
        ++i)
    {
      CORBA::Policy_ptr policy = policies[i];
      policy->destroy ();
    }

    // Create object for shutdown commanded by client.
    {
        // create the object
        Demo_HelloWorld_i * hello = new Demo_HelloWorld_i(orb.in());

        // Get the Object ID.
        PortableServer::ObjectId_var oid =  PortableServer::string_to_ObjectId ("shutdown");
        demoPOA->activate_object_with_id (oid.in (),  hello);


        // Create an object reference.
        CORBA::Object_var myhello = demoPOA->id_to_reference(oid.in());

        // Put the object reference as an IOR string
        ofstream out(ACE_TEXT_ALWAYS_CHAR (shutdown_ior_output_file));
        CORBA::String_var ior = orb->object_to_string (myhello.in ());
        out  << ior.in();
        // save the reference into a file
        out.close();
    }

    // Create object to handle client sayHello requests.
    {
        // create the object
        Demo_HelloWorld_i * hello = new Demo_HelloWorld_i(orb.in());

        // Get the Object ID.
        PortableServer::ObjectId_var oid =  PortableServer::string_to_ObjectId ("hello");
        demoPOA->activate_object_with_id (oid.in (),  hello);


        // Create an object reference.
        CORBA::Object_var myhello = demoPOA->id_to_reference(oid.in());

        // Put the object reference as an IOR string
        ofstream out(ACE_TEXT_ALWAYS_CHAR (ior_output_file));
        CORBA::String_var ior = orb->object_to_string (myhello.in ());
        out  << ior.in();
        // save the reference into a file
        out.close();
    }



    //////////////////////////////////////////////////////////////////////////////////////////////////
    poa_manager->activate ();

    std::cout << ior_output_file << " is ready " << std::endl;
    orb->run ();


    // Destroy the POA, waiting until the destruction terminates
    rootPOA->destroy (1, 1);
    orb->destroy ();
  }
  catch (const CORBA::Exception &e)
  {
    std::cerr << "Unexpected exception: " << e << std::endl;
    return 1;
  }

  return 0;
}
예제 #17
0
PortableServer::POA_ptr
Server_i::create_poa (const char *name,
                      int servant_retention_policy)
{
  PortableServer::POA_ptr my_poa = 0;


  try
    {
      policies_.length (4);

      // ID Assignment Policy.
      policies_[0] =
        root_poa_->create_id_assignment_policy
        (PortableServer::USER_ID);

      // Lifespan Policy.
      policies_[1] =
        root_poa_->create_lifespan_policy
        (PortableServer::PERSISTENT);

      // Request Processing Policy.
      policies_[2] =
        root_poa_->create_request_processing_policy
        (PortableServer::USE_SERVANT_MANAGER);

      // Servant Retention Policy.
      if (servant_retention_policy == 1)
        {
          policies_[3] =
            root_poa_->create_servant_retention_policy
            (PortableServer::RETAIN);
        }

      if (servant_retention_policy == 0)
        {
          policies_[3] =
            root_poa_->create_servant_retention_policy
            (PortableServer::NON_RETAIN);
        }

      // Create myPOA as the child of RootPOA with the above
      // policies_. myPOA will use SERVANT_ACTIVATOR or
      // SERVANT_LOCATOR depending upon the servant retention policy
      // being RETAIN or NONRETAIN respectively.
      my_poa = root_poa_->create_POA (name,
                                      poa_manager_.in (),
                                      policies_);

      // Destroy the policy objects as they have been passed to
      // create_POA and no longer needed.
      for (CORBA::ULong i = 0;
           i < policies_.length ();
           ++i)
        {
          CORBA::Policy_ptr policy = policies_[i];
          policy->destroy ();
        }
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Server_i:create_poa ()");
      return 0;
    }

  return my_poa;
}
예제 #18
0
int
TAO_FT_Naming_Server::init_naming_manager_with_orb (int, ACE_TCHAR *[], CORBA::ORB_ptr orb)
{
  int result = 0;

  // Need to lock during startup to prevent access of partially
  // initialized variables
  ACE_GUARD_THROW_EX (ACE_SYNCH_RECURSIVE_MUTEX,
                      ace_mon,
                      this->lock_,
                      CORBA::INTERNAL ());

  try
    {
      if (CORBA::is_nil (this->orb_.in ()))
        {
          this->orb_ = CORBA::ORB::_duplicate (orb);
        }

      // Get the POA from the ORB.
      CORBA::Object_var poa_object =
        orb->resolve_initial_references ("RootPOA");

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

      if (result != 0)
        return result;

      this->root_poa_ = PortableServer::POA::_narrow (poa_object.in ());
      PortableServer::POAManager_var poa_manager =
        this->root_poa_->the_POAManager ();

      int numPolicies = 2;
      CORBA::PolicyList policies (numPolicies);
      policies.length (numPolicies);
      policies[0] =
        this->root_poa_->create_id_assignment_policy (PortableServer::USER_ID);
      policies[1] =
        this->root_poa_->create_lifespan_policy (PortableServer::PERSISTENT);

      this->naming_manager_poa_ =
        this->root_poa_->create_POA ("NamingManager",
                                     poa_manager.in (),
                                     policies);

      for (CORBA::ULong i = 0; i < policies.length (); ++i)
        {
          CORBA::Policy_ptr policy = policies[i];
          policy->destroy ();
        }
      poa_manager->activate ();

      PortableServer::ObjectId_var id =
        PortableServer::string_to_ObjectId ("NamingManager");

      this->naming_manager_poa_->activate_object_with_id (id.in (), &this->naming_manager_);
      this->assign (size_t(GROUP), true, this->naming_manager_poa_->id_to_reference (id.in ()));

      if (write (size_t(GROUP)) != 0)
        return -1;


      this->naming_manager_.initialize (this->orb_.in (),
                                        this->naming_manager_poa_.in ());

    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
                               ACE_TEXT ("TAO_FT_Naming_Server::init_naming_manager_with_orb"));
      return -1;
    }
  CORBA::Object_var table_object =
    orb->resolve_initial_references ("IORTable");

  IORTable::Table_var ior_table =
    IORTable::Table::_narrow (table_object.in ());
  if (!CORBA::is_nil (ior_table))
    {
      ior_table->bind ("NamingManager",
                       this->iors_[GROUP].ior_.c_str ());
    }
  return 0;
}