Merge pull request #2306 from mitza-oci/warnings
[ACE_TAO.git] / TAO / examples / AMI / FL_Callback / Progress_i.cpp
blob6fc01d788298ad6fbedf6fd7c1dc9e0ac812dc59
1 #include "Progress_i.h"
3 #include <FL/Fl_Slider.H>
4 #include <FL/Fl_Button.H>
6 Progress_i::Progress_i (Progress_Window *window)
7 : window_ (window)
11 void
12 Progress_i::sent_request (CORBA::Long id)
14 //ACE_DEBUG ((LM_DEBUG, "Progress (%t) - sent request %d\n", id));
15 this->window_->sent_request (id);
18 void
19 Progress_i::recv_reply (CORBA::Long id)
21 this->window_->recv_reply (id);
24 CORBA::Long
25 Progress_i::bind (Peer_ptr a_peer)
27 ACE_DEBUG ((LM_DEBUG, "Progress (%t) - peer bound\n"));
28 return this->window_->bind (a_peer);
31 // ****************************************************************
33 Progress_Window::Progress_Window (int n_peers,
34 int n_iterations,
35 int x, int y,
36 int w, int h,
37 const char* l)
38 : Fl_Box (x, y, w, h, l),
39 n_peers_ (n_peers),
40 peers_ (n_peers),
41 n_iterations_ (n_iterations)
43 ACE_NEW (this->request_progress_, Fl_Widget*[this->n_peers_]);
44 ACE_NEW (this->reply_progress_, Fl_Widget*[this->n_peers_]);
46 // @@ leak...
47 Fl_Widget *button = new Fl_Button (x + 5, y + 5,
48 50, h - 10,
49 "Start");
50 button->callback (Progress_Window::start_callback, this);
52 // Compute the slider height, leaving a little margin...
53 int sh = h / ( 2 * this->n_peers_);
54 sh = sh - 5;
56 // The initial position, with margin...
57 int sy = y + 5;
59 // Set the width of the sliders...
60 int sx = x + 60;
61 int sw = w - 65;
62 int max = this->n_peers_ * this->n_iterations_;
63 for (int i = 0; i < this->n_peers_; ++i)
65 Fl_Slider *obj;
67 this->request_progress_[i] = obj =
68 new Fl_Slider (FL_HOR_FILL_SLIDER, sx, sy, sw, sh, "");
69 obj->color (FL_BLACK);
70 obj->selection_color (FL_RED);
71 obj->bounds (0, max);
72 obj->precision (0);
73 obj->value (0);
74 sy += sh + 5;
76 this->reply_progress_[i] = obj =
77 new Fl_Slider (FL_HOR_FILL_SLIDER, sx, sy, sw, sh, "");
78 obj->color (FL_BLACK);
79 obj->selection_color (FL_GREEN);
80 obj->bounds (0, max);
81 obj->precision (0);
82 obj->value (0);
83 sy += sh + 5;
87 void
88 Progress_Window::sent_request (CORBA::Long id)
90 if (id < 0 || id >= this->n_peers_)
91 return;
92 Fl_Slider *obj =
93 dynamic_cast<Fl_Slider*> (this->request_progress_[id]);
94 obj->value (obj->value () + 1);
95 obj->redraw ();
97 int i = static_cast<int> (obj->value ());
98 if (i % 100 == 0)
99 ACE_DEBUG ((LM_DEBUG, "Progress (%t) - recv reply %d\n", i));
102 void
103 Progress_Window::recv_reply (CORBA::Long id)
105 if (id < 0 || id >= this->n_peers_)
106 return;
107 Fl_Slider *obj =
108 dynamic_cast<Fl_Slider*> (this->reply_progress_[id]);
109 obj->value (obj->value () + 1);
110 obj->redraw ();
112 int i = static_cast<int> (obj->value ());
113 if (i % 100 == 0)
114 ACE_DEBUG ((LM_DEBUG, "Progress (%t) - recv reply %d\n", i));
117 CORBA::Long
118 Progress_Window::bind (Peer_ptr a_peer)
120 CORBA::ULong l = this->peers_.length ();
121 this->peers_.length (l + 1);
122 this->peers_[l] = Peer::_duplicate (a_peer);
124 return l;
127 void
128 Progress_Window::start_callback (Fl_Widget* /* widget */,
129 void *data)
131 Progress_Window *self = static_cast<Progress_Window*> (data);
132 self->start ();
135 void
136 Progress_Window::start ()
138 if (this->peers_.length () < CORBA::ULong (this->n_peers_))
139 return;
141 for (CORBA::ULong i = 0; i != this->peers_.length (); ++i)
145 this->peers_[i]->start (this->peers_,
146 this->n_iterations_);
148 catch (const CORBA::Exception& ex)
150 // Ignore exceptions