summaryrefslogtreecommitdiff
path: root/modules/CIAO/connectors/dds4ccm/examples/Quoter/Connector/Quoter_Connector_exec.cpp
blob: 5eab90d13c79ee1aeeacd3e8c33165d0aff32743 (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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
// -*- C++ -*-
//
// $Id$

/**
 * Code generated by the The ACE ORB (TAO) IDL Compiler v1.7.2
 * 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 University
 *       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 "Quoter_Connector_exec.h"
#include "ciao/CIAO_common.h"

#include "dds4ccm/impl/ndds/NDDS_Traits.h"
#include "dds4ccm/impl/ndds/DomainParticipantFactory.h"
#include "dds4ccm/impl/ndds/DomainParticipant.h"

// should be removed after lem fix
#include "../Broker/BrokerEC.h"

// should be removed after we refactor stuff back into ndds impl.
#include "dds4ccm/impl/ndds/DataReader.h"
#include "dds4ccm/impl/ndds/ListenerControl.h"

namespace CIAO_Quoter_Quoter_Connector_Impl
{
  //============================================================
  // Facet Executor Implementation Class: Stock_Info_Reader_exec_i
  //============================================================

  Stock_Info_Reader_exec_i::Stock_Info_Reader_exec_i (void)
  {
  }

  Stock_Info_Reader_exec_i::~Stock_Info_Reader_exec_i (void)
  {
  }

  // Operations from ::CCM_DDS::Stock_Info_Reader

  void
  Stock_Info_Reader_exec_i::read_all (
    ::CCM_DDS::Stock_Info_Reader::Stock_InfoSeq_out /* instances */,
    ::CCM_DDS::ReadInfoSeq_out /* infos */)
  {
    /* Your code here. */
  }

  void
  Stock_Info_Reader_exec_i::read_all_history (
    ::CCM_DDS::Stock_Info_Reader::Stock_InfoSeq_out /* instances */,
    ::CCM_DDS::ReadInfoSeq_out /* infos */)
  {
    /* Your code here. */
  }

  void
  Stock_Info_Reader_exec_i::read_one (
    ::Quoter::Stock_Info & /* an_instance */,
    ::CCM_DDS::ReadInfo_out /* info */)
  {
    /* Your code here. */
  }

  void
  Stock_Info_Reader_exec_i::read_one_history (
    const ::Quoter::Stock_Info & /* an_instance */,
    ::CCM_DDS::Stock_Info_Reader::Stock_InfoSeq_out /* instances */,
    ::CCM_DDS::ReadInfoSeq_out /* infos */)
  {
    /* Your code here. */
  }

  ::CCM_DDS::QueryFilter *
  Stock_Info_Reader_exec_i::filter (void)
  {
    /* Your code here. */
    return 0;
  }

  void
  Stock_Info_Reader_exec_i::filter (
    const ::CCM_DDS::QueryFilter & /* filter */)
  {
    /* Your code here. */
  }

  //============================================================
  // Component Executor Implementation Class: Quoter_Connector_exec_i
  //============================================================

  Quoter_Connector_exec_i::Quoter_Connector_exec_i (void)
    : default_domain_configured_ (false),
      domain_id_ (0),
      default_topic_configured_ (false),
      topic_name_ ("Quoter_Topic"),
      __info_in_configured_ (false),
      __info_out_configured_ (false),
      __info_out_rawlistener_enabled_ (false)

  {
  }

  Quoter_Connector_exec_i::~Quoter_Connector_exec_i (void)
  {
  }

  // Supported operations and attributes.

  // Component attributes.

  char *
  Quoter_Connector_exec_i::topic_name (void)
  {
    // @from DDS_TopicBase
    return CORBA::string_dup (this->topic_name_.in ());
  }

  void
  Quoter_Connector_exec_i::topic_name (
    const char * topic_name)
  {
    // @from DDS_TopicBase
    this->topic_name_ = topic_name;
  }

  ::DDS::StringSeq *
  Quoter_Connector_exec_i::key_fields (void)
  {
    // @from DDS_TopicBase
    ::DDS::StringSeq *retval =
      new ::DDS::StringSeq (this->key_fields_.length ());

    for (CORBA::ULong i = 0; i < this->key_fields_.length (); ++i)
      (*retval)[i] = CORBA::string_dup (this->key_fields_[i]);

    return retval;
  }

  void
  Quoter_Connector_exec_i::key_fields (
    const ::DDS::StringSeq & key_fields)
  {
    // @from DDS_TopicBase
    this->key_fields_.length (key_fields.length ());

    for (CORBA::ULong i = 0; i < this->key_fields_.length (); ++i)
      this->key_fields_[i] = CORBA::string_dup (key_fields[i]);
  }

  ::DDS::DomainId_t
  Quoter_Connector_exec_i::domain_id (void)
  {
    // @from DDS_Base
    return this->domain_id_;
  }

  void
  Quoter_Connector_exec_i::domain_id (
    ::DDS::DomainId_t domain_id)
  {
    // @from DDS_Base
    this->domain_id_ = domain_id;
  }

  char *
  Quoter_Connector_exec_i::qos_profile (void)
  {
    // @from DDS_Base
    return CORBA::string_dup (this->qos_profile_.in ());
  }

  void
  Quoter_Connector_exec_i::qos_profile (
    const char * qos_profile)
  {
    // @from DDS_Base
    this->qos_profile_ = qos_profile;
  }

  // Port operations.

  void
  Quoter_Connector_exec_i::configure_default_domain_ (void)
  {
    CIAO_DEBUG ((LM_TRACE, CLINFO "Quoter_Connector_exec_i::configure_default_domain_ - "
                 "Configuring default domain\n"));

    if (this->default_domain_configured_) return;

    try
      {
        NDDSConfigLogger::get_instance()->set_verbosity_by_category(NDDS_CONFIG_LOG_CATEGORY_API,
                                                                   NDDS_CONFIG_LOG_VERBOSITY_STATUS_ALL );

        // Generic code
        this->domain_factory_ = new ::CIAO::DDS4CCM::RTI::RTI_DomainParticipantFactory_i ();

        ::DDS::DomainParticipantQos qos;
        this->domain_ =
          this->domain_factory_->create_participant (this->domain_id_,
                                                     qos,
                                                     0,
                                                     0);
      }
    catch (...)
      {
        CIAO_ERROR ((LM_ERROR, "Caught unknown C++ exception whilst configuring default domain\n"));
        throw CORBA::INTERNAL ();
      }
  }

  void
  Quoter_Connector_exec_i::configure_default_topic_ (void)
  {
    CIAO_DEBUG ((LM_TRACE, CLINFO "Quoter_Connector_exec_i::configure_default_topic_ - "
                 "Configuring default topic\n"));
    if (this->default_topic_configured_) return;

    this->configure_default_domain_ ();

    try
      {
        if (CORBA::is_nil (this->topic_))
          {
            CIAO::DDS4CCM::RTI::RTI_DomainParticipant_i *part = dynamic_cast< CIAO::DDS4CCM::RTI::RTI_DomainParticipant_i * > (this->domain_.in ());
            DDS_ReturnCode_t retcode = Stock_Info_Traits::type_support::register_type(
              part->get_participant (), Stock_Info_Traits::type_support::get_type_name ());
            if (retcode == DDS_RETCODE_OK)
              {
                ::DDS::TopicQos tqos;
                this->topic_ =
                  this->domain_->create_topic (this->topic_name_.in (),
                                               Stock_Info_Traits::type_support::get_type_name (),
                                               tqos,
                                               0,
                                               0);
              }
            else
              {
                throw CORBA::INTERNAL ();
              }
          }
      }
    catch (...)
      {
        CIAO_ERROR ((LM_ERROR, "Caught unknown error while configuring default topic\n"));
        throw CORBA::INTERNAL ();
      }
  }

  void
  Quoter_Connector_exec_i::configure_port_info_in_ (void)
  {
    if (this->__info_in_configured_)
      return;

    this->configure_default_topic_ ();

    try
      {
        if (CORBA::is_nil (this->__info_in_publisher_.in ()))
          {
            ::DDS::PublisherQos pqos;
            this->__info_in_publisher_ = this->domain_->create_publisher (pqos,
                                                                          0,
                                                                          0);
          }

        if (CORBA::is_nil  (this->__info_in_datawriter_.in ()))
          {
            ::DDS::DataWriterQos dwqos;
            ::DDS::DataWriter_var dwv_tmp = this->__info_in_publisher_->create_datawriter (this->topic_.in (),
                                                                                           dwqos,
                                                                                           0,
                                                                                           0);
            this->__info_in_datawriter_ = ::DDS::CCM_DataWriter::_narrow (dwv_tmp);
          }
      }
    catch (...)
      {
        CIAO_ERROR ((LM_ERROR, "Caught unknown C++ exception while configuring port info_in_\n"));
        throw CORBA::INTERNAL ();
      }
  }


  class info_out_Listener :
    public virtual ::DDS::DataReaderListener
  {
  public:
    info_out_Listener (::CCM_DDS::Stock_Info_RawListener_ptr listen,
		       ::CCM_DDS::PortStatusListener_ptr psl,
		       ACE_Atomic_Op <TAO_SYNCH_MUTEX, bool> &enabled)
      : listener_ (::CCM_DDS::Stock_Info_RawListener::_duplicate (listen)),
        portlistener_ (::CCM_DDS::PortStatusListener::_duplicate (psl)),
	enable_ (enabled)
    {
    };

    // from DataReaderListener
    virtual void on_data_available( ::DDS::DataReader *rdr)
    {
      printf ("*** on data available\n");
      if (!this->enable_.value ())
        return;

      ::CIAO::DDS4CCM::RTI::RTI_DataReader_i* rd = dynamic_cast < ::CIAO::DDS4CCM::RTI::RTI_DataReader_i*>(rdr);
      ::Quoter::Stock_InfoDataReader * reader = dynamic_cast< ::Quoter::Stock_InfoDataReader * > ((rd->get_datareader ()));

      if (!reader) {
        /* In this specific case, this will never fail */
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("Stock_InfoDataReader::narrow failed.\n")));
        return;
      }

      /* Loop until there are messages available in the queue */
      for(;;) {
        ::Quoter::Stock_Info instance;
        ::DDS_SampleInfo sampleinfo;
        ::DDS::ReturnCode_t result  = reader->take_next_sample(instance,
                                                               sampleinfo);
        if (result == DDS_RETCODE_NO_DATA) {
	  printf ("no more samples\n");
            /* No more samples */
            break;
        } else if (result != DDS_RETCODE_OK) {
            ACE_ERROR ((LM_ERROR, ACE_TEXT ("Unable to take data from data reader, error %d.\n"), result));
            return;
        }
        if (sampleinfo.valid_data) {
	  printf ("got valid data\n");
            ::CCM_DDS::ReadInfo empty;
            listener_->on_data (instance, empty);
        }

      }

    };

    virtual void on_requested_deadline_missed (::DDS::DataReader_ptr the_reader,
                                               const ::DDS::RequestedDeadlineMissedStatus & status)
    {
      this->portlistener_->on_requested_deadline_missed (the_reader, status);
    };


    virtual void on_sample_lost (::DDS::DataReader_ptr the_reader,
                                 const ::DDS::SampleLostStatus & status)
    {
      this->portlistener_->on_sample_lost (the_reader, status);
    };

  private:
    ::CCM_DDS::Stock_Info_RawListener_var listener_;
    ::CCM_DDS::PortStatusListener_var portlistener_;
    ACE_Atomic_Op <TAO_SYNCH_MUTEX, bool> &enable_;
  };

  void
  Quoter_Connector_exec_i::configure_port_info_out_ (void)
  {
    if (this->__info_out_configured_)
      return;

    this->configure_default_topic_ ();

    try
      {
        if (CORBA::is_nil (this->__info_out_subscriber_.in ()))
          {
            ::DDS::SubscriberQos sqos;
            this->__info_out_subscriber_ = this->domain_->create_subscriber (sqos,
                                                                              0,
                                                                              0);
          }

        if (CORBA::is_nil (this->__info_out_datareader_.in ()))
          {
            this->__info_out_portstatus_ = this->context_->get_connection_info_out_status ();

            this->__info_out_datareaderlistener = new info_out_Listener (this->context_->get_connection_info_out_listener (),
                                                                         this->context_->get_connection_info_out_status (),
									 this->__info_out_rawlistener_enabled_);

            ::DDS::DataReaderQos drqos;
            this->__info_out_datareader_ =
              this->__info_out_subscriber_->create_datareader (this->topic_.in (),
                                                               drqos,
                                                               this->__info_out_datareaderlistener.in (),
                                                               DDS_DATA_AVAILABLE_STATUS);
          }

      }
    catch (...)
      {
        CIAO_ERROR ((LM_EMERGENCY, "Caught unknown c++ exception while creating subscriber entities\n"));
        throw CORBA::INTERNAL ();
      }
  }

  ::CCM_DDS::CCM_Stock_Info_Writer_ptr
  Quoter_Connector_exec_i::get_info_in_data (void)
  {
    std::cerr << "get_info_in_data" << std::endl;

    this->configure_port_info_in_ ();

    return new CIAO::DDS4CCM::RTI::Writer_T<Stock_Info_Traits,
      ::CCM_DDS::CCM_Stock_Info_Writer> (this->__info_in_datawriter_.in ());
  }

  ::DDS::CCM_DataWriter_ptr
  Quoter_Connector_exec_i::get_info_in_dds_entity (void)
  {
    this->configure_port_info_in_ ();

    return this->__info_in_datawriter_.in ();
  }

  ::CCM_DDS::CCM_Stock_Info_Reader_ptr
  Quoter_Connector_exec_i::get_info_out_data (void)
  {
    /* Your code here. */
    return ::CCM_DDS::CCM_Stock_Info_Reader::_nil ();
  }

  ::CCM_DDS::CCM_ListenerControl_ptr
  Quoter_Connector_exec_i::get_info_out_control (void)
  {
    /* Your code here. */
    return new CCM_DDS_ListenerControl_i (this->__info_out_rawlistener_enabled_);
  }

  ::DDS::CCM_DataReader_ptr
  Quoter_Connector_exec_i::get_info_out_dds_entity (void)
  {
    /* Your code here. */
    return ::DDS::CCM_DataReader::_nil ();
  }

  // Operations from Components::SessionComponent.

  void
  Quoter_Connector_exec_i::set_session_context (
    ::Components::SessionContext_ptr ctx)
  {
    ::Quoter::CCM_Quoter_Connector_Context_var lctx =
      ::Quoter::CCM_Quoter_Connector_Context::_narrow (ctx);

    if ( ::CORBA::is_nil (lctx.in ()))
      {
        throw ::CORBA::INTERNAL ();
      }

    this->context_ = lctx;
  }

  void
  Quoter_Connector_exec_i::configuration_complete (void)
  {
  }

  void
  Quoter_Connector_exec_i::ccm_activate (void)
  {
    /* Your code here. */
    if (!CORBA::is_nil (this->context_->get_connection_info_out_listener ()) ||
	!CORBA::is_nil (this->context_->get_connection_info_out_status ()))
      {
	this->configure_port_info_out_ ();
      }
  }

  void
  Quoter_Connector_exec_i::ccm_passivate (void)
  {
    /* Your code here. */
  }

  void
  Quoter_Connector_exec_i::ccm_remove (void)
  {
    /* Your code here. */
  }

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

    ACE_NEW_NORETURN (
      retval,
      Quoter_Connector_exec_i);

    return retval;
  }
}