summaryrefslogtreecommitdiff
path: root/TAO/tao/IFR_Client/IFR_Client_Adapter_Impl.cpp
blob: 4c4336104d030e71325c9f6b81b9500b8ed18a0b (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
// $Id$

#include "IFR_Client_Adapter_Impl.h"
#include "IFR_ExtendedC.h"
#include "tao/ORB_Core.h"
#include "tao/Invocation_Adapter.h"
#include "tao/Stub.h"
#include "tao/NVList.h"

ACE_RCSID (IFR_Client,
           IFR_Client_Adapter_Impl,
           "$Id$")

namespace TAO
{
  ACE_TEMPLATE_SPECIALIZATION
  class TAO_IFR_Client_Export Arg_Traits<CORBA::InterfaceDef>
    : public
        Object_Arg_Traits_T<
            CORBA::InterfaceDef_ptr,
            CORBA::InterfaceDef_var,
            CORBA::InterfaceDef_out,
            TAO::Objref_Traits<CORBA::InterfaceDef>
          >
  {
  };
}

TAO_IFR_Client_Adapter_Impl::~TAO_IFR_Client_Adapter_Impl (void)
{
}

CORBA::Boolean
TAO_IFR_Client_Adapter_Impl::interfacedef_cdr_insert (
    TAO_OutputCDR &cdr,
    CORBA::InterfaceDef_ptr object_type
  )
{
  return cdr << object_type;
}

void
TAO_IFR_Client_Adapter_Impl::interfacedef_any_insert (
    CORBA::Any &any,
    CORBA::InterfaceDef_ptr object_type
  )
{
  any <<= object_type;
}

void
TAO_IFR_Client_Adapter_Impl::dispose (
    CORBA::InterfaceDef_ptr orphan
  )
{
  CORBA::release (orphan);
}

CORBA::InterfaceDef_ptr
TAO_IFR_Client_Adapter_Impl::get_interface (
    CORBA::ORB_ptr orb,
    const char *repo_id
    ACE_ENV_ARG_DECL
  )
{
  CORBA::Object_var obj =
    orb->resolve_initial_references ("InterfaceRepository"
                                     ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (CORBA::InterfaceDef::_nil ());

  if (CORBA::is_nil (obj.in ()))
    {
      ACE_THROW_RETURN (CORBA::INTF_REPOS (),
                        CORBA::InterfaceDef::_nil ());
    }

  CORBA::Repository_var repo =
    CORBA::Repository::_narrow (obj.in ()
                                ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (CORBA::InterfaceDef::_nil ());

  if (CORBA::is_nil (repo.in ()))
    {
      ACE_THROW_RETURN (CORBA::INTF_REPOS (),
                        CORBA::InterfaceDef::_nil ());
    }

  CORBA::Contained_var result = repo->lookup_id (repo_id
                                                 ACE_ENV_ARG_PARAMETER);
  ACE_CHECK_RETURN (CORBA::InterfaceDef::_nil ());

  if (CORBA::is_nil (result.in ()))
    {
      return CORBA::InterfaceDef::_nil ();
    }
  else
    {
      return CORBA::InterfaceDef::_narrow (result.in ()
                                           ACE_ENV_ARG_PARAMETER);
    }
}

CORBA::InterfaceDef_ptr
TAO_IFR_Client_Adapter_Impl::get_interface_remote (
    CORBA::Object_ptr target
    ACE_ENV_ARG_DECL
  )
{
  TAO::Arg_Traits<CORBA::InterfaceDef>::ret_val _tao_retval;

  TAO::Argument *_tao_signature [] =
    {
      &_tao_retval
    };

  TAO::Invocation_Adapter _tao_call (
      target,
      _tao_signature,
      1,
      "_interface",
      10,
      0
    );

  ACE_TRY
    {
      _tao_call.invoke (0, 0 ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK (_tao_retval.excp ());
    }
  ACE_CATCH (CORBA::OBJECT_NOT_EXIST, ex)
    {
      return CORBA::InterfaceDef::_nil ();
    }
  ACE_CATCHANY
    {
      ACE_RE_THROW;
    }
  ACE_ENDTRY;

  return _tao_retval.retn ();
}

void
TAO_IFR_Client_Adapter_Impl::create_operation_list (
    CORBA::ORB_ptr orb,
    CORBA::OperationDef_ptr opDef,
    CORBA::NVList_ptr& result
    ACE_ENV_ARG_DECL
  )
{
   // Create an empty NVList.
   //
   orb->create_list (0, result);

   // Get the parameters (if any) from the OperationDef, and for each
   // parameter add a corresponding entry to the result.
   //
   CORBA::ParDescriptionSeq* params = opDef->params();
   CORBA::ULong paramCount = params->length();
   if (paramCount > 0)
   {
      for (CORBA::ULong i = 0; i < paramCount; i++)
      {
         CORBA::ParameterDescription* param = &((*params)[i]);

         // Get name.
         //
         char* name = CORBA::string_dup (param->name);

         // Create an any using the parameter's TypeCode.
         //
         CORBA::Any* value;
         ACE_NEW_THROW_EX (value,
                           CORBA::Any (),
                           CORBA::NO_MEMORY (
                           CORBA::SystemException::_tao_minor_code (
                               TAO_DEFAULT_MINOR_CODE,
                               ENOMEM),
                              CORBA::COMPLETED_NO));
         ACE_CHECK;

         value->_tao_set_typecode ((param->type).in());

         // Get mode.
         //
         CORBA::Flags flags;
         switch (param->mode)
         {
         case CORBA::PARAM_IN:
            flags = CORBA::ARG_IN;
            break;
         case CORBA::PARAM_OUT:
            flags = CORBA::ARG_OUT;
            break;
         case CORBA::PARAM_INOUT:
            flags = CORBA::ARG_INOUT;
            break;
         default:
            // Shouldn't happen.
            //
            ACE_THROW (CORBA::INTERNAL());
            break;
         }

         // Add an argument to the result list. The list takes ownership
         // of name and value.
         //
         result->add_value_consume (name, value, flags);
      }
   }

}

// *********************************************************************

// Initialization and registration of dynamic service object.

int
TAO_IFR_Client_Adapter_Impl::Initializer (void)
{
  TAO_ORB_Core::ifr_client_adapter_name ("Concrete_IFR_Client_Adapter");

  return ACE_Service_Config::process_directive (ace_svc_desc_TAO_IFR_Client_Adapter_Impl);
}

ACE_STATIC_SVC_DEFINE (
    TAO_IFR_Client_Adapter_Impl,
    ACE_TEXT ("Concrete_IFR_Client_Adapter"),
    ACE_SVC_OBJ_T,
    &ACE_SVC_NAME (TAO_IFR_Client_Adapter_Impl),
    ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
    0
  )

ACE_FACTORY_DEFINE (TAO_IFR_Client, TAO_IFR_Client_Adapter_Impl)