summaryrefslogtreecommitdiff
path: root/modules/CIAO/ciaosvcs/Events/CIAO_RTEC/CIAO_RTEvent.cpp
blob: 1ef5b1ad8894335305178c1bbffe94f8969a71c1 (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
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
// -*- C++ -*-

//=============================================================================
/**
 *  @file CIAO_RTEvent.cpp
 *
 *  $Id$
 *
 *  @author Gan Deng <dengg@dre.vanderbilt.edu>
 *  @author George Edwards <g.edwards@vanderbilt.edu>
 */
//=============================================================================

#include "CIAO_RTEvent.h"
#include "ciao/CIAO_common.h"
#include "SimpleAddressServer.h"
#include "tao/ORB_Core.h"
#include "tao/AnyTypeCode/Any_Unknown_IDL_Type.h"
#include "orbsvcs/CosNamingC.h"

#include <sstream>

namespace CIAO
{


  RTEventService::RTEventService (CORBA::ORB_ptr orb,
                                  PortableServer::POA_ptr poa,
                                  const char * ec_name) :
    orb_ (CORBA::ORB::_duplicate (orb)),
    root_poa_ (PortableServer::POA::_duplicate (poa))
  {
    this->create_rt_event_channel (ec_name);
  }


  RTEventService::~RTEventService (void)
  {
  }


  Supplier_Config_ptr
  RTEventService::create_supplier_config (void)
    ACE_THROW_SPEC ((CORBA::SystemException))
  {
    RTEvent_Supplier_Config_impl * supplier_config = 0;
    ACE_NEW_RETURN (supplier_config,
                    RTEvent_Supplier_Config_impl (this->root_poa_.in ()),
                    Supplier_Config::_nil ());
    RTEvent_Supplier_Config_var return_rtec =
      supplier_config->_this ();
    return return_rtec._retn ();
  }


  Consumer_Config_ptr
  RTEventService::create_consumer_config (void)
    ACE_THROW_SPEC ((CORBA::SystemException))
  {
    RTEvent_Consumer_Config_impl * consumer_config = 0;
    ACE_NEW_RETURN (consumer_config,
                    RTEvent_Consumer_Config_impl (this->root_poa_.in ()),
                    Consumer_Config::_nil ());
    RTEvent_Consumer_Config_var return_rtec =
      consumer_config->_this ();
    return return_rtec._retn ();
  }


  // @@TODO: We might want to maintain a map for managing multiple proxy consumers
  // to multiple event suppliers.
  void
  RTEventService::connect_event_supplier (
      Supplier_Config_ptr supplier_config)
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    if (CIAO::debug_level () > 9)
      {
        ACE_DEBUG ((LM_DEBUG, "CIAO::RTEventService::connect_event_supplier\n"));
      }

    RTEvent_Supplier_Config_ptr rt_config =
      RTEvent_Supplier_Config::_narrow (supplier_config);

    if (CORBA::is_nil (rt_config))
      {
        throw CORBA::BAD_PARAM ();
      }

    // Get a proxy push consumer from the EventChannel.
    RtecEventChannelAdmin::SupplierAdmin_var supplier_admin =
      this->rt_event_channel_->for_suppliers ();

    RtecEventChannelAdmin::ProxyPushConsumer_var proxy_push_consumer =
      supplier_admin->obtain_push_consumer();

    // Create and register supplier servant
    RTEventServiceSupplier_impl * supplier_servant = 0;
    ACE_NEW (supplier_servant,
             RTEventServiceSupplier_impl (root_poa_.in ()));
    RtecEventComm::PushSupplier_var push_supplier =
      supplier_servant->_this ();

    RtecEventChannelAdmin::SupplierQOS_var qos =
      rt_config->rt_event_qos ();

    ACE_SupplierQOS_Factory supplier_qos;
    supplier_qos.insert (ACE_ES_EVENT_SOURCE_ANY, ACE_ES_EVENT_ANY, 0, 1);

    supplier_qos.insert (ACE_ES_EVENT_SOURCE_ANY,
                       ACE_ES_EVENT_ANY,
                       0,    // handle to the rt_info structure
                       1);

    proxy_push_consumer->connect_push_supplier (push_supplier.in (),
                                                supplier_qos.get_SupplierQOS ());


    this->proxy_consumer_map_.bind (
      supplier_config->supplier_id (),
      proxy_push_consumer._retn ());
  }

  void
  RTEventService::connect_event_consumer (
      Consumer_Config_ptr consumer_config)
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    if (CIAO::debug_level () > 9)
      {
        ACE_DEBUG ((LM_DEBUG, "CIAO::RTEventService::connect_event_consumer\n"));
      }

    RTEvent_Consumer_Config_ptr rt_config =
      RTEvent_Consumer_Config::_narrow (consumer_config);

    if (CORBA::is_nil (rt_config))
      {
        throw CORBA::BAD_PARAM ();
      }

    Components::EventConsumerBase_var consumer =
      consumer_config->consumer ();

    if (CORBA::is_nil (consumer.in ()))
      ACE_DEBUG ((LM_DEBUG, "nil event consumer\n"));

    RtecEventChannelAdmin::ConsumerAdmin_var consumer_admin =
      this->rt_event_channel_->for_consumers ();

    RtecEventChannelAdmin::ProxyPushSupplier_var proxy_supplier =
      consumer_admin->obtain_push_supplier ();

    // Create and register consumer servant
    RTEventServiceConsumer_impl * consumer_servant = 0;
    ACE_NEW (consumer_servant,
             RTEventServiceConsumer_impl (
               root_poa_.in (),
               consumer.in ()));
    RtecEventComm::PushConsumer_var push_consumer =
      consumer_servant->_this ();

    RtecEventChannelAdmin::ConsumerQOS_var qos =
      rt_config->rt_event_qos ();

    ACE_DEBUG ((LM_DEBUG, "\n======== ConsumerQoS length is: %d\n\n",
                qos->dependencies.length ()));

    if (qos->dependencies.length () == 0)
      {
        qos->dependencies.length (1);
        qos->dependencies[0].event.header.type = ACE_ES_EVENT_ANY;
        qos->dependencies[0].event.header.source = ACE_ES_EVENT_SOURCE_ANY;
        qos->dependencies[0].rt_info = 0;

        ACE_DEBUG ((LM_DEBUG, "\n======== Normalized ConsumerQoS length is: %d\n\n",
                    qos->dependencies.length ()));
      }

    proxy_supplier->connect_push_consumer (push_consumer.in (),
                                           qos.in ()
                                           //qos_factory.get_ConsumerQOS ()
                                           );

    ACE_CString consumer_id =
      consumer_config->consumer_id ();

    this->proxy_supplier_map_.bind (consumer_id.c_str (), proxy_supplier._retn ());
  }

  void
  RTEventService::disconnect_event_supplier (
      const char * connection_id)
    ACE_THROW_SPEC ((
      CORBA::SystemException,
      Components::InvalidConnection))
  {
    ACE_UNUSED_ARG (connection_id);

    RtecEventChannelAdmin::ProxyPushConsumer_var proxy_consumer;

    this->proxy_consumer_map_.unbind (connection_id, proxy_consumer);

    proxy_consumer->disconnect_push_consumer ();
  }

  void
  RTEventService::disconnect_event_consumer (
      const char * connection_id)
    ACE_THROW_SPEC ((
      CORBA::SystemException,
      Components::InvalidConnection))
  {
    RtecEventChannelAdmin::ProxyPushSupplier_var proxy_supplier;

    this->proxy_supplier_map_.unbind (connection_id, proxy_supplier);

    proxy_supplier->disconnect_push_supplier ();
  }

  void
  RTEventService::push_event (
      Components::EventBase * ev)
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    ACE_UNUSED_ARG (ev);
    if (CIAO::debug_level () > 10)
      {
        ACE_DEBUG ((LM_DEBUG, "------CIAO::RTEventService::push_event------\n"));
      }
  }

  void
  RTEventService::ciao_push_event (
      Components::EventBase * ev,
      const char * source_id,
      CORBA::TypeCode_ptr tc)
    ACE_THROW_SPEC ((
      CORBA::SystemException,
      Components::BadEventType))
  {
    if (CIAO::debug_level () > 10)
      {
        ACE_DEBUG ((LM_DEBUG, "------CIAO::RTEventService::ciao_push_event------\n"));
      }
    RtecEventComm::EventSet events (1);
    events.length (1);

    ACE_Hash<ACE_CString> hasher;

    events[0].header.source = hasher (source_id);
    events[0].header.type = ACE_ES_EVENT_ANY;
    events[0].header.ttl = 10;

    // We can't use the Any insert operator here, since it will put the
    // EventBase typecode into the Any, and the actual eventtype's fields
    // (if any) will get truncated when the Any is demarshaled. So the
    // signature of this method has been changed to pass in the derived
    // typecode, and TAO-specific methods are used to assign it as the
    // Any's typecode and encode the value. This incurs an extra
    // encoding, which we may want to try to optimize someday.
    TAO_OutputCDR out;
    out << ev;
    TAO_InputCDR in (out);
    TAO::Unknown_IDL_Type *unk = 0;
    ACE_NEW (unk,
             TAO::Unknown_IDL_Type (tc, in));
    events[0].data.any_value.replace (unk);

    ACE_DEBUG ((LM_DEBUG, "******* push event for source string: %s\n", source_id));
    ACE_DEBUG ((LM_DEBUG, "******* push event for source id: %i\n", events[0].header.source));

    RtecEventChannelAdmin::ProxyPushConsumer_var proxy_consumer;

    if (this->proxy_consumer_map_.find (source_id, proxy_consumer) != 0)
      {
        ACE_DEBUG ((LM_DEBUG,
                    "CIAO (%P|%t) - RTEventService::ciao_push_event, "
                    "Error in finding the proxy consumer object.\n"));
        throw Components::BadEventType ();
      }

    proxy_consumer->push (events);
  }

  void
  RTEventService::create_rt_event_channel (const char * ec_name)
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    if (CIAO::debug_level () > 10)
      {
        ACE_DEBUG ((LM_DEBUG, "CIAO::EventService_Factory_impl::create_rt_event_channel\n"));
      }

    TAO_EC_Default_Factory::init_svcs ();

    TAO_EC_Event_Channel_Attributes attributes (this->root_poa_.in (),
                                                this->root_poa_.in ());
    TAO_EC_Event_Channel * ec_servant = 0;
    ACE_NEW (ec_servant, TAO_EC_Event_Channel (attributes));
    ec_servant->activate ();
    this->rt_event_channel_ = ec_servant->_this ();

    if (false)
      {
        // Find the Naming Service.
        CORBA::Object_var obj = orb_->resolve_initial_references("NameService");
        CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in());

        // Bind the Event Channel using Naming Services
        CosNaming::Name_var name = root_context->to_name (ec_name);
        ACE_DEBUG ((LM_DEBUG, "\nRegister naming: %s\n", ec_name));
        root_context->rebind (name.in(), rt_event_channel_.in());
      }
  }

  ::CORBA::Boolean
  RTEventService::create_addr_serv (
        const char * name,
        ::CORBA::UShort port,
        const char * address)
      ACE_THROW_SPEC ((
        ::CORBA::SystemException))
  {
    ACE_DEBUG ((LM_ERROR, "Create an address server using port [%d]\n", port));

    // Initialize the address server with the desired address.
    // This will be used by the sender object and the multicast
    // receiver.
    ACE_INET_Addr send_addr (port, address);

    SimpleAddressServer * addr_srv_impl = new SimpleAddressServer (send_addr);

    PortableServer::ObjectId_var addr_srv_oid =
      this->root_poa_->activate_object (addr_srv_impl);
    CORBA::Object_var addr_srv_obj =
      this->root_poa_->id_to_reference (addr_srv_oid.in());
    RtecUDPAdmin::AddrServer_var addr_srv =
      RtecUDPAdmin::AddrServer::_narrow (addr_srv_obj.in());

/*
      // First we convert the string into an INET address, then we
      // convert that into the right IDL structure:
      ACE_INET_Addr udp_addr (address);
      ACE_DEBUG ((LM_DEBUG,
                  "udp mcast address is: %s\n",
                  address));
      RtecUDPAdmin::UDP_Addr addr;
      addr.ipaddr = udp_addr.get_ip_address ();
      addr.port   = udp_addr.get_port_number ();

      // Now we create and activate the servant
      SimpleAddressServer as_impl (addr);
      RtecUDPAdmin::AddrServer_var addr_srv =
        as_impl._this ();
*/

    this->addr_serv_map_.bind (
      name,
      RtecUDPAdmin::AddrServer::_duplicate (addr_srv.in ()));


    return true;
  }

  ::CORBA::Boolean
  RTEventService::create_sender (
        const char * addr_serv_id)
      ACE_THROW_SPEC ((
        ::CORBA::SystemException))
  {
    ACE_DEBUG ((LM_DEBUG, "Create a Sender object with addr_serv_id: %s\n",addr_serv_id ));

    // We need a local socket to send the data, open it and check
    // that everything is OK:
    TAO_ECG_Refcounted_Endpoint endpoint(new TAO_ECG_UDP_Out_Endpoint);
    if (endpoint->dgram ().open (ACE_Addr::sap_any) == -1)
      {
        ACE_ERROR_RETURN ((LM_ERROR, "Cannot open send endpoint\n"),
                          1);
      }

    RtecUDPAdmin::AddrServer_var addr_srv;
    if (this->addr_serv_map_.find (addr_serv_id, addr_srv) != 0)
      return false;

    // Now we setup the sender:
    TAO_EC_Servant_Var<TAO_ECG_UDP_Sender> sender = TAO_ECG_UDP_Sender::create();
    sender->init (this->rt_event_channel_.in (),
                  addr_srv.in (),
                  endpoint);

    // Setup the subscription and connect to the EC
    ACE_ConsumerQOS_Factory cons_qos_fact;
    cons_qos_fact.start_disjunction_group ();
    cons_qos_fact.insert (ACE_ES_EVENT_SOURCE_ANY, ACE_ES_EVENT_ANY, 0);
    RtecEventChannelAdmin::ConsumerQOS sub = cons_qos_fact.get_ConsumerQOS ();
    sub.is_gateway = 1;
    sender->connect (sub);

    return true;
  }

  ::CORBA::Boolean
  RTEventService::create_receiver (
        const char * addr_serv_id,
        ::CORBA::Boolean is_multicast,
        ::CORBA::UShort listen_port)
      ACE_THROW_SPEC ((
        ::CORBA::SystemException))
  {
    ACE_DEBUG ((LM_DEBUG, "Create a receiver object with addr_serv_id: %s\n",addr_serv_id ));

    // Create and initialize the receiver
    TAO_EC_Servant_Var<TAO_ECG_UDP_Receiver> receiver =
                                      TAO_ECG_UDP_Receiver::create();

    // AddressServer is necessary when "multicast" is enabled, but not for "udp"
    if (is_multicast)
      {
        TAO_ECG_UDP_Out_Endpoint endpoint;
        if (endpoint.dgram ().open (ACE_Addr::sap_any) == -1)
          {
            ACE_DEBUG ((LM_ERROR, "Cannot open send endpoint\n"));
            return false;
          }

        // TAO_ECG_UDP_Receiver::init() takes a TAO_ECG_Refcounted_Endpoint.
        // If we don't clone our endpoint and pass &endpoint, the receiver will
        // attempt to delete endpoint during shutdown.
        TAO_ECG_UDP_Out_Endpoint* clone;
        ACE_NEW_RETURN (clone,
                        TAO_ECG_UDP_Out_Endpoint (endpoint),
                        false);

        RtecUDPAdmin::AddrServer_var addr_srv;

        if (this->addr_serv_map_.find (addr_serv_id, addr_srv) != 0)
          return false;

        receiver->init (this->rt_event_channel_.in (),
                        clone,
                        addr_srv.in ());
      }
    else
      {
        receiver->init (this->rt_event_channel_.in (), 0, 0);
      }

    // Setup the registration and connect to the event channel
    ACE_SupplierQOS_Factory supp_qos_fact;
    supp_qos_fact.insert (ACE_ES_EVENT_SOURCE_ANY, ACE_ES_EVENT_ANY, 0, 1);
    RtecEventChannelAdmin::SupplierQOS pub = supp_qos_fact.get_SupplierQOS ();
    receiver->connect (pub);

    // Create the appropriate event handler and register it with the reactor

    if (is_multicast)
      {
        auto_ptr<TAO_ECG_Mcast_EH> mcast_eh (new TAO_ECG_Mcast_EH (receiver.in()));
        mcast_eh->reactor (this->orb_->orb_core ()->reactor ());
        mcast_eh->open (this->rt_event_channel_.in());
        mcast_eh.release();
      }
    else
      {
        ACE_DEBUG ((LM_DEBUG, "\nUDP Event Handler Port [%d]\n", listen_port));

        //auto_ptr<TAO_ECG_UDP_EH> udp_eh (new TAO_ECG_UDP_EH (receiver.in()));
        TAO_ECG_UDP_EH * udp_eh = new TAO_ECG_UDP_EH (receiver.in());

        udp_eh->reactor (this->orb_->orb_core ()->reactor ());

        ACE_INET_Addr local_addr (listen_port);
        if (udp_eh->open (local_addr) == -1)
          {
            ACE_DEBUG ((LM_ERROR, "Cannot open event handler on port [%d]\n", listen_port));
            return false;
          }
        //udp_eh.release ();
      }

    return true;
  }


  ::RtecEventChannelAdmin::EventChannel_ptr
  RTEventService::tao_rt_event_channel ()
    ACE_THROW_SPEC ((::CORBA::SystemException))
  {
    return this->rt_event_channel_.in ();
  }

  //////////////////////////////////////////////////////////////////////
  ///                 Supplier Servant Implementation
  //////////////////////////////////////////////////////////////////////

  RTEventServiceSupplier_impl::RTEventServiceSupplier_impl (
    PortableServer::POA_ptr poa) :
  poa_ (PortableServer::POA::_duplicate (poa))
  {
  }

  void
  RTEventServiceSupplier_impl::disconnect_push_supplier (void)
    ACE_THROW_SPEC ((
         CORBA::SystemException))
  {
    PortableServer::ObjectId_var oid = this->poa_->servant_to_id (this);
    this->poa_->deactivate_object (oid);
    this->_remove_ref ();
  }

  //////////////////////////////////////////////////////////////////////
  ///                   Consumer Servant Implementation
  //////////////////////////////////////////////////////////////////////

  RTEventServiceConsumer_impl::RTEventServiceConsumer_impl (
    PortableServer::POA_ptr poa,
    Components::EventConsumerBase_ptr consumer) :
  poa_ (PortableServer::POA::_duplicate (poa)),
  event_consumer_ (Components::EventConsumerBase::_duplicate (consumer))
  {
  }

  void
  RTEventServiceConsumer_impl::push (const RtecEventComm::EventSet& events)
    ACE_THROW_SPEC ((CORBA::SystemException))
  {
    if (CIAO::debug_level () > 10)
      {
        ACE_DEBUG ((LM_DEBUG, "CIAO::RTEventServiceConsumer_impl::push\n"));
      }

    for (size_t i = 0; i < events.length (); ++i)
      {
        std::ostringstream out;
        out << "Received event,"
            << "  type: "   << events[i].header.type
            << "  source: " << events[i].header.source;

        ACE_OS::printf("%s\n", out.str().c_str()); // printf is synchronized

        Components::EventBase * ev = 0;
        try
        {
          TAO::Unknown_IDL_Type *unk =
              dynamic_cast<TAO::Unknown_IDL_Type *> (events[i].data.any_value.impl ());
          TAO_InputCDR for_reading (unk->_tao_get_cdr ());

          if (for_reading >> ev)
            {
              ev->_add_ref ();
              this->event_consumer_->push_event (ev);
            }
          else
            {
              ACE_ERROR ((LM_ERROR, "CIAO::RTEventServiceConsumer_impl::push(), "
                                    "failed to extract event\n"));
            }
        }
        catch (const CORBA::Exception& ex)
        {
          ACE_ERROR ((LM_ERROR,
                      "CORBA EXCEPTION caught\n"));
          ex._tao_print_exception ("RTEventServiceConsumer_impl::push()\n");
        }
      }

  }

  void
  RTEventServiceConsumer_impl::disconnect_push_consumer (void)
    ACE_THROW_SPEC ((CORBA::SystemException))
  {
    if (CIAO::debug_level () > 10)
      {
        ACE_DEBUG ((LM_DEBUG, "CIAO::RTEventServiceConsumer_impl::disconnect_push_consumer\n"));
      }

    PortableServer::ObjectId_var oid = this->poa_->servant_to_id (this);
    this->poa_->deactivate_object (oid);
    this->_remove_ref ();
  }


  //////////////////////////////////////////////////////////////////////
  ///                   Supplier Config Implementation
  //////////////////////////////////////////////////////////////////////

  RTEvent_Supplier_Config_impl::RTEvent_Supplier_Config_impl (PortableServer::POA_ptr poa) :
    service_type_ (RTEC),
    poa_ (PortableServer::POA::_duplicate (poa))
  {
  }

  RTEvent_Supplier_Config_impl::~RTEvent_Supplier_Config_impl (void)
  {
    if (CIAO::debug_level () > 10)
      {
        ACE_DEBUG
          ((LM_DEBUG, "RTEvent_Supplier_Config_impl::~RTEvent_Supplier_Config_impl\n"));
      }
  }

  void
  RTEvent_Supplier_Config_impl::supplier_id (
      const char * supplier_id)
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
  if (CIAO::debug_level () > 10)
    {
      ACE_DEBUG ((LM_DEBUG, "supplier's id: %s\n", supplier_id));
    }

    this->supplier_id_ = supplier_id;

    ACE_Hash<ACE_CString> hasher;

    RtecEventComm::EventSourceID source_id =
      hasher (this->supplier_id_.c_str ());
