2 //=============================================================================
6 * @author Source code used in TAO has been modified and adapted from thecode provided in the book
7 * @author "Advanced CORBA Programming with C++"by Michi Henning and Steve Vinoski. Copyright1999. Addison-Wesley
9 * @author MA. Used with permission ofAddison-Wesley.Modified for TAO by Mike Moran <mm4@cs.wustl.edu>
11 //=============================================================================
15 #include "tao/debug.h"
16 #include "ace/Get_Opt.h"
17 #include "ace/OS_NS_stdio.h"
18 #include "ace/OS_NS_unistd.h"
19 #include "ace/OS_NS_time.h"
21 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("server.ior");
25 parse_args (int argc
, ACE_TCHAR
*argv
[])
27 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:d"));
30 while ((c
= get_opts ()) != -1)
34 ior_output_file
= get_opts
.opt_arg ();
41 ACE_ERROR_RETURN ((LM_ERROR
,
48 // Indicates successful parsing of the command line
57 time_t time_now
= ACE_OS::time (0);
58 struct tm
*time_p
= ACE_OS::gmtime (&time_now
);
61 tod
.hour
= time_p
->tm_hour
;
62 tod
.minute
= time_p
->tm_min
;
63 tod
.second
= time_p
->tm_sec
;
70 void do_something_else()
72 // Sleep a bit so we don't eat up
78 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
83 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
85 if (parse_args (argc
, argv
) != 0)
90 // Get reference to Root POA.
92 = orb
->resolve_initial_references ("RootPOA");
94 PortableServer::POA_var poa
95 = PortableServer::POA::_narrow (obj
.in ());
97 // Activate POA manager.
98 PortableServer::POAManager_var mgr
99 = poa
->the_POAManager ();
104 Time_impl time_servant
;
106 // Write its stringified reference to stdout.
107 PortableServer::ObjectId_var id
=
108 poa
->activate_object (&time_servant
);
110 CORBA::Object_var object
= poa
->id_to_reference (id
.in ());
112 Time_var tm
= Time::_narrow (object
.in ());
114 CORBA::String_var str
= orb
->object_to_string (tm
.in ());
116 ACE_DEBUG ((LM_DEBUG
,
120 if (ior_output_file
!= 0)
122 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
124 if (output_file
== 0)
128 "Cannot open output file for writing IOR: %s",
134 ACE_OS::fprintf (output_file
,
137 ACE_OS::fclose (output_file
);
140 // Explicit Event Loop.
143 CORBA::Boolean pending
=
144 orb
->work_pending ();
148 orb
->perform_work ();
150 do_something_else ();
157 catch (const CORBA::Exception
& ex
)
159 ex
._tao_print_exception ("server: a CORBA exception occurred");
164 ACE_ERROR_RETURN ((LM_ERROR
,
166 "client: an unknown exception was caught\n"),