2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "tao/XtResource/XtResource_Loader.h"
6 #include "Stopwatch_display.h"
9 const ACE_TCHAR
*ior_output_file
= 0;
12 parse_args (int argc
, ACE_TCHAR
*argv
[])
14 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
17 while ((c
= get_opts ()) != -1)
21 ior_output_file
= get_opts
.opt_arg ();
26 ACE_ERROR_RETURN ((LM_ERROR
,
33 // Indicates successful parsing of the command line
38 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
40 // We do the command line parsing first
41 if (parse_args (argc
, argv
) != 0)
45 Widget toplevel
= XtAppInitialize (&app
,
55 TAO::XtResource_Loader
xt_loader (app
);
57 Stopwatch_display
stopwatch (toplevel
);
63 CORBA::ORB_init (argc
, argv
);
65 CORBA::Object_var poa_object
=
66 orb
->resolve_initial_references ("RootPOA");
68 if (CORBA::is_nil (poa_object
.in ()))
69 ACE_ERROR_RETURN ((LM_ERROR
,
70 " (%P|%t) Unable to initialize the POA.\n"),
73 PortableServer::POA_var root_poa
=
74 PortableServer::POA::_narrow (poa_object
.in ());
76 PortableServer::POAManager_var poa_manager
=
77 root_poa
->the_POAManager ();
82 Timer_imp
timer (app
, 100, &stopwatch
);
84 Stopwatch_imp
server_impl (orb
.in (), &timer
);
86 PortableServer::ObjectId_var id
=
87 root_poa
->activate_object (&server_impl
);
89 CORBA::Object_var object
= root_poa
->id_to_reference (id
.in ());
91 Stopwatch_var server
=
92 Stopwatch::_narrow (object
.in ());
94 CORBA::String_var ior
=
95 orb
->object_to_string (server
.in ());
97 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
99 // If the ior_output_file exists, output the ior to it
100 if (ior_output_file
!= 0)
102 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
103 if (output_file
== 0)
104 ACE_ERROR_RETURN ((LM_ERROR
,
105 "Cannot open output file for writing IOR: %s",
108 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
109 ACE_OS::fclose (output_file
);
112 poa_manager
->activate ();
114 XtRealizeWidget (toplevel
);
115 /* Looks like there seems to be a problem with ST cases using
116 XtAppMainLoop. Havent been able to figure out what the
117 problem could be. The funny part is that orb->run () works
118 fine. The XtRector actually calls XtAppProcessEvent (), which
119 actually does something similar to this. Need to investigate
120 this when we have time*/
121 #if defined (ACE_HAS_THREADS)
125 #endif /*ACE_HAS_THREADS*/
127 catch (const CORBA::Exception
& ex
)
129 ex
._tao_print_exception ("Caught exception:");