summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_component/component_svh.cpp
blob: 97257994785d8c61a5173fe078ec97c98b2515e3 (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
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
//
// $Id$
//

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    component_svh.cpp
//
// = DESCRIPTION
//    Visitor generating code for Components in the servant header.
//
// = AUTHOR
//    Jeff Parsons
//
// ============================================================================

ACE_RCSID (be_visitor_component,
           component_svh,
           "$Id$")

// ******************************************************
// Component visitor for server header
// ******************************************************

be_visitor_component_svh::be_visitor_component_svh (be_visitor_context *ctx)
  : be_visitor_component (ctx),
    node_ (0),
    os_ (*ctx->stream ()),
    export_macro_ (be_global->svnt_export_macro ()),
    in_ancestor_ (false)
{
  /// All existing CIAO examples set the servant export values in the CIDL
  /// compiler to equal the IDL compiler's skel export values. Below is a
  /// partial effort to decouple them, should be completely decoupled
  /// sometime. See comment in codegen.cpp, line 1173.
  if (export_macro_ == "")
    {
      export_macro_ = be_global->skel_export_macro ();
    }
}

be_visitor_component_svh::~be_visitor_component_svh (void)
{
}

int
be_visitor_component_svh::visit_component (be_component *node)
{
  node_ = node;

  if (this->gen_facets () == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("be_visitor_component_svh::")
                         ACE_TEXT ("visit_component - ")
                         ACE_TEXT ("gen_facets() failed\n")),
                        -1);
    }

  /// CIDL-generated namespace used 'CIDL_' + composition name.
  /// Now we use 'CIAO_' + component's flat name.
  os_ << be_nl << be_nl
      << "namespace CIAO_" << node_->flat_name ()
      << "_Impl" << be_nl
      << "{" << be_idt;

  this->gen_context_class ();

  if (this->gen_servant_class () == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("be_visitor_component_svh::")
                         ACE_TEXT ("visit_component - ")
                         ACE_TEXT ("gen_servant_class() failed\n")),
                        -1);
    }

  this->gen_entrypoint ();

  os_ << be_uidt_nl
      << "}";

  return 0;
}

int
be_visitor_component_svh::visit_operation (be_operation *node)
{
  be_visitor_operation_ch v (this->ctx_);
  return v.visit_operation (node);
}

int
be_visitor_component_svh::visit_attribute (be_attribute *node)
{
  be_visitor_attribute v (this->ctx_);
  return v.visit_attribute (node);
}

int
be_visitor_component_svh::visit_extended_port (
  be_extended_port *)
{
  return 0;
}

int
be_visitor_component_svh::visit_mirror_port (
  be_mirror_port *)
{
  return 0;
}

int
be_visitor_component_svh::gen_facets (void)
{
  for (UTL_ScopeActiveIterator si (node_, UTL_Scope::IK_decls);
       !si.is_done ();
       si.next ())
    {
      AST_Decl *d = si.item ();
      AST_Decl::NodeType nt = d->node_type ();

      switch (nt)
        {
          case AST_Decl::NT_provides:
            {
              be_provides *p =
                be_provides::narrow_from_decl (d);

              if (p->gen_facet_svnt_decl (os_) == -1)
                {
                  ACE_ERROR_RETURN ((LM_ERROR,
                                     ACE_TEXT ("be_visitor_component_svh")
                                     ACE_TEXT ("::gen_facets - ")
                                     ACE_TEXT ("gen_facet_svnt_decl() ")
                                     ACE_TEXT ("failed\n")),
                                    -1);
                }
                
              break;
            }
          case AST_Decl::NT_ext_port:
            {
              be_extended_port *ep =
                be_extended_port::narrow_from_decl (d);

              be_visitor_extended_port_facet_svh visitor (this->ctx_);
              
              if (visitor.visit_extended_port (ep) == -1)
                {
                  ACE_ERROR_RETURN ((LM_ERROR,
                                     "be_visitor_component_svh::gen_facets - "
                                     "visit_extended_port() failed\n"),
                                    -1);
                }
                
              break;
            }
          case AST_Decl::NT_mirror_port:
            {
              be_mirror_port *mp =
                be_mirror_port::narrow_from_decl (d);

              if (this->visit_mirror_port (mp) == -1)
                {
                  ACE_ERROR_RETURN ((LM_ERROR,
                                     "be_visitor_component_svh::gen_facets - "
                                     "visit_mirror_port() failed\n"),
                                    -1);
                }
                
              break;
            }
          default:
            continue;
        }
    }

  return 0;
}

