2 #include "ace/Get_Opt.h"
3 #include "orbsvcs/PortableGroup/GOA.h"
4 #include "tao/Policy_Manager.h"
5 #include "Hello_Impl.h"
7 #define HELLO_CALL_NUMBER 100
9 const ACE_TCHAR
*uipmc_url
= 0;
10 const ACE_TCHAR
*ior_output_file
= 0;
13 parse_args (int argc
, ACE_TCHAR
*argv
[])
15 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("u:o:"));
16 const unsigned char full_success
= 0x03;
17 unsigned char success
= 0;
22 if (success
== full_success
&& c
== -1)
26 ACE_ERROR_RETURN ((LM_ERROR
,
37 uipmc_url
= get_opts
.opt_arg ();
41 ior_output_file
= get_opts
.opt_arg ();
48 // Indicates successful parsing of the command line
53 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
55 MessageLog
logger(HELLO_CALL_NUMBER
);
60 CORBA::ORB_init (argc
, argv
);
62 CORBA::Object_var poa_object
=
63 orb
->resolve_initial_references("RootPOA");
65 PortableGroup::GOA_var root_poa
=
66 PortableGroup::GOA::_narrow (poa_object
.in ());
68 if (CORBA::is_nil (root_poa
.in ()))
69 ACE_ERROR_RETURN ((LM_ERROR
,
70 " (%P|%t) Panic: nil RootPOA\n"),
73 PortableServer::POAManager_var poa_manager
=
74 root_poa
->the_POAManager ();
77 Hello_Impl
* hello_impl
;
78 ACE_NEW_RETURN (hello_impl
,
79 Hello_Impl (orb
.in (), &logger
),
81 PortableServer::ServantBase_var
owner_transfer (hello_impl
);
83 if (parse_args (argc
, argv
) != 0)
86 // create UIPMC reference
87 CORBA::String_var multicast_url
=
88 CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(uipmc_url
));
89 CORBA::Object_var miop_ref
=
90 orb
->string_to_object (multicast_url
.in ());
93 PortableServer::ObjectId_var id
=
94 root_poa
->create_id_for_reference (miop_ref
.in ());
96 // activate Hello Object
97 root_poa
->activate_object_with_id (id
.in (),
100 CORBA::String_var ior
=
101 orb
->object_to_string (miop_ref
.in ());
103 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
105 // If the ior_output_file exists, output the ior to it
106 if (ior_output_file
!= 0)
108 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
110 if (output_file
== 0)
112 ACE_ERROR_RETURN ((LM_ERROR
,
113 "Cannot open output file for writing IOR: %s",
118 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
119 ACE_OS::fclose (output_file
);
122 poa_manager
->activate ();
126 root_poa
->destroy (true, true);
130 if (logger
.report_statistics () == 0)
131 ACE_ERROR_RETURN ((LM_ERROR
,
132 "\n (%P|%t) ERROR: No single call got through to the server\n"),
135 catch (const CORBA::Exception
& ex
)
137 ex
._tao_print_exception ("Exception caught in server main ():");
141 ACE_DEBUG ((LM_DEBUG
,
142 "\n (%P|%t) server finished successfully..\n"));