コード例 #1
0
ファイル: client.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 object =
        orb->string_to_object (ior);

      Simple_Server_var server =
        Simple_Server::_narrow (object.in ());

      if (CORBA::is_nil (server.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Object reference <%s> is nil.\n",
                             ior),
                            1);
        }

      object =
        orb->resolve_initial_references ("ORBPolicyManager");

      CORBA::PolicyManager_var policy_manager =
        CORBA::PolicyManager::_narrow (object.in ());

      object =
        orb->resolve_initial_references ("PolicyCurrent");

      CORBA::PolicyCurrent_var policy_current =
        CORBA::PolicyCurrent::_narrow (object.in ());

      TimeBase::TimeT mid_value =
        10000 * (min_timeout + max_timeout) / 2; // convert from msec to "TimeT" (0.1 usec units)

      CORBA::Any any_orb;
      any_orb <<= mid_value;
      CORBA::Any any_thread;
      any_thread <<= mid_value + 10000; // midvalue + 1 msec
      CORBA::Any any_object;
      any_object <<= mid_value + 20000; // midvalue + 2 msec

      CORBA::PolicyList policy_list (1);
      policy_list.length (1);
      policy_list[0] =
        orb->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
                            any_object);
      object =
        server->_set_policy_overrides (policy_list,
                                       CORBA::SET_OVERRIDE);

      Simple_Server_var timeout_server =
        Simple_Server::_narrow (object.in ());

      policy_list[0]->destroy ();
      policy_list[0] = CORBA::Policy::_nil ();

      ACE_DEBUG ((LM_DEBUG,
                  "client (%P) testing from %d to %d milliseconds\n",
                  min_timeout, max_timeout));

      for (CORBA::Long t = min_timeout; t < max_timeout; ++t)
       {
         ACE_DEBUG ((LM_DEBUG,
                     "\n================================\n"
                     "Trying with timeout = %d msec\n", t));

         ACE_DEBUG ((LM_DEBUG,
                     "Cleanup ORB/Thread/Object policies\n"));

          policy_list.length (0);
          policy_manager->set_policy_overrides (policy_list,
                                                CORBA::SET_OVERRIDE);
          policy_current->set_policy_overrides (policy_list,
                                                CORBA::SET_OVERRIDE);

          send_echo (none, orb.in (), server.in (), t);




          ACE_DEBUG ((LM_DEBUG,
                      "client(%P) Set the ORB policies\n"));

          policy_list.length (1);
          policy_list[0] =
            orb->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
                                any_orb);

          policy_manager->set_policy_overrides (policy_list,
                                                CORBA::SET_OVERRIDE);

          send_echo (orb1, orb.in (), server.in (), t);

          policy_list[0]->destroy ();







          ACE_DEBUG ((LM_DEBUG,
                      "client(%P) Set the thread policies\n"));

          policy_list.length (1);
          policy_list[0] =
            orb->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE,
                                any_thread);

          policy_current->set_policy_overrides (policy_list,
                                                CORBA::SET_OVERRIDE);

          send_echo (thread1, orb.in (), server.in (), t);

          policy_list[0]->destroy ();







          ACE_DEBUG ((LM_DEBUG,
                      "client(%P) Use the object policies\n"));
          send_echo (object1, orb.in (), timeout_server.in (), t);
        }

      ACE_DEBUG ((LM_DEBUG,
                  "\n\n\nclient(%P) Test completed, "
                  "resynch with server\n"));
      policy_list.length (0);
      policy_manager->set_policy_overrides (policy_list,
                                            CORBA::SET_OVERRIDE);
      policy_current->set_policy_overrides (policy_list,
                                            CORBA::SET_OVERRIDE);

      send_echo (none, orb.in (), server.in (), 0);

      server->shutdown ();

      int timeout_count_total = 0;
      int in_time_count_total = 0;
      for (int i = 0; i < 4; i++) {
        timeout_count_total += timeout_count[i];
        in_time_count_total += in_time_count[i];
        ACE_DEBUG ((LM_DEBUG, "in_time_count[%C]= %d timeout_count[%C]= %d\n",
                    to_type_names[i], in_time_count[i],
                    to_type_names[i], timeout_count[i]));
      }

      if (timeout_count_total == 0)
        ACE_ERROR ((LM_ERROR,
                    "ERROR: No messages timed out\n"));

      //FUZZ: disable check_for_lack_ACE_OS
      if (in_time_count_total == 0)
        ACE_ERROR ((LM_ERROR,
                    "ERROR: No messages on time (within time limit)\n"));
      //FUZZ: enable check_for_lack_ACE_OS

      ACE_DEBUG ((LM_DEBUG, "in_time_count_total = %d, timeout_count_total = %d\n",
                  in_time_count_total, timeout_count_total));

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }
  return 0;
}
コード例 #2
0
ファイル: client.cpp プロジェクト: INMarkus/ATCD
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  MIF_Scheduler* scheduler=0;
  RTScheduling::Current_var current;
  int prio;
  int max_prio;
  ACE_Sched_Params::Policy  sched_policy = ACE_SCHED_RR;
  int sched_scope = ACE_SCOPE_THREAD;
  long flags;

  if (sched_policy == ACE_SCHED_RR)
    flags = THR_NEW_LWP | THR_BOUND | THR_JOINABLE | THR_SCHED_RR;
  else
    flags = THR_NEW_LWP | THR_BOUND | THR_JOINABLE | THR_SCHED_FIFO;

  ACE_hthread_t main_thr_handle;
  ACE_Thread::self (main_thr_handle);

  max_prio = ACE_Sched_Params::priority_max (sched_policy,
                                             sched_scope);

  //FUZZ: disable check_for_lack_ACE_OS
  ACE_Sched_Params sched_params (sched_policy, max_prio);
  //FUZZ: enable check_for_lack_ACE_OS

  ACE_OS::sched_params (sched_params);

  if (ACE_Thread::getprio (main_thr_handle, prio) == -1)
    {
      if (errno == ENOTSUP)
        {
          ACE_ERROR((LM_ERROR,
                     ACE_TEXT ("getprio not supported\n")
                     ));
        }
      else
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("%p\n")
                      ACE_TEXT ("thr_getprio failed")));
        }
    }

  ACE_DEBUG ((LM_DEBUG, "(%t): main thread prio is %d\n", prio));

  try
    {
      RTScheduling::Scheduler_var sched_owner;

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

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

      CORBA::Object_var object =
        orb->string_to_object (ior);

      Simple_Server_var server =
        Simple_Server::_narrow (object.in ());

      if (CORBA::is_nil (server.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Object reference <%s> is nil.\n",
                             ior),
                            1);
        }

      if (enable_dynamic_scheduling)
        {
          ACE_DEBUG ((LM_DEBUG, "Dyn Sched enabled\n"));
          CORBA::Object_var manager_obj =
            orb->resolve_initial_references ("RTSchedulerManager");

          TAO_RTScheduler_Manager_var manager =
            TAO_RTScheduler_Manager::_narrow (manager_obj.in ());

          Kokyu::DSRT_Dispatcher_Impl_t disp_impl_type;
          if (enable_yield)
            {
              disp_impl_type = Kokyu::DSRT_CV_BASED;
            }
          else
            {
              disp_impl_type = Kokyu::DSRT_OS_BASED;
            }

          ACE_NEW_RETURN (scheduler,
                          MIF_Scheduler (orb.in (),
                                         disp_impl_type,
                                         sched_policy,
                                         sched_scope), -1);
          sched_owner = scheduler;

          manager->rtscheduler (scheduler);

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

          current  =
            RTScheduling::Current::_narrow (object.in ());

        }

      Worker worker1 (orb.in (), server.in (), current.in (), scheduler, 10, 15);

      if (worker1.activate (flags, 1, 0, max_prio) != 0)
        {
          ACE_ERROR ((LM_ERROR,
                      "(%t|%T) cannot activate worker thread.\n"));
        }

      ACE_OS::sleep(2);

      Worker worker2 (orb.in (), server.in (), current.in (), scheduler, 12, 5);

      if (worker2.activate (flags, 1, 0, max_prio) != 0)
        {
          ACE_ERROR ((LM_ERROR,
                      "(%t|%T) cannot activate scheduler thread in RT mode.\n"));
        }

      worker1.wait ();
      worker2.wait ();

      ACE_DEBUG ((LM_DEBUG,
                  "(%t): wait for worker threads done in main thread\n"));

      if (do_shutdown)
        {
          if (enable_dynamic_scheduling)
            {
              MIF_Scheduling::SchedulingParameter sched_param;
              sched_param.importance = 0;
              CORBA::Policy_var sched_param_policy =
                scheduler->create_scheduling_parameter (sched_param);
              CORBA::Policy_ptr implicit_sched_param = 0;
              current->begin_scheduling_segment (0,
                                                 sched_param_policy.in (),
                                                 implicit_sched_param);
            }

            ACE_DEBUG ((LM_DEBUG, "(%t): about to call server shutdown\n"));
            server->shutdown ();

            ACE_DEBUG ((LM_DEBUG, "after shutdown call in main thread\n"));


            if (enable_dynamic_scheduling)
            {
              current->end_scheduling_segment (0);
            }
        }

      scheduler->shutdown ();
      ACE_DEBUG ((LM_DEBUG, "scheduler shutdown done\n"));

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

  return 0;
}
コード例 #3
0
ファイル: client.cpp プロジェクト: asdlei00/ACE
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;

      A::AMI_Test_var server;

      CORBA::Object_var object =
        orb->string_to_object (ior);
      server =  A::AMI_Test::_narrow (object.in ());

      if (CORBA::is_nil (server.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Object reference <%s> is nil.\n",
                             ior),
                            1);
        }

      // Activate POA to handle the call back.

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

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

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

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

      poa_manager->activate ();

      // Let the client perform the test in a separate thread
      Handler handler;
      PortableServer::ObjectId_var id =
        root_poa->activate_object (&handler);

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

      A::AMI_AMI_TestHandler_var the_handler_var =
        A::AMI_AMI_TestHandler::_narrow (hnd_object.in ());

      handler.set_ami_test (server.in ());

      Client client (server.in (), niterations, the_handler_var.in ());
      if (client.activate (THR_NEW_LWP | THR_JOINABLE,
                           nthreads) != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot activate client threads\n"),
                          1);

      // Main thread collects replies. It needs to collect
      // <nthreads*niterations> replies.
      number_of_replies = nthreads *niterations;

      if (debug)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "(%P|%t) : Entering perform_work loop to receive <%d> replies\n",
                      number_of_replies.value ()));
        }

      // ORB loop.

      Worker worker (orb.in ());
      if (worker.activate (THR_NEW_LWP | THR_JOINABLE,
                           nthreads) != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot activate client threads\n"),
                          1);

      worker.thr_mgr ()->wait ();

      if (debug)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "(%P|%t) : Exited perform_work loop Received <%d> replies\n",
                      (nthreads*niterations) - number_of_replies.value ()));
        }

      client.thr_mgr ()->wait ();

      ACE_DEBUG ((LM_DEBUG, "threads finished\n"));

      server->shutdown ();

      root_poa->destroy (1,  // ethernalize objects
                         0  // wait for completion
                        );

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

  return parameter_corruption;
}
コード例 #4
0
ファイル: client.cpp プロジェクト: asdlei00/ACE
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      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::Object_var object =
        orb->resolve_initial_references ("PolicyCurrent");

      CORBA::PolicyCurrent_var policy_current =
        CORBA::PolicyCurrent::_narrow (object.in ());

      if (CORBA::is_nil (policy_current.in ()))
        {
          ACE_ERROR ((LM_ERROR,
                      "ERROR: Nil policy current\n"));
          return 1;
        }
      CORBA::Any scope_as_any;
      scope_as_any <<= Messaging::SYNC_WITH_TRANSPORT;

      CORBA::PolicyList policies(1);
      policies.length (1);
      policies[0] =
        orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
                            scope_as_any);

      policy_current->set_policy_overrides (policies,
                                            CORBA::ADD_OVERRIDE);

      policies[0]->destroy ();

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

      PortableServer::Servant_var<Echo> impl;
      {
        Echo * tmp;
        // ACE_NEW_RETURN is the worst possible way to handle
        // exceptions (think: what if the constructor allocates memory
        // and fails?), but I'm not in the mood to fight for a more
        // reasonable way to handle allocation errors in ACE.
        ACE_NEW_RETURN (tmp,
                        Echo (orb.in (), 100),
                        1);
        impl = tmp;
      }

      PortableServer::ObjectId_var id =
        root_poa->activate_object (impl.in ());

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

      Test::Echo_var echo =
        Test::Echo::_narrow (object_act.in ());

      CORBA::Object_var tmp =
        orb->string_to_object(ior);

      Test::Echo_Caller_var server =
        Test::Echo_Caller::_narrow(tmp.in ());

      if (CORBA::is_nil (echo.in ()))
        {
          ACE_ERROR_RETURN ((LM_DEBUG,
                             "Nil Test::Echo_Caller reference <%s>\n",
                             ior),
                            1);
        }

      poa_manager->activate ();

      Client_Task ctask (orb.in ());

      server->start_task (echo.in());

      if (ctask.activate (THR_NEW_LWP | THR_JOINABLE,
                          4,
                          1) == -1)
        {
          ACE_ERROR ((LM_ERROR,
                      "Error activating client task\n"));

          return 1;
        }

      ACE_Thread_Manager::instance ()->wait ();

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) client - event loop finished\n"));

      // Actually the code here should never be reached.
      root_poa->destroy (1,
                         1);

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

  return 0;
}
コード例 #5
0
ファイル: ServerApp.cpp プロジェクト: OspreyHub/ATCD
int
ServerApp::run_i(int argc, ACE_TCHAR *argv[])
{
  // Initialize the ORB before parsing our own args.
  CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

  // Parse the command-line args for this application.
  // * Returns -1 if problems are encountered.
  // * Returns 1 if the usage statement was explicitly requested.
  // * Returns 0 otherwise.
  int result = this->parse_args (argc, argv);
  if (result != 0)
    {
      return result;
    }

  TheAppShutdown->init(orb.in(), num_clients_);

  // Get the Root POA
  PortableServer::POA_var root_poa =
           RefHelper<PortableServer::POA>::resolve_initial_ref(orb.in(),
                                                               "RootPOA");

  // Get the POAManager from the Root POA.
  PortableServer::POAManager_var poa_manager
    = root_poa->the_POAManager();

  // Create the child POA Policies.
  CORBA::PolicyList policies(0);
  policies.length(0);

  // Create the child POA
  PortableServer::POA_var child_poa =
                              AppHelper::create_poa("ChildPoa",
                                                    root_poa.in(),
                                                    poa_manager.in(),
                                                    policies);

  // Create the servant object.
  Foo_A_i* servant = new Foo_A_i();

  // Local smart pointer variable to deal with releasing the reference
  // to the servant object when the variable falls out of scope.
  PortableServer::ServantBase_var servant_owner(servant);

  // Obtain the object reference using the servant
  CORBA::Object_var obj = AppHelper::activate_servant(child_poa.in(),
                                                      servant);

  // Stringify and save the object reference to a file
  AppHelper::ref_to_file(orb.in(),
                         obj.in(),
                         this->ior_filename_.c_str());

  // Activate the POA Manager
  poa_manager->activate();

  ACE_DEBUG((LM_DEBUG,
             "(%P|%t) ServerApp is ready.  Running the ORB event loop.\n"));

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

  ACE_DEBUG((LM_DEBUG,
             "(%P|%t) ServerApp ORB event loop has completed.\n"));

  TheAppShutdown->wait ();

  // Calling wait on ACE_Thread_Manager singleton to avoid the problem
  // that the main thread might exit before all CSD Threads exit.

  // Wait for all CSD task threads exit.
  ACE_Thread_Manager::instance ()->wait ();

  ACE_DEBUG((LM_DEBUG,
             "(%P|%t) ServerApp is destroying the Root POA.\n"));

  root_poa->destroy(1, 1);

  ACE_DEBUG((LM_DEBUG,
             "(%P|%t) ServerApp is destroying the ORB.\n"));

  orb->destroy();

  ACE_DEBUG((LM_DEBUG,
             "(%P|%t) ServerApp has completed running successfully.\n"));

  return 0;
}
コード例 #6
0
ファイル: MessengerServer.cpp プロジェクト: asdlei00/ACE
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try {
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in());

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

    const char* poa_name = "MessengerService";

    PortableServer::POA_var messenger_poa = createPOA(root_poa.in(), poa_name);

    Terminator terminator;
    if (terminator.open (0) == -1)
      ACE_ERROR_RETURN((LM_ERROR,
                        ACE_TEXT ("main Error opening terminator\n")),-1);

    PortableServer::Servant_var<Messenger_i> messenger_servant =
      new Messenger_i(orb.in(), terminator);

    PortableServer::ObjectId_var object_id =
      PortableServer::string_to_ObjectId("messenger_object");

    //
    // Activate the servant with the messenger POA,
    // obtain its object reference, and get a
    // stringified IOR.
    //
    messenger_poa->activate_object_with_id(object_id.in(), messenger_servant.in());

    //
    // Create binding between "MessengerService" and
    // the messenger object reference in the IOR Table.
    // Use a TAO extension to get the non imrified poa
    // to avoid forwarding requests back to the ImR.

    TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*>(messenger_poa.in());
    obj = tpoa->id_to_reference_i(object_id.in(), false);
    CORBA::String_var messenger_ior = orb->object_to_string(obj.in());
    obj = orb->resolve_initial_references("IORTable");
    IORTable::Table_var table = IORTable::Table::_narrow(obj.in());
    table->bind(poa_name, messenger_ior.in());

    //
    // This server is now ready to run.
    // This version does not create an IOR
    // file as demonstrated in the
    // Developer's Guide.  It assumes that
    // users create IORs for the client using
    // the tao_imr utility.
    //
    //
    // Stop discarding requests.
    //
    mgr->activate();

    std::cout << "Messenger server ready." << std::endl;

    orb->run();

    std::cout << "Messenger server shutting down." << std::endl;

    root_poa->destroy(1,1);
    orb->destroy();

    ACE_Message_Block *mb;
    ACE_NEW_RETURN(mb, ACE_Message_Block(0, ACE_Message_Block::MB_HANGUP), -1);
    terminator.putq(mb);
    terminator.wait();
  }
  catch(const CORBA::Exception& ex) {
    std::cerr << "Server main() Caught CORBA::Exception" << ex << std::endl;
    return 1;
  }

  return 0;
}
コード例 #7
0
ファイル: server.cpp プロジェクト: chenbk85/ACE-Middleware
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

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

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

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

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

      // Install a persistent POA in order to achieve a persistent IOR
      // for our object.
      CORBA::PolicyList policies;
      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 persistent_poa =
        root_poa->create_POA("persistent",
                             poa_manager.in (),
                             policies);

      policies[0]->destroy ();

      policies[1]->destroy ();

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

      UDP_i udp_i (orb.in ());

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

      persistent_poa->activate_object_with_id (id.in (),
                                               &udp_i);

      CORBA::Object_var obj =
        persistent_poa->id_to_reference (id.in ());


      UDP_var udp_var = UDP::_narrow (obj.in ());

      // UDP_var udp_var = udp_i._this ();
      if (CORBA::is_nil (udp_var.in ()))
        ACE_DEBUG ((LM_DEBUG,
                    "Failed to narrow correct object reference.\n"));

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

      ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));

      // If the ior_output_file exists, output the ior to it
      if (ior_output_file != 0)
        {
          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);
        }

      poa_manager->activate ();

      orb->run ();

      ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));

      root_poa->destroy (1,  // ethernalize objects
                         0); // wait for completion

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

  return 0;
}
コード例 #8
0
ファイル: server.cpp プロジェクト: OspreyHub/ATCD
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
#if TAO_HAS_INTERCEPTORS == 1
      PortableInterceptor::ORBInitializer_ptr temp_initializer =
        PortableInterceptor::ORBInitializer::_nil ();

      ACE_NEW_RETURN (temp_initializer,
                      Echo_Server_ORBInitializer,
                      -1);  // No exceptions yet!
      PortableInterceptor::ORBInitializer_var orb_initializer =
        temp_initializer;

      PortableInterceptor::register_orb_initializer (orb_initializer.in ());