void
be_visitor_component_svh::gen_context_class (void)
{
  AST_Decl *scope = ScopeAsDecl (node_->defined_in ());
  ACE_CString sname_str (scope->full_name ());
  const char *sname = sname_str.c_str ();

  // No '_cxx_' prefix.
  const char *lname =
    node_->original_local_name ()->get_string ();

  const char *global = (sname_str == "" ? "" : "::");
  bool swapping = be_global->gen_component_swapping ();

  os_ << be_nl
      << "class " << lname << "_Servant;"
      << be_nl << be_nl;

  os_ << "class " << export_macro_.c_str () << " " << lname
      << "_Context" << be_idt_nl
      << ": public virtual ::CIAO::"
      << (swapping ? "Upgradeable_" : "")
      << "Context_Impl<" << be_idt << be_idt_nl
      << global << sname << "::CCM_" << lname
      << "_Context," << be_nl
      << lname << "_Servant," << be_nl
      << "::" << node_->name () << ">" << be_uidt << be_uidt << be_uidt_nl
      << "{" << be_nl
      << "public:" << be_idt_nl;

  os_ << "// Allow the servant to access our state." << be_nl
      << "friend class " << lname << "_Servant;"
      << be_nl << be_nl;

  os_ << "// Some useful typedefs." << be_nl<< be_nl
      << "typedef" << be_nl
      << "::CIAO::Context_Impl<" << be_idt << be_idt_nl
      << global << sname << "::CCM_"
      << lname << "_Context," << be_nl
      << lname << "_Servant," << be_nl
      << "::" << node_->name () << ">" << be_uidt_nl
      << "base_type;" << be_uidt_nl << be_nl;

  os_ << "typedef base_type::context_type context_type;" << be_nl
      << "typedef base_type::servant_type servant_type;" << be_nl
      << "typedef base_type::component_type component_type;"
      << be_nl << be_nl;

  os_ << lname << "_Context (" << be_idt_nl
      << "::Components::CCMHome_ptr h," << be_nl
      << "::CIAO::Container_ptr c," << be_nl
      << lname << "_Servant *sv);" << be_uidt_nl << be_nl;

  os_ << "virtual ~" << lname << "_Context (void);";

  os_ << be_nl << be_nl
      << "// CIAO-specific." << be_nl
      << "static " << lname << "_Context *" << be_nl
      << "_narrow ( ::Components::SessionContext_ptr p);";

  this->gen_context_r (node_);

  if (swapping)
    {
      os_ << be_nl << be_nl
          << "/// Operation defined in " << sname << "::CCM_"
          << lname << "_Context" << be_nl
          << "/// that enable component swapping in the container."
          << be_nl
          << "virtual ::Components::ConsumerDescriptions *" << be_nl
          << "get_registered_consumers (const char * publisher_name);";
    }

  os_ << be_uidt_nl
      << "};";
}

void
be_visitor_component_svh::gen_context_r (AST_Component *node)
{
  if (node == 0)
    {
      return;
    }

  AST_Decl *scope = ScopeAsDecl (node->defined_in ());
  ACE_CString sname_str (scope->full_name ());
  const char *sname = sname_str.c_str ();

  // No '_cxx_' prefix.
  const char *lname =
    node->original_local_name ()->get_string ();

  const char *global = (sname_str == "" ? "" : "::");

  os_ << be_nl << be_nl
      << "// Operations for " << lname
      << " receptacles and event sources,"
      << be_nl
      << "// defined in " << global << sname
      << "::CCM_" << lname << "_Context.";

  this->gen_ports (node, AST_Decl::NT_uses, false);
  this->gen_ports (node, AST_Decl::NT_publishes, false);
  this->gen_ports (node, AST_Decl::NT_emits, false);

  AST_Component *ancestor = node->base_component ();
  in_ancestor_ |= (ancestor != 0);

  this->gen_context_r (ancestor);
}

