Merge pull request #2306 from mitza-oci/warnings
[ACE_TAO.git] / TAO / examples / AMI / FL_Callback / Peer_i.cpp
bloba64e45258b37939b00fe03540d058efc636653ec
1 #include "Peer_i.h"
2 #include "ace/OS_NS_unistd.h"
4 Peer_Handler_i::Peer_Handler_i (Peer_i *peer)
5 : peer_ (peer)
9 void
10 Peer_Handler_i::request (CORBA::Long retval)
12 static int i = 0;
13 i++;
14 if (i % 100 == 0)
15 ACE_DEBUG ((LM_DEBUG, "(%P|%t) %d replies received\n", i));
16 this->peer_->reply (retval);
20 void
21 Peer_Handler_i::request_excep (
22 ::Messaging::ExceptionHolder *)
26 void
27 Peer_Handler_i::start ()
31 void
32 Peer_Handler_i::shutdown ()
37 Peer_i::Peer_i ()
38 : reply_handler_ (this)
42 Peer_i::~Peer_i ()
46 void
47 Peer_i::init (CORBA::ORB_ptr orb,
48 Progress_ptr progress,
49 const ACE_Time_Value &delay)
51 this->orb_ = CORBA::ORB::_duplicate (orb);
52 this->progress_ = Progress::_duplicate (progress);
53 this->delay_ = delay;
55 Peer_var peer = this->_this ();
57 ACE_DEBUG ((LM_DEBUG, "Peer (%P|%t) - binding\n"));
58 this->id_ = this->progress_->bind (peer.in ());
61 void
62 Peer_i::reply (CORBA::Long result)
64 this->progress_->recv_reply (result);
67 CORBA::Long
68 Peer_i::request (CORBA::Long id)
70 ACE_Time_Value tv = this->delay_;
71 ACE_OS::sleep (tv);
73 return id;
76 void
77 Peer_i::start (const PeerSet &the_peers,
78 CORBA::Long iterations)
80 AMI_PeerHandler_var handler =
81 this->reply_handler_._this ();
83 // @@ Report errors as exceptions...
84 Peer_Task *task;
85 ACE_NEW (task, Peer_Task (the_peers,
86 iterations,
87 this->progress_.in (),
88 handler.in (),
89 this->id_));
90 task->activate ();
93 void
94 Peer_i::shutdown ()
96 this->orb_->shutdown (false);
99 // ****************************************************************
101 Peer_Task::Peer_Task (const PeerSet& the_peers,
102 CORBA::Long iterations,
103 Progress_ptr progress,
104 AMI_PeerHandler_ptr handler,
105 CORBA::Long id)
106 : the_peers_ (the_peers),
107 iterations_ (iterations),
108 progress_ (Progress::_duplicate (progress)),
109 handler_ (AMI_PeerHandler::_duplicate (handler)),
110 id_ (id)
115 Peer_Task::svc ()
117 for (int i = 0; i != this->iterations_; ++i)
119 CORBA::ULong l = this->the_peers_.length ();
120 for (CORBA::ULong j = 0; j != l; ++j)
124 this->the_peers_[j]->sendc_request (this->handler_.in (),
125 this->id_);
127 this->progress_->sent_request (this->id_);
129 catch (const CORBA::Exception&)
131 // Ignore exceptions;
134 if (i % 100 == 0)
135 ACE_DEBUG ((LM_DEBUG, "(%P|%t) %d requests sent\n", i));
137 return 0;