2 //=============================================================================
6 * Implementation of the server running the Timeout object.
8 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
10 //=============================================================================
13 #include "timeout_client.h"
14 #include "tao/debug.h"
15 #include "ace/Get_Opt.h"
17 const ACE_TCHAR
*ior_output_file
= 0;
20 parse_args (int argc
, ACE_TCHAR
*argv
[])
22 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:d"));
25 while ((c
= get_opts ()) != -1)
29 ior_output_file
= get_opts
.opt_arg ();
36 ACE_ERROR_RETURN ((LM_ERROR
,
43 // Indicates successful parsing of the command line
48 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
53 CORBA::ORB_init (argc
, argv
);
55 CORBA::Object_var poa_object
=
56 orb
->resolve_initial_references ("RootPOA");
58 if (CORBA::is_nil (poa_object
.in ()))
59 ACE_ERROR_RETURN ((LM_ERROR
,
60 " (%P|%t) Unable to initialize the POA.\n"),
63 PortableServer::POA_var root_poa
=
64 PortableServer::POA::_narrow (poa_object
.in ());
66 PortableServer::POAManager_var poa_manager
=
67 root_poa
->the_POAManager ();
69 if (parse_args (argc
, argv
) != 0)
72 Timeout_i
timeout_i (orb
.in ());
74 PortableServer::ObjectId_var id
=
75 root_poa
->activate_object (&timeout_i
);
77 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
79 TimeoutObj_var timeout_var
=
80 TimeoutObj::_narrow (object
.in ());
82 CORBA::String_var ior
=
83 orb
->object_to_string (timeout_var
.in ());
85 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
87 // If the ior_output_file exists, output the ior to it
88 if (ior_output_file
!= 0)
90 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
92 ACE_ERROR_RETURN ((LM_ERROR
,
93 "Cannot open output file for writing IOR: %s",
96 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
97 ACE_OS::fclose (output_file
);
100 poa_manager
->activate ();
102 // Instantiate reply handler
103 TimeoutHandler_i timeoutHandler_i
;
105 PortableServer::ObjectId_var idu
=
106 root_poa
->activate_object (&timeoutHandler_i
);
108 CORBA::Object_var objectu
= root_poa
->id_to_reference (idu
.in ());
110 AMI_TimeoutObjHandler_var timeoutHandler_var
=
111 AMI_TimeoutObjHandler::_narrow (objectu
.in ());
113 // Instantiate client
115 TimeoutClient* client = new TimeoutClient (orb,
117 timeoutHandler_var.in (),
125 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
127 root_poa
->destroy (true, // ethernalize objects
128 false); // wait for completion
134 catch (const CORBA::Exception
& ex
)
136 ex
._tao_print_exception ("Caught exception:");