int
be_visitor_component_svh::gen_servant_class (void)
{
  AST_Decl *scope = ScopeAsDecl (node_->defined_in ());
  ACE_CString sname_str (scope->full_name ());
  const char *sname = sname_str.c_str ();

  // No '_cxx_' prefix.
  const char *lname =
    node_->original_local_name ()->get_string ();

  const char *global = (sname_str == "" ? "" : "::");

  os_ << be_nl << be_nl
      << "class " << export_macro_.c_str () << " " << lname
      << "_Servant" << be_idt_nl
      << ": public virtual" << be_idt << be_idt_nl
      << "::CIAO::Servant_Impl<" << be_idt_nl
      << "::" << node_->full_skel_name () << "," << be_nl
      << global << sname << "::CCM_" << lname << "," << be_nl
      << lname << "_Context>"
      << be_uidt << be_uidt << be_uidt << be_uidt_nl
      << "{" << be_nl
      << "public:" << be_idt_nl;

  os_ << "typedef " << global << sname << "::CCM_" << lname
      << " _exec_type;" << be_nl;

  os_ << be_nl
      << lname << "_Servant (" << be_idt_nl
      << global << sname << "::CCM_"
      << lname << "_ptr executor," << be_nl
      << "::Components::CCMHome_ptr h," << be_nl
      << "const char * ins_name," << be_nl
      << "::CIAO::Home_Servant_Impl_Base *hs," << be_nl
      << "::CIAO::Container_ptr c);" << be_uidt_nl;

  os_ << be_nl
      << "virtual ~" << lname << "_Servant"
      << " (void);" << be_nl;

  os_ << be_nl
      << "virtual void" << be_nl
      << "set_attributes (const "
      << "::Components::ConfigValues & descr);"
      << be_nl;

  os_ << be_nl
      << "// Supported operations and attributes.";

  int status =
    node_->traverse_inheritance_graph (
      be_interface::facet_op_attr_decl_helper,
      &os_,
      false,
      false);

  if (status == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "be_visitor_component_svh::"
                         "gen_servant_class - "
                         "inheritance graph traversal failed\n"),
                        -1);
    }

  /// Reset flag for servant class.
  in_ancestor_ = false;

  status = this->gen_servant_r (node_);

  if (status == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "be_visitor_component_svh::"
                         "gen_servant_class - "
                         "gen_servant_r() failed\n"),
                        -1);
    }

  this->gen_non_type_specific ();

  os_ << be_uidt_nl
      << "};";

  return 0;
}

int
be_visitor_component_svh::gen_servant_r (AST_Component *node)
{
  if (node == 0)
    {
      return 0;
    }

  os_ << be_nl << be_nl
      << "// " << (in_ancestor_ ? "Inherited p" : "P")
      << "orts code.";

  this->gen_ports (node, AST_Decl::NT_provides, true);
  this->gen_ports (node, AST_Decl::NT_uses, true);
  this->gen_ports (node, AST_Decl::NT_publishes, true);
  this->gen_ports (node, AST_Decl::NT_emits, true);
  this->gen_ports (node, AST_Decl::NT_consumes, true);

  os_ << be_nl << be_nl
      << "// " << (in_ancestor_ ? "Inherited c" : "C")
      << "omponent attributes.";

  int status = this->gen_component_attrs (node);

  if (status == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("be_visitor_component_svh::")
                         ACE_TEXT ("gen_servant_r - ")
                         ACE_TEXT ("gen_component_attrs() failed\n")),
                        -1);
    }

  AST_Component *ancestor = node->base_component ();
  in_ancestor_ |= (ancestor != 0);

  return gen_servant_r (ancestor);
}

