summaryrefslogtreecommitdiff
path: root/TAO/IIOP/lib/runtime/request.cpp
blob: 2143603ae2cc4a69a2c901b9affcaad566bbe472 (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
// @(#)request.cpp	1.6 95/09/24
// Copyright 1994-1995 by Sun Microsystems Inc.
// All Rights Reserved
//
// Implementation of Dynamic Invocation Interface
//
#include	<corba/orb.hh>
#include	<corba/stub.hh>

#include        <initguid.h>

#include	"runtime/debug.hh"
#include	"runtime/cdr.hh"
#include	"runtime/thread.hh"


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

#ifdef	_POSIX_THREADS
static pthread_mutex_t	refcnt_lock = PTHREAD_MUTEX_INITIALIZER;
#endif	// _POSIX_THREADS

 
ULONG
__stdcall
CORBA_Request::AddRef ()
{
#ifdef  _POSIX_THREADS
    Critical            region (&refcnt_lock);
#endif
 
    return _refcount++;
}
 
ULONG
__stdcall
CORBA_Request::Release ()
{
#ifdef  _POSIX_THREADS
    Critical            region (&refcnt_lock);
#endif
 
    assert (this != 0);
 
    if (--_refcount != 0)
        return _refcount;

    delete this;
    return 0;
}
 
HRESULT
__stdcall
CORBA_Request::QueryInterface (
    REFIID      riid,
    void        **ppv
)
{
    *ppv = 0;
 
    if (IID_CORBA_Request == riid || IID_IUnknown == riid)
        *ppv = this;
 
    if (*ppv == 0)
        return ResultFromScode (E_NOINTERFACE);
 
    (void) AddRef ();
    return NOERROR;
}

//
// Reference counting for DII Request object
//
void
CORBA_release (CORBA_Request_ptr req)
{
    if (req)
        req->Release ();
}

CORBA_Boolean
CORBA_is_nil (CORBA_Request_ptr req)
{
    return (CORBA_Boolean)(req == 0);
}

//
// DII Request class implementation
//
CORBA_Request::CORBA_Request (
    CORBA_Object_ptr	    obj,
    const CORBA_Char        *op,
    CORBA_NVList_ptr        args,
    CORBA_NamedValue_ptr    result,
    CORBA_Flags             flags
) :
    _args   	    	    (args),
    _result 	    	    (result),
    _flags  	    	    (flags),
    _refcount	    	    (1)
{
    _target = CORBA_Object::_duplicate (obj);
    _opname = CORBA_string_copy (op);
}


CORBA_Request::CORBA_Request (
    CORBA_Object_ptr		obj,
    const CORBA_Char		*op
) :
    _flags			(0),
    _refcount			(1)
{
    _target = CORBA_Object::_duplicate (obj);
    _opname = CORBA_string_copy (op);

    _args = new CORBA_NVList;
    _result = new CORBA_NamedValue;
}

CORBA_Request::~CORBA_Request ()
{
    assert (_refcount == 0);

    CORBA_release (_target);
    CORBA_string_free ((CORBA_String)_opname);
    CORBA_release (_args);
    CORBA_release (_result);
}

//
// The public DII interfaces:  normal and oneway calls.
//
// NOTE that using DII, programmers can get the special behaviour of
// discarding the response for normal calls.  This doesn't change the
// semantics of any OMG-IDL interface, it just streamlines control flow
// in some exotic situations.
//
void
CORBA_Request::invoke ()
{
    STUB_Object     *stub;

    if (_target->QueryInterface (IID_STUB_Object, (void **) &stub) != NOERROR) {
        _env.exception (new CORBA_DATA_CONVERSION (COMPLETED_NO));
	return;
    }

    stub->do_dynamic_call ((char *)_opname, CORBA_B_TRUE,
                            _args, _result, _flags, _exceptions, _env);
    stub->Release ();
}

void
CORBA_Request::send_oneway ()
{
    STUB_Object     *stub;

    if (_target->QueryInterface (IID_STUB_Object, (void **) &stub) != NOERROR) {
        _env.exception (new CORBA_DATA_CONVERSION (COMPLETED_NO));
	return;
    }
    stub->do_dynamic_call ((char *)_opname, CORBA_B_TRUE,
                            _args, _result, _flags, _exceptions, _env);
    stub->Release ();
}