1 #include "publisher_impl.h"
2 #include "tao/Messaging/Messaging.h"
3 #include "tao/AnyTypeCode/Any.h"
4 #include "ace/Get_Opt.h"
7 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("ior.out");
10 parse_args (int argc
, ACE_TCHAR
*argv
[])
12 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
15 while ((c
= get_opts ()) != -1)
19 ior_output_file
= get_opts
.opt_arg ();
24 ACE_ERROR_RETURN ((LM_ERROR
,
31 // Indicates successful parsing of the command line
35 class ThreadPool
: public ACE_Task_Base
38 ThreadPool (CORBA::ORB_ptr orb
);
45 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
49 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
51 if (parse_args (argc
, argv
) != 0)
54 CORBA::Object_var poa_object
= orb
->resolve_initial_references("RootPOA");
56 if (CORBA::is_nil (poa_object
.in ()))
57 ACE_ERROR_RETURN ((LM_ERROR
,
58 " (%P|%t) Unable to initialize the POA.\n"),
61 PortableServer::POA_var root_poa
= PortableServer::POA::_narrow (poa_object
.in ());
62 PortableServer::POAManager_var poa_manager
=
63 root_poa
->the_POAManager();
65 Publisher_impl
publisher(orb
.in ());
66 PortableServer::ObjectId_var id
= root_poa
->activate_object (&publisher
);
68 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
70 Publisher_var publisher_var
= Publisher::_narrow (object
.in ());
72 CORBA::String_var ior
= orb
->object_to_string(publisher_var
.in());
73 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in()));
76 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
78 ACE_ERROR_RETURN ((LM_ERROR
,
79 "Cannot open output file for writing IOR: %s\n",
82 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
83 ACE_OS::fclose (output_file
);
85 poa_manager
->activate();
87 const CORBA::Object_var
pmobj (orb
->resolve_initial_references("ORBPolicyManager" ));
88 CORBA::PolicyManager_var policy_manager
= CORBA::PolicyManager::_narrow(pmobj
.in());
91 orb_level
<<= Messaging::SYNC_NONE
;
92 CORBA::PolicyList policy_list
;
93 policy_list
.length(1);
94 policy_list
[0] = orb
->create_policy(Messaging::SYNC_SCOPE_POLICY_TYPE
,
96 policy_manager
->set_policy_overrides(policy_list
,
99 ThreadPool
pool (orb
.in ());
100 if (pool
.activate(THR_NEW_LWP
| THR_JOINABLE
, 5) != 0)
101 ACE_ERROR_RETURN ((LM_ERROR
,
102 "Cannot activate client threads\n"),
105 pool
.thr_mgr ()->wait ();
107 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
109 catch (const CORBA::Exception
& ex
)
111 ex
._tao_print_exception ("Exception caught:");
118 // ****************************************************************
120 ThreadPool::ThreadPool(CORBA::ORB_ptr orb
)
121 : orb_(CORBA::ORB::_duplicate (orb
))
125 int ThreadPool::svc ()