int
be_visitor_component_svh::gen_component_attrs (AST_Component *node)
{
  /// Traverse the scope and ignore everything but attributes.
  for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
       !si.is_done ();
       si.next ())
    {
      AST_Decl *d = si.item ();
      be_attribute *attr = be_attribute::narrow_from_decl (d);

      if (attr == 0)
        {
          continue;
        }

      if (attr->accept (this) == -1)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT ("be_visitor_component_svh::")
                             ACE_TEXT ("gen_component_attrs - ")
                             ACE_TEXT ("be_attribute::accept() failed\n")),
                            -1);
        }
    }

 return 0;
}

void
be_visitor_component_svh::gen_ports (AST_Component *node,
                                     AST_Decl::NodeType nt,
                                     bool in_servant)
{
  os_ << be_nl << be_nl;

  switch (nt)
    {
      case AST_Decl::NT_provides:
        os_ << "// Facets.";
        break;
      case AST_Decl::NT_uses:
        os_ << "// Receptacles.";
        break;
      case AST_Decl::NT_publishes:
        os_ << "// Event publishers.";
        break;
      case AST_Decl::NT_consumes:
        os_ << "// Event consumers.";
        break;
      case AST_Decl::NT_emits:
        os_ << "// Event emitters.";
        break;
      default:
        break;
    }

  for (UTL_ScopeActiveIterator si (node, UTL_Scope::IK_decls);
       !si.is_done ();
       si.next ())
    {
      AST_Decl *d = si.item ();

      if (d->node_type () != nt)
        {
          continue;
        }

      switch (nt)
        {
          case AST_Decl::NT_provides:
            this->gen_provides (AST_Provides::narrow_from_decl (d));
            break;
          case AST_Decl::NT_uses:
            this->gen_uses (AST_Uses::narrow_from_decl (d),
                            in_servant);
            break;
          case AST_Decl::NT_publishes:
            this->gen_publishes (AST_Publishes::narrow_from_decl (d),
                                 in_servant);
            break;
          case AST_Decl::NT_emits:
            this->gen_emits (AST_Emits::narrow_from_decl (d),
                             in_servant);
            break;
          case AST_Decl::NT_consumes:
            this->gen_consumes (AST_Consumes::narrow_from_decl (d));
            break;
          default:
            break;
        }
    }
}

void
be_visitor_component_svh::gen_provides (AST_Provides *p)
{
  const char *obj_name = p->provides_type ()->full_name ();
  const char *port_name = p->local_name ()->get_string ();

  os_ << be_uidt_nl << be_nl
      << "public:" << be_idt_nl
      << "virtual ::" << obj_name << "_ptr" << be_nl
      << "provide_" << port_name << " (void);"
      << be_uidt_nl << be_nl;

  os_ << "private:" << be_idt_nl
      << "::CORBA::Object_ptr" << be_nl
      << "provide_" << port_name << "_i (void);"
      << be_uidt_nl << be_nl;

  os_ << "private:" << be_idt_nl
      << "::" << obj_name << "_var" << be_nl
      << "provide_" << port_name << "_;";
}

