summaryrefslogtreecommitdiff
path: root/modules/TAO/TAO_IDL/be/be_visitor_home/home_svh.cpp
blob: c6c3118fb0bf878ba8544c280fbaf59144d61a48 (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
//
// $Id$
//

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

// ******************************************************
// Home visitor for server header
// ******************************************************

be_visitor_home_svh::be_visitor_home_svh (be_visitor_context *ctx)
  : be_visitor_scope (ctx),
    node_ (0),
    comp_ (0),
    os_ (*ctx->stream ()),
    export_macro_ (be_global->svnt_export_macro ())
{
  /// 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_home_svh::~be_visitor_home_svh (void)
{
}

int
be_visitor_home_svh::visit_home (be_home *node)
{
  if (node->imported ())
    {
      return 0;
    }
    
  node_ = node;
  comp_ = node_->managed_component ();
  
  /// CIDL-generated namespace used 'CIDL_' + composition name.
  /// Now we use 'CIAO_' + component's flat name.
  os_ << be_nl << be_nl
      << "namespace CIAO_" << comp_->flat_name () << "_Impl" << be_nl
      << "{" << be_idt;
     
  if (this->gen_servant_class () == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("be_visitor_home_svh::")
                         ACE_TEXT ("visit_home - ")
                         ACE_TEXT ("gen_servant_class() failed\n")),
                        -1);
    }
    
  this->gen_entrypoint ();

  os_ << be_uidt_nl
      << "}";
     
  return 0;
}

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

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

int
be_visitor_home_svh::visit_factory (be_factory *node)
{
  os_ << be_nl << be_nl
      << "virtual ::" << comp_->name () << "_ptr" << be_nl
      << node->local_name ();
      
  // We can reuse this visitor.
  be_visitor_valuetype_init_arglist_ch v (this->ctx_);
  
  if (v.visit_factory (node) != 0)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("be_visitor_home_svh::")
                         ACE_TEXT ("visit_factory - ")
                         ACE_TEXT ("codegen for argument ")
                         ACE_TEXT ("list failed\n")),
                        -1);
    }
    
  os_ << ";";
    
  return 0;
}

int
be_visitor_home_svh::visit_finder (be_finder *node)
{
  return this->visit_factory (node);
}

int
be_visitor_home_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 *clname = comp_->local_name ()->get_string ();
  const char *global = (sname_str == "" ? "" : "::");
  bool swapping = be_global->gen_component_swapping ();
  
  os_ << be_nl
      << "class " << export_macro_.c_str () << " " << lname
      << "_Servant" << be_idt_nl
      << ": public virtual" << be_idt << be_idt_nl
      << "::CIAO::"
      << (swapping ? "Swapping_" : "")
      << "Home_Servant_Impl<" << be_idt_nl
      << "::" << node_->full_skel_name () << "," << be_nl
      << global << sname << "::CCM_" << lname << "," << be_nl
      << clname << "_Servant>"
      << be_uidt << be_uidt << be_uidt << be_uidt_nl
      << "{" << be_nl
      << "public:" << be_idt_nl;
      
  os_ << lname << "_Servant (" << be_idt_nl
      << global << sname << "::CCM_" << lname << "_ptr exe," << be_nl
      << "const char * ins_name," << be_nl
      << "::CIAO::Container_ptr c);" << be_uidt;
      
  os_ << be_nl << be_nl
      << "virtual ~" << lname << "_Servant (void);";
      
  AST_Type *pk = node_->primary_key ();
  
  if (pk != 0)
    {
      os_ << be_nl << be_nl
          << "// Implicit home primary key operations - not supported.";
          
      os_ << be_nl << be_nl
          << "virtual ::" << comp_->name () << "_ptr" << be_nl
          << "create (" << be_idt_nl
          << "::" << pk->name () << " * key);" << be_uidt;
          
      os_ << be_nl << be_nl
          << "virtual ::" << comp_->name () << "_ptr" << be_nl
          << "find_by_primary_key (" << be_idt_nl
          << "::" << pk->name () << " * key);" << be_uidt;
          
      os_ << be_nl << be_nl
          << "virtual void" << be_nl
          << "remove (" << be_idt_nl
          << "::" << pk->name () << " * key);" << be_uidt;
          
      os_ << be_nl << be_nl
          << "virtual ::" << pk->name () << " *" << be_nl
          << "get_primary_key (" << be_idt_nl
          << "::" << comp_->name () << "_ptr comp);" << be_uidt;
    }
    
  be_home *h = node_;
  
  while (h != 0)
    {
      if (this->visit_scope (h) != 0)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT ("be_visitor_home_svh::")
                             ACE_TEXT ("gen_servant_class - ")
                             ACE_TEXT ("visit_scope() failed\n")),
                            -1);
        }
        
      for (long i = 0; i < h->n_inherits (); ++i)
        {
          // A closure of all the supported interfaces is stored
          // in the base class 'pd_inherits_flat' member.
          be_interface *bi =
            be_interface::narrow_from_decl (h->inherits ()[i]);
   
          int status =
            bi->traverse_inheritance_graph (
              be_visitor_home_svh::op_attr_decl_helper,
              &os_);
              
          if (status == -1)
            {
              ACE_ERROR_RETURN ((LM_ERROR,
                                 ACE_TEXT ("be_visitor_home_svh::")
                                 ACE_TEXT ("gen_servant_class - ")
                                 ACE_TEXT ("traverse_inheritance_graph() ")
                                 ACE_TEXT ("failed for %s\n"),
                                 bi->full_name ()),
                                -1);
            }
        }  
        
      h = be_home::narrow_from_decl (h->base_home ());
    }

  os_ << be_uidt_nl
      << "};";
     
  return 0;
}

void
be_visitor_home_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::HomeExecutorBase_ptr p," << be_nl
      << "::CIAO::Container_ptr c," << be_nl
      << "const char * ins_name);" << be_uidt; 
}

int
be_visitor_home_svh::op_attr_decl_helper (be_interface * /* derived */,
                                          be_interface *ancestor,
                                          TAO_OutStream *os)
{
  /// We're in a static method, so we have to instantiate a temporary
  /// visitor and context.
  be_visitor_context ctx;
  ctx.state (TAO_CodeGen::TAO_ROOT_SVH);
  ctx.stream (os);
  be_visitor_home_svh visitor (&ctx);
  
  /// Since this visitor overriddes only visit_operation() and 
  /// visit_attribute(), we can get away with this for the declarations.
  return visitor.visit_scope (ancestor);
}