Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / MT_NoUpcall_Client_Leader / chatter.cpp
blob891214d0c96a32d90c41d736fc3c165a045da157
1 #include "SharedIntf_i.h"
2 #include "worker.h"
3 #include "chatter.h"
5 Chatter::Chatter (CORBA::ORB_ptr orb, const ACE_TCHAR *ior, ACE_Condition<ACE_Mutex>& cond)
6 : Worker (orb),
7 nrequests_ (0),
8 nreplies_ (0),
9 ior_ (ior),
10 cond_ (cond)
14 long
15 Chatter::nreplies ()
17 return this->nreplies_;
20 long
21 Chatter::nrequests ()
23 return this->nrequests_;
26 int
27 Chatter::svc ()
29 long nrq = -1;
30 try
32 //sleep(1);
34 // get server ior from file
35 CORBA::Object_var rawObject = orb_->string_to_object(ior_);
37 Test_Idl::SharedIntf_var intf_var =
38 Test_Idl::SharedIntf::_narrow(rawObject.in());
40 if (CORBA::is_nil (intf_var.in ()))
41 ACE_ERROR_RETURN ((LM_ERROR, "Nil reference <%s>\n", ior_), -1);
43 // make call on server
45 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, request_reply_count_mutex_, -1);
46 nrq= nrequests ();
47 nrequests_++;
49 ACE_DEBUG((LM_INFO,"(%P|%t) Chatter[%d] started for %s\n", nrq, ior_));
50 intf_var->ping();
52 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, guard, request_reply_count_mutex_, -1);
53 nreplies_++;
56 ACE_DEBUG((LM_INFO,"(%P|%t) Chatter[%d,%d,%d] completed for %s\n", nrq, nrequests_, nreplies_, ior_));
57 cond_.signal();
58 return 0;
60 catch (const CORBA::Exception& ex)
62 ex._tao_print_exception ("Exception caught:");
63 ACE_DEBUG((LM_INFO,"(%P|%t) Chatter[%d] %p for %s\n", nrq, "failed", ior_));
65 return -1;
68 int
69 Chatter::farewell ()
71 try
73 ACE_DEBUG((LM_INFO,"(%P|%t) Farewell requested for %s\n", ior_));
75 // get server ior from file
76 CORBA::Object_var rawObject = orb_->string_to_object( ior_);
78 Test_Idl::SharedIntf_var intf_var =
79 Test_Idl::SharedIntf::_narrow(rawObject.in());
81 if (CORBA::is_nil (intf_var.in ()))
82 ACE_ERROR_RETURN ((LM_ERROR, "Nil reference <%s>\n", ior_), -1);
84 // make call on server
85 ACE_DEBUG((LM_INFO,"(%P|%t) farewell START for %s\n", ior_));
86 intf_var->farewell();
88 ACE_DEBUG((LM_INFO,"(%P|%t) farewell COMPLETE for %s\n", ior_));
90 catch (const CORBA::Exception& ex)
92 ex._tao_print_exception ("Exception caught:");
93 ACE_DEBUG((LM_INFO,"(%P|%t) %p for %s\n", "farewell FAILED", ior_));
95 return 0;