Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Nested_Event_Loop / test_i.cpp
blob26856a86a8348511e733531ee59e0f5abde4eb76
1 #include "test_i.h"
2 #include "ace/OS_NS_string.h"
4 server_i::server_i (CORBA::ORB_ptr orb)
5 : orb_ (CORBA::ORB::_duplicate (orb))
9 void
10 server_i::loop (client_ptr remote_partner,
11 CORBA::ULong event_loop_depth,
12 CORBA::ULong event_loop_iterations)
14 ACE_DEBUG ((LM_DEBUG,
15 "server_i::loop: event_loop_depth = %2.2d; event_loop_iterations = %2.2d\n",
16 event_loop_depth,
17 event_loop_iterations));
19 this->run_no_ops (remote_partner,
20 event_loop_iterations / 2);
22 if (--event_loop_depth != 0)
24 remote_partner->loop (event_loop_depth,
25 event_loop_iterations);
28 this->run_no_ops (remote_partner,
29 event_loop_iterations / 2);
32 void
33 server_i::run_no_ops (client_ptr remote_partner,
34 CORBA::ULong iterations)
36 while (iterations != 0)
38 CORBA::ULong *pointer_to_iterations = &iterations;
39 size_t sizeof_pointer_to_iterations = sizeof (pointer_to_iterations);
41 act act_for_iterations (sizeof_pointer_to_iterations);
42 act_for_iterations.length (sizeof_pointer_to_iterations);
44 ACE_OS::memcpy (act_for_iterations.get_buffer (),
45 &pointer_to_iterations,
46 sizeof_pointer_to_iterations);
48 CORBA::ULong got_reply = 0;
50 CORBA::ULong *pointer_to_flag = &got_reply;
51 size_t sizeof_pointer_to_flag = sizeof (pointer_to_flag);
53 act act_for_flag (sizeof_pointer_to_flag);
54 act_for_flag.length (sizeof_pointer_to_flag);
56 ACE_OS::memcpy (act_for_flag.get_buffer (),
57 &pointer_to_flag,
58 sizeof_pointer_to_flag);
60 remote_partner->oneway_no_op (act_for_iterations,
61 act_for_flag);
63 while (!got_reply)
65 this->orb_->perform_work ();
70 void
71 server_i::no_op (client_ptr remote_partner,
72 const act &act_for_iterations,
73 const act &act_for_flag)
75 CORBA::ULong *pointer_to_iterations = 0;
77 ACE_OS::memcpy (&pointer_to_iterations,
78 act_for_iterations.get_buffer (),
79 act_for_iterations.length ());
81 CORBA::ULong *pointer_to_flag = 0;
83 ACE_OS::memcpy (&pointer_to_flag,
84 act_for_flag.get_buffer (),
85 act_for_flag.length ());
87 ACE_DEBUG ((LM_DEBUG,
88 "server_i::no_op: iterations = %d\n",
89 *pointer_to_iterations));
91 --(*pointer_to_iterations);
93 *pointer_to_flag = 1;
95 remote_partner->twoway_no_op ();
98 void
99 server_i::shutdown (void)
101 this->orb_->shutdown (0);
104 client_i::client_i (server_ptr remote_partner)
105 : remote_partner_ (server::_duplicate (remote_partner))
107 #if defined (CORBA_E_COMPACT) || defined (CORBA_E_MICRO)
108 PortableServer::POA_var poa = this->_default_POA ();
109 PortableServer::ObjectId_var id = poa->activate_object (this);
110 CORBA::Object_var object = poa->id_to_reference (id.in ());
111 self_ = client::_unchecked_narrow (object.in ());
112 #else
113 self_ = this->_this ();
114 #endif /* CORBA_E_COMPACT || CORBA_E_MICRO */
117 void
118 client_i::loop (CORBA::ULong event_loop_depth,
119 CORBA::ULong event_loop_iterations)
121 ACE_DEBUG ((LM_DEBUG,
122 "client_i::loop: event_loop_depth = %2.2d; event_loop_iterations = %2.2d\n",
123 event_loop_depth,
124 event_loop_iterations));
129 this->remote_partner_->loop (self_.in (),
130 event_loop_depth,
131 event_loop_iterations);
133 catch (const CORBA::Exception& ex)
135 ex._tao_print_exception ("Exception caught in client_i::loop:");
139 void
140 client_i::oneway_no_op (const act &act_for_iterations,
141 const act &act_for_flag)
146 this->remote_partner_->no_op (self_.in (),
147 act_for_iterations,
148 act_for_flag);
150 catch (const CORBA::Exception& ex)
152 ex._tao_print_exception ("Exception caught in client_i::oneway_no_op:");
156 void
157 client_i::twoway_no_op (void)
159 ACE_DEBUG ((LM_DEBUG,
160 "client_i::twoway_no_op\n"));