forked from oracle/python-cx_Oracle
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMsgProps.c
More file actions
413 lines (351 loc) · 15.7 KB
/
MsgProps.c
File metadata and controls
413 lines (351 loc) · 15.7 KB
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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
//-----------------------------------------------------------------------------
// Copyright 2016, 2017, Oracle and/or its affiliates. All rights reserved.
//
// Portions Copyright 2007-2015, Anthony Tuininga. All rights reserved.
//
// Portions Copyright 2001-2007, Computronix (Canada) Ltd., Edmonton, Alberta,
// Canada. All rights reserved.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// MsgProps.c
// Implements the message properties object used in Advanced Queuing.
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// structures used for handling AQ options and message properties
//-----------------------------------------------------------------------------
typedef struct {
PyObject_HEAD
dpiMsgProps *handle;
const char *encoding;
} udt_MsgProps;
//-----------------------------------------------------------------------------
// Declaration of methods used for message properties
//-----------------------------------------------------------------------------
static udt_MsgProps *MsgProps_New(udt_Connection*);
static void MsgProps_Free(udt_MsgProps*);
static PyObject *MsgProps_GetNumAttempts(udt_MsgProps*, void*);
static PyObject *MsgProps_GetCorrelation(udt_MsgProps*, void*);
static PyObject *MsgProps_GetDelay(udt_MsgProps*, void*);
static PyObject *MsgProps_GetDeliveryMode(udt_MsgProps*, void*);
static PyObject *MsgProps_GetEnqTime(udt_MsgProps*, void*);
static PyObject *MsgProps_GetExceptionQ(udt_MsgProps*, void*);
static PyObject *MsgProps_GetExpiration(udt_MsgProps*, void*);
static PyObject *MsgProps_GetOriginalMsgId(udt_MsgProps*, void*);
static PyObject *MsgProps_GetPriority(udt_MsgProps*, void*);
static PyObject *MsgProps_GetState(udt_MsgProps*, void*);
static int MsgProps_SetCorrelation(udt_MsgProps*, PyObject*, void*);
static int MsgProps_SetDelay(udt_MsgProps*, PyObject*, void*);
static int MsgProps_SetExceptionQ(udt_MsgProps*, PyObject*, void*);
static int MsgProps_SetExpiration(udt_MsgProps*, PyObject*, void*);
static int MsgProps_SetOriginalMsgId(udt_MsgProps*, PyObject*, void*);
static int MsgProps_SetPriority(udt_MsgProps*, PyObject*, void*);
//-----------------------------------------------------------------------------
// declaration of calculated members for Python type "MessageProperties"
//-----------------------------------------------------------------------------
static PyGetSetDef g_MessagePropertiesCalcMembers[] = {
{ "attempts", (getter) MsgProps_GetNumAttempts, 0, 0, 0 },
{ "correlation", (getter) MsgProps_GetCorrelation,
(setter) MsgProps_SetCorrelation, 0, 0 },
{ "delay", (getter) MsgProps_GetDelay, (setter) MsgProps_SetDelay, 0, 0 },
{ "deliverymode", (getter) MsgProps_GetDeliveryMode, 0, 0, 0 },
{ "enqtime", (getter) MsgProps_GetEnqTime, 0, 0, 0 },
{ "exceptionq", (getter) MsgProps_GetExceptionQ,
(setter) MsgProps_SetExceptionQ, 0, 0 },
{ "expiration", (getter) MsgProps_GetExpiration,
(setter) MsgProps_SetExpiration, 0, 0 },
{ "msgid", (getter) MsgProps_GetOriginalMsgId,
(setter) MsgProps_SetOriginalMsgId, 0, 0 },
{ "priority", (getter) MsgProps_GetPriority,
(setter) MsgProps_SetPriority, 0, 0 },
{ "state", (getter) MsgProps_GetState, 0, 0, 0 },
{ NULL }
};
//-----------------------------------------------------------------------------
// Python type declarations
//-----------------------------------------------------------------------------
static PyTypeObject g_MessagePropertiesType = {
PyVarObject_HEAD_INIT(NULL, 0)
"cx_Oracle.MessageProperties", // tp_name
sizeof(udt_MsgProps), // tp_basicsize
0, // tp_itemsize
(destructor) MsgProps_Free, // tp_dealloc
0, // tp_print
0, // tp_getattr
0, // tp_setattr
0, // tp_compare
0, // tp_repr
0, // tp_as_number
0, // tp_as_sequence
0, // tp_as_mapping
0, // tp_hash
0, // tp_call
0, // tp_str
0, // tp_getattro
0, // tp_setattro
0, // tp_as_buffer
Py_TPFLAGS_DEFAULT, // tp_flags
0, // tp_doc
0, // tp_traverse
0, // tp_clear
0, // tp_richcompare
0, // tp_weaklistoffset
0, // tp_iter
0, // tp_iternext
0, // tp_methods
0, // tp_members
g_MessagePropertiesCalcMembers, // tp_getset
0, // tp_base
0, // tp_dict
0, // tp_descr_get
0, // tp_descr_set
0, // tp_dictoffset
0, // tp_init
0, // tp_alloc
0, // tp_new
0, // tp_free
0, // tp_is_gc
0 // tp_bases
};
//-----------------------------------------------------------------------------
// MsgProps_New()
// Create a new message properties object.
//-----------------------------------------------------------------------------
static udt_MsgProps *MsgProps_New(udt_Connection *connection)
{
udt_MsgProps *self;
self = (udt_MsgProps*)
g_MessagePropertiesType.tp_alloc(&g_MessagePropertiesType, 0);
if (!self)
return NULL;
if (dpiConn_newMsgProps(connection->handle, &self->handle) < 0) {
Py_DECREF(self);
Error_RaiseAndReturnNull();
return NULL;
}
self->encoding = connection->encodingInfo.encoding;
return self;
}
//-----------------------------------------------------------------------------
// MsgProps_Free()
// Free the memory associated with the message properties object.
//-----------------------------------------------------------------------------
static void MsgProps_Free(udt_MsgProps *self)
{
if (self->handle) {
dpiMsgProps_release(self->handle);
self->handle = NULL;
}
Py_TYPE(self)->tp_free((PyObject*) self);
}
//-----------------------------------------------------------------------------
// MsgProps_GetAttrInt32()
// Get the value of the attribute as a 32-bit integer.
//-----------------------------------------------------------------------------
static PyObject *MsgProps_GetAttrInt32(udt_MsgProps *self,
int (*func)(dpiMsgProps *props, int32_t *value))
{
int32_t value;
if ((*func)(self->handle, &value) < 0)
return Error_RaiseAndReturnNull();
return PyInt_FromLong(value);
}
//-----------------------------------------------------------------------------
// MsgProps_SetAttrInt32()
// Set the value of the attribute as a 32-bit integer.
//-----------------------------------------------------------------------------
static int MsgProps_SetAttrInt32(udt_MsgProps *self, PyObject *valueObj,
int (*func)(dpiMsgProps *props, int32_t value))
{
int32_t value;
value = PyInt_AsLong(valueObj);
if (PyErr_Occurred())
return -1;
if ((*func)(self->handle, value) < 0)
return Error_RaiseAndReturnInt();
return 0;
}
//-----------------------------------------------------------------------------
// MsgProps_GetNumAttempts()
// Get the value of the attempts property.
//-----------------------------------------------------------------------------
static PyObject *MsgProps_GetNumAttempts(udt_MsgProps *self, void *unused)
{
return MsgProps_GetAttrInt32(self, dpiMsgProps_getNumAttempts);
}
//-----------------------------------------------------------------------------
// MsgProps_GetCorrelation()
// Get the value of the correlation property.
//-----------------------------------------------------------------------------
static PyObject *MsgProps_GetCorrelation(udt_MsgProps *self, void *unused)
{
uint32_t valueLength;
const char *value;
if (dpiMsgProps_getCorrelation(self->handle, &value, &valueLength) < 0)
return Error_RaiseAndReturnNull();
if (!value)
Py_RETURN_NONE;
return cxString_FromEncodedString(value, valueLength, self->encoding);
}
//-----------------------------------------------------------------------------
// MsgProps_GetDelay()
// Get the value of the delay property.
//-----------------------------------------------------------------------------
static PyObject *MsgProps_GetDelay(udt_MsgProps *self, void *unused)
{
return MsgProps_GetAttrInt32(self, dpiMsgProps_getDelay);
}
//-----------------------------------------------------------------------------
// MsgProps_GetDeliveryMode()
// Get the value of the delivery mode property.
//-----------------------------------------------------------------------------
static PyObject *MsgProps_GetDeliveryMode(udt_MsgProps *self, void *unused)
{
dpiMessageDeliveryMode value;
if (dpiMsgProps_getDeliveryMode(self->handle, &value) < 0)
return Error_RaiseAndReturnNull();
return PyInt_FromLong(value);
}
//-----------------------------------------------------------------------------
// MsgProps_GetEnqTime()
// Get the value of the enqueue time property.
//-----------------------------------------------------------------------------
static PyObject *MsgProps_GetEnqTime(udt_MsgProps *self, void *unused)
{
dpiTimestamp value;
if (dpiMsgProps_getEnqTime(self->handle, &value) < 0)
return Error_RaiseAndReturnNull();
return PyDateTime_FromDateAndTime(value.year, value.month, value.day,
value.hour, value.minute, value.second, 0);
}
//-----------------------------------------------------------------------------
// MsgProps_GetExceptionQ()
// Get the value of the exception queue property.
//-----------------------------------------------------------------------------
static PyObject *MsgProps_GetExceptionQ(udt_MsgProps *self, void *unused)
{
uint32_t valueLength;
const char *value;
if (dpiMsgProps_getExceptionQ(self->handle, &value, &valueLength) < 0)
return Error_RaiseAndReturnNull();
if (!value)
Py_RETURN_NONE;
return cxString_FromEncodedString(value, valueLength, self->encoding);
}
//-----------------------------------------------------------------------------
// MsgProps_GetExpiration()
// Get the value of the expiration property.
//-----------------------------------------------------------------------------
static PyObject *MsgProps_GetExpiration(udt_MsgProps *self, void *unused)
{
return MsgProps_GetAttrInt32(self, dpiMsgProps_getExpiration);
}
//-----------------------------------------------------------------------------
// MsgProps_GetOriginalMsgId()
// Get the value of the expiration property.
//-----------------------------------------------------------------------------
static PyObject *MsgProps_GetOriginalMsgId(udt_MsgProps *self, void *unused)
{
uint32_t valueLength;
const char *value;
if (dpiMsgProps_getOriginalMsgId(self->handle, &value, &valueLength) < 0)
return Error_RaiseAndReturnNull();
if (!value)
Py_RETURN_NONE;
return PyBytes_FromStringAndSize(value, valueLength);
}
//-----------------------------------------------------------------------------
// MsgProps_GetPriority()
// Get the value of the priority property.
//-----------------------------------------------------------------------------
static PyObject *MsgProps_GetPriority(udt_MsgProps *self, void *unused)
{
return MsgProps_GetAttrInt32(self, dpiMsgProps_getPriority);
}
//-----------------------------------------------------------------------------
// MsgProps_GetState()
// Get the value of the state property.
//-----------------------------------------------------------------------------
static PyObject *MsgProps_GetState(udt_MsgProps *self, void *unused)
{
dpiMessageState value;
if (dpiMsgProps_getState(self->handle, &value) < 0)
return Error_RaiseAndReturnNull();
return PyInt_FromLong(value);
}
//-----------------------------------------------------------------------------
// MsgProps_SetCorrelation()
// Set the value of the correlation property.
//-----------------------------------------------------------------------------
static int MsgProps_SetCorrelation(udt_MsgProps *self, PyObject *valueObj,
void *unused)
{
udt_Buffer buffer;
int status;
if (cxBuffer_FromObject(&buffer, valueObj, self->encoding))
return -1;
status = dpiMsgProps_setCorrelation(self->handle, buffer.ptr, buffer.size);
cxBuffer_Clear(&buffer);
if (status < 0)
return Error_RaiseAndReturnInt();
return 0;
}
//-----------------------------------------------------------------------------
// MsgProps_SetDelay()
// Set the value of the delay property.
//-----------------------------------------------------------------------------
static int MsgProps_SetDelay(udt_MsgProps *self, PyObject *valueObj,
void *unused)
{
return MsgProps_SetAttrInt32(self, valueObj, dpiMsgProps_setDelay);
}
//-----------------------------------------------------------------------------
// MsgProps_SetExceptionQ()
// Set the value of the exception queue property.
//-----------------------------------------------------------------------------
static int MsgProps_SetExceptionQ(udt_MsgProps *self, PyObject *valueObj,
void *unused)
{
udt_Buffer buffer;
int status;
if (cxBuffer_FromObject(&buffer, valueObj, self->encoding))
return -1;
status = dpiMsgProps_setExceptionQ(self->handle, buffer.ptr, buffer.size);
cxBuffer_Clear(&buffer);
if (status < 0)
return Error_RaiseAndReturnInt();
return 0;
}
//-----------------------------------------------------------------------------
// MsgProps_SetExpiration()
// Set the value of the expiration property.
//-----------------------------------------------------------------------------
static int MsgProps_SetExpiration(udt_MsgProps *self, PyObject *valueObj,
void *unused)
{
return MsgProps_SetAttrInt32(self, valueObj, dpiMsgProps_setExpiration);
}
//-----------------------------------------------------------------------------
// MsgProps_SetOriginalMsgId()
// Set the value of the original message id property.
//-----------------------------------------------------------------------------
static int MsgProps_SetOriginalMsgId(udt_MsgProps *self, PyObject *valueObj,
void *unused)
{
Py_ssize_t valueLength;
char *value;
if (PyBytes_AsStringAndSize(valueObj, &value, &valueLength) < 0)
return -1;
if (dpiMsgProps_setOriginalMsgId(self->handle, value,
(uint32_t) valueLength) < 0)
return Error_RaiseAndReturnInt();
return 0;
}
//-----------------------------------------------------------------------------
// MsgProps_SetPriority()
// Set the value of the expiration property.
//-----------------------------------------------------------------------------
static int MsgProps_SetPriority(udt_MsgProps *self, PyObject *valueObj,
void *unused)
{
return MsgProps_SetAttrInt32(self, valueObj, dpiMsgProps_setPriority);
}