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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
// @(#)orbobj.cpp 1.8 95/09/24
// Copyright 1994-1995 by Sun Microsystems Inc.
// All Rights Reserved
//
// ORB: CORBA::ORB operations
//
// XXX as with TOA, this has a strong coupling to the Internet ORB (IIOP)
// code. We should make it know less about that protocol component and
// have a loose table-driven coupling to ORB/protocol library components.
//
#include <assert.h>
#include <limits.h>
#include <signal.h>
#include <string.h>
#include <orb.hh>
#include <stub.hh>
#include "debug.hh"
#include "iioporb.hh" // XXX
#include <initguid.h>
extern void __TC_init_table ();
extern void __TC_init_standard_exceptions (CORBA_Environment &env);
#if defined (SIG_IGN_BROKEN)
# undef SIG_IGN
# define SIG_IGN ((RETSIGTYPE (*)(int))1)
#endif // NeXT
//
// Constructor and destructor are accessible to subclasses
//
CORBA_ORB::CORBA_ORB ()
{
_refcount = 1;
}
CORBA_ORB::~CORBA_ORB ()
{
assert (_refcount == 0);
}
//
// CORBA dup/release build on top of COM's (why not).
//
void
CORBA_release (
CORBA_ORB_ptr obj
)
{
if (obj)
obj->Release ();
}
CORBA_ORB_ptr
CORBA_ORB::_duplicate (CORBA_ORB_ptr obj)
{
if (obj)
obj->AddRef ();
return obj;
}
//
// Null pointers represent nil objects.
//
CORBA_ORB_ptr
CORBA_ORB::_nil ()
{
return 0;
}
CORBA_Boolean
CORBA_is_nil (CORBA_ORB_ptr obj)
{
return (CORBA_Boolean) (obj == 0);
}
//
// COM's IUnknown support
//
// {A201E4C6-F258-11ce-9598-0000C07CA898}
DEFINE_GUID (IID_CORBA_ORB,
0xa201e4c6, 0xf258, 0x11ce, 0x95, 0x98, 0x0, 0x0, 0xc0, 0x7c, 0xa8, 0x98);
#if 0
// {A201E4C7-F258-11ce-9598-0000C07CA898}
DEFINE_GUID (IID_STUB_Object,
0xa201e4c7, 0xf258, 0x11ce, 0x95, 0x98, 0x0, 0x0, 0xc0, 0x7c, 0xa8, 0x98);
#endif
ULONG
__stdcall
CORBA_ORB::AddRef ()
{
ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0);
return _refcount++;
}
ULONG
__stdcall
CORBA_ORB::Release ()
{
ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock_, 0);
assert (this != 0);
if (--_refcount != 0)
return _refcount;
guard.release();
delete this;
return 0;
}
//
// ORB initialisation, per OMG document 94-9-46.
//
// XXX in addition to the "built in" Internet ORB, there will be ORBs which
// are added separately, e.g. through a DLL listed in the registry. Registry
// will be used to assign orb names and to establish which is the default.
//
static CORBA_ORB_ptr the_orb;
CORBA_ORB_ptr
CORBA_ORB_init (
int &, // argc
char *const *, // argv
char *orb_name,
CORBA_Environment &env
)
{
static ACE_Thread_Mutex lock;
ACE_GUARD_RETURN(ACE_Thread_Mutex, guard, lock, 0);
env.clear ();
//
// Initialising is done only once.
//
// XXX Applications that can't tell if they've initialized (e.g.
// some library modules) must check for a particular error and ignore
// it if they get it. We need a minor code to indicate this case.
// In general, one-time initialization is suboptimal.
//
// XXX We also need to enable initialising more than one ORB!!
//
if (the_orb)
{
env.exception (new CORBA_INITIALIZE (COMPLETED_NO));
return 0;
}
//
// Verify some of the basic implementation requirements. This test
// gets optimized away by a decent compiler (or else the rest of the
// routine does).
//
// NOTE: we still "just" assume that native floating point is IEEE.
//
if (sizeof (CORBA_Short) != 2
|| sizeof (CORBA_Long) != 4
|| sizeof (CORBA_LongLong) != 8
|| sizeof (CORBA_Float) != 4
|| sizeof (CORBA_Double) != 8
|| sizeof (CORBA_LongDouble) != 16
|| sizeof (CORBA_WChar) < 2
|| sizeof (void *) != SIZEOF_VOID_P
)
{
env.exception (new CORBA_INITIALIZE (COMPLETED_NO));
return 0;
}
//
// ignoring argc, argv for now -- no arguments we care about
//
// XXX should remove any of the "-ORB*" arguments that we know
// about ... and report errors for the rest.
//
#ifdef DEBUG
//
// Make it a little easier to debug programs using this code.
//
{
char *value = ACE_OS::getenv ("ORB_DEBUG");
if (value != 0) {
debug_level = ACE_OS::atoi (value);
if (debug_level <= 0)
debug_level = 1;
dmsg1 ("debug_level == %d", debug_level);
}
}
#endif // DEBUG
//
// On Win32, we should be collecting information from the Registry
// such as what ORBs are configured, specific configuration details
// like whether they generate IOR or URL style stringified objrefs
// and which addresses they listen to (e.g. allowing multihomed
// hosts to implement firewalls), user-meaningful orb names (they
// will normally indicate domains), and more.
//
// On UNIX, we should collect that from some private config file.
//
// Instead, this just treats the "internet" ORB name specially and
// makes it always use URL-style stringified objrefs, where the
// hostname and TCP port number are explicit (and the whole objref
// is readable by mortals).
//
CORBA_Boolean use_ior;
if (orb_name != 0 && ACE_OS::strcmp (orb_name, "internet") == 0)
use_ior = CORBA_B_FALSE;
else
use_ior = CORBA_B_TRUE;
#ifdef SIGPIPE
//
// Impractical to have each call to the ORB protect against the
// implementation artifact of potential writes to dead connections,
// as it'd be way expensive. Do it here; who cares about SIGPIPE
// in these kinds of applications, anyway?
//
(void) ACE_OS::signal (SIGPIPE, SIG_IGN);
#endif // SIGPIPE
#if defined(ACE_INVALID_HANDLE)
ACE_OS::socket_init(ACE_WSOCK_VERSION);
#elif defined (_WINSOCKAPI_)
//
// winsock needs explicit initialization, and applications must manage
// versioning problems directly.
//
WSADATA wsadata;
if (WSAStartup (MAKEWORD (1, 1), &wsadata) != 0)
{
dsockerr ("WSAStartup");
env.exception (new CORBA_INITIALIZE (COMPLETED_NO));
return 0;
}
if (LOBYTE (wsadata.wVersion) != 1 || HIBYTE (wsadata.wVersion != 1))
{
dmsg2 ("bad winsock version %d.%d",
HIBYTE (wsadata.wVersion), LOBYTE (wsadata.wVersion));
env.exception (new CORBA_INITIALIZE (COMPLETED_NO));
return 0;
}
#endif // _WINSOCKAPI_
//
// Call various internal initialization routines.
//
__TC_init_table ();
__TC_init_standard_exceptions (env);
if (env.exception () != 0)
return 0;
//
// Inititalize the "ORB" pseudo-object now.
//
the_orb = new IIOP_ORB (use_ior);
return the_orb;
}
void
CORBA_ORB::create_list (
CORBA_Long count,
CORBA_NVList_ptr &retval
)
{
assert (count <= UINT_MAX);
retval = new CORBA_NVList;
if (count != 0) {
retval->_len = 0;
retval->_max = (unsigned) count;
retval->_values = (CORBA_NamedValue_ptr) calloc ((unsigned) count,
sizeof (CORBA_NamedValue));
}
}
//
// This is a server-side internal routine; it's not available to any
// portable code except method code, which moreover may not access the
// state variable directly since its implemention may differ between ORBs.
//
// XXX it's server-side so should be OA-specific and not in this module
//
CORBA_ORB_ptr
_orb ()
{
return the_orb;
}
|