void
be_visitor_component_svh::gen_uses (
  AST_Uses *u,
  bool in_servant)
{
  const char *obj_name = u->uses_type ()->full_name ();
  const char *port_name = u->local_name ()->get_string ();
  bool is_multiple = u->is_multiple ();

  os_ << be_uidt_nl << be_nl
      << "public:" << be_idt_nl
      << "virtual ";

  if (is_multiple)
    {
      os_ << "::" << node_->full_name () << "::"
          << port_name << "Connections *" << be_nl
          << "get_connections_" << port_name << " (void);";
    }
  else
    {
      os_ << "::" << obj_name << "_ptr" << be_nl
          << "get_connection_" << port_name << " (void);";
    }

  os_ << be_nl;

  if (!in_servant)
    {
      os_ << be_uidt_nl
          << "protected:" << be_idt;
    }

  os_ << be_nl
      << "virtual "
      << (is_multiple ? "::Components::Cookie *" : "void")
      << be_nl
      << "connect_" << port_name << " (" << be_idt_nl
      << "::" << obj_name << "_ptr);"
      << be_uidt_nl << be_nl;

  os_ << "virtual ::" << obj_name << "_ptr" << be_nl
      << "disconnect_" << port_name << " (";

     if (is_multiple)
      {
        os_ << be_idt_nl
            << "::Components::Cookie * ck);" << be_uidt;
      }
    else
      {
        os_ << "void);";
      }

  if (!in_servant)
    {
      os_ << be_uidt_nl << be_nl
          << "protected:" << be_idt_nl;

      if (is_multiple)
        {
          os_ << "// Multiplex " << port_name << " connection." << be_nl
              << "typedef ACE_Array_Map<ptrdiff_t," << be_nl
              << "                      ::"
              << obj_name << "_var>" << be_idt_nl
              << tao_cg->upcase (port_name)
              << "_TABLE;" << be_uidt_nl
              << tao_cg->upcase (port_name) << "_TABLE "
              << "ciao_uses_" << port_name << "_;" << be_nl
              << "TAO_SYNCH_MUTEX " << port_name << "_lock_;";
        }
      else
        {
          os_ << "// Simplex " << port_name << " connection." << be_nl
              << "::" << obj_name << "_var" << be_nl
              << "ciao_uses_" << port_name << "_;";
        }
    }
}

void
be_visitor_component_svh::gen_publishes (AST_Publishes *p,
                                         bool in_servant)
{
  const char *obj_name = p->publishes_type ()->full_name ();
  const char *port_name = p->local_name ()->get_string ();

  os_ << be_uidt_nl << be_nl
      << "public:" << be_idt_nl;

  if (!in_servant)
    {
      os_ << "virtual void" << be_nl
          << "push_" << port_name << " (" << be_idt_nl
          << "::" << obj_name << " * ev);" << be_uidt_nl;

      os_ << be_uidt_nl
          << "protected:" << be_idt_nl;
    }

  os_ << "virtual ::Components::Cookie *" << be_nl
      << "subscribe_" << port_name << " (" << be_idt_nl
      << "::" << obj_name << "Consumer_ptr c);" << be_uidt_nl;

  os_ << be_nl
      << "// CIAO-specific." << be_nl
      << "::Components::Cookie *" << be_nl
      << "subscribe_" << port_name << "_generic (" << be_idt_nl
      << "::Components::EventConsumerBase_ptr c);" << be_uidt_nl;

  os_ << be_nl
      << "virtual ::" << obj_name << "Consumer_ptr" << be_nl
      << "unsubscribe_" << port_name << " (" << be_idt_nl
      << "::Components::Cookie * ck);" << be_uidt;

  if (!in_servant)
    {
      os_ << be_uidt_nl << be_nl
          << "protected:" << be_idt_nl;

      os_ << "typedef ACE_Array_Map<ptrdiff_t," << be_nl
          << "                      ::" << obj_name
          << "Consumer_var>" << be_idt_nl
          << tao_cg->upcase (port_name) << "_TABLE;" << be_uidt_nl
          << tao_cg->upcase (port_name) << "_TABLE ciao_publishes_"
          << port_name << "_;" << be_nl
          << "TAO_SYNCH_MUTEX " << port_name << "_lock_;"
          << be_nl << be_nl;

      os_ << "typedef ACE_Array_Map<ptrdiff_t," << be_nl
          << "                      ::Components::EventConsumerBase_var>"
          << be_idt_nl
          << tao_cg->upcase (port_name)
          << "_GENERIC_TABLE;" << be_uidt_nl
          << tao_cg->upcase (port_name)
          << "_GENERIC_TABLE ciao_publishes_"
          << port_name << "_generic_;";
    }
}

