summaryrefslogtreecommitdiff
path: root/modules/CIAO/connectors/AMI_CCM/examples/AMI/AMI_exec.cpp
blob: f84da8ceeb383a37b3cd15ac3d88be894813ae57 (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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
// -*- C++ -*-
//
// $Id$

// ****  Code generated by the The ACE ORB (TAO) IDL Compiler v1.7.1 ****
// TAO and the TAO IDL Compiler have been developed by:
//       Center for Distributed Object Computing
//       Washington University
//       St. Louis, MO
//       USA
//       http://www.cs.wustl.edu/~schmidt/doc-center.html
// and
//       Distributed Object Computing Laboratory
//       University of California at Irvine
//       Irvine, CA
//       USA
//       http://doc.ece.uci.edu/
// and
//       Institute for Software Integrated Systems
//       Vanderbilt Universityaaa
//       Nashville, TN
//       USA
//       http://www.isis.vanderbilt.edu/
//
// Information about TAO is available at:
//     http://www.cs.wustl.edu/~schmidt/TAO.html

// TAO_IDL - Generated from
// be/be_codegen.cpp:1278

#include "AMI_exec.h"
#include "ciao/CIAO_common.h"
#include "AMI_MyFoo_i.h"
#include "AMI_MyInterface_i.h"
#include "ace/OS_NS_unistd.h"

namespace CIAO_Hello_AMI_AMI_Impl
{
  //============================================================
  // Worker thread to call "perform_work"
  //============================================================
  AMI_perform_work::AMI_perform_work (CORBA::ORB_ptr orb)
  :  orb_ (CORBA::ORB::_duplicate (orb))
  {
  }

  int AMI_perform_work::svc ()
  {
    try
      {
        printf ("AMI :\tPerform work started\n");
        while (1)
          {
            if (orb_->work_pending())
                orb_->perform_work();
            ACE_Time_Value tv (0, 1000);
            ACE_OS::sleep (tv);
          }
      }
    catch (const CORBA::Exception& ex)
      {
        ex._tao_print_exception ("Caught exception:");
        return 1;
      }
    printf ("AMI :\t Exiting perform work");
    return 0;
  }
  

  //============================================================
  // Facet Executor Implementation Class: AMI_MyFoo_exec_i
  //============================================================
  AMI_MyFoo_exec_i::AMI_MyFoo_exec_i (
    ::CCM_AMI::AMI_MyFoo_callback_ptr foo_callback)
  : foo_callback_ (::CCM_AMI::AMI_MyFoo_callback::_duplicate (foo_callback))
  {
    //initialize AMI client
    int argc = 2;
    ACE_TCHAR **argv = new ACE_TCHAR *[argc];
    argv[0] = ACE::strnew (ACE_TEXT ("-ORBAMICollocation"));
    argv[1] = ACE::strnew (ACE_TEXT ("0"));
    CORBA::ORB_var orb =
      CORBA::ORB_init (argc, argv, ACE_TEXT ("AMI_foo_client"));

    CORBA::Object_var object =
      orb->string_to_object ("file://foo.ior");
    ami_foo_server_ = CCM_AMI::MyFoo::_narrow (object.in ());

    if (CORBA::is_nil (ami_foo_server_.in ()))
      {
        printf ("Server is NIL\n");
      }
    // Activate POA to handle the call back.
    CORBA::Object_var poa_object =
      orb->resolve_initial_references("RootPOA");

    if (CORBA::is_nil (poa_object.in ()))
      printf ("POA is NIL!\n");

    PortableServer::POA_var root_poa =
      PortableServer::POA::_narrow (poa_object.in ());

    PortableServer::POAManager_var poa_manager =
      root_poa->the_POAManager ();

    poa_manager->activate ();
    AMI_perform_work *pw = new AMI_perform_work (orb.in ());
    pw->activate ();
  }

  AMI_MyFoo_exec_i::~AMI_MyFoo_exec_i (void)
  {
  }

  // Operations from ::CCM_AMI::AMI_ami_foo

  void
  AMI_MyFoo_exec_i::sendc_foo (
    const char * in_str)
  {
    printf ("AMI (FOO) :\tsendc_foo <%s>\n", in_str);

    ::CCM_CORBA_AMI_MyFoo_Impl::AMI_MyFoo_reply_handler*  handler =
        new ::CCM_CORBA_AMI_MyFoo_Impl::AMI_MyFoo_reply_handler (foo_callback_);
    CCM_AMI::AMI_MyFooHandler_var the_handler_var = handler->_this ();
    printf ("AMI (FOO) :\tSending string <%s> to AMI CORBA server\n", in_str);
    ami_foo_server_->sendc_foo (the_handler_var.in (), in_str);
    printf ("AMI (FOO) : \tInvoked sendc_foo\n");
  }
  
  void
  AMI_MyFoo_exec_i::sendc_hello ()
  {
    printf ("AMI (FOO) :\tsendc_hello\n");

    ::CCM_CORBA_AMI_MyFoo_Impl::AMI_MyFoo_reply_handler*  handler =
        new ::CCM_CORBA_AMI_MyFoo_Impl::AMI_MyFoo_reply_handler (foo_callback_);
    CCM_AMI::AMI_MyFooHandler_var the_handler_var = handler->_this ();
    printf ("AMI (FOO) :\tCalling AMI CORBA server\n");
    ami_foo_server_->sendc_hello (the_handler_var.in ());
    printf ("AMI (FOO) : \tInvoked sendc_foo\n");
  }
  
  //============================================================
  // Facet Executor Implementation Class: AMI_MyFoo_exec_i
  //============================================================

  AMI_MyInterface_exec_i::AMI_MyInterface_exec_i (
  ::CCM_AMI::AMI_MyInterface_callback_ptr interface_callback)
  : interface_callback_ (::CCM_AMI::AMI_MyInterface_callback::_duplicate (interface_callback))
  {
    //initialize AMI client
    int argc = 2;
    ACE_TCHAR **argv = new ACE_TCHAR *[argc];
    argv[0] = ACE::strnew (ACE_TEXT ("-ORBAMICollocation"));
    argv[1] = ACE::strnew (ACE_TEXT ("0"));
    CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv, ACE_TEXT ("AMI_Interface_client"));

    CORBA::Object_var object =
        orb->string_to_object ("file://interface.ior");
    ami_interface_server_ = CCM_AMI::MyInterface::_narrow (object.in ());

    if (CORBA::is_nil (ami_interface_server_.in ()))
    {
      printf ("Server is NIL\n");
    }
    // Activate POA to handle the call back.
    CORBA::Object_var poa_object =
        orb->resolve_initial_references("RootPOA");

    if (CORBA::is_nil (poa_object.in ()))
      printf ("POA is NIL!\n");

    PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in ());

    PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();

    poa_manager->activate ();
    AMI_perform_work *pw = new AMI_perform_work (orb.in ());
    pw->activate ();
  }

  AMI_MyInterface_exec_i::~AMI_MyInterface_exec_i (void)
  {
  }

  // Operations from ::CCM_AMI::AMI_ami_foo

  void
  AMI_MyInterface_exec_i::sendc_do_something_with_something (
      ::CCM_AMI::AMI_MyInterface_callback_ptr cb_handler,
      CORBA::Short something)
  {
    printf ("AMI (INTERFACE) :\tsendc_do_something_with_something <%d>\n", something);
    if (CORBA::is_nil (cb_handler))
      { //treat it as an oneway CORBA invocation
        printf ("AMI (INTERFACE) :\tONE WAY INVOCATION. Sending short <%d> to AMI CORBA server\n", something);
        ami_interface_server_->sendc_do_something_with_something (0, something);
        printf ("AMI (INTERFACE) : \tInvoked sendc_do_something_with_something\n");
      }
    else
      {
        ::CCM_CORBA_AMI_MyInterface_Impl::AMI_MyInterface_reply_handler*  handler =
            new ::CCM_CORBA_AMI_MyInterface_Impl::AMI_MyInterface_reply_handler (cb_handler);
        CCM_AMI::AMI_MyInterfaceHandler_var the_handler_var = handler->_this ();
        printf ("AMI (INTERFACE) :\tSending short <%d> to AMI CORBA server\n", something);
        ami_interface_server_->sendc_do_something_with_something (the_handler_var.in (), something);
        printf ("AMI (INTERFACE) : \tInvoked sendc_do_something_with_something\n");
      }
  }

  //============================================================
  // Component Executor Implementation Class: AMI_exec_i
  //============================================================
  
  AMI_exec_i::AMI_exec_i (void)
  {
  }
  
  AMI_exec_i::~AMI_exec_i (void)
  {
  }
  
  // Supported operations and attributes.
  
  // Component attributes.
  
  // Port operations.
  
  ::CCM_AMI::CCM_AMI_MyFoo_ptr
  AMI_exec_i::get_perform_asynch_my_foo (void)
  {
    ::CCM_AMI::AMI_MyFoo_callback_var foo_callback =
      this->context_->get_connection_callback_my_foo ();
    return new AMI_MyFoo_exec_i (foo_callback.in ());
  }

  ::CCM_AMI::CCM_AMI_MyInterface_ptr
  AMI_exec_i::get_perform_asynch_my_interface ()
  {
    ::CCM_AMI::AMI_MyInterface_callback_var interface_callback =
        this->context_->get_connection_callback_my_interface ();
    return new AMI_MyInterface_exec_i (interface_callback.in ());
  }

  // Operations from Components::SessionComponent.
  
  void
  AMI_exec_i::set_session_context (
    ::Components::SessionContext_ptr ctx)
  {
    this->context_ =
      ::Hello_AMI::CCM_AMI_Context::_narrow (ctx);
    
    if ( ::CORBA::is_nil (this->context_.in ()))
      {
        throw ::CORBA::INTERNAL ();
      }
  }
  
  void
  AMI_exec_i::configuration_complete (void)
  {
    /* Your code here. */
  }
  
  void
  AMI_exec_i::ccm_activate (void)
  {
    ::CCM_AMI::MyFoo_var receiver_foo =
        this->context_->get_connection_my_foo_receiver ();
    ::CCM_CORBA_AMI_MyFoo_Impl::CORBA_MyFoo_server* foo_srv =
        new ::CCM_CORBA_AMI_MyFoo_Impl::CORBA_MyFoo_server (receiver_foo.in ());
    printf ("AMI :\tStarting MyFoo CORBA server thread.\n");
    foo_srv->activate ();

    ::CCM_AMI::MyInterface_var receiver_interface =
        this->context_->get_connection_my_interface_receiver ();
    ::CCM_CORBA_AMI_MyInterface_Impl::CORBA_MyInterface_server* interface_srv =
        new ::CCM_CORBA_AMI_MyInterface_Impl::CORBA_MyInterface_server (receiver_interface.in ());
    printf ("AMI :\tStarting MyInterface CORBA server thread.\n");
    interface_srv->activate ();
  }
  
  void
  AMI_exec_i::ccm_passivate (void)
  {
    /* Your code here. */
  }
  
  void
  AMI_exec_i::ccm_remove (void)
  {
    /* Your code here. */
  }
  
  extern "C"  ::Components::EnterpriseComponent_ptr
  create_Hello_AMI_AMI_Impl (void)
  {
    ::Components::EnterpriseComponent_ptr retval =
      ::Components::EnterpriseComponent::_nil ();
    
    ACE_NEW_RETURN (
      retval,
      AMI_exec_i,
      ::Components::EnterpriseComponent::_nil ());
    
    return retval;
  }
}

namespace CIAO_Hello_AMI_AMI_Impl
{
  //============================================================
  // Home Executor Implementation Class: AMIHome_exec_i
  //============================================================
  
  AMIHome_exec_i::AMIHome_exec_i (void)
  {
  }
  
  AMIHome_exec_i::~AMIHome_exec_i (void)
  {
  }
  
  // All operations and attributes.
  
  // Factory operations.
  
  // Finder operations.
  
  // Implicit operations.
  
  ::Components::EnterpriseComponent_ptr
  AMIHome_exec_i::create (void)
  {
    ::Components::EnterpriseComponent_ptr retval =
      ::Components::EnterpriseComponent::_nil ();
    
    ACE_NEW_THROW_EX (
      retval,
      AMI_exec_i,
      ::CORBA::NO_MEMORY ());
    
    return retval;
  }
  
  extern "C"  ::Components::HomeExecutorBase_ptr
  create_Hello_AMI_AMIHome_Impl (void)
  {
    ::Components::HomeExecutorBase_ptr retval =
      ::Components::HomeExecutorBase::_nil ();
    
    ACE_NEW_RETURN (
      retval,
      AMIHome_exec_i,
      ::Components::HomeExecutorBase::_nil ());
    
    return retval;
  }
}