Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / tests / FL_Cube / client.cpp
blobb66b9ae2cdf151252bdb399badc4b9e9c52cff63
1 #include "tao/FlResource/FlResource_Loader.h"
2 #include "testC.h"
3 #include "ace/Get_Opt.h"
5 #include <FL/Fl.H>
6 #include <FL/Fl_Window.H>
7 #include <FL/Fl_Roller.H>
9 class Client
11 // = TITLE
12 // Run the client thread
14 // = DESCRIPTION
15 // Use the ACE_Task_Base class to run the client threads.
17 public:
18 Client (CORBA::ORB_ptr orb,
19 Fl_Window* parent);
20 // ctor
22 ~Client ();
24 void show ();
25 // Call show on all the window objects
27 void parse_args (int argc, ACE_TCHAR *argv[]);
29 private:
30 static void x_cb (Fl_Widget *widget, void* cookie);
31 static void y_cb (Fl_Widget *widget, void* cookie);
32 // The callbacks
34 void x_changed ();
35 void y_changed ();
36 // The methods for the callbacks
38 private:
39 CORBA::ORB_var orb_;
40 // The ORB
42 Fl_Roller* x_roller_;
43 Fl_Roller* y_roller_;
44 // The rollers
46 Simple_Server_var server_;
47 // The server.
50 int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
52 TAO::FlResource_Loader fl_loader;
54 try
56 CORBA::ORB_var orb =
57 CORBA::ORB_init (argc, argv);
59 Fl_Window window (300, 100);
61 Client client (orb.in (), &window);
63 window.end ();
65 window.show ();
67 client.show ();
69 client.parse_args (argc, argv);
71 Fl::run ();
73 catch (const CORBA::Exception& ex)
75 ex._tao_print_exception ("Caught exception:");
76 return 1;
78 return 0;
81 Client::Client (CORBA::ORB_ptr orb,
82 Fl_Window* parent)
83 : orb_ (CORBA::ORB::_duplicate (orb))
85 this->x_roller_ =
86 new Fl_Roller (10, parent->h () / 2 - 20,
87 parent->w () / 2 - 10, 40);
88 this->x_roller_->type (FL_HORIZONTAL);
89 this->x_roller_->callback (Client::x_cb, this);
90 this->x_roller_->range (-360, 360);
91 this->x_roller_->step (1);
93 this->y_roller_ =
94 new Fl_Roller (3 * parent->w () / 4 - 20, 10,
95 40, parent->h () - 20);
96 this->y_roller_->type (FL_VERTICAL);
97 this->y_roller_->callback (Client::y_cb, this);
98 this->y_roller_->range (-360, 360);
99 this->y_roller_->step (1);
102 Client::~Client ()
104 delete x_roller_;
105 delete y_roller_;
108 void
109 Client::show ()
111 this->x_roller_->show ();
112 this->y_roller_->show ();
115 void
116 Client::x_cb (Fl_Widget*, void* cookie)
118 Client *self = static_cast<Client*> (cookie);
119 self->x_changed ();
122 void
123 Client::y_cb (Fl_Widget*, void* cookie)
125 Client *self = static_cast<Client*> (cookie);
126 self->y_changed ();
129 void
130 Client::x_changed ()
134 CORBA::Long x = CORBA::Long (this->x_roller_->value ());
135 this->server_->set_x_angle (x);
137 catch (const CORBA::Exception& ex)
139 ex._tao_print_exception ("Client::x_changed");
143 void
144 Client::y_changed ()
148 CORBA::Long y = CORBA::Long (this->y_roller_->value ());
149 this->server_->set_y_angle (y);
151 catch (const CORBA::Exception& ex)
153 ex._tao_print_exception ("Client::x_changed");
157 void
158 Client::parse_args (int argc, ACE_TCHAR *argv[])
160 const ACE_TCHAR *ior = ACE_TEXT ("file://test.ior");
162 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
163 int c;
165 while ((c = get_opts ()) != -1)
166 switch (c)
168 case 'k':
169 ior = get_opts.opt_arg ();
170 break;
171 case '?':
172 default:
173 ACE_ERROR ((LM_ERROR,
174 "usage: %s "
175 "-k <ior> "
176 "\n",
177 argv [0]));
180 CORBA::Object_var object =
181 this->orb_->string_to_object (ior);
183 this->server_ =
184 Simple_Server::_narrow (object.in ());