void
be_visitor_component_svh::gen_consumes (AST_Consumes *c)
{
  const char *obj_name = c->consumes_type ()->full_name ();
  const char *port_name = c->local_name ()->get_string ();

  ACE_CString holder (obj_name);
  ACE_CString::size_type pos = holder.rfind (':');
  const char *ev_lname = 0;

  if (pos == ACE_CString::npos)
    {
      ev_lname = obj_name;
    }
  else
    {
      holder = holder.substr (pos + 1);
      ev_lname = holder.c_str ();
    }

  os_ << be_uidt_nl << be_nl
      << "public:" << be_idt_nl;

  os_ << "// Servant class for the " << port_name
      << " consumer." << be_nl
      << "class " << export_macro_.c_str () << " " << ev_lname
      << "Consumer_" << port_name << "_Servant" << be_idt_nl
      << ": public virtual ::POA_" << obj_name << "Consumer"
      << be_uidt_nl
      << "{" << be_nl
      << "public:" << be_idt_nl;

  ACE_CString sname_str (
    ScopeAsDecl (node_->defined_in ())->full_name ());
  const char *sname = sname_str.c_str ();
  const char *lname = node_->local_name ();
  const char *global = (sname_str == "" ? "" : "::");

  os_ << ev_lname << "Consumer_" << port_name
      << "_Servant (" << be_idt_nl
      << global << sname << "::CCM_" << lname
      << "_ptr executor," << be_nl
      << global << sname << "::CCM_" << lname
      << "_Context_ptr c);" << be_uidt_nl << be_nl;

  os_ << "virtual ~" << ev_lname << "Consumer_" << port_name
      << "_Servant (void);";

  os_ << be_nl << be_nl
      << "virtual void" << be_nl
      << "push_" << ev_lname << " (" << be_idt_nl
      << "::" << obj_name << " * evt);" << be_uidt;

  os_ << be_nl << be_nl
      << "// Inherited from ::Components::EventConsumerBase." << be_nl
      << "virtual void" << be_nl
      << "push_event ( ::Components::EventBase * ev);";

  os_ << be_nl << be_nl
      << "// CIAO-specific in ::Components::EventConsumerBase." << be_nl
      << "virtual void" << be_nl
      << "ciao_push_event ( ::Components::EventBase * ev," << be_nl
      << "                 const char * source_id," << be_nl
      << "                 ::CORBA::TypeCode_ptr tc);";

  os_ << be_nl << be_nl
      << "// CIAO-specific in ::Components::EventConsumerBase." << be_nl
      << "virtual ::CORBA::Boolean" << be_nl
      << "ciao_is_substitutable (const char * event_repo_id);";

  os_ << be_nl << be_nl
      << "// Get component implementation." << be_nl
      << "virtual ::CORBA::Object_ptr" << be_nl
      << "_get_component (void);";

  os_ << be_uidt_nl << be_nl
      << "protected:" << be_idt_nl;

  os_ << global << sname << "::CCM_" << lname << "_var" << be_nl
      << "executor_;";

  os_ << be_nl << be_nl
      << global << sname << "::CCM_"
      << lname << "_Context_var" << be_nl
      << "ctx_;";

  os_ << be_uidt_nl
      << "};";

  os_ << be_nl << be_nl
      << "virtual ::" << obj_name << "Consumer_ptr" << be_nl
      << "get_consumer_" << port_name << " (void);";

  os_ << be_uidt_nl << be_nl
      << "private:" << be_idt_nl;

  os_ << "::Components::EventConsumerBase_ptr" << be_nl
      << "get_consumer_" << port_name << "_i (void);";

  os_ << be_uidt_nl << be_nl
      << "private:" << be_idt_nl;

  os_ << "::" << obj_name << "Consumer_var" << be_nl
      << "consumes_" << port_name << "_;";
}

