summaryrefslogtreecommitdiff
path: root/modules/CIAO/connectors/ami4ccm/tests/InterOutArgs/Sender/InterOutArgsT_Sender_exec.cpp
blob: 642bcb9502587538fe8829c39034399ed049cdd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
// -*- C++ -*-
// $Id$

// test of different datatypes as in-argumenten
#include "InterOutArgsT_Sender_exec.h"
#include "ace/OS_NS_unistd.h"

namespace CIAO_InterOutArgsT_Sender_Impl
{
  CORBA::Short nr_of_received = 0;
 
  //============================================================
  // Facet Executor Implementation Class: MyFoo_callback_exec_i
  //============================================================
  MyFoo_callback_exec_i::MyFoo_callback_exec_i (void)
  {
  }

  MyFoo_callback_exec_i::~MyFoo_callback_exec_i (void)
  {
  }

  //============================================================
  // Operations from ::CCM_AMI::MyFoo_callback
  //============================================================
  // FOO methods
  void
  MyFoo_callback_exec_i::var_outs (
  const char * answer, CORBA::Double d_cmd, CORBA::Long l_cmd )
  {
    if (d_cmd != 3.14)
      {
        ACE_ERROR ((LM_ERROR, "ERROR MyFoo_callback_exec_i::var_outs: "
                              "received the wrong double, expected 3.14,"
                              " received %2.2f\n",
                              d_cmd));
      }
    else if (l_cmd != 100)
      {
        ACE_ERROR ((LM_ERROR, "ERROR MyFoo_callback_exec_i::var_outs: "
                              "received the wrong double, expected 3.14,"
                              " received %lu\n",
                              l_cmd));
      }
    else
      {
        ++nr_of_received;
      }
  };

  void
  MyFoo_callback_exec_i::var_outs_excep (
                    ::CCM_AMI::ExceptionHolder_ptr excep_holder)
  {
    excep_holder->raise_exception ();
  };

  void
  MyFoo_callback_exec_i::var_div_outs (
                    const InterOutArgsT::TestTopic &test_topic,
                    const InterOutArgsT::TopicString &topic_str,
                    const InterOutArgsT::TopicArray &topic_arr)
  {
    CORBA::Boolean error = false;
    if ((ACE_OS::strcmp (test_topic.key, "aaa") != 0) || (test_topic.x != 10))
      {
        ACE_ERROR ((LM_ERROR, "ERROR MyFoo_exec_i::var_div_outs: "
                              "received the wrong struct, "
                              "expected key 'aaa', x = 10,"
                              " received key '%C' , x = %u\n",
                              test_topic.key,test_topic.x));
        error = true;
      }
    if (( ACE_OS::strcmp (topic_str.key,"bbb") != 0) ||
        (ACE_OS::strcmp (topic_str.x_str, "ccc") != 0))
      {
        ACE_ERROR ((LM_ERROR, "ERROR MyFoo_exec_i::var_div_outs: "
                              "received the wrong struct, "
                              "expected key 'bbb', x = 'ccc',"
                              " received key '%C' , x = %C\n",
                              topic_str.key ,topic_str.x_str));
        error = true;
      }
    if (( ACE_OS::strcmp (topic_arr.key,"ddd") != 0) ||
        (topic_arr.x_array[1] != 100))
      {
        ACE_ERROR ((LM_ERROR, "ERROR MyFoo_exec_i::var_div_outs: "
                              "received the wrong struct, "
                              "expected key 'ddd', second elem 100 ,"
                              " received key '%C', second elem %u\n",
                              topic_arr.key, topic_arr.x_array[1]));
        error = true;
      }
    if (error == false)
      {
        ++nr_of_received;
      }
   };

  void
  MyFoo_callback_exec_i::var_div_outs_excep (
                   ::CCM_AMI::ExceptionHolder_ptr excep_holder)
  {
    excep_holder->raise_exception ();
  };
  
  void
  MyFoo_callback_exec_i::var_div2_outs (
                     const InterOutArgsT::X_Union &x_uni,
                     const InterOutArgsT::test_seq &seq)
  {
    CORBA::Boolean error = false;

    if (x_uni.x_long() != 11)
      {
        ACE_ERROR ((LM_ERROR, "ERROR MyFoo_exec_i::var_div2_outs: "
                              "received the wrong union, "
                              "expected x_long = 11,"
                              " received x_long = %u\n",
                               x_uni.x_long()));
        error = true;
      }
    if (( ACE_OS::strcmp (seq[0].x_teststr, "fff") != 0) ||
        (seq[0].x_test != 12))
      {
        ACE_ERROR ((LM_ERROR, "ERROR MyFoo_exec_i::var_div2_outs: "
                              "received the wrong sequence, "
                              "expected key 'fff', x = 12,"
                              " received key '%C' , x = %u\n",
                              seq[0].x_teststr,seq[0].x_test));
        error = true;
      }
    if (error == false)
      {
        ++nr_of_received;
      }
   };

  void
  MyFoo_callback_exec_i::var_div2_outs_excep (
                     ::CCM_AMI::ExceptionHolder_ptr excep_holder)
  {
    excep_holder->raise_exception ();
  };

