2 //=============================================================================
6 * Implementation of the server.
8 * @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
9 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
11 //=============================================================================
14 #include "ami_test_i.h"
16 #include "tao/debug.h"
17 #include "ace/Get_Opt.h"
18 #include "ace/OS_NS_sys_socket.h"
21 const ACE_TCHAR
*ior_output_file
= 0;
24 parse_args (int argc
, ACE_TCHAR
*argv
[])
26 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:d"));
29 while ((c
= get_opts ()) != -1)
33 ior_output_file
= get_opts
.opt_arg ();
40 ACE_ERROR_RETURN ((LM_ERROR
,
47 // Indicates successful parsing of the command line
52 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
57 CORBA::ORB_init (argc
, argv
);
59 CORBA::Object_var poa_object
=
60 orb
->resolve_initial_references("RootPOA");
62 if (CORBA::is_nil (poa_object
.in ()))
63 ACE_ERROR_RETURN ((LM_ERROR
,
64 " (%P|%t) Unable to initialize the POA.\n"),
67 PortableServer::POA_var root_poa
=
68 PortableServer::POA::_narrow (poa_object
.in ());
70 PortableServer::POAManager_var poa_manager
=
71 root_poa
->the_POAManager ();
73 if (parse_args (argc
, argv
) != 0)
76 ACE_OS::socket_init ();
78 AMI_Test_i
ami_test_i (orb
.in ());
80 A::AMI_Test_var ami_test_var
=
83 CORBA::String_var ior
=
84 orb
->object_to_string (ami_test_var
.in ());
86 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
88 // If the ior_output_file exists, output the ior to it
89 if (ior_output_file
!= 0)
91 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
93 ACE_ERROR_RETURN ((LM_ERROR
,
94 "Cannot open output file for writing IOR: %s",
97 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
98 ACE_OS::fclose (output_file
);
101 poa_manager
->activate ();
105 root_poa
->destroy (true, // ethernalize objects
106 false); // wait for completion
110 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
112 catch (const CORBA::Exception
& ex
)
114 ex
._tao_print_exception ("Caught exception:");