void
be_visitor_component_svh::gen_emits (AST_Emits *e,
                                     bool in_servant)
{
  const char *obj_name = e->emits_type ()->full_name ();
  const char *port_name = e->local_name ()->get_string ();

  if (in_servant)
    {
      os_ << be_nl << be_nl;
    }
  else
    {
      os_ << be_uidt_nl << be_nl
          << "public:" << be_idt_nl;

      os_ << "virtual void" << be_nl
          << "push_" << port_name << " (" << be_idt_nl
          << "::" << obj_name << " * ev);" << be_uidt;

      os_ << be_uidt_nl << be_nl
          << "protected:" << be_idt_nl;
    }

  os_ << "virtual void" << be_nl
      << "connect_" << port_name << " (" << be_idt_nl
      << "::" << obj_name << "Consumer_ptr c);" << be_uidt;

  os_ << be_nl << be_nl
      << "virtual ::" << obj_name << "Consumer_ptr" << be_nl
      << "disconnect_" << port_name << " (void);";

  if (!in_servant)
    {
      os_ << be_uidt_nl << be_nl
          << "protected:" << be_idt_nl
          << "::" << obj_name << "Consumer_var" << be_nl
          << "ciao_emits_" << port_name << "_consumer_;";
    }
}

void
be_visitor_component_svh::gen_non_type_specific (void)
{
  os_ << be_nl << be_nl
      << "// Base class overrides.";

  os_ << be_uidt_nl << be_nl
      << "public:" << be_idt_nl
      << "virtual ::Components::Cookie *" << be_nl
      << "connect (const char * name," << be_nl
      << "         ::CORBA::Object_ptr connection);";

  os_ << be_nl << be_nl
      << "virtual ::CORBA::Object_ptr" << be_nl
      << "disconnect (const char * name," << be_nl
      << "            ::Components::Cookie * ck);";

  os_ << be_nl << be_nl
      << "virtual ::Components::ReceptacleDescriptions *" << be_nl
      << "get_all_receptacles (void);";

  os_ << be_nl << be_nl
      << "virtual ::Components::Cookie *" << be_nl
      << "subscribe (const char * publisher_name," << be_nl
      << "           ::Components::EventConsumerBase_ptr subscriber);";

  os_ << be_nl << be_nl
      << "virtual ::Components::EventConsumerBase_ptr" << be_nl
      << "unsubscribe (const char * publisher_name," << be_nl
      << "             ::Components::Cookie * ck);";

  os_ << be_nl << be_nl
      << "virtual void" << be_nl
      << "connect_consumer (const char * emitter_name," << be_nl
      << "                  ::Components::EventConsumerBase_ptr consumer);";

  os_ << be_nl << be_nl
      << "virtual ::Components::EventConsumerBase_ptr" << be_nl
      << "disconnect_consumer (const char * source_name);";

  os_ << be_nl << be_nl
      << "virtual ::Components::PublisherDescriptions *" << be_nl
      << "get_all_publishers (void);";

  os_ << be_nl << be_nl
      << "virtual ::Components::EmitterDescriptions *" << be_nl
      << "get_all_emitters (void);";

  os_ << be_nl << be_nl
      << "// CIAO-specific." << be_nl
      << "::CORBA::Object_ptr" << be_nl
      << "get_facet_executor (const char * name);";

  os_ << be_uidt_nl << be_nl
      << "private:" << be_idt_nl
      << "void" << be_nl
      << "populate_port_tables (void);";

  os_ << be_uidt_nl << be_nl
      << "private:" << be_idt_nl
      << "const char * ins_name_;";
}

void
be_visitor_component_svh::gen_entrypoint (void)
{
  os_ << be_nl << be_nl
      << "extern \"C\" " << export_macro_.c_str ()
      << " ::PortableServer::Servant" << be_nl
      << "create_" << node_->flat_name ()
      << "_Servant (" << be_idt_nl
      << "::Components::EnterpriseComponent_ptr p," << be_nl
      << "::CIAO::Container_ptr c," << be_nl
      << "const char * ins_name);" << be_uidt;
}