Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Xt_Stopwatch / client.cpp
blob8990d63b475ca513e89e9e3681a3254c739532b8
1 #include "testC.h"
2 #include "ace/Get_Opt.h"
4 #include "Control.h"
5 #include "Client.h"
7 int
8 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
10 XtAppContext app;
11 Widget toplevel = XtAppInitialize (&app,
12 "Start & Stop",
15 &argc,
16 argv,
19 0);
21 TAO::XtResource_Loader xt_loader (app);
23 Control control (toplevel);
26 try
28 CORBA::ORB_var orb =
29 CORBA::ORB_init (argc, argv);
31 Client client (orb.in ());
33 client.parse_args (argc, argv);
35 client.add_callback (control);
37 // Manage the widgets
38 control.manage ();
39 XtRealizeWidget (toplevel);
40 XtAppMainLoop (app);
42 catch (const CORBA::Exception& ex)
44 ex._tao_print_exception ("Caught exception:");
45 return 1;
47 return 0;
50 Client::Client (CORBA::ORB_ptr orb)
51 : orb_ (CORBA::ORB::_duplicate (orb))
55 Client::~Client ()
59 void
60 Client::parse_args (int argc,
61 ACE_TCHAR *argv[])
63 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
65 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
66 int c;
68 while ((c = get_opts ()) != -1)
69 switch (c)
71 case 'k':
72 ior = get_opts.opt_arg ();
73 break;
74 case '?':
75 default:
76 ACE_ERROR ((LM_ERROR,
77 "usage: %s "
78 "-k <ior> "
79 "\n",
80 argv [0]));
83 CORBA::Object_var object =
84 this->orb_->string_to_object (ior);
86 this->server_ =
87 Stopwatch::_narrow (object.in ());
89 if (CORBA::is_nil(this->server_.in ()))
91 ACE_DEBUG ((LM_DEBUG,
92 "\n The server value is nil "));
96 void
97 Client::add_callback (Control &ctrl)
99 XtPointer client_data = static_cast<XtPointer> (this);
101 // Register callbacks, specifying the object's instance pointer as
102 // client data.
103 XtAddCallback (ctrl.startwidget (),
104 XmNactivateCallback,
105 &Client::start_callback,
106 client_data);
108 XtAddCallback (ctrl.stopwidget (),
109 XmNactivateCallback,
110 &Client::stop_callback,
111 client_data);
114 void
115 Client::start_callback (Widget /*widget*/,
116 XtPointer client_data,
117 XtPointer)
119 Client *self = static_cast<Client *> (client_data);
120 self->start_hook ();
123 void
124 Client::stop_callback (Widget /*widget*/,
125 XtPointer client_data,
126 XtPointer )
128 Client *self = static_cast<Client *> (client_data);
129 self->stop_hook ();
132 void
133 Client::start_hook ()
137 this->server_->start ();
139 catch (const CORBA::Exception& ex)
141 ex._tao_print_exception (
142 "Caught an exception in the start button callback");
143 return;
147 void
148 Client::stop_hook ()
152 this->server_->stop ();
154 catch (const CORBA::Exception& ex)
156 ex._tao_print_exception (
157 "Caught an exception in the stop button callback");