Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Xt_Stopwatch / server.cpp
blob4158a3b7318c518b9975530caac8b9fbd699e7dd
1 #include "test_i.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "tao/XtResource/XtResource_Loader.h"
5 #include <Xm/Xm.h>
6 #include "Stopwatch_display.h"
7 #include "timer.h"
9 const ACE_TCHAR *ior_output_file = 0;
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'o':
21 ior_output_file = get_opts.opt_arg ();
22 break;
24 case '?':
25 default:
26 ACE_ERROR_RETURN ((LM_ERROR,
27 "usage: %s "
28 "-o <iorfile>"
29 "\n",
30 argv [0]),
31 -1);
33 // Indicates successful parsing of the command line
34 return 0;
37 int
38 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
40 // We do the command line parsing first
41 if (parse_args (argc, argv) != 0)
42 return 1;
44 XtAppContext app;
45 Widget toplevel = XtAppInitialize (&app,
46 "Stopwatch",
49 &argc,
50 argv,
53 0);
55 TAO::XtResource_Loader xt_loader (app);
57 Stopwatch_display stopwatch (toplevel);
60 try
62 CORBA::ORB_var orb =
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"),
71 1);
73 PortableServer::POA_var root_poa =
74 PortableServer::POA::_narrow (poa_object.in ());
76 PortableServer::POAManager_var poa_manager =
77 root_poa->the_POAManager ();
79 stopwatch.manage ();
81 // Make a timer class
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",
106 ior_output_file),
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)
122 XtAppMainLoop (app);
123 #else
124 orb->run ();
125 #endif /*ACE_HAS_THREADS*/
127 catch (const CORBA::Exception& ex)
129 ex._tao_print_exception ("Caught exception:");
130 return 1;
132 return 0;