  //============================================================
  // Worker thread for asynchronous invocations for MyFoo
  //============================================================
  asynch_foo_generator::asynch_foo_generator (
    ::InterOutArgsT::AMI_MyFoo_ptr my_foo_ami)
  : my_foo_ami_ (::InterOutArgsT::AMI_MyFoo::_duplicate (my_foo_ami))
  {
  }

  int asynch_foo_generator::svc ()
  {
    ACE_OS::sleep (3);
    if (CORBA::is_nil (my_foo_ami_))
      {
        ACE_ERROR ((LM_ERROR, "ERROR Sender (ASYNCH) :\tfoo_ami is NIL !\n"));  
       return 1;
      }
    else
      {
        //Invoke Asynchronous calls to test 
        my_foo_ami_->sendc_var_outs ( new MyFoo_callback_exec_i (),
                                      "Send me a double and a long.");
        my_foo_ami_->sendc_var_div_outs (new MyFoo_callback_exec_i ());
        my_foo_ami_->sendc_var_div2_outs (new MyFoo_callback_exec_i ());
      }
    return 0;
  }

  //============================================================
  // Worker thread for synchronous invocations for MyFoo
  //============================================================
  synch_foo_generator::synch_foo_generator (
    ::InterOutArgsT::MyFoo_ptr my_foo_ami)
  : my_foo_ami_ (::InterOutArgsT::MyFoo::_duplicate (my_foo_ami))
  {
  }

  int synch_foo_generator::svc ()
  {
    ACE_OS::sleep (3);
    //run some synch calls
    InterOutArgsT::TestTopic_var test_topic = 0;
    InterOutArgsT::TopicString_var topic_str = 0;
    InterOutArgsT::TopicArray_var topic_arr = 0;
    CORBA::Double d_cmd = 0;
    CORBA::Long l_cmd = 0;
    char * out_str = 0;
    try
      {
        my_foo_ami_->var_outs ("Do something synchronous",
                                                out_str,
                                                d_cmd ,
                                                l_cmd);
        if ( (d_cmd == 3.14 ) && (l_cmd == 100))
          {
            ++nr_of_received;
          }
      } 
    catch (const InterOutArgsT::InternalError&)
      {
        ACE_ERROR ((LM_ERROR, "ERROR: synch_foo_generator::var_outs: "
                              "Unexpected exception.\n"));  
      }
    try
      {
        my_foo_ami_->var_div_outs(test_topic,topic_str,topic_arr);
        if ((ACE_OS::strcmp (test_topic->key, "aaa") == 0) &&
            (test_topic->x == 10))
          {
            ++nr_of_received;
          }
        else
         {
           ACE_ERROR ((LM_ERROR, "ERROR: synch_foo_generator::var_div_outs: "
                                "Unexpected data returned.\n"));  
         }
      }
    catch (const InterOutArgsT::InternalError&)
      {
        ACE_ERROR ((LM_ERROR, "ERROR: synch_foo_generator::var_div_outs: "
                              "Unexpected exception.\n"));  
      }
    return 0;
  }

  //============================================================
  // Component Executor Implementation Class: Sender_exec_i
  //============================================================
  Sender_exec_i::Sender_exec_i (void)
  : global_foo_callback_ (0)
  {
  }

  Sender_exec_i::~Sender_exec_i (void)
  {
  }

  // Supported operations and attributes.
  // Component attributes.
  // Operations from Components::SessionComponent.

  void
  Sender_exec_i::set_session_context (
    ::Components::SessionContext_ptr ctx)
  {
    this->context_ =
      ::InterOutArgsT::CCM_Sender_Context::_narrow (ctx);
    if ( ::CORBA::is_nil (this->context_.in ()))
      {
        throw ::CORBA::INTERNAL ();
      }
  }

  void
  Sender_exec_i::configuration_complete (void)
  {
  }

  void
  Sender_exec_i::ccm_activate (void)
  {
    ::InterOutArgsT::AMI_MyFoo_var asynch_foo =
      this->context_->get_connection_sendc_run_my_foo();
    asynch_foo_generator* asynch_foo_gen =
        new asynch_foo_generator (asynch_foo);
    asynch_foo_gen->activate (THR_NEW_LWP | THR_JOINABLE, 1);

    ::InterOutArgsT::MyFoo_var synch_foo =
        this->context_->get_connection_run_my_foo ();
    synch_foo_generator* synch_foo_gen =
      new synch_foo_generator (synch_foo);
    synch_foo_gen->activate (THR_NEW_LWP | THR_JOINABLE, 1);
  }

  void
  Sender_exec_i::ccm_passivate (void)
  {
  }

  void
  Sender_exec_i::ccm_remove (void)
  {
    if (nr_of_received == 5)
      {
        ACE_DEBUG ((LM_DEBUG, "OK: Received all expected data"
                              " for syn- and asynchronous calls\n"));  
      }
    else
      {
        ACE_ERROR ((LM_ERROR, "ERROR: Received not all expected data"
                              " for syn- and asynchronous calls\n"));  
      }
  }

  extern "C"  ::Components::EnterpriseComponent_ptr
  create_InterOutArgsT_AMI_Sender_Impl (void)
  {
    ::Components::EnterpriseComponent_ptr retval =
      ::Components::EnterpriseComponent::_nil ();

    ACE_NEW_RETURN (
      retval,
      Sender_exec_i,
      ::Components::EnterpriseComponent::_nil ());

    return retval;
  }
}