2 #include "Object_Factory_i.h"
3 #include "ace/Get_Opt.h"
6 int msglen
= 100; //default length of reply message is 100 bytes
8 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
11 parse_args (int argc
, ACE_TCHAR
*argv
[])
13 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:n:l:t:"));
16 while ((c
= get_opts ()) != -1)
20 ior_output_file
= get_opts
.opt_arg ();
24 msglen
= ACE_OS::atoi( get_opts
.opt_arg ());
28 nthreads
= ACE_OS::atoi (get_opts
.opt_arg ());
33 ACE_ERROR_RETURN ((LM_ERROR
,
37 " -l <size of message in bytes>"
42 // Indicates successful parsing of the command line
47 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
53 CORBA::ORB_init (argc
, argv
);
55 // Get initial reference to the Root POA
56 CORBA::Object_var poa_object
=
57 orb
->resolve_initial_references("RootPOA");
59 // Narrow down to the appropriate type
60 PortableServer::POA_var root_poa
=
61 PortableServer::POA::_narrow (poa_object
.in ());
63 if (CORBA::is_nil (root_poa
.in ()))
64 ACE_ERROR_RETURN ((LM_ERROR
,
65 " (%P|%t) Panic: nil RootPOA\n"),
68 // Get referencee to the POA manager
69 PortableServer::POAManager_var poa_manager
=
70 root_poa
->the_POAManager ();
72 // Parse the arguments
73 if (parse_args (argc
, argv
) != 0)
76 ACE_DEBUG(( LM_DEBUG
, "ior file = %s\t#threads = %d\t"
78 ior_output_file
, nthreads
, msglen
));
80 // Create the factory servant
81 Object_Factory_i
*factory_impl
= 0;
82 ACE_NEW_THROW_EX (factory_impl
,
83 Object_Factory_i (orb
.in (), msglen
),
85 PortableServer::ServantBase_var
safe (factory_impl
);
87 // _this method registers the object withe the POA and returns
88 // an object reference
89 PortableServer::ObjectId_var id
=
90 root_poa
->activate_object (factory_impl
);
92 CORBA::Object_var object_act
= root_poa
->id_to_reference (id
.in ());
94 Two_Objects_Test::Object_Factory_var factory
=
95 Two_Objects_Test::Object_Factory::_narrow (object_act
.in ());
97 // Convert the object reference to a string so that it can
98 // be saved in a file and used by clinet programs later
99 CORBA::String_var ior
=
100 orb
->object_to_string (factory
.in ());
102 // If the ior_output_file exists, output the ior to it
103 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
105 if (output_file
== 0)
106 ACE_ERROR_RETURN ((LM_ERROR
,
107 "Cannot open output file for writing IOR: %s",
111 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
112 ACE_OS::fclose (output_file
);
114 // Activate the POA manager
115 poa_manager
->activate ();
117 // Instantiate the specified # of worker threads
118 Worker
worker (orb
.in ());
120 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
122 ACE_ERROR_RETURN ((LM_ERROR
,
123 "Cannot activate server threads\n"),
126 // Wait for all threads to get done
127 worker
.thr_mgr ()->wait ();
129 ACE_DEBUG ((LM_DEBUG
, "(%P|%t) event loop finished\n"));
131 root_poa
->destroy (true, true);
135 catch (const CORBA::Exception
& ex
)
137 ex
._tao_print_exception ("Exception caught:");