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 //=============================================================================
13 #include "ami_test_i.h"
14 #include "tao/debug.h"
15 #include "ace/OS_NS_stdio.h"
16 #include "ace/Get_Opt.h"
19 const ACE_TCHAR
*ior_output_file
= 0;
25 * Use the ACE_Task_Base class to run server threads
27 class Worker
: public ACE_Task_Base
31 Worker (CORBA::ORB_ptr orb
);
33 // The thread entry point.
42 parse_args (int argc
, ACE_TCHAR
*argv
[])
44 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:d"));
47 while ((c
= get_opts ()) != -1)
51 ior_output_file
= get_opts
.opt_arg ();
58 ACE_ERROR_RETURN ((LM_ERROR
,
65 // Indicates successful parsing of the command line
70 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
75 CORBA::ORB_init (argc
, argv
);
77 CORBA::Object_var poa_object
=
78 orb
->resolve_initial_references("RootPOA");
80 if (CORBA::is_nil (poa_object
.in ()))
81 ACE_ERROR_RETURN ((LM_ERROR
,
82 " (%P|%t) Unable to initialize the POA.\n"),
85 PortableServer::POA_var root_poa
=
86 PortableServer::POA::_narrow (poa_object
.in ());
88 PortableServer::POAManager_var poa_manager
=
89 root_poa
->the_POAManager ();
91 if (parse_args (argc
, argv
) != 0)
94 AMI_Test_i
ami_test_i (orb
.in ());
96 PortableServer::ObjectId_var id
=
97 root_poa
->activate_object (&ami_test_i
);
99 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
101 A::AMI_Test_var ami_test_var
=
102 A::AMI_Test::_narrow (object
.in ());
104 CORBA::String_var ior
=
105 orb
->object_to_string (ami_test_var
.in ());
107 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
109 // If the ior_output_file exists, output the ior to it
110 if (ior_output_file
!= 0)
112 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
113 if (output_file
== 0)
114 ACE_ERROR_RETURN ((LM_ERROR
,
115 "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 ();
124 Worker
worker (orb
.in ());
125 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
127 ACE_ERROR_RETURN ((LM_ERROR
,
128 "Cannot activate client threads\n"),
131 worker
.thr_mgr ()->wait ();
133 root_poa
->destroy (true, // ethernalize objects
134 false); // wait for completion
138 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
140 catch (const CORBA::Exception
& ex
)
142 ex
._tao_print_exception ("Caught exception:");
149 Worker::Worker (CORBA::ORB_ptr orb
)
150 : orb_ (CORBA::ORB::_duplicate (orb
))
161 catch (const CORBA::Exception
&)