summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_interface/interface_sh.cpp
blob: 62b52961f6c3224a25cc1dd76608d481e467d8a6 (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
//
// $Id$
//

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    interface_sh.cpp
//
// = DESCRIPTION
//    Visitor generating code for Interfaces in the server header
//
// = AUTHOR
//    Aniruddha Gokhale
//
// ============================================================================

#include	"idl.h"
#include	"idl_extern.h"
#include	"be.h"

#include "be_visitor_interface.h"

ACE_RCSID(be_visitor_interface, interface_sh, "$Id$")


// ************************************************************
// Interface visitor for server header
// ************************************************************

be_visitor_interface_sh::be_visitor_interface_sh (be_visitor_context *ctx)
  : be_visitor_interface (ctx)
{
}

be_visitor_interface_sh::~be_visitor_interface_sh (void)
{
}

int
be_visitor_interface_sh::visit_interface (be_interface *node)
{
  TAO_OutStream *os; // output stream
  long i; // loop index
  static char namebuf [NAMEBUFSIZE]; // holds the class name

  if (node->srv_hdr_gen () || node->imported ())
    return 0;

  ACE_OS::memset (namebuf, '\0', NAMEBUFSIZE);

  os = this->ctx_->stream ();

  // generate the skeleton class name

  os->indent (); // start with whatever indentation level we are at

  // we shall have a POA_ prefix only if we are at the topmost level
  if (!node->is_nested ())
    {
      // we are outermost
      ACE_OS::sprintf (namebuf, "POA_%s", node->local_name ()->get_string ());
    }
  else
    {
      ACE_OS::sprintf (namebuf, "%s", node->local_name ()->get_string ());
    }

  *os << "class " << namebuf << ";" << be_nl;

  // generate the _ptr declaration
  *os << "typedef " << namebuf << " *" << namebuf
      << "_ptr;" << be_nl;

  // now generate the class definition
  *os << "class " << idl_global->export_macro ()
      << " " << namebuf << " : ";
  if (node->n_inherits () > 0)
    {
      // this interface inherits from other interfaces
      be_interface *intf; // inherited interface

      *os << "public virtual ";
      intf = be_interface::narrow_from_decl (node->inherits ()[0]);
      *os << intf->relative_skel_name (node->full_skel_name ());
      for (i = 1; i < node->n_inherits (); i++)
        {
          *os << ", public virtual ";
          intf = be_interface::narrow_from_decl (node->inherits ()[i]);
          *os << intf->relative_skel_name (node->full_skel_name ());
        }  // end of for loop
    }
  else
    {
      // We don't inherit from another user defined object, hence our
      // base class is the ServantBase class.
      *os << " public virtual PortableServer::ServantBase";
    }
  *os << be_nl
      << "{" << be_nl
      << "protected:" << be_idt_nl
      << namebuf << " (void);" << be_uidt_nl
      << "public:" << be_idt_nl
      << namebuf << " (" << namebuf << "& rhs);" << be_nl
      << "virtual ~" << namebuf << " (void);" << be_nl;

  *os << "virtual CORBA::Boolean _is_a (" << be_idt << be_idt_nl
      << "const char* logical_type_id," << be_nl
      << "CORBA::Environment &_tao_environment = " << be_idt_nl
      << "CORBA::Environment::default_environment ()"
      << be_uidt << be_uidt_nl
      << ");" << be_uidt_nl;

  *os << "virtual void* _downcast (" << be_idt << be_idt_nl
      << "const char* logical_type_id" << be_uidt_nl
      << ");\n" << be_uidt;

  // generate code for elements in the scope (e.g., operations)
  if (this->visit_scope (node) ==  -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "be_visitor_interface_sh::"
                         "visit_interface - "
                         "codegen for scope failed\n"),
                        -1);
    }
  // add a skeleton for our _is_a method
  os->indent ();
  *os << "static void _is_a_skel (" << be_idt << be_idt_nl
      << "CORBA::ServerRequest &req," << be_nl
      << "void *obj," << be_nl
      << "void *context," << be_nl
      << "CORBA::Environment &_tao_enviroment = " << be_idt_nl
      << "CORBA::Environment::default_environment ()"
      << be_uidt << be_uidt_nl
      << ");" << be_uidt << "\n\n";

  // add a skeleton for our _non_existent method
  os->indent ();
  *os << "static void _non_existent_skel (" << be_idt << be_idt_nl
      << "CORBA::ServerRequest &req," << be_nl
      << "void *obj," << be_nl
      << "void *context," << be_nl
      << "CORBA::Environment &_tao_enviroment = " << be_idt_nl
      << "CORBA::Environment::default_environment ()"
      << be_uidt << be_uidt_nl
      << ");" << be_uidt << "\n\n";

  // add a method that says whether we are involved in a multiple inheritance
  // or not
  os->indent ();
  *os << "CORBA::Boolean in_mult_inheritance (void);\n\n";

  // generate skeletons for operations of our base classes. These skeletons
  // just cast the pointer to the appropriate type before invoking the call
  if (node->traverse_inheritance_graph (be_interface::gen_skel_helper, os) == -1)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "be_visitor_interface_sh::"
                         "visit_interface - "
                         "inheritance graph traversal failed\n"),
                        -1);
    }

  // add the dispatch method
  os->indent ();
  *os << "virtual void _dispatch (" << be_idt << be_idt_nl
      << "CORBA::ServerRequest &_tao_req," << be_nl
      << "void *_tao_context," << be_nl
      << "CORBA::Environment &_tao_env = " << be_idt_nl
      << "CORBA::Environment::default_environment ()"
      << be_uidt << be_uidt_nl
      << ");" << be_uidt << "\n\n";

  // Print out the _this() method.
  os->indent ();
  *os << node->name () << " *_this (" << be_idt << be_idt_nl
      << "CORBA::Environment &_tao_environment = " << be_idt_nl
      << "CORBA::Environment::default_environment ()"
      << be_uidt << be_uidt_nl
      << ");" << be_uidt << "\n";

  // the _interface_repository_id method
  os->indent ();
  *os << "virtual const char* _interface_repository_id (void) const;\n";
  os->decr_indent ();

  *os << "};\n\n";

  // generate the collocated class
  be_visitor_context ctx (*this->ctx_);
  ctx.state (TAO_CodeGen::TAO_INTERFACE_COLLOCATED_SH);
  be_visitor *visitor = tao_cg->make_visitor (&ctx);
  if (!visitor || (node->accept (visitor) == -1))
    {
      delete visitor;
      ACE_ERROR_RETURN ((LM_ERROR,
                         "be_visitor_interface_sh::"
                         "visit_interface - "
                         "codegen for collocated class failed\n"),
                        -1);
    }

  // generate the TIE class
  ctx = *this->ctx_;
  ctx.state (TAO_CodeGen::TAO_INTERFACE_TIE_SH);
  visitor = tao_cg->make_visitor (&ctx);
  if (!visitor || (node->accept (visitor) == -1))
    {
      delete visitor;
      ACE_ERROR_RETURN ((LM_ERROR,
                         "be_visitor_interface_sh::"
                         "visit_interface - "
                         "codegen for TIE class failed\n"),
                        -1);
    }

  *os << "\n";
  ctx.stream (tao_cg->server_template_header ());

  return 0;
}