/*
    this->qos_.insert (source_id,
                       ACE_ES_EVENT_ANY,
                       0,
                       1);

*/

    this->qos_.insert (ACE_ES_EVENT_SOURCE_ANY,
                       ACE_ES_EVENT_ANY,
                       0,    // handle to the rt_info structure
                       1);

    ACE_DEBUG ((LM_DEBUG, "supplier's source id is: %d\n", source_id));
  }

  CONNECTION_ID
  RTEvent_Supplier_Config_impl::supplier_id ()
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    return CORBA::string_dup (this->supplier_id_.c_str ());
  }

  EventServiceType
  RTEvent_Supplier_Config_impl::service_type ()
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    return this->service_type_;
  }

  RtecEventChannelAdmin::SupplierQOS *
  RTEvent_Supplier_Config_impl::rt_event_qos ()
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    RtecEventChannelAdmin::SupplierQOS * supplier_qos = 0;
    ACE_NEW_RETURN (supplier_qos,
                    RtecEventChannelAdmin::SupplierQOS (this->qos_.get_SupplierQOS ()),
                    0);
    return supplier_qos;
  }

  void
  RTEvent_Supplier_Config_impl::destroy ()
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    PortableServer::ObjectId_var oid = this->poa_->servant_to_id (this);
    this->poa_->deactivate_object (oid);
    this->_remove_ref ();
  }

  //////////////////////////////////////////////////////////////////////
  ///                   Consumer Config Implementation
  //////////////////////////////////////////////////////////////////////

  RTEvent_Consumer_Config_impl::RTEvent_Consumer_Config_impl (PortableServer::POA_ptr poa) :
    service_type_ (RTEC),
    poa_ (PortableServer::POA::_duplicate (poa))
  {
  }

  RTEvent_Consumer_Config_impl::~RTEvent_Consumer_Config_impl (void)
  {
    ACE_DEBUG
      ((LM_DEBUG, "RTEvent_Consumer_Config_impl::~RTEvent_Consumer_Config_impl\n"));
  }

  void
  RTEvent_Consumer_Config_impl::start_conjunction_group (
      CORBA::Long size)
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    ACE_DEBUG
      ((LM_DEBUG, "RTEvent_Consumer_Config_impl::start_conjunction_group\n"));

    this->qos_.start_conjunction_group (size);
  }

  void
  RTEvent_Consumer_Config_impl::start_disjunction_group (
      CORBA::Long size)
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    // Note, since we only support basic builder here...
    if (size == 0L)
      this->qos_.start_disjunction_group ();
    else
      this->qos_.start_disjunction_group (size);
  }

  void
  RTEvent_Consumer_Config_impl::insert_source (
      const char * source_id)
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    ACE_Hash<ACE_CString> hasher;
    RtecEventComm::EventSourceID int_source_id = hasher (source_id);

    ACE_DEBUG ((LM_DEBUG, "******* the source string is: %s\n", source_id));
    ACE_DEBUG ((LM_DEBUG, "******* the source id is: %i\n", int_source_id));

    this->qos_.insert_source (int_source_id, 0);
  }

  void
  RTEvent_Consumer_Config_impl::insert_type (
        ::CORBA::Long event_type)
      ACE_THROW_SPEC ((::CORBA::SystemException))
  {
    if (event_type == 0L)
      this->qos_.insert_type (ACE_ES_EVENT_ANY, 0);
    else
      this->qos_.insert_type (event_type,
                              0);
  }

  void
  RTEvent_Consumer_Config_impl::consumer_id (
      const char * consumer_id)
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    if (CIAO::debug_level () > 10)
      {
        ACE_DEBUG ((LM_DEBUG,
                    "RTEvent_Consumer_Config_impl::set_consumer_id:%s\n",
                    consumer_id));
      }

    this->consumer_id_ = consumer_id;
  }


  void
  RTEvent_Consumer_Config_impl::consumer (
      Components::EventConsumerBase_ptr consumer)
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    this->consumer_ = Components::EventConsumerBase::_duplicate (consumer);
  }

  CONNECTION_ID
  RTEvent_Consumer_Config_impl::consumer_id ()
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    return CORBA::string_dup (this->consumer_id_.c_str ());
  }


  EventServiceType
  RTEvent_Consumer_Config_impl::service_type ()
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    return this->service_type_;
  }

  Components::EventConsumerBase_ptr
  RTEvent_Consumer_Config_impl::consumer ()
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    if (CIAO::debug_level () > 10)
      {
        ACE_DEBUG ((LM_DEBUG, "RTEvent_Consumer_Config_impl::get_consumer\n"));
      }

    return Components::EventConsumerBase::_duplicate (this->consumer_.in ());
  }

  RtecEventChannelAdmin::ConsumerQOS *
  RTEvent_Consumer_Config_impl::rt_event_qos ()
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    RtecEventChannelAdmin::ConsumerQOS * consumer_qos = 0;
    ACE_NEW_RETURN (consumer_qos,
                    RtecEventChannelAdmin::ConsumerQOS (this->qos_.get_ConsumerQOS ()),
                    0);

    return consumer_qos;
  }

  void
  RTEvent_Consumer_Config_impl::destroy ()
    ACE_THROW_SPEC ((
      CORBA::SystemException))
  {
    if (CIAO::debug_level () > 10)
      {
        ACE_DEBUG
          ((LM_DEBUG, "RTEvent_Consumer_Config_impl::destroy\n"));
      }

    PortableServer::ObjectId_var oid = this->poa_->servant_to_id (this);
    this->poa_->deactivate_object (oid);
    this->_remove_ref ();
  }
}