2 //=============================================================================
6 * Implementation of the server running the UDP object.
8 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
10 //=============================================================================
15 #include "tao/debug.h"
16 #include "ace/OS_NS_stdio.h"
17 #include "ace/Get_Opt.h"
19 // The following include file forces DIOP to be linked into the
20 // executable and initialized for static builds.
21 #include "tao/Strategies/advanced_resource.h"
23 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
26 parse_args (int argc
, ACE_TCHAR
*argv
[])
28 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:d"));
31 while ((c
= get_opts ()) != -1)
35 ior_output_file
= get_opts
.opt_arg ();
42 ACE_ERROR_RETURN ((LM_ERROR
,
49 // Indicates successful parsing of the command line
54 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
59 CORBA::ORB_init (argc
, argv
);
61 CORBA::Object_var poa_object
=
62 orb
->resolve_initial_references("RootPOA");
64 if (CORBA::is_nil (poa_object
.in ()))
65 ACE_ERROR_RETURN ((LM_ERROR
,
66 " (%P|%t) Unable to initialize the POA.\n"),
69 PortableServer::POA_var root_poa
=
70 PortableServer::POA::_narrow (poa_object
.in ());
72 PortableServer::POAManager_var poa_manager
=
73 root_poa
->the_POAManager ();
75 // Install a persistent POA in order to achieve a persistent IOR
77 CORBA::PolicyList policies
;
80 root_poa
->create_lifespan_policy(PortableServer::PERSISTENT
);
82 root_poa
->create_id_assignment_policy (PortableServer::USER_ID
);
85 PortableServer::POA_var persistent_poa
=
86 root_poa
->create_POA("persistent",
90 policies
[0]->destroy ();
92 policies
[1]->destroy ();
94 if (parse_args (argc
, argv
) != 0)
97 UDP_i
udp_i (orb
.in ());
99 PortableServer::ObjectId_var id
=
100 PortableServer::string_to_ObjectId ("UDP_Object");
102 persistent_poa
->activate_object_with_id (id
.in (),
105 CORBA::Object_var obj
=
106 persistent_poa
->id_to_reference (id
.in ());
109 UDP_var udp_var
= UDP::_narrow (obj
.in ());
111 // UDP_var udp_var = udp_i._this ();
112 if (CORBA::is_nil (udp_var
.in ()))
113 ACE_DEBUG ((LM_DEBUG
,
114 "Failed to narrow correct object reference.\n"));
116 CORBA::String_var ior
=
117 orb
->object_to_string (udp_var
.in ());
119 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
121 // If the ior_output_file exists, output the ior to it
122 if (ior_output_file
!= 0)
124 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
125 if (output_file
== 0)
126 ACE_ERROR_RETURN ((LM_ERROR
,
127 "Cannot open output file for writing IOR: %s",
130 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
131 ACE_OS::fclose (output_file
);
134 poa_manager
->activate ();
138 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
140 root_poa
->destroy (true, // ethernalize objects
141 false); // wait for completion
145 catch (const CORBA::Exception
& ex
)
147 ex
._tao_print_exception ("Caught exception:");