summaryrefslogtreecommitdiff
path: root/TAO/TAO_IDL/be/be_visitor_operation/upcall_command_ss.cpp
blob: e948c012ca460962cc8fcb3f63f8efb29d022a4b (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
// $Id$

// ============================================================================
//
// = LIBRARY
//    TAO IDL
//
// = FILENAME
//    upcall_command_ss.cpp
//
// = DESCRIPTION
//    Visitor that generates operation-specific TAO::Upcall_Command
//    objects in skeletons.
//
// = AUTHOR
//    Ossama Othman
//
// ============================================================================


ACE_RCSID (be_visitor_operation,
           upcall_command_ss,
           "$Id$")


be_visitor_operation_upcall_command_ss
::be_visitor_operation_upcall_command_ss (
    be_visitor_context *ctx)
  : be_visitor_operation (ctx)
{
}

be_visitor_operation_upcall_command_ss
::~be_visitor_operation_upcall_command_ss (void)
{
}

int
be_visitor_operation_upcall_command_ss::visit_operation (be_operation * node)
{
  TAO_OutStream & os = *this->ctx_->stream ();

  be_visitor_context ctx (*this->ctx_);

  // save the node.
  this->ctx_->node (node);

  os << be_nl << be_nl << "// TAO_IDL - Generated from" << be_nl
     << "// " << __FILE__ << ":" << __LINE__ << be_nl << be_nl;

  // Generate the operation-specific TAO::Upcall_Command concrete class.

  be_interface * const intf = this->ctx_->attribute ()
    ? be_interface::narrow_from_scope (this->ctx_->attribute ()->defined_in ())
    : be_interface::narrow_from_scope (node->defined_in ());

  if (!intf)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "(%N:%l) be_visitor_upcall_command_ss::"
                         "visit_operation - "
                         "bad interface scope\n"),
                        -1);
    }

  // Generate an operation-specific concrete TAO::Upcall_Command
  // class, an instance of which will be invoked by the
  // TAO::Upcall_Wrapper object.

  os << "class Upcall_Command" << be_nl
     << "  : public TAO::Upcall_Command" << be_nl
     << "{" << be_nl
     << "public:" << be_idt_nl << be_nl;

  // Generate constructor
  os << "inline Upcall_Command (" << be_idt_nl
     << intf->full_skel_name () << " * servant";

  // No need to accept an argument array parameter if the operation
  // has no arguments.
  if (!node->void_return_type () || node->argument_count () > 0)
    {
      os << "," << be_nl
         << "TAO::Argument * const args[])" << be_nl;
    }
  else
    {
      os << ")" << be_nl;
    }

  os << ": servant_ (servant)";

  // If the operation has no arguments don't generate a member
  // initializer for the class argument array member/attribute.
  if (!node->void_return_type () || node->argument_count () > 0)
    {
      os << be_nl
         << ", args_ (args)";
    }

  os << be_uidt_nl;

  os << "{" << be_nl
     << "}" << be_nl << be_nl;

  // Generate execute() method.
  os << "virtual void execute (ACE_ENV_SINGLE_ARG_DECL)" << be_nl
     << "{" << be_idt_nl;

  if (!node->void_return_type ())
    {
      os << "static_cast<TAO::SArg_Traits< ";

      this->gen_arg_template_param_name (node,
                                         node->return_type (),
                                         &os);

      os << ">::ret_base *> (this->args_[0])->arg () =" << be_idt_nl;
    }

  if (this->gen_upcall (node) == -1)
    {
      return -1;
    }

  if (!node->void_return_type ())
    {
      os << be_uidt;
    }

  os << be_nl
     << "ACE_CHECK;" << be_uidt_nl
     << "}" << be_uidt_nl << be_nl;

  // Prevent copying/assignment and generation of default copy
  // constructor and assignment operator.
  os << "private:" << be_idt_nl << be_nl
     << "Upcall_Command ("
     << "Upcall_Command const &);" << be_nl
     << "void operator= (Upcall_Command const &);"
     << be_uidt_nl << be_nl;

  // Generate class attributes.
  os << "private:" << be_idt_nl << be_nl
     << intf->full_skel_name () << " * const servant_;";

  // Don't bother generating an argument array attribute if the
  // operation has no arguments.
  if (!node->void_return_type () || node->argument_count () > 0)
    {
      os << be_nl
         << "TAO::Argument * const * const args_;";
    }

  os << be_uidt_nl
     << "};" << be_nl;

  return 0;
}

int
be_visitor_operation_upcall_command_ss::gen_upcall (be_operation * node)
{
  // @@ Based on
  //    be_visitor_operation_thru_poa_proxy_impl_ss::gen_invoke().

  TAO_OutStream & os = *this->ctx_->stream ();

  os << "this->servant_->" << node->local_name () << " ("
      << be_idt;

  UTL_ScopeActiveIterator si (node,
                              UTL_Scope::IK_decls);

  if (si.is_done ())
    {
      os << be_nl
         << "ACE_ENV_SINGLE_ARG_PARAMETER" << be_uidt_nl
         << ");";

      return 0;
    }

  int index = 1;

  for (; !si.is_done (); si.next (), ++index)
    {
      AST_Argument * const arg =
        AST_Argument::narrow_from_decl (si.item ());

      os << (index == 1 ? "" : ",") << be_nl
         << "static_cast<TAO::SArg_Traits< ";

      this->gen_arg_template_param_name (arg,
                                         arg->field_type (),
                                         &os);

      os << ">::";

      switch (arg->direction ())
        {
        case AST_Argument::dir_IN:
          os << "in";
          break;
        case AST_Argument::dir_INOUT:
          os << "inout";
          break;
        case AST_Argument::dir_OUT:
          os << "out";
        default:
          break;
        }

      os << "_arg_base *> (this->args_[" << index << "])->arg ()";
    }

  // End the upcall
  os << be_nl
     << "ACE_ENV_ARG_PARAMETER" << be_uidt_nl
     << ");";

  return 0;
}