#endif /* TAO_HAS_INTERCEPTORS == 1 */

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

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

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

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

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

      poa_manager->activate ();

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

      Visual_i server_impl (orb.in ());

      PortableServer::ObjectId_var id =
        root_poa->activate_object (&server_impl);

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

      Test_Interceptors::Visual_var server =
        Test_Interceptors::Visual::_narrow (test_obj.in ());

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

      ACE_DEBUG ((LM_DEBUG, "Test_Interceptors::Visual: <%s>\n", ior.in ()));

      // If the ior_output_file exists, output the ior to it
      if (ior_output_file != 0)
        {
          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);
        }

      orb->run ();

      ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));

      root_poa->destroy (1, 1);

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

  return 0;
}
コード例 #9
0
ファイル: client.cpp プロジェクト: asdlei00/ACE
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      if (parse_args (argc, argv) != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("ERROR: wrong arguments\n")),
                          -1);

      if (id_offset + client_threads >= ACE_OS::strlen (Test::ClientIDs))
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("ERROR: too many clients\n")),
                          -1);

      CORBA::Object_var obj = orb->string_to_object (ior);

      // Create Hello reference.
      Test::Hello_var hello = Test::Hello::_narrow (obj.in ());

      if (CORBA::is_nil (hello.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT ("ERROR: nil Hello object\n")),
                          -1);

      if (do_shutdown)
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("\nClient sending server shutdown message....\n")));
          ACE_OS::sleep (7);
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("Shutting down NOW\n")));
          hello->shutdown ();
        }
      else
        {
          Test::UIPMC_Object_var uipmc_obj = hello->get_object ();

          {
            // start clients
            ClientThread cln_thr (uipmc_obj.in (), payload_length,
                                  id_offset, payload_calls, sleep_millis);
            cln_thr.activate (THR_NEW_LWP | THR_JOINABLE, client_threads);
            cln_thr.wait ();
          }

          // Give a chance to flush all OS buffers for client.
          while (orb->work_pending ())
            orb->perform_work ();
        }

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

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("\nClient finished successfully.\n")));
  return 0;
}
コード例 #10
0
ファイル: server.cpp プロジェクト: asdlei00/ACE
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
ファイル: receiver.cpp プロジェクト: CCJY/ATCD
int
ACE_TMAIN (int argc,
      ACE_TCHAR *argv[])
{
  try
    {
      // Initialize the ORB first.
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

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

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

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

      mgr->activate ();

      // Initialize the AVStreams components.
      TAO_AV_CORE::instance ()->init (orb.in (),
                                      root_poa.in ());

      int result =
        parse_args (argc,
                    argv);

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

      // Make sure we have a valid <output_file>
      output_file = ACE_OS::fopen (output_file_name,
                                   "w");
      if (output_file == 0)
        ACE_ERROR_RETURN ((LM_DEBUG,
                           "Cannot open output file %s\n",
                           output_file_name),
                          -1);

      else
        ACE_DEBUG ((LM_DEBUG,
                    "File Opened Successfully\n"));

      Receiver receiver;
      result =
        receiver.init (argc,
                       argv);

      if (result != 0)
        return result;

      orb->run ();

      // Hack for now....
      ACE_OS::sleep (1);

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

  ACE_OS::fclose (output_file);

  return 0;
}
コード例 #12
0
ファイル: client.cpp プロジェクト: CCJY/ATCD
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  CORBA::Boolean result = 0;
  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

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

      // First perform the test with an IOR
      CORBA::Object_var tmp =
        orb->string_to_object(ior);

      Test::Hello_var hello =
        Test::Hello::_narrow(tmp.in ());

      if (CORBA::is_nil (hello.in ()))
        {
          ACE_ERROR_RETURN ((LM_DEBUG,
                             "Test failed - Not regression - Unexpected Nil Test::Hello reference <%s>\n",
                             ior),
                            1);
        }

      // Check this isn't generating exceptions for any other reason
      hello->ping ();

      if (hello->has_ft_request_service_context ())
        {
          ACE_DEBUG ((LM_ERROR, "ERROR - REGRESSION - Request made on a plain IOR has a FT_REQUEST service context.\n" ));
          result = 1;
        }
      else
        {
          ACE_DEBUG ((LM_DEBUG, "Request made on a plain IOR has no FT_REQUEST service context. This is OK.\n" ));
        }

      // Now repeat the test (for the converse result) with an IOGR
      tmp =
        orb->string_to_object(iogr);

      hello =
        Test::Hello::_narrow(tmp.in ());

      if (CORBA::is_nil (hello.in ()))
        {
          ACE_ERROR_RETURN ((LM_DEBUG,
                             "Test failed - Not regression - Unexpected Nil Test::Hello reference <%s>\n",
                             iogr),
                            1);
        }

      // Check this isn't generating transients for any other reason
      hello->ping ();

      if (! hello->has_ft_request_service_context ())
        {
          ACE_DEBUG ((LM_ERROR, "ERROR - REGRESSION - Request made on an IOGR has no FT_REQUEST service context.\n" ));
          result = 1;
        }
      else
        {
          ACE_DEBUG ((LM_DEBUG, "Request made on an IOGR has a FT_REQUEST service context. This is OK.\n" ));
        }

      hello->shutdown ();

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception (
        "Test failed (Not regression) because unexpected exception caught:");
      return 1;
    }

  if (result)
    {
      ACE_DEBUG ((LM_ERROR, "Error: REGRESSION identified!!!\n"));
    }
  else
    {
      ACE_DEBUG ((LM_DEBUG, "Test passed !!!\n"));
    }
  return result;
}
コード例 #13
0
ファイル: client.cpp プロジェクト: OspreyHub/ATCD
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{

  char str [255];
  // Initialize the ORB
  try
    {
      ACE_OS::strcpy (str,
                      "CORBA::ORB_init");
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      // Parse the command-line arguments to get the location of the
      // IOR
      if (parse_args (argc, argv) == -1)
        return -1;

      if (IOR == 0)
        {
          int result = read_IOR_from_file ();
          if (result != 0)
            ACE_ERROR_RETURN ((LM_ERROR,
                               "Cannot read IOR from %s\n",
                               IOR_file),
                              -1);
        }

      ACE_OS::strcpy (str,
                      "CORBA::ORB::string_to_object");

      // Get the object reference with the IOR
      CORBA::Object_var object = orb->string_to_object (IOR);

      ACE_OS::strcpy (str,
                      "Database::Agent::_narrow");

      // Narrow the object reference to a Database::Agent
      Database::Agent_var database_agent =
        Database::Agent::_narrow (object.in ());

      Database::NVPairSequence employee_attributes (2);
      employee_attributes.length (2);

      Database::NamedValue &first =
        employee_attributes[0];
      Database::NamedValue &second =
        employee_attributes[1];

      const char *name = "irfan";
      CORBA::Long id = 555;

      first.name = CORBA::string_dup ("name");
      first.value <<= name;
      second.name = CORBA::string_dup ("id");
      second.value <<= id;

      ACE_OS::strcpy (str,
                      "Database::Agent::create_entry");

      // Create an employee
      Database::Entry_var entry =
        database_agent->create_entry ("irfan",
                                      "Employee",
                                      employee_attributes);

      ACE_OS::strcpy (str, "Database::Employee::_narrow");

      Database::Employee_var employee =
        Database::Employee::_narrow (entry.in ());

      /*
       *
       *  NOT IMPLEMENTED YET
       *
       *
       */

#if 0
      // Reset the id
      ACE_OS::strcpy (str, "Database::Employee::id");
      employee->id (666);
#endif /* 0 */

      ACE_OS::strcpy (str, "Database::Entry::find");
      // Find the employee
      entry = database_agent->find_entry ("irfan",
                                          "Employee");

      ACE_OS::strcpy (str, "Database::Entry::destroy");
      // Destroy the employee
      database_agent->destroy_entry ("irfan",
                                     "Employee");

      ACE_OS::strcpy (str, "Shutdown server");

      if (shutdown_server)
        {
          database_agent->shutdown ();
        }

      ACE_OS::free (IOR);

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

  return 0;
}
コード例 #14
0
ファイル: server.cpp プロジェクト: CCJY/ATCD
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int priority =
    (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
     + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
  priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO,
                                                  priority);
  // Enable FIFO scheduling, e.g., RT scheduling class on Solaris.

  if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
                                              priority,
                                              ACE_SCOPE_PROCESS)) != 0)
    {
      if (ACE_OS::last_error () == EPERM)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "server (%P|%t): user is not superuser, "
                      "test runs in time-shared class\n"));
        }
      else
        ACE_ERROR ((LM_ERROR,
                    "server (%P|%t): sched_params failed\n"));
    }

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

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

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

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

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

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

      Roundtrip *roundtrip_impl;
      ACE_NEW_RETURN (roundtrip_impl,
                      Roundtrip (orb.in ()),
                      1);
      PortableServer::ServantBase_var owner_transfer(roundtrip_impl);

      PortableServer::ObjectId_var id =
        root_poa->activate_object (roundtrip_impl);

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

      Test::Roundtrip_var roundtrip =
        Test::Roundtrip::_narrow (object.in ());

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

      // If the ior_output_file exists, output the ior to it
      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);

      poa_manager->activate ();

      Worker_Thread worker (orb.in ());

      worker.activate (THR_NEW_LWP | THR_JOINABLE, 4, 1);
      worker.thr_mgr ()->wait ();

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));

      root_poa->destroy (1, 1);

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

  return 0;
}
コード例 #15
0
ファイル: server.cpp プロジェクト: OspreyHub/ATCD
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      {
        PortableInterceptor::ORBInitializer_var initializer(
            new Server_ORBInitializer);
        PortableInterceptor::register_orb_initializer(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 ();

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

      Echo *echo_impl;
      ACE_NEW_RETURN (echo_impl,
                      Echo (orb.in ()),
                      1);
      PortableServer::ServantBase_var owner_transfer(echo_impl);

      PortableServer::ObjectId_var id =
        root_poa->activate_object (echo_impl);

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

      Test::Echo_var echo =
        Test::Echo::_narrow (object.in ());

      CORBA::String_var ior =
        orb->object_to_string (echo.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",
                           ior_output_file),
                              1);
      ACE_OS::fprintf (output_file, "%s", ior.in ());
      ACE_OS::fclose (output_file);

      poa_manager->activate ();

      orb->run ();

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));

      root_poa->destroy (1, 1);

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

  return 0;
}
コード例 #16
0
ファイル: client.cpp プロジェクト: chenbk85/ACE
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int exit_status = 0;
  try
    {
      CORBA::ORB_var orb (CORBA::ORB_init (argc, argv));

      CORBA::Object_var compression_manager_obj (
        orb->resolve_initial_references("CompressionManager"));

      ::Compression::CompressionManager_var compression_manager (
        ::Compression::CompressionManager::_narrow (
          compression_manager_obj.in ()));

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

      //register Zlib compressor
      ::Compression::CompressorFactory_ptr compressor_factory;
      ACE_NEW_RETURN (compressor_factory, TAO::Zlib_CompressorFactory (), 1);
      ::Compression::CompressorFactory_var compr_fact (compressor_factory);
      compression_manager->register_factory (compr_fact.in ());

      //Register Client ZIOP policies
      CORBA::PolicyList policies(4);
      policies.length(4);

      ::Compression::CompressorIdLevelList compressor_id_list;
      compressor_id_list.length (1);
      compressor_id_list[0].compressor_id     = ::Compression::COMPRESSORID_ZLIB;
      compressor_id_list[0].compression_level = 9;
      CORBA::Any any;
      any <<= compressor_id_list;

      policies[0] = orb->create_policy (ZIOP::COMPRESSOR_ID_LEVEL_LIST_POLICY_ID, any);
      any <<= static_cast <CORBA::ULong> (190u); // shutdown is 180, send_forty_two is 192
      policies[1] = orb->create_policy (ZIOP::COMPRESSION_LOW_VALUE_POLICY_ID, any);
      any <<= CORBA::Any::from_boolean (true);
      policies[2] = orb->create_policy (ZIOP::COMPRESSION_ENABLING_POLICY_ID, any);
      any <<= static_cast <Compression::CompressionRatio> (0.50); // send_forty_two is 0.66, send_large_octet_array is 0.06
      policies[3] = orb->create_policy (ZIOP::COMPRESSION_MIN_RATIO_POLICY_ID, any);

      // Parse our own client arguments
      if (parse_args (argc, argv) != 0)
        return 1;

      // Obtain the servant reference with our active ZIOP policies.
      CORBA::Object_var tmp (orb->string_to_object(ior));
      tmp = tmp->_set_policy_overrides (policies, CORBA::ADD_OVERRIDE);

      /* Do an unchecked narrow since there's no way to do an is_a on
       * a multicast reference (yet...).
       */
      Test::McastHello_var hello =
        TAO::Narrow_Utils<Test::McastHello>::unchecked_narrow (
            tmp.in ());

      if (CORBA::is_nil (hello.in ()))
        {
          ACE_ERROR_RETURN ((LM_DEBUG,
                             "Nil Test::Hello reference <%s>\n",
                             ior),
                            1);
        }

      // To enable us to check that we compress the correct messages.
      ::Compression::Compressor_var compressor (
        compression_manager->get_compressor (
          compressor_id_list[0].compressor_id,
          compressor_id_list[0].compression_level));
      if (CORBA::is_nil (compressor.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "ERROR : compressor not found!\n"),
                            1);
        }

      ACE_DEBUG ((LM_DEBUG,
                  "Client sending send_forty_two() message to server\n"));
      hello->send_forty_two (42);
      // Note we can't actually check that we did NOT compress the message,
      // as the compressor is used to TRIAL the compression before it is
      // rejected based upon the min ratio. The compressor thus records
      // this trail compression data length.  (ZIOP is almost completely
      // transparrent in operation to the client and server when operating).
      CORBA::ULong total_compressed_so_far= compressor->compressed_bytes ();

      Test::Octets payload (MAX_MIOP_OCTET_SEQUENCE);
      payload.length (MAX_MIOP_OCTET_SEQUENCE);

      for (CORBA::ULong j = 0; j != MAX_MIOP_OCTET_SEQUENCE; ++j)
        {
          payload[j] = j % 256;
        }

      ACE_DEBUG ((LM_DEBUG,
                  "Client sending send_large_octet_array() message to server\n"));
      hello->send_large_octet_array (payload);
      // Check we did compress the message
      if (compressor->compressed_bytes ()-total_compressed_so_far)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "Correct. Client did use compression!\n"));
        }
      else
        {
          ACE_DEBUG ((LM_ERROR,
                      "ERROR : check_results, no compression used!\n"));
          exit_status = 1;
        }
      total_compressed_so_far= compressor->compressed_bytes ();

      // Now shutdown the server
      ACE_DEBUG ((LM_DEBUG,
                  "Client sending shutdown() message to server\n"));
      hello->shutdown ();
      // Check we did NOT compress the message
      if (compressor->compressed_bytes ()-total_compressed_so_far)
        {
          ACE_DEBUG ((LM_ERROR,
                      "ERROR : check_results, Client did use compression!\n"));
          exit_status = 1;
        }
      else
        {
          ACE_DEBUG ((LM_DEBUG,
                      "Correct. Client did NOT use compression!\n"));
        }
      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      exit_status = 1;
    }

  return exit_status;
}
コード例 #17
0
ファイル: server.cpp プロジェクト: CCJY/ATCD
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      ORBInitializer *initializer = 0;
      ACE_NEW_RETURN (initializer,
                      ORBInitializer,
                      -1);  // No exceptions yet!
      PortableInterceptor::ORBInitializer_var orb_initializer =
        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");

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

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

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

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

      poa_manager->activate ();

      CORBA::Object_var lm_object =
        orb->resolve_initial_references ("LoadManager");

      CosLoadBalancing::LoadManager_var load_manager =
        CosLoadBalancing::LoadManager::_narrow (lm_object.in ());

      RPS_Monitor * monitor_servant;
      ACE_NEW_THROW_EX (monitor_servant,
                        RPS_Monitor (initializer->interceptor ()),
                        CORBA::NO_MEMORY ());

      PortableServer::ServantBase_var safe_monitor_servant (monitor_servant);

      CosLoadBalancing::LoadMonitor_var load_monitor =
        monitor_servant->_this ();

      PortableGroup::Location_var location =
        load_monitor->the_location ();

      CORBA::Object_var stockfactory =
        ::join_object_group (orb.in (),
                             load_manager.in (),
                             location.in ());

      TAO_LB_LoadAlert & alert_servant = initializer->load_alert ();

      CosLoadBalancing::LoadAlert_var load_alert =
        alert_servant._this ();


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

      // If the ior_output_file exists, output the ior to it
      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);

      load_manager->register_load_monitor (location.in (),
                                           load_monitor.in ());

      load_manager->register_load_alert (location.in (),
                                         load_alert.in ());

      orb->run ();

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));

      root_poa->destroy (1, 1);

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

  return 0;
}
コード例 #18
0
ファイル: server.cpp プロジェクト: chenbk85/ACE-Middleware
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{

  try
    {
      // Initialize the ORB first.
      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");

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

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

      // Create a servant.
      reference_counted_test_i *servant = 0;
      ACE_NEW_RETURN (servant,
                      reference_counted_test_i (orb.in (),
                                                root_poa.in ()),
                      -1);

      // Get Object Reference for the servant object.
      test_var test = servant->_this ();

      // This means that the ownership of <servant> now belongs to
      // the POA.
      servant->_remove_ref ();

      // Stringyfy all the object references and print them out.
      CORBA::String_var ior = orb->object_to_string (test.in ());

      ACE_DEBUG ((LM_DEBUG,
                  "%C\n",
                  ior.in ()));

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

      poa_manager->activate ();

      orb->run ();

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

  return 0;
}
コード例 #19
0
ファイル: qci.cpp プロジェクト: BackupTheBerlios/qedo-svn
/**
 * starts the server for the component installer object
 */
int
main (int argc, char** argv)
{
	std::cout << "Qedo Component Installer " << QEDO_VERSION << std::endl;

	//
	// Resolve config values from config file
	//
	if (! strcmp (Qedo::ConfigurationReader::instance()->lookup_config_value ("/General/VerboseOutput"), "true"))
	{
		Qedo::debug_output = true;
	}

	for (int i = 1; i < argc; i++)
	{
		if (! strcmp (argv[i], "--verbose"))
		{
			Qedo::debug_output = true;
		}
	}

	//
	// get the qedo dir
	//
	Qedo::g_qedo_dir = Qedo::getEnvironment( "QEDO" );
	if(Qedo::g_qedo_dir.empty())
	{
	    std::cout << "Missing Environment Variable QEDO" << std::endl;
	    std::cout << "Assuming current dir as local deployment dir" << std::endl; 
	    Qedo::g_qedo_dir = Qedo::getCurrentDirectory();
	}
	std::cout << "..... Qedo directory is " << Qedo::g_qedo_dir << std::endl;

	//
	// init ORB
	//
	orb = CORBA::ORB_init (argc, argv);

	Qedo::ComponentInstallationImpl* component_installation = new Qedo::ComponentInstallationImpl (orb);

	try
	{
		component_installation->initialize();
	}
	catch (Qedo::ComponentInstallationImpl::CannotInitialize&)
	{
		std::cerr << "Cannot initialize Component Installer... exiting." << std::endl;
		orb->destroy();
		exit (1);
	}

#ifdef HAVE_SIGACTION
	 struct sigaction act;

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

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

    /*
     * Make these values effective. If we were writing a real 
     * application, we would probably save the old value instead of 
     * passing NULL.
     */
    if (sigaction(SIGINT, &act, NULL) < 0) 
    {
		 std::cerr << "sigaction failed" << std::endl;
        return 1;
    }
#else
	 signal ( SIGINT, handle_sigint );
#endif

	std::cout << "Qedo Component Installer is up and running ...\n";
	orb->run();
	return 0;
}
コード例 #20
0
ファイル: shmiop_test.cpp プロジェクト: milan-mpathix/ATCD
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      ACE_Get_Opt opts (argc, argv, ACE_TEXT ("s:c:"));
      const ACE_TCHAR *server = 0, *client = 0;
      for (int o; (o = opts ()) != -1;)
        {
          switch (o)
            {
            case 's':
              server = opts.opt_arg ();
              break;
            case 'c':
              client = opts.opt_arg ();
              break;
            }
        }

      Servant srv (orb);
      ORBTask task (orb);

      if (server)
        {
          CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA");
          PortableServer::POA_var poa = PortableServer::POA::_narrow (obj);
          PortableServer::POAManager_var pm = poa->the_POAManager ();
          pm->activate ();
          Test::Hello_var srv_obj = srv._this ();
          CORBA::String_var srv_str = orb->object_to_string (srv_obj);
          FILE *f = ACE_OS::fopen (server, "w");
          ACE_OS::fputs (srv_str, f);
          ACE_OS::fclose (f);
          if (!client)
            task.activate();
        }

      if (client)
        {
          ACE_CString ior ("file://");
          ior += ACE_TEXT_ALWAYS_CHAR (client);
          CORBA::Object_var obj = orb->string_to_object (ior.c_str ());
          Test::Hello_var hello = Test::Hello::_narrow (obj);
          CORBA::String_var str = hello->get_string ();
          ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) - returned <%C>\n"),
                      str.in ()));
          hello->shutdown ();
        }
      else if (server)
        {
          task.wait ();
        }

      orb->destroy ();
      return 0;
    }
  catch (const CORBA::Exception &e)
    {
      e._tao_print_exception ("Exception caught:");
    }
  catch (...)
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("ERROR unknown exception ")
                            ACE_TEXT ("caught in main\n")));
    }
  return 1;
}
コード例 #21
0
ファイル: PL_Daemon.cpp プロジェクト: DOCGroup/DAnCE
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  DANCE_DISABLE_TRACE ();

  int retval = 0;

  try
    {
      DAnCE::Logger_Service * dlf =
        ACE_Dynamic_Service<DAnCE::Logger_Service>::instance ("DAnCE_Logger");

      if (dlf)
        {
          dlf->init (argc, argv);
        }

      DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO
                    ACE_TEXT("PL_Daemon - initializing ORB\n")));

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

      DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO
                       ACE_TEXT("PL_Daemon - initializing module instance\n")));


      TAO::Utils::ORB_Destroyer safe_orb (orb);

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

      PortableServer::POA_var poa
        = PortableServer::POA::_narrow (poa_obj.in ());

      PortableServer::POAManager_var mgr = poa->the_POAManager ();
      PortableServer::POA_var persistent_poa;
      TAO::Utils::PolicyList_Destroyer policies (2);
      policies.length (2);
      try
        {
          DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO ACE_TEXT("PL_Daemon - ")
                           ACE_TEXT("before creating the \"Managers\" POA.\n")));

          policies[0] = poa->create_id_assignment_policy (PortableServer::USER_ID);
          policies[1] = poa->create_lifespan_policy (PortableServer::PERSISTENT);
          persistent_poa = poa->create_POA ("Managers",
                                            mgr.in(),
                                            policies);
        }
      catch (const PortableServer::POA::AdapterAlreadyExists &)
        {
          persistent_poa = poa->find_POA ("Managers", 0);
        }

      DAnCE::Plan_Launcher_Daemon_i *pl_daemon (0);

      ACE_NEW_RETURN (pl_daemon,
                      DAnCE::Plan_Launcher_Daemon_i (orb.in ()),
                      0);

      PortableServer::ServantBase_var safe_servant (pl_daemon);

      PortableServer::ObjectId_var oid =
        PortableServer::string_to_ObjectId ("Plan_Launcher_Daemon");
      persistent_poa->activate_object_with_id (oid, pl_daemon);

      CORBA::Object_var pl_obj = persistent_poa->id_to_reference (oid.in ());
      CORBA::String_var pl_ior = orb->object_to_string (pl_obj.in ());

      DAnCE::Utility::write_IOR (ACE_TEXT ("PL_Daemon.ior"),
                                 pl_ior.in ());

      orb->run ();

      DANCE_TRACE_LOG (DANCE_LOG_TRACE, (LM_TRACE, DLINFO
                                         ACE_TEXT("PL_Daemon - destroying ORB\n")));

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      DANCE_ERROR (DANCE_LOG_EMERGENCY,
                   (LM_EMERGENCY, DLINFO
                    "PL_Daemon - Error - CORBA Exception :%C\n",
                    ex._info ().c_str ()));
      retval = -1;
    }
  catch (...)
    {
      DANCE_ERROR (DANCE_LOG_EMERGENCY,
                   (LM_ERROR, "PL_Daemon - Error: Unknown exception.\n"));
      retval = -1;
    }

  return retval;
}
コード例 #22
0
ファイル: server.cpp プロジェクト: akostrikov/ATCD
int TestTask::svc()
{

    try {
        // Get reference to Root POA
        CORBA::Object_var obj = orb_->resolve_initial_references("RootPOA");
        PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());

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

        // Find the Naming Service
        obj = orb_->string_to_object ("corbaloc:iiop:1.2@localhost:9932/NameService");
        CosNaming::NamingContext_var root =
            CosNaming::NamingContext::_narrow(obj.in());

        if (CORBA::is_nil(root.in())) {
            ACE_ERROR ((LM_ERROR, "Error, Nil Naming Context reference\n"));
            return 1;
        }
        // Bind the example Naming Context, if necessary
        CosNaming::NamingContext_var example_nc;
        CosNaming::Name name;
        name.length(1);
        name[0].id = CORBA::string_dup("example");
        try
        {
            obj = root->resolve(name);
            example_nc =
                CosNaming::NamingContext::_narrow(obj.in());
        }
        catch (const CosNaming::NamingContext::NotFound&)
        {
            example_nc = root->bind_new_context(name);
        }

        // Bind the Test object
        name.length(2);
        name[1].id = CORBA::string_dup("Hello");

        // Create an object
        Hello servant(orb_.in ());
        PortableServer::ObjectId_var oid = poa->activate_object(&servant);
        obj = poa->id_to_reference(oid.in());
        root->rebind(name, obj.in());

        ACE_DEBUG ((LM_INFO, "Hello object bound in Naming Service B\n"));

        name.length(1);
        obj = orb_->string_to_object ("corbaloc:iiop:1.2@localhost:9931/NameService");
        root = CosNaming::NamingContext::_narrow(obj.in());
        root->bind_context (name, example_nc.in ());

        ACE_DEBUG ((LM_INFO, "'example' context of NS B bound in Naming Service A\n"));

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

        // Output the IOR to the <ior_output_file>
        FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
        if (output_file == 0)
            ACE_ERROR_RETURN ((LM_ERROR,
                               "Cannot open output file %s for writing IOR: %C\n",
                               ior_output_file,
                               ior.in ()),
                              1);
        ACE_OS::fprintf (output_file, "%s", ior.in ());
        ACE_OS::fclose (output_file);

        ACE_DEBUG ((LM_INFO, "Wrote IOR file\n"));

        // Normally we run the orb and the orb is shutdown by
        // calling TestTask::end().
        // Accept requests
        orb_->run();
        orb_->destroy();

        return 0;
    }
    catch (const CORBA::Exception& ex)
    {
        ex._tao_print_exception ("CORBA exception: ");
    }

    return -1;
}
コード例 #23
0
ファイル: server2.cpp プロジェクト: OspreyHub/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;
}
コード例 #24
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  CORBA::ORB_var orb;
  try
  {
    orb = CORBA::ORB_init (argc, argv);

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

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

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

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

    poaMgr->activate ();

    CORBA::PolicyList policies;
    policies.length (3);
    policies[0] = rootPOA->create_id_assignment_policy (
      PortableServer::SYSTEM_ID);
    policies[1] = rootPOA->create_implicit_activation_policy (
      PortableServer::NO_IMPLICIT_ACTIVATION);
    policies[2] = rootPOA->create_lifespan_policy (
      PortableServer::TRANSIENT);

    PortableServer::POA_var fooPoa = rootPOA->create_POA (
      "FOO_POA", poaMgr.in (), policies );

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

    Foo_i servant;
    PortableServer::ObjectId_var oid = fooPoa->activate_object( &servant );

    CORBA::Object_var obj = fooPoa->id_to_reference (oid.in ());

    foo_var client = foo::_narrow (obj.in());

    client->check();

    if (vc_check(client.in()))
    {
      orb->destroy();
      return 1;
    }

    fooPoa->deactivate_object (oid.in () );  //servant is gone

    if (vc_check(client.in(), false))  //exception expected
    {
      orb->destroy();
      return 2;
    }
  }
  catch(...)
  {
    return 3;
  }
  return 0;
}
コード例 #25
0
ファイル: client.cpp プロジェクト: svn2github/ACE-Middleware
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int status = 0;
  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

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

       CORBA::Object_var object =
        orb->string_to_object (ior);

      // To use the smart proxy it is necessary to allocate the
      // user-defined smart factory on the heap as the smart proxy
      // generated classes take care of destroying the object. This
      // way it a win situation for the application developer who
      // doesnt have to make sure to destoy it and also for the smart
      // proxy designer who now can manage the lifetime of the object
      // much surely.
      Smart_Test_Factory *test_factory = 0;
      ACE_NEW_RETURN (test_factory,
                      Smart_Test_Factory,
                      -1);

      ACE_UNUSED_ARG (test_factory);

      Test_var server =
        Test::_narrow (object.in ());

      if (CORBA::is_nil (server.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Object reference <%s> is nil.\n",
                           ior),
                          1);

      try
        {
          CORBA::String_var sm_ior = orb->object_to_string (server.in ());
          if (Smart_Test_Proxy::fake_ior () != sm_ior.in ())
            {
              status = 1;
              ACE_ERROR ((LM_ERROR,
                          "ERROR: The Smart Proxy IOR is:\n%C\n"
                          "but should have been: %C\n",
                          sm_ior.in (),
                          Smart_Test_Proxy::fake_ior ().c_str ()));
            }
        }
      catch (const CORBA::MARSHAL& ex)
        {
          status = 1;
          ex._tao_print_exception ("Unexpected MARSHAL exception:");
        }

      server->method (0);

      server->shutdown ();

      // The following sleep is a hack to make sure the above oneway
      // request gets sent before we exit. Otherwise, at least on
      // Windows XP, the server may not even get the request.
      ACE_Time_Value tv (0, 100000);
      ACE_OS::sleep(tv);

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Client-side exception:");
      status = 1;
    }

  return status;
}
コード例 #26
0
ファイル: qci.cpp プロジェクト: BackupTheBerlios/qedo-svn
/**
 * starts the server for the component installer object
 */
