summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_connector/executor_ami_exs.cpp
blob: 9747958a30f4bae737048cffddbd757a39e9c2d0 (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

//=============================================================================
/**
 *  @file    executor_ami_exs.cpp
 *
 *  $Id$
 *
 *  Visitor generating code for executors in the AMI connector
 *  impl source.
 *
 *
 *  @author Jeff Parsons
 */
//=============================================================================
be_visitor_executor_ami_exs::be_visitor_executor_ami_exs (
      be_visitor_context *ctx)
  : be_visitor_component_scope (ctx)
{
}

be_visitor_executor_ami_exs::~be_visitor_executor_ami_exs (void)
{
}

int
be_visitor_executor_ami_exs::visit_connector (be_connector *node)
{
  node_ = node;

  const char *suffix = "_exec_i";
  AST_Decl *scope = ScopeAsDecl (node->defined_in ());
  ACE_CString class_name_str (scope->local_name ()->get_string ());
  class_name_str += suffix;
  const char *class_name = class_name_str.c_str ();

  os_ << be_nl_2
      << class_name << "::"
      << class_name << " (void)" << be_idt_nl;

  /// The port is the only item in the connector's scope.
  UTL_ScopeActiveIterator j (node, UTL_Scope::IK_decls);
  AST_Extended_Port *p =
    AST_Extended_Port::narrow_from_decl (j.item ());

  bool first = true;
  int port_nr = 0;
  for (UTL_ScopeActiveIterator i (p->port_type (), UTL_Scope::IK_decls);
       !i.is_done ();
       i.next ())
    {
      AST_Decl *d = i.item ();
      AST_Provides *p = AST_Provides::narrow_from_decl (d);

      if (p != 0)
        {
          if (first)
            {
             os_  << ": facet_exec_" << port_nr << "_ (new ";
             os_ << p->provides_type ()->local_name ();
             os_ << suffix << " ())" << be_nl;
             first = false;
            }
          else
            {
             os_  << ", facet_exec_" << port_nr << "_ (new ";
             os_ << p->provides_type ()->local_name ();
             os_ << suffix << " ())" << be_uidt_nl;
            }
          port_nr++;
        }
    }

  os_ << "{" << be_nl
      << "}";

  os_ << be_nl_2
      << class_name << "::~"
      << class_name << " (void)" << be_nl
      << "{" << be_idt_nl;
  for (int i = 0; i < port_nr; i ++)
    {
      os_ << "::CORBA::release (this->facet_exec_" << i <<"_);" << be_nl;
    }
  os_ << be_uidt_nl
      << "}";

  if (this->visit_scope (node) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("be_visitor_executor_ami_exs::")
                         ACE_TEXT ("visit_connector - ")
                         ACE_TEXT ("visit_scope() failed\n")),
                        -1);
    }

  const char *container_type = be_global->ciao_container_type ();

  os_ << be_nl_2
      << "void" << be_nl
      << class_name << "::set_"
      << tao_cg->downcase (container_type)
      << "_context (" << be_idt_nl
      << "::Components::" << be_global->ciao_container_type ()
      << "Context_ptr ctx)"
      << be_uidt_nl
      << "{" << be_idt_nl;
   for (int i = 0; i < port_nr; i ++)
    {
      os_ << "this->facet_exec_" << i << "_->set_"
      << tao_cg->downcase (container_type)
      << "_context "
      << "(ctx);" << be_nl;
   }
   os_  << be_uidt_nl << "}";

  os_ << be_nl_2
      << "void" << be_nl
      << class_name << "::configuration_complete (void)" << be_nl
      << "{" << be_idt_nl;
   for (int i = 0; i < port_nr; i ++)
    {
      os_ << "this->facet_exec_" << i << "_->_set_component (this);" << be_nl;
    }
  os_ << be_uidt_nl << "}";

  os_ << be_nl_2
      << "void" << be_nl
      << class_name << "::ccm_activate (void)" << be_nl
      << "{" << be_nl
      << "}";

  os_ << be_nl_2
      << "void" << be_nl
      << class_name << "::ccm_passivate (void)" << be_nl
      << "{" << be_nl
      << "}";

  AST_Decl *s = ScopeAsDecl (this->node_->defined_in ());
  bool is_global =
   (s->node_type () == AST_Decl::NT_root);
  const char *smart_scope = (is_global ? "" : "::");

  os_ << be_nl_2
      << "void" << be_nl
      << class_name << "::ccm_remove (void)" << be_nl
      << "{" << be_idt_nl;
   for (int i = 0; i < port_nr; i ++)
    {
      os_ << "this->facet_exec_" << i <<"_->_set_component (" << be_idt_nl
      << "::" << s->name () << smart_scope
      << "CCM_" << this->node_->local_name ()
      << "::_nil ());" << be_uidt_nl;
   }
  os_ << be_uidt_nl << "}";

  return 0;
}

int
be_visitor_executor_ami_exs::visit_provides (be_provides *node)
{
  AST_Type *t = node->provides_type ();
   AST_Decl *scope = ScopeAsDecl (t->defined_in ());
  bool global = (scope->node_type () == AST_Decl::NT_root);
  const char *smart_scope = (global ? "" : "::");

  os_ << be_nl_2
      << smart_scope << scope->full_name () << "::CCM_"
      << t->local_name () << "_ptr" << be_nl
      << ScopeAsDecl (this->node_->defined_in ())->local_name ()
      << "_exec_i::get_";

  /// The port is the only thing in the connector's scope, and
  /// we need to insert its name into the operation name.
  UTL_ScopeActiveIterator i (this->node_, UTL_Scope::IK_decls);
  AST_Decl *d = i.item ();

  const char * loc_name = node->local_name()->get_string();
  const char *exec_ext = (strstr (loc_name, "sync") ? "1" : "0");

    os_ << d->local_name () << "_"
      << node->local_name () << " (void)" << be_nl
      << "{" << be_idt_nl
      << "return "
      << smart_scope << scope->full_name () << "::CCM_" << t->local_name () << "::_duplicate ("
      << "this->facet_exec_" << exec_ext << "_);" << be_uidt_nl
      << "}";

  return 0;
}