2 //=============================================================================
6 * Implementation of the server running the UDP object.
8 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
10 //=============================================================================
13 #include "ace/Get_Opt.h"
17 // The following include file forces DIOP to be linked into the
18 // executable and initialized for static builds.
19 #include "tao/Strategies/advanced_resource.h"
22 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("test.ior");
25 parse_args (int argc
, ACE_TCHAR
*argv
[])
27 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
30 while ((c
= get_opts ()) != -1)
34 ior_output_file
= get_opts
.opt_arg ();
39 ACE_ERROR_RETURN ((LM_ERROR
,
46 // Indicates successful parsing of the command line
50 int ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
55 CORBA::ORB_init (argc
,
59 if (parse_args (argc
, argv
) != 0)
62 CORBA::Object_var poa_object
=
63 orb
->resolve_initial_references("RootPOA");
65 if (CORBA::is_nil (poa_object
.in ()))
66 ACE_ERROR_RETURN ((LM_ERROR
,
67 " (%P|%t) Unable to initialize the POA.\n"),
70 PortableServer::POA_var root_poa
=
71 PortableServer::POA::_narrow (poa_object
.in ());
73 PortableServer::POAManager_var poa_manager
=
74 root_poa
->the_POAManager ();
76 Simple_Server_i
server_impl (orb
.in ());
78 PortableServer::ObjectId_var oidServer
= root_poa
->activate_object (&server_impl
);
80 CORBA::Object_var objOne
= root_poa
->id_to_reference (oidServer
.in ());
82 Simple_Server_var server
= Simple_Server::_narrow (objOne
.in ());
84 CORBA::String_var ior
=
85 orb
->object_to_string (server
.in ());
87 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
89 // If the ior_output_file exists, output the ior to it
90 if (ior_output_file
!= 0)
92 FILE *output_file
= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_output_file
), "w");
94 ACE_ERROR_RETURN ((LM_ERROR
,
95 "Cannot open output file for writing IOR: %s",
96 ACE_TEXT_ALWAYS_CHAR(ior_output_file
)),
98 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
99 ACE_OS::fclose (output_file
);
102 poa_manager
->activate ();
106 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
108 root_poa
->destroy (true, true);
112 catch (const CORBA::Exception
& ex
)
114 ex
._tao_print_exception ("Caught exception:");