3 #include "ace/Get_Opt.h"
4 #include "orbsvcs/PortableGroup/GOA.h"
7 ACE_TCHAR
const *uipmc_url
=
8 ACE_TEXT ("corbaloc:miop:1.0@1.0-test-1/225.1.1.8:32158");
9 ACE_TCHAR
const *ior_output_file
= ACE_TEXT ("test.ior");
10 CORBA::ULong threads
= 2u;
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT ("o:u:t:"));
18 while ((c
= get_opts ()) != -1)
22 ior_output_file
= get_opts
.opt_arg ();
26 uipmc_url
= get_opts
.opt_arg ();
30 threads
= ACE_OS::strtoul (get_opts
.opt_arg (), 0, 10);
35 ACE_ERROR_RETURN ((LM_ERROR
,
36 ACE_TEXT ("usage: %s ")
37 ACE_TEXT ("-o <iorfile> ")
38 ACE_TEXT ("-u <uipmc_url> ")
39 ACE_TEXT ("-t <threads> ")
44 // Indicates sucessful parsing of the command line.
48 class OrbThread
: public ACE_Task_Base
51 OrbThread (CORBA::ORB_ptr orb
)
52 : orb_ (CORBA::ORB::_duplicate (orb
))
56 virtual int svc (void)
62 catch (const CORBA::Exception
& ex
)
64 ex
._tao_print_exception ("Exception caught in OrbThread:");
76 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
80 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
82 if (parse_args (argc
, argv
) != 0)
83 ACE_ERROR_RETURN ((LM_ERROR
,
84 ACE_TEXT ("ERROR: wrong arguments\n")),
87 CORBA::Object_var poa_object
=
88 orb
->resolve_initial_references("RootPOA");
90 PortableGroup::GOA_var root_goa
=
91 PortableGroup::GOA::_narrow (poa_object
.in ());
93 if (CORBA::is_nil (root_goa
.in ()))
94 ACE_ERROR_RETURN ((LM_ERROR
,
95 ACE_TEXT ("ERROR: nil RootPOA\n")),
98 PortableServer::POAManager_var poa_manager
= root_goa
->the_POAManager ();
100 // Create UIPMC reference.
101 CORBA::Object_var obj
= orb
->string_to_object (uipmc_url
);
104 PortableServer::ObjectId_var id
=
105 root_goa
->create_id_for_reference (obj
.in ());
107 // Activate UIPMC Object.
108 UIPMC_Object_Impl
* uipmc_impl
;
109 ACE_NEW_RETURN (uipmc_impl
,
110 UIPMC_Object_Impl (orb
.in (), threads
),
112 PortableServer::ServantBase_var
owner_transfer1 (uipmc_impl
);
113 root_goa
->activate_object_with_id (id
.in (), uipmc_impl
);
115 Test::UIPMC_Object_var uipmc_obj
=
116 Test::UIPMC_Object::_unchecked_narrow (obj
.in ());
118 if (CORBA::is_nil (uipmc_obj
.in ()))
119 ACE_ERROR_RETURN ((LM_ERROR
,
120 ACE_TEXT ("ERROR: nil Hello object\n")),
122 CORBA::String_var ior
= orb
->object_to_string (obj
.in ());
124 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("MIOP object is <%C>\n"), ior
.in ()));
126 //obj = hello_impl->_this ();
128 // If the ior_output_file exists, output the ior to it.
129 if (ior_output_file
!= 0)
131 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
133 if (output_file
== 0)
135 ACE_ERROR_RETURN ((LM_ERROR
,
136 ACE_TEXT ("Cannot open output file ")
137 ACE_TEXT ("for writing IOR: %s"),
142 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
143 ACE_OS::fclose (output_file
);
146 poa_manager
->activate ();
149 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Starting %u thread, thread pool\n"), (unsigned) threads
));
150 // start server thread pool
151 OrbThread
orb_thr (orb
.in ());
152 orb_thr
.activate (THR_NEW_LWP
| THR_JOINABLE
, threads
);
154 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Stopping thread pool\n")));
157 root_goa
->destroy (1, 1);
161 catch (const CORBA::Exception
& ex
)
163 ex
._tao_print_exception ("Exception caught in server main ():");
167 ACE_DEBUG ((LM_DEBUG
,
168 ACE_TEXT ("\nServer finished successfully.\n")));