summaryrefslogtreecommitdiff
path: root/TAO/tao/svrrqst.cpp
blob: 0533726f88365b660fbc1dcf19c97fccfefbef31 (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
// @(#)svrrqst.cpp	1.9 95/11/04
// Copyright 1994-1995 by Sun Microsystems Inc.
// All Rights Reserved
//
// Implementation of the Dynamic Server Skeleton Interface

#include "tao/corba.h"

// {77420086-F276-11ce-9598-0000C07CA898}
DEFINE_GUID (IID_IIOP_ServerRequest,
0x77420086, 0xf276, 0x11ce, 0x95, 0x98, 0x0, 0x0, 0xc0, 0x7c, 0xa8, 0x98);

// {4B48D881-F7F0-11ce-9598-0000C07CA898}
DEFINE_GUID (IID_CORBA_ServerRequest,
0x4b48d881, 0xf7f0, 0x11ce, 0x95, 0x98, 0x0, 0x0, 0xc0, 0x7c, 0xa8, 0x98);

IIOP_ServerRequest::IIOP_ServerRequest (CDR *msg,
                                        CORBA::ORB_ptr the_orb,
                                        CORBA::POA_ptr the_poa)
  : incoming_ (msg),
    params_ (0), 
    retval_ (0),
    exception_ (0),
    ex_type_ (CORBA::NO_EXCEPTION),
    refcount_ (1),
    orb_ (the_orb),
    poa_ (the_poa)
{
}

IIOP_ServerRequest::~IIOP_ServerRequest (void)
{
  ACE_ASSERT (refcount_ == 0);

  if (params_)
    CORBA::release (params_);
  if (retval_)
    delete retval_;
  if (exception_)
    delete exception_;
}

ULONG __stdcall
IIOP_ServerRequest::AddRef (void)
{
  ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, guard, lock_, 0));

  ACE_ASSERT (refcount_ > 0);
  return refcount_++;
}

ULONG __stdcall
IIOP_ServerRequest::Release (void)
{
  {
    ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, mon, this->lock_, 0));

    ACE_ASSERT (this != 0);

    if (--refcount_ != 0)
      return refcount_;
  }

  delete this;
  return 0;
}

HRESULT __stdcall
IIOP_ServerRequest::QueryInterface (REFIID riid,
				    void **ppv)
{
  ACE_ASSERT (refcount_ > 0);
  *ppv = 0;

  if (IID_IIOP_ServerRequest == riid
      || IID_CORBA_ServerRequest == riid
      || IID_IUnknown == riid)
    *ppv = this;

  if (*ppv == 0)
    return ResultFromScode (E_NOINTERFACE);

 (void) AddRef ();
  return NOERROR;
}

// Unmarshal in/inout params, and set up to marshal the appropriate
// inout/out/return values later on.

void __stdcall
IIOP_ServerRequest::params (CORBA::NVList_ptr list,
			    CORBA::Environment &env)
{
  env.clear ();

  // Save params for later use when marshaling the reply.
  this->params_ = list;

  // Then unmarshal each "in" and "inout" parameter.
  for (u_int i = 0; i < list->count (); i++)
    {
      CORBA::NamedValue_ptr nv = list->item (i);

      if (ACE_BIT_DISABLED (nv->flags (), CORBA::ARG_IN | CORBA::ARG_INOUT))
	continue;

      // First, make sure the memory into which we'll be unmarshaling
      // exists, and is the right size.
      //
      // NOTE: desirable to have a way to let the dynamic
      // implementation routine preallocate this data, for
      // environments where DSI is just being used in lieu of a
      // language mapped server-side API and the size is really
      // knowable in advance.

      CORBA::Any_ptr any = nv->value ();
      CORBA::TypeCode_ptr tc = any->type ();

      tc->AddRef ();

      void *value;
      if (!any->value ())
        { // not preallocated
          ACE_NEW (value, char [tc->size (env)]);

          any->replace (tc, value, CORBA::B_TRUE, env);

          // Decrement the refcount of "tc".
          //
          // The earlier AddRef is needed since Any::replace () releases
          // the typecode inside the Any.  Without the dup, the reference
          // count can go to zero, and the typecode would then be deleted.
          //
          // This Release ensures that the reference count is correct so
          // the typecode can be deleted some other time.

          tc->Release ();
        }
      else
        value = (void *)any->value ();

      // Then just unmarshal the value.
      (void) incoming_->decode (tc, value, 0, env);
    }

  // If any data is left over, it'd be context values ... else error.
  // We don't support context values, so it's always an error.

  if (incoming_->bytes_remaining () != 0)
    {
      dmsg1 ("params (), %d bytes remaining (error)",
	     incoming_->bytes_remaining ());
      env.exception (new CORBA::BAD_PARAM (CORBA::COMPLETED_NO));
    }
}

// Store the result value.  There's either an exception, or a result,
// but not both of them.  Results (and exceptions) can be reported
// only after the parameter list has been provided (maybe empty).

void __stdcall
IIOP_ServerRequest::result (CORBA::Any_ptr value,
			    CORBA::Environment &env)
{
  env.clear ();

  if (!params_ || retval_ || exception_)
    env.exception (new CORBA::BAD_INV_ORDER (CORBA::COMPLETED_NO));
  else
    retval_ = value;

  // XXX send the message now!
}

// Store the exception value.

void __stdcall
IIOP_ServerRequest::exception (CORBA::ExceptionType type,
			       CORBA::Any_ptr value,
			       CORBA::Environment &env)
{
  if (!params_ || retval_ || exception_)
    env.exception (new CORBA::BAD_INV_ORDER (CORBA::COMPLETED_NO));
  else
    {
      env.clear ();
      exception_ = value;
      ex_type_ = type;
    }

  // XXX send the message now!
}

// Invocation attributes.

CORBA::String __stdcall
IIOP_ServerRequest::op_name (void)
{
  return opname_;
}

CORBA::Object_ptr __stdcall
IIOP_ServerRequest::target (void)
{
  // XXX implement me!!  Code from TCP_OA exists ...
  return 0;
}

CORBA::Principal_ptr __stdcall
IIOP_ServerRequest::caller (void)
{
  // XXX ... return client's principal
  return 0;
}

CORBA::ORB_ptr __stdcall
IIOP_ServerRequest::orb (void)
{
  return orb_;
}

CORBA::POA_ptr __stdcall
IIOP_ServerRequest::oa (void)
{
  return poa_;
}