sedna 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/{CHANGES → CHANGES.rdoc} +9 -0
- data/{README → README.rdoc} +23 -25
- data/Rakefile +32 -9
- data/ext/{extconf.rb → sedna/extconf.rb} +33 -21
- data/ext/{sedna.c → sedna/sedna.c} +48 -40
- data/test/sedna_test.rb +9 -9
- data/vendor/sedna/AUTHORS +18 -0
- data/vendor/sedna/COPYRIGHT +90 -0
- data/vendor/sedna/LICENSE +202 -0
- data/vendor/sedna/Makefile.include +423 -0
- data/vendor/sedna/Makefile.platform +31 -0
- data/vendor/sedna/depend.sed +48 -0
- data/vendor/sedna/driver/c/Makefile +98 -0
- data/vendor/sedna/driver/c/libsedna.c +1998 -0
- data/vendor/sedna/driver/c/libsedna.h +199 -0
- data/vendor/sedna/driver/c/sednamt.def +21 -0
- data/vendor/sedna/driver/c/sp_defs.h +186 -0
- data/vendor/sedna/kernel/common/FastXptrHash.cpp +101 -0
- data/vendor/sedna/kernel/common/IntHash.h +314 -0
- data/vendor/sedna/kernel/common/IntList.h +224 -0
- data/vendor/sedna/kernel/common/Makefile +30 -0
- data/vendor/sedna/kernel/common/SSMMsg.cpp +459 -0
- data/vendor/sedna/kernel/common/SSMMsg.h +142 -0
- data/vendor/sedna/kernel/common/XptrHash.h +435 -0
- data/vendor/sedna/kernel/common/argtable.c +972 -0
- data/vendor/sedna/kernel/common/argtable.h +896 -0
- data/vendor/sedna/kernel/common/base.cpp +339 -0
- data/vendor/sedna/kernel/common/base.h +226 -0
- data/vendor/sedna/kernel/common/bit_set.cpp +157 -0
- data/vendor/sedna/kernel/common/bit_set.h +55 -0
- data/vendor/sedna/kernel/common/commutil.h +67 -0
- data/vendor/sedna/kernel/common/config.h +62 -0
- data/vendor/sedna/kernel/common/counted_ptr.h +74 -0
- data/vendor/sedna/kernel/common/errdbg/ErrorCodes.java +1056 -0
- data/vendor/sedna/kernel/common/errdbg/Makefile +34 -0
- data/vendor/sedna/kernel/common/errdbg/assert.c +133 -0
- data/vendor/sedna/kernel/common/errdbg/d_printf.c +150 -0
- data/vendor/sedna/kernel/common/errdbg/d_printf.h +91 -0
- data/vendor/sedna/kernel/common/errdbg/error.codes +1743 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes.c +531 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes.h +549 -0
- data/vendor/sedna/kernel/common/errdbg/error_codes_scm.scm +527 -0
- data/vendor/sedna/kernel/common/errdbg/event_log.c +956 -0
- data/vendor/sedna/kernel/common/errdbg/event_log.h +226 -0
- data/vendor/sedna/kernel/common/errdbg/exceptions.cpp +155 -0
- data/vendor/sedna/kernel/common/errdbg/exceptions.h +559 -0
- data/vendor/sedna/kernel/common/errdbg/gen_error_codes +0 -0
- data/vendor/sedna/kernel/common/errdbg/gen_error_codes.c +345 -0
- data/vendor/sedna/kernel/common/gmm.cpp +192 -0
- data/vendor/sedna/kernel/common/gmm.h +29 -0
- data/vendor/sedna/kernel/common/ipc_ops.cpp +435 -0
- data/vendor/sedna/kernel/common/ipc_ops.h +51 -0
- data/vendor/sedna/kernel/common/lfsGlobals.h +12 -0
- data/vendor/sedna/kernel/common/lm_base.h +90 -0
- data/vendor/sedna/kernel/common/mmgr/Makefile +11 -0
- data/vendor/sedna/kernel/common/mmgr/aset.c +1185 -0
- data/vendor/sedna/kernel/common/mmgr/mcxt.c +741 -0
- data/vendor/sedna/kernel/common/mmgr/memnodes.h +70 -0
- data/vendor/sedna/kernel/common/mmgr/memutils.h +145 -0
- data/vendor/sedna/kernel/common/mmgr/se_alloc.h +321 -0
- data/vendor/sedna/kernel/common/mmgr/track.c +214 -0
- data/vendor/sedna/kernel/common/pping.cpp +672 -0
- data/vendor/sedna/kernel/common/pping.h +119 -0
- data/vendor/sedna/kernel/common/rcv_test.cpp +273 -0
- data/vendor/sedna/kernel/common/rcv_test.h +19 -0
- data/vendor/sedna/kernel/common/sedna.c +128 -0
- data/vendor/sedna/kernel/common/sedna.h +49 -0
- data/vendor/sedna/kernel/common/sedna_ef.h +52 -0
- data/vendor/sedna/kernel/common/sm_vmm_data.h +144 -0
- data/vendor/sedna/kernel/common/sp.c +93 -0
- data/vendor/sedna/kernel/common/sp.h +36 -0
- data/vendor/sedna/kernel/common/st/Makefile +20 -0
- data/vendor/sedna/kernel/common/st/os_linux/stacktrace.c +213 -0
- data/vendor/sedna/kernel/common/st/os_nt/stacktrace.c +338 -0
- data/vendor/sedna/kernel/common/st/os_other/stacktrace.c +39 -0
- data/vendor/sedna/kernel/common/st/stacktrace.h +72 -0
- data/vendor/sedna/kernel/common/st/stacktrfmt.c +64 -0
- data/vendor/sedna/kernel/common/tr_debug.cpp +112 -0
- data/vendor/sedna/kernel/common/tr_debug.h +22 -0
- data/vendor/sedna/kernel/common/u/Makefile +14 -0
- data/vendor/sedna/kernel/common/u/u.c +268 -0
- data/vendor/sedna/kernel/common/u/u.h +715 -0
- data/vendor/sedna/kernel/common/u/uatomic.h +12 -0
- data/vendor/sedna/kernel/common/u/udl.h +31 -0
- data/vendor/sedna/kernel/common/u/uevent.c +406 -0
- data/vendor/sedna/kernel/common/u/uevent.h +71 -0
- data/vendor/sedna/kernel/common/u/ugnames.cpp +330 -0
- data/vendor/sedna/kernel/common/u/ugnames.h +134 -0
- data/vendor/sedna/kernel/common/u/uhash_map.h +77 -0
- data/vendor/sedna/kernel/common/u/uhdd.c +1018 -0
- data/vendor/sedna/kernel/common/u/uhdd.h +206 -0
- data/vendor/sedna/kernel/common/u/ummap.cpp +268 -0
- data/vendor/sedna/kernel/common/u/ummap.h +60 -0
- data/vendor/sedna/kernel/common/u/umutex.c +145 -0
- data/vendor/sedna/kernel/common/u/umutex.h +65 -0
- data/vendor/sedna/kernel/common/u/upipe.cpp +244 -0
- data/vendor/sedna/kernel/common/u/upipe.h +74 -0
- data/vendor/sedna/kernel/common/u/uprocess.c +767 -0
- data/vendor/sedna/kernel/common/u/uprocess.h +91 -0
- data/vendor/sedna/kernel/common/u/usafesync.h +41 -0
- data/vendor/sedna/kernel/common/u/usecurity.c +150 -0
- data/vendor/sedna/kernel/common/u/usecurity.h +55 -0
- data/vendor/sedna/kernel/common/u/usem.c +891 -0
- data/vendor/sedna/kernel/common/u/usem.h +83 -0
- data/vendor/sedna/kernel/common/u/ushm.c +222 -0
- data/vendor/sedna/kernel/common/u/ushm.h +46 -0
- data/vendor/sedna/kernel/common/u/usocket.c +541 -0
- data/vendor/sedna/kernel/common/u/usocket.h +118 -0
- data/vendor/sedna/kernel/common/u/usystem.c +57 -0
- data/vendor/sedna/kernel/common/u/usystem.h +46 -0
- data/vendor/sedna/kernel/common/u/uthread.c +259 -0
- data/vendor/sedna/kernel/common/u/uthread.h +95 -0
- data/vendor/sedna/kernel/common/u/utime.c +65 -0
- data/vendor/sedna/kernel/common/u/utime.h +40 -0
- data/vendor/sedna/kernel/common/u/uutils.c +142 -0
- data/vendor/sedna/kernel/common/u/uutils.h +65 -0
- data/vendor/sedna/kernel/common/ugc.cpp +156 -0
- data/vendor/sedna/kernel/common/ugc.h +15 -0
- data/vendor/sedna/kernel/common/utils.cpp +156 -0
- data/vendor/sedna/kernel/common/utils.h +133 -0
- data/vendor/sedna/kernel/common/version.c +16 -0
- data/vendor/sedna/kernel/common/version.h +21 -0
- data/vendor/sedna/kernel/common/wustructures.h +18 -0
- data/vendor/sedna/kernel/common/wutypes.h +34 -0
- data/vendor/sedna/kernel/common/xptr.cpp +17 -0
- data/vendor/sedna/kernel/common/xptr.h +211 -0
- data/vendor/sedna/ver +1 -0
- metadata +142 -14
@@ -0,0 +1,71 @@
|
|
1
|
+
/*
|
2
|
+
* File: uevent.h
|
3
|
+
* Copyright (C) 2008 The Institute for System Programming of the Russian Academy of Sciences (ISP RAS)
|
4
|
+
*/
|
5
|
+
|
6
|
+
#if (_MSC_VER>1000)
|
7
|
+
#pragma once
|
8
|
+
#endif
|
9
|
+
|
10
|
+
#ifndef UEVENT_H_INCLUDED
|
11
|
+
#define UEVENT_H_INCLUDED
|
12
|
+
|
13
|
+
#include "common/u/u.h"
|
14
|
+
#include "common/u/usecurity.h"
|
15
|
+
|
16
|
+
#define U_AUTORESET_EVENT 99
|
17
|
+
#define U_MANUALRESET_EVENT 17
|
18
|
+
|
19
|
+
typedef struct UEvent_tag_
|
20
|
+
{
|
21
|
+
#ifdef __cplusplus
|
22
|
+
private:
|
23
|
+
#endif
|
24
|
+
#ifdef _WIN32
|
25
|
+
HANDLE handle;
|
26
|
+
#else
|
27
|
+
int semid;
|
28
|
+
#endif
|
29
|
+
}
|
30
|
+
UEvent;
|
31
|
+
|
32
|
+
#ifdef __cplusplus
|
33
|
+
extern "C" {
|
34
|
+
#endif
|
35
|
+
|
36
|
+
|
37
|
+
int UEventUnlink(global_name gn,
|
38
|
+
sys_call_error_fun fun);
|
39
|
+
|
40
|
+
int UEventCreate(UEvent *uEvent,
|
41
|
+
USECURITY_ATTRIBUTES* sa,
|
42
|
+
int eventType,
|
43
|
+
int isSet,
|
44
|
+
global_name gn,
|
45
|
+
sys_call_error_fun fun);
|
46
|
+
|
47
|
+
int UEventOpen(UEvent *uEvent,
|
48
|
+
global_name gn,
|
49
|
+
sys_call_error_fun fun);
|
50
|
+
|
51
|
+
int UEventClose(UEvent *uEvent,
|
52
|
+
sys_call_error_fun fun);
|
53
|
+
|
54
|
+
int UEventCloseAndUnlink(UEvent *uEvent,
|
55
|
+
sys_call_error_fun fun);
|
56
|
+
|
57
|
+
int UEventSet(UEvent *uEvent,
|
58
|
+
sys_call_error_fun fun);
|
59
|
+
|
60
|
+
int UEventReset(UEvent *uEvent,
|
61
|
+
sys_call_error_fun fun);
|
62
|
+
|
63
|
+
int UEventWait(UEvent *uEvent,
|
64
|
+
sys_call_error_fun fun);
|
65
|
+
|
66
|
+
#ifdef __cplusplus
|
67
|
+
}
|
68
|
+
#endif
|
69
|
+
|
70
|
+
|
71
|
+
#endif
|
@@ -0,0 +1,330 @@
|
|
1
|
+
#include <stdlib.h>
|
2
|
+
#include <string.h>
|
3
|
+
#include <stdio.h>
|
4
|
+
#include <assert.h>
|
5
|
+
#include "common/errdbg/exceptions.h"
|
6
|
+
#include "ugnames.h"
|
7
|
+
|
8
|
+
/* {% globals */
|
9
|
+
|
10
|
+
static UGlobalNamesRegistryItem *registry = NULL;
|
11
|
+
static UGlobalNamesRegistrySearchProc searchProc = NULL;
|
12
|
+
|
13
|
+
/* }% */
|
14
|
+
|
15
|
+
#ifdef _WIN32
|
16
|
+
#define IPC_PRIVATE 0
|
17
|
+
#ifndef snprintf
|
18
|
+
#define snprintf _snprintf
|
19
|
+
#endif
|
20
|
+
#else
|
21
|
+
#include <sys/types.h>
|
22
|
+
#include <sys/ipc.h>
|
23
|
+
#endif
|
24
|
+
|
25
|
+
void
|
26
|
+
UReleaseGlobalNamesRegistry()
|
27
|
+
{
|
28
|
+
registry = NULL;
|
29
|
+
searchProc = NULL;
|
30
|
+
}
|
31
|
+
|
32
|
+
static
|
33
|
+
const UGlobalNamesRegistryItem *
|
34
|
+
SearchGlobalNamesRegistry(const UGlobalNamesRegistryItem *registry,
|
35
|
+
const char *basename)
|
36
|
+
{
|
37
|
+
assert(registry);
|
38
|
+
while (registry->basename && 0!=strcmp(registry->basename,basename)) ++registry;
|
39
|
+
return registry->basename ? registry : NULL;
|
40
|
+
}
|
41
|
+
|
42
|
+
static void ThrowSystemException(const char *msg)
|
43
|
+
{
|
44
|
+
throw SYSTEM_EXCEPTION(msg);
|
45
|
+
}
|
46
|
+
|
47
|
+
static int ValidateBaseName(const char *baseName)
|
48
|
+
{
|
49
|
+
/* TODO: implement validation */
|
50
|
+
return 1;
|
51
|
+
}
|
52
|
+
|
53
|
+
static int ValidateGlobalName(const char *globalName)
|
54
|
+
{
|
55
|
+
/* TODO: implement validation */
|
56
|
+
return 1;
|
57
|
+
}
|
58
|
+
|
59
|
+
static int ValidateCompoundName(const char *compoundName)
|
60
|
+
{
|
61
|
+
/* TODO: implement validation */
|
62
|
+
return 1;
|
63
|
+
}
|
64
|
+
|
65
|
+
void
|
66
|
+
UInitGlobalNamesRegistry(UGlobalNamesRegistryItem *registryParam,
|
67
|
+
UGlobalNamesRegistrySearchProc searchProcParam,
|
68
|
+
int rangeBegin,
|
69
|
+
int rangeEnd)
|
70
|
+
{
|
71
|
+
int rangeSizeMin = 0;
|
72
|
+
UGlobalNamesRegistryItem *i = NULL;
|
73
|
+
char errorBuf[128];
|
74
|
+
|
75
|
+
assert(registryParam);
|
76
|
+
/* first let's estimate the required range size */
|
77
|
+
for (i = registryParam; i->basename; ++i)
|
78
|
+
{
|
79
|
+
if (!ValidateBaseName(i->basename) || i->nObjectsMax<1 || (i->prefix==NULL && i->nObjectsMax > 1))
|
80
|
+
{
|
81
|
+
snprintf(errorBuf, sizeof errorBuf,
|
82
|
+
"UInitGlobalNamesRegistry: bad item '%s'", i->basename);
|
83
|
+
errorBuf[(sizeof errorBuf)-1]=0;
|
84
|
+
ThrowSystemException(errorBuf);
|
85
|
+
}
|
86
|
+
rangeSizeMin+=i->nObjectsMax;
|
87
|
+
}
|
88
|
+
registry = registryParam;
|
89
|
+
/* check if the passed range is ok */
|
90
|
+
if (rangeEnd - rangeBegin < rangeSizeMin)
|
91
|
+
ThrowSystemException("InitGlobalNamesRegistry: range too small");
|
92
|
+
/* now initialize per-entry ranges */
|
93
|
+
for (i = registry; i->basename; ++i)
|
94
|
+
{
|
95
|
+
i->rangeBegin = rangeBegin;
|
96
|
+
rangeBegin = i->rangeEnd = rangeBegin + i->nObjectsMax;
|
97
|
+
}
|
98
|
+
/* complete initialization */
|
99
|
+
searchProc = (searchProcParam ? searchProcParam : SearchGlobalNamesRegistry);
|
100
|
+
}
|
101
|
+
|
102
|
+
const char *
|
103
|
+
UCreateGlobalName(const char *basename,
|
104
|
+
int objectId,
|
105
|
+
char *buf,
|
106
|
+
size_t bufSize)
|
107
|
+
{
|
108
|
+
char prefix[32] = "", errorBuf[128];
|
109
|
+
int ordinal = 0;
|
110
|
+
const UGlobalNamesRegistryItem *item = NULL;
|
111
|
+
size_t stored = 0;
|
112
|
+
|
113
|
+
assert (basename);
|
114
|
+
item = searchProc(registry, basename);
|
115
|
+
if (!item)
|
116
|
+
{
|
117
|
+
snprintf(errorBuf, sizeof errorBuf, "CreateGlobalName: '%s' not found", basename);
|
118
|
+
errorBuf[(sizeof errorBuf)-1]=0;
|
119
|
+
ThrowSystemException(errorBuf);
|
120
|
+
}
|
121
|
+
ordinal = item->rangeBegin + objectId;
|
122
|
+
if (item->prefix)
|
123
|
+
{
|
124
|
+
stored = snprintf(prefix, sizeof prefix, "%s%d.", item->prefix, objectId);
|
125
|
+
if (stored<0 || stored>=(sizeof prefix))
|
126
|
+
ThrowSystemException("UCreateGlobalName: prefix too long");
|
127
|
+
}
|
128
|
+
if (ordinal >= item->rangeEnd || ordinal < item->rangeBegin)
|
129
|
+
ThrowSystemException("CreateGlobalName: generated ordinal out of range");
|
130
|
+
|
131
|
+
stored = snprintf(buf, bufSize, "SEDNA%d.%s%s@%d", registry->rangeBegin, prefix, basename, ordinal);
|
132
|
+
if (stored<0 || stored>=bufSize)
|
133
|
+
ThrowSystemException("CreateGlobalName: buffer too small");
|
134
|
+
|
135
|
+
return buf;
|
136
|
+
}
|
137
|
+
|
138
|
+
struct GlobalNameComponents
|
139
|
+
{
|
140
|
+
const char *strNameBegin, *strNameEnd;
|
141
|
+
int base, ordinal;
|
142
|
+
};
|
143
|
+
|
144
|
+
static
|
145
|
+
void ParseGlobalName(GlobalNameComponents *components,
|
146
|
+
const char *globalName)
|
147
|
+
{
|
148
|
+
assert(components);
|
149
|
+
if (globalName==NULL)
|
150
|
+
{
|
151
|
+
components->strNameBegin = NULL;
|
152
|
+
components->strNameEnd = NULL;
|
153
|
+
components->base = 0;
|
154
|
+
components->ordinal = 0;
|
155
|
+
}
|
156
|
+
else
|
157
|
+
{
|
158
|
+
const char *sep = NULL;
|
159
|
+
char *tail = NULL;
|
160
|
+
int ordinal = 0, base = 0;
|
161
|
+
|
162
|
+
sep = strchr(globalName,'@');
|
163
|
+
if (sep==NULL || (ordinal=strtol(sep+1,&tail,10), *tail!='\0'))
|
164
|
+
{
|
165
|
+
ThrowSystemException("ParseGlobalName: bad global name syntax");
|
166
|
+
}
|
167
|
+
components->strNameBegin = globalName;
|
168
|
+
components->strNameEnd = sep;
|
169
|
+
components->base = base;
|
170
|
+
components->ordinal = ordinal;
|
171
|
+
}
|
172
|
+
}
|
173
|
+
|
174
|
+
static
|
175
|
+
const char *StrNameFromGlobalName(const char *globalName,
|
176
|
+
size_t limit,
|
177
|
+
const char *prefix,
|
178
|
+
char *buf,
|
179
|
+
size_t bufSize)
|
180
|
+
{
|
181
|
+
char bufjr[16];
|
182
|
+
size_t partSz = 0, stored = 0;
|
183
|
+
GlobalNameComponents components = {NULL};
|
184
|
+
|
185
|
+
assert(prefix);
|
186
|
+
ParseGlobalName(&components,globalName);
|
187
|
+
if (globalName == NULL)
|
188
|
+
{
|
189
|
+
buf = NULL;
|
190
|
+
}
|
191
|
+
else
|
192
|
+
{
|
193
|
+
partSz = (size_t)(components.strNameEnd - components.strNameBegin);
|
194
|
+
stored = snprintf(buf, bufSize, "%s%.*s", prefix, partSz, components.strNameBegin);
|
195
|
+
if (stored<0 || stored>=bufSize)
|
196
|
+
ThrowSystemException("StrNameFromGlobalName: buffer too small");
|
197
|
+
if (limit>0 && stored>limit)
|
198
|
+
{
|
199
|
+
stored = snprintf(bufjr, sizeof bufjr, "~%d", components.ordinal);
|
200
|
+
if (stored<0 || stored>=sizeof bufjr) ThrowSystemException("StrNameFromGlobalName: internal error");
|
201
|
+
if (stored>limit) ThrowSystemException("StrNameFromGlobalName: impossible limit");
|
202
|
+
strcpy(buf+limit-stored, bufjr);
|
203
|
+
}
|
204
|
+
}
|
205
|
+
return buf;
|
206
|
+
}
|
207
|
+
|
208
|
+
const char *UWinIPCNameFromGlobalName(const char *globalName,
|
209
|
+
char *buf,
|
210
|
+
size_t bufSize)
|
211
|
+
{
|
212
|
+
return StrNameFromGlobalName(globalName, 0, "", buf, bufSize);
|
213
|
+
}
|
214
|
+
|
215
|
+
const char *UPosixIPCNameFromGlobalName(const char *globalName,
|
216
|
+
char *buf,
|
217
|
+
size_t bufSize)
|
218
|
+
{
|
219
|
+
const char *prefix = "/";
|
220
|
+
size_t limit = 0;
|
221
|
+
|
222
|
+
#if (defined(FreeBSD) || defined(DARWIN))
|
223
|
+
prefix = "/tmp/";
|
224
|
+
#endif
|
225
|
+
|
226
|
+
#if defined(DARWIN)
|
227
|
+
limit = 30;
|
228
|
+
#endif
|
229
|
+
|
230
|
+
return StrNameFromGlobalName(globalName, limit, prefix, buf, bufSize);
|
231
|
+
}
|
232
|
+
|
233
|
+
int USys5IPCKeyFromGlobalName(const char *globalName)
|
234
|
+
{
|
235
|
+
int key = 0;
|
236
|
+
GlobalNameComponents components = {NULL};
|
237
|
+
|
238
|
+
ParseGlobalName(&components,globalName);
|
239
|
+
if (globalName == NULL)
|
240
|
+
{
|
241
|
+
key = IPC_PRIVATE;
|
242
|
+
}
|
243
|
+
else
|
244
|
+
{
|
245
|
+
key = components.ordinal;
|
246
|
+
if (key==IPC_PRIVATE)
|
247
|
+
ThrowSystemException("USys5IPCKeyFromGlobalName: bad key");
|
248
|
+
}
|
249
|
+
return key;
|
250
|
+
}
|
251
|
+
|
252
|
+
const char *
|
253
|
+
UCreateCompoundName(const char **namesVec,
|
254
|
+
size_t namesCount,
|
255
|
+
char *buf,
|
256
|
+
size_t bufSize)
|
257
|
+
{
|
258
|
+
size_t nameLen = 0;
|
259
|
+
const char **nameCur = namesVec, **namesEnd = namesVec+namesCount;
|
260
|
+
char *bufpos = buf;
|
261
|
+
assert(buf && bufSize>0);
|
262
|
+
strcpy(bufpos,"");
|
263
|
+
while(nameCur != namesEnd)
|
264
|
+
{
|
265
|
+
if (nameCur!=namesVec)
|
266
|
+
{
|
267
|
+
/* checked there is enough room in buf on previous iteration */
|
268
|
+
strcpy(bufpos,",");
|
269
|
+
++bufpos; bufSize-=1;
|
270
|
+
}
|
271
|
+
if (!ValidateGlobalName(*nameCur))
|
272
|
+
ThrowSystemException("UCreateCompoundName: bad global name syntax");
|
273
|
+
nameLen = (*nameCur?strlen(*nameCur):0);
|
274
|
+
if (bufSize < nameLen + 2)
|
275
|
+
ThrowSystemException("UCreateCompoundName: buffer too small");
|
276
|
+
if (*nameCur)
|
277
|
+
{
|
278
|
+
strcpy(bufpos, *nameCur);
|
279
|
+
bufpos+=nameLen;
|
280
|
+
bufSize-=nameLen;
|
281
|
+
}
|
282
|
+
++nameCur;
|
283
|
+
}
|
284
|
+
return buf;
|
285
|
+
}
|
286
|
+
|
287
|
+
const char *
|
288
|
+
UGlobalNameFromCompoundName(const char *compoundName,
|
289
|
+
int index,
|
290
|
+
char *buf,
|
291
|
+
size_t bufSize)
|
292
|
+
{
|
293
|
+
const char *pos = NULL, *epos=NULL;
|
294
|
+
assert(buf && compoundName);
|
295
|
+
if (!ValidateCompoundName(compoundName))
|
296
|
+
{
|
297
|
+
ThrowSystemException("UGlobalNameFromCompoundName: bad compound name syntax");
|
298
|
+
}
|
299
|
+
else
|
300
|
+
{
|
301
|
+
pos = compoundName;
|
302
|
+
while(index > 0 && pos)
|
303
|
+
{
|
304
|
+
pos = strchr(pos,',');
|
305
|
+
if (pos) pos+=1;
|
306
|
+
--index;
|
307
|
+
}
|
308
|
+
if (!pos || index<0)
|
309
|
+
{
|
310
|
+
ThrowSystemException("UGlobalNameFromCompoundName: index out of range");
|
311
|
+
}
|
312
|
+
epos = strchr(pos,',');
|
313
|
+
if (!epos) epos=pos+strlen(pos);
|
314
|
+
if (bufSize < (unsigned int) (epos-pos+1))
|
315
|
+
{
|
316
|
+
ThrowSystemException("UGlobalNameFromCompoundName: buffer too small");
|
317
|
+
}
|
318
|
+
if (pos == epos)
|
319
|
+
{
|
320
|
+
buf = NULL;
|
321
|
+
}
|
322
|
+
else
|
323
|
+
{
|
324
|
+
memcpy(buf,pos,epos-pos);
|
325
|
+
buf[epos-pos]=0;
|
326
|
+
}
|
327
|
+
}
|
328
|
+
return buf;
|
329
|
+
}
|
330
|
+
|
@@ -0,0 +1,134 @@
|
|
1
|
+
#if (_MSC_VER>1000)
|
2
|
+
#pragma once
|
3
|
+
#endif
|
4
|
+
|
5
|
+
#ifndef UGNAMES_H_INCLUDED
|
6
|
+
#define UGNAMES_H_INCLUDED
|
7
|
+
|
8
|
+
/* Introducing a novel approach to cross-platform global names.
|
9
|
+
|
10
|
+
Problem:
|
11
|
+
Windows uses strings for naming IPC objects.
|
12
|
+
SYS 5 IPC uses key_t integers.
|
13
|
+
Posix IPC uses strings.
|
14
|
+
We are using both SYS 5 and Posix IPC on Linux.
|
15
|
+
|
16
|
+
Solution:
|
17
|
+
We define global_name type to hold a global name.
|
18
|
+
Global_name is a c-string and it is the same on all
|
19
|
+
platforms. In the 'U' layer the global_name is converted
|
20
|
+
into platform-specific IPC name.
|
21
|
+
|
22
|
+
Example:
|
23
|
+
base name - SHMEM_BUFFERS
|
24
|
+
global name - SEDNA1500.DB7.SHMEM_BUFFERS@1802
|
25
|
+
UWinIPCNameFromGlobalName() - SEDNA1500.DB7.SHMEM_BUFFERS
|
26
|
+
USys5IPCKeyFromGlobalName() - 1802
|
27
|
+
UPosixIPCNameFromGlobalName() - /SEDNA1500.DB7.SHMEM_BUFFERS
|
28
|
+
|
29
|
+
Generation:
|
30
|
+
Global names generation is automated. All global names
|
31
|
+
should be listed in globalNamesRegistry table. Entries
|
32
|
+
in the table are not for *individual* names but rather
|
33
|
+
for *name families*. Consider a shared memory segment
|
34
|
+
used as the buffer memory. Every database instance has
|
35
|
+
it's own buffer memory, but only one entry in the registry
|
36
|
+
is made for SHMEM_BUFFERS (the basename).
|
37
|
+
|
38
|
+
The global name is generated with UCreateGlobalName() function.
|
39
|
+
The function prepends prefixes to the basename resulting in
|
40
|
+
(assume database id is 7) SEDNA1500.DB7.SHMEM_BUFFERS. Finally a '@1802'
|
41
|
+
part is appended (1802 is a generated ordinal number).
|
42
|
+
The call to CreateGlobalName() with the same
|
43
|
+
parameters produces the same global name. If parameters change
|
44
|
+
the generated name is not the same (including the ordinal number).
|
45
|
+
|
46
|
+
The ordinal number is used as the source for SYS 5 IPC key.
|
47
|
+
|
48
|
+
Private IPC objects:
|
49
|
+
NULL global name by convention stands for "private" object.
|
50
|
+
|
51
|
+
Compound names:
|
52
|
+
Sometimes it is handy to pass only one name while multiple
|
53
|
+
IPC objects are to be created. Compound name is just an
|
54
|
+
array of global names packed in the single string, ex:
|
55
|
+
"SEDNA1500.DB7.SHMEM_SM_TALK@1852,SEDNA1500.DB7.SEMARR_SM_TALK@1902" */
|
56
|
+
|
57
|
+
#ifndef EXTERNC
|
58
|
+
#ifdef __cplusplus
|
59
|
+
#define EXTERNC extern "C"
|
60
|
+
#else
|
61
|
+
#define EXTERNC
|
62
|
+
#endif
|
63
|
+
#endif
|
64
|
+
|
65
|
+
/* An item of the global names registry. */
|
66
|
+
typedef struct UGlobalNamesRegistryItem_tag_
|
67
|
+
{
|
68
|
+
const char *basename; /* used for registry lookup and for names generation */
|
69
|
+
const char *prefix; /* when we have multiple global names in the family we need prefix */
|
70
|
+
int nObjectsMax; /* how many objects we are going to have */
|
71
|
+
int rangeBegin; /* internal */
|
72
|
+
int rangeEnd; /* internal */
|
73
|
+
}
|
74
|
+
UGlobalNamesRegistryItem;
|
75
|
+
|
76
|
+
typedef
|
77
|
+
const UGlobalNamesRegistryItem *
|
78
|
+
(* UGlobalNamesRegistrySearchProc)(const UGlobalNamesRegistryItem *registry,
|
79
|
+
const char *basename);
|
80
|
+
|
81
|
+
/* Initialize global names registry. */
|
82
|
+
EXTERNC
|
83
|
+
void
|
84
|
+
UInitGlobalNamesRegistry(UGlobalNamesRegistryItem *registry,
|
85
|
+
UGlobalNamesRegistrySearchProc searchProc,
|
86
|
+
int rangeBegin,
|
87
|
+
int rangeEnd);
|
88
|
+
|
89
|
+
/* Release allocated resources. */
|
90
|
+
EXTERNC
|
91
|
+
void
|
92
|
+
UReleaseGlobalNamesRegistry();
|
93
|
+
|
94
|
+
/* Create a global name. */
|
95
|
+
EXTERNC
|
96
|
+
const char *
|
97
|
+
UCreateGlobalName(const char *basename,
|
98
|
+
int objectId,
|
99
|
+
char *buf,
|
100
|
+
size_t bufSize);
|
101
|
+
|
102
|
+
/* Create a compound name (an array of global names). */
|
103
|
+
EXTERNC
|
104
|
+
const char *
|
105
|
+
UCreateCompoundName(const char **nameVec,
|
106
|
+
size_t namesCount,
|
107
|
+
char *buf,
|
108
|
+
size_t bufSize);
|
109
|
+
|
110
|
+
/* Extract a component of the compound name. */
|
111
|
+
EXTERNC
|
112
|
+
const char *
|
113
|
+
UGlobalNameFromCompoundName(const char *compoundName,
|
114
|
+
int index,
|
115
|
+
char *buf,
|
116
|
+
size_t bufSize);
|
117
|
+
|
118
|
+
/* Create a Windows IPC object name from the global name. */
|
119
|
+
EXTERNC
|
120
|
+
const char *UWinIPCNameFromGlobalName(const char *globalName,
|
121
|
+
char *buf,
|
122
|
+
size_t bufSize);
|
123
|
+
|
124
|
+
/* Create a SYS 5 IPC key from the global name. */
|
125
|
+
EXTERNC
|
126
|
+
int USys5IPCKeyFromGlobalName(const char *globalName);
|
127
|
+
|
128
|
+
/* Create a Posix IPC name from the global name. */
|
129
|
+
EXTERNC
|
130
|
+
const char *UPosixIPCNameFromGlobalName(const char *globalName,
|
131
|
+
char *buf,
|
132
|
+
size_t bufSize);
|
133
|
+
|
134
|
+
#endif
|