int
main (int argc, char** argv)
{
#ifdef HAVE_LIBPTHREAD
    // block SIGINT
    // Only the signal thread will handle this signal
    sigset_t sigs;
    sigset_t osigs;
    sigemptyset (&sigs);
    sigaddset (&sigs, SIGINT);
    assert(pthread_sigmask (SIG_BLOCK, &sigs, &osigs) == 0);

    // this thread will do the signal handling
    Qedo::QedoThread* signal_thread;

    signal_thread = Qedo::qedo_startDetachedThread(signal_handler_thread,0);

#else // HAVE_LIBPTHREAD
#ifdef HAVE_SIGACTION
    struct sigaction act;

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

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

    /*
     * Make these values effective. If we were writing a real
     * application, we would probably save the old value instead of
     * passing NULL.
     */
    if (sigaction(SIGINT, &act, NULL) < 0)
    {
        std::cerr << "sigaction failed" << std::endl;
        return 1;
    }
#else // HAVE_SIGACTION
    signal ( SIGINT, handle_sigint );
#endif // HAVE_SIGACTION
#endif // HAVE_LIBPTHREAD
    std::cout << "Qedo Component Installer " << QEDO_VERSION << " " << QEDO_REVISION << std::endl;

    //
    // Resolve config values from config file
    //
    if ( Qedo::ConfigurationReader::instance()->lookup_config_value ("/General/VerboseOutput") == "true")
    {
        Qedo::debug_output = true;
    }

    for (int i = 1; i < argc; i++)
    {
        if (! strcmp (argv[i], "--verbose"))
        {
            Qedo::debug_output = true;
        }
    }

    //
    // get the qedo dir
    //
    Qedo::g_qedo_dir = Qedo::getEnvironment( "QEDO" );
    if(Qedo::g_qedo_dir.empty())
    {
        std::cout << "Missing Environment Variable QEDO" << std::endl;
        std::cout << "Assuming current dir as local deployment dir" << std::endl;
        Qedo::g_qedo_dir = Qedo::getCurrentDirectory();
    }
    std::cout << "..... Qedo directory is " << Qedo::g_qedo_dir << std::endl;

    // create arguments for ORB_init
    char *orb_argv[27];
    int orb_argc=argc;
    int orb_n = 0;
    for (orb_n = 0; orb_n < argc; orb_n++)
    {
        orb_argv[orb_n] = strdup(argv[orb_n]);
    };

    // check for Host Name Resolving
    std::string resolve = Qedo::ConfigurationReader::instance()->lookup_config_value ("/General/ResolveHostName");
    if (!resolve.compare("false"))
    {

        orb_argv[orb_argc] = "-ORBNoResolve";
        orb_argc++;
    };

    //
    // init ORB
    //
    orb = CORBA::ORB_init (orb_argc, orb_argv);
    Qedo::set_ORB(orb);

    Qedo::ComponentInstallationImpl* component_installation = new Qedo::ComponentInstallationImpl (orb);

    try
    {
        component_installation->initialize();
    }
    catch (Qedo::ComponentInstallationImpl::CannotInitialize&)
    {
        std::cerr << "Cannot initialize Component Installer... exiting." << std::endl;
        orb->destroy();
        exit (1);
    }

    std::cout << "Qedo Component Installer is up and running ...\n";
    orb->run();

#ifdef HAVE_LIBPTHREAD
    // It is not sure, that only SIGINT will break the orb/run
    // so we have to terminate the signal thread here also
    signal_handler_thread_stop = true;
    signal_thread->stop();
    signal_thread->join();
    delete signal_thread;
#endif // HAVE_LIBPTHREAD

    component_installation->_remove_ref();
    orb->destroy();
    return 0;
}
コード例 #27
0
ファイル: server.cpp プロジェクト: manut/TAO
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      // Initialize the ORB
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      // Get initial reference to the Root POA
      CORBA::Object_var poa_object =
        orb->resolve_initial_references("RootPOA");

      // Narrow down to the appropriate type
      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);

      // Get referencee to the POA manager
      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();

      // Parse the arguments
      if (parse_args (argc, argv) != 0)
        return 1;

      ACE_DEBUG(( LM_DEBUG, "ior file = %s\t#threads = %d\t"
                  "msglen = %d\n",
                  ior_output_file, nthreads, msglen));

      // Create the factory servant
      Object_Factory_i *factory_impl = 0;
      ACE_NEW_THROW_EX (factory_impl,
                        Object_Factory_i (orb.in (), msglen),
                        CORBA::NO_MEMORY ());
      PortableServer::ServantBase_var safe (factory_impl);

      // _this method registers the object withe the POA and returns
      // an object reference
      PortableServer::ObjectId_var id =
        root_poa->activate_object (factory_impl);

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

      Two_Objects_Test::Object_Factory_var factory =
        Two_Objects_Test::Object_Factory::_narrow (object_act.in ());

      // Convert the object reference to a string so that it can
      // be saved in a file and used by clinet programs later
      CORBA::String_var ior =
        orb->object_to_string (factory.in ());

      // If the ior_output_file exists, output the ior to it
      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);

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

      // Instantiate the specified # of worker threads
      Worker worker (orb.in ());

      if (worker.activate (THR_NEW_LWP | THR_JOINABLE,
                           nthreads) != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot activate server threads\n"),
                          1);

      // Wait for all threads to get done
      worker.thr_mgr ()->wait ();

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) event loop finished\n"));

      root_poa->destroy (1, 1);

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

  return 0;
}
コード例 #28
0
ファイル: server.cpp プロジェクト: OspreyHub/ATCD
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      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) Unable to initialize the POA.\n"),
                          1);

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

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

      Simple_Server_i server_impl (orb.in ());

      PortableServer::ObjectId_var id =
        root_poa->activate_object (&server_impl);

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

      Simple_Server_var server =
        Simple_Server::_narrow (object.in ());

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

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

      IORTable::Table_var table =
        IORTable::Table::_narrow (table_object.in ());
      if (CORBA::is_nil (table.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to initialize the IORTable.\n"),
                          1);
      table->bind ("Simple_Server", ior.in ());

      //ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));

      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);

      poa_manager->activate ();

      orb->run ();

      ACE_DEBUG ((LM_DEBUG, "(%P|%t)server: event loop finished\n"));

      root_poa->destroy (1, 1);

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

  return 0;
}
コード例 #29
0
ファイル: server.cpp プロジェクト: CCJY/ATCD
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  MessageLog logger(HELLO_CALL_NUMBER);

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

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

      PortableGroup::GOA_var root_poa =
        PortableGroup::GOA::_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 ();

      // servant
      Hello_Impl* hello_impl;
      ACE_NEW_RETURN (hello_impl,
                      Hello_Impl (orb.in (), &logger),
                      1);
      PortableServer::ServantBase_var owner_transfer (hello_impl);

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

      // create UIPMC reference
      CORBA::String_var multicast_url =
        CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(uipmc_url));
      CORBA::Object_var miop_ref =
        orb->string_to_object (multicast_url.in ());

      // create id
      PortableServer::ObjectId_var id =
        root_poa->create_id_for_reference (miop_ref.in ());

      // activate Hello Object
      root_poa->activate_object_with_id (id.in (),
                                         hello_impl);

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

      ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));

      // If the ior_output_file exists, output the ior to it
      if (ior_output_file != 0)
        {
          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);
        }

      poa_manager->activate ();

      orb->run ();

      root_poa->destroy (1, 1);

      orb->destroy ();

      if (logger.report_statistics () == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "\n (%P|%t) ERROR: No single call got through to the server\n"),
                           3);
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught in server main ():");
      return 4;
    }

  ACE_DEBUG ((LM_DEBUG,
              "\n (%P|%t) server finished successfully..\n"));
  return 0;
}
コード例 #30
0
ファイル: TimeoutTestMain.cpp プロジェクト: CCJY/ATCD
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      // Initialize the ORB.
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
      CORBA::ORB_var s_orb;

      // Find the Naming Service.
      CORBA::Object_var obj = orb->resolve_initial_references ("NameService");
      CosNaming::NamingContextExt_var root_context =
        CosNaming::NamingContextExt::_narrow (obj.in ());

      obj = root_context->resolve_str ("CosEventService");

      // Downcast the object reference to an EventChannel reference.
      CosEventChannelAdmin::EventChannel_var ec =
        CosEventChannelAdmin::EventChannel::_narrow (obj.in ());
      if (CORBA::is_nil (ec.in ()))
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("Could not narrow the EventChannel.\n")));
          return 1;
        }
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Found the EventChannel.\n")));

      bool consumer = false;
      bool supplier = false;
      bool hang = false;
      for (int i=1; i < argc; ++i)
        {
          if (0 == ACE_OS::strcasecmp (argv[i], ACE_TEXT ("-consumer")))
            consumer = true;
          else if (0 == ACE_OS::strcasecmp (argv[i], ACE_TEXT ("-supplier")))
            supplier = true;
          else if (0 == ACE_OS::strcasecmp (argv[i], ACE_TEXT ("-hang")))
            hang = true;
        }

      TestEventConsumer_i servant (orb.in (), hang);

      if (consumer)
        {
          // Register it with the RootPOA.
          obj = orb->resolve_initial_references ("RootPOA");
          PortableServer::POA_var poa =
            PortableServer::POA::_narrow (obj.in ());
          PortableServer::ObjectId_var oid = poa->activate_object (&servant);
          CORBA::Object_var consumer_obj = poa->id_to_reference (oid.in ());
          CosEventComm::PushConsumer_var consumer =
            CosEventComm::PushConsumer::_narrow (consumer_obj.in ());

          // Get a ConsumerAdmin object from the EventChannel.
          CosEventChannelAdmin::ConsumerAdmin_var consumerAdmin =
            ec->for_consumers ();

          // Get a ProxyPushSupplier from the ConsumerAdmin.
          CosEventChannelAdmin::ProxyPushSupplier_var supplier =
            consumerAdmin->obtain_push_supplier ();

          // Connect to the ProxyPushSupplier, passing our PushConsumer object
          // reference to it.
          supplier->connect_push_consumer (consumer.in ());
          ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Consumer connected\n")));

          // Activate the POA via its POAManager.
          PortableServer::POAManager_var poa_manager = poa->the_POAManager ();
          poa_manager->activate ();
          servant.activate ();
        }

      ACE_Auto_Ptr<SupplierTask> pST;
      if (supplier)
        {
          // The supplier will use its own ORB.
          CORBA::String_var ec_str = orb->object_to_string (ec.in ());

          int no_args = 0;
          ACE_TCHAR **no_argv = 0;
          s_orb = CORBA::ORB_init (no_args, no_argv,
                                   "Supplier_pure_client_ORB");

          CORBA::Object_var s_ec_obj = s_orb->string_to_object (ec_str.in ());

          CosEventChannelAdmin::EventChannel_var s_ec =
            CosEventChannelAdmin::EventChannel::_narrow (s_ec_obj.in ());

          // Get a SupplierAdmin object from the EventChannel.
          CosEventChannelAdmin::SupplierAdmin_var supplierAdmin =
            s_ec->for_suppliers ();

          // Get a ProxyPushConsumer from the SupplierAdmin.
          CosEventChannelAdmin::ProxyPushConsumer_var consumer =
            supplierAdmin->obtain_push_consumer ();

          // Connect to the ProxyPushConsumer as a PushSupplier
          // (passing a nil PushSupplier object reference to it because
          // we don't care to be notified about disconnects).
          consumer->connect_push_supplier
            (CosEventComm::PushSupplier::_nil ());

          SupplierTask *tmp = 0;
          ACE_NEW_RETURN (tmp, SupplierTask (consumer.in (), s_orb.in ()), -1);
          pST.reset (tmp);
          pST->activate ();
        }

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Ready to receive events...\n")));

      // Enter the ORB event loop.
      orb->run ();

      ACE_Thread_Manager::instance ()->wait ();

      if (!CORBA::is_nil (s_orb.in ()))
        {
          s_orb->destroy ();
        }

      orb->destroy ();
      return 0;
    }
  catch (const CORBA::Exception &ex)
    {
      ex._tao_print_exception (
        ACE_TEXT (
          "TimeoutTest: Caught CORBA::Exception:"));
    }

  return 1;
}