Codebase list python-cx-oracle / c96b65d2-3e23-4bee-a1af-16923dd42dcc/main src / cxoMsgProps.c
c96b65d2-3e23-4bee-a1af-16923dd42dcc/main

Tree @c96b65d2-3e23-4bee-a1af-16923dd42dcc/main (Download .tar.gz)

cxoMsgProps.c @c96b65d2-3e23-4bee-a1af-16923dd42dcc/mainraw · history · blame

  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
//-----------------------------------------------------------------------------
// Copyright (c) 2016, 2018, 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.
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
// cxoMsgProps.c
//   Implements the message properties object used in Advanced Queuing.
//-----------------------------------------------------------------------------

#include "cxoModule.h"

//-----------------------------------------------------------------------------
// Declaration of methods used for message properties
//-----------------------------------------------------------------------------
static void cxoMsgProps_free(cxoMsgProps*);
static PyObject *cxoMsgProps_getNumAttempts(cxoMsgProps*, void*);
static PyObject *cxoMsgProps_getCorrelation(cxoMsgProps*, void*);
static PyObject *cxoMsgProps_getDelay(cxoMsgProps*, void*);
static PyObject *cxoMsgProps_getDeliveryMode(cxoMsgProps*, void*);
static PyObject *cxoMsgProps_getEnqTime(cxoMsgProps*, void*);
static PyObject *cxoMsgProps_getExceptionQ(cxoMsgProps*, void*);
static PyObject *cxoMsgProps_getExpiration(cxoMsgProps*, void*);
static PyObject *cxoMsgProps_getOriginalMsgId(cxoMsgProps*, void*);
static PyObject *cxoMsgProps_getPriority(cxoMsgProps*, void*);
static PyObject *cxoMsgProps_getState(cxoMsgProps*, void*);
static int cxoMsgProps_setCorrelation(cxoMsgProps*, PyObject*, void*);
static int cxoMsgProps_setDelay(cxoMsgProps*, PyObject*, void*);
static int cxoMsgProps_setExceptionQ(cxoMsgProps*, PyObject*, void*);
static int cxoMsgProps_setExpiration(cxoMsgProps*, PyObject*, void*);
static int cxoMsgProps_setOriginalMsgId(cxoMsgProps*, PyObject*, void*);
static int cxoMsgProps_setPriority(cxoMsgProps*, PyObject*, void*);


//-----------------------------------------------------------------------------
// declaration of calculated members for Python type "MessageProperties"
//-----------------------------------------------------------------------------
static PyGetSetDef cxoMsgPropsCalcMembers[] = {
    { "attempts", (getter) cxoMsgProps_getNumAttempts, 0, 0, 0 },
    { "correlation", (getter) cxoMsgProps_getCorrelation,
            (setter) cxoMsgProps_setCorrelation, 0, 0 },
    { "delay", (getter) cxoMsgProps_getDelay, (setter) cxoMsgProps_setDelay, 0,
            0 },
    { "deliverymode", (getter) cxoMsgProps_getDeliveryMode, 0, 0, 0 },
    { "enqtime", (getter) cxoMsgProps_getEnqTime, 0, 0, 0 },
    { "exceptionq", (getter) cxoMsgProps_getExceptionQ,
            (setter) cxoMsgProps_setExceptionQ, 0, 0 },
    { "expiration", (getter) cxoMsgProps_getExpiration,
            (setter) cxoMsgProps_setExpiration, 0, 0 },
    { "msgid", (getter) cxoMsgProps_getOriginalMsgId,
            (setter) cxoMsgProps_setOriginalMsgId, 0, 0 },
    { "priority", (getter) cxoMsgProps_getPriority,
            (setter) cxoMsgProps_setPriority, 0, 0 },
    { "state", (getter) cxoMsgProps_getState, 0, 0, 0 },
    { NULL }
};


//-----------------------------------------------------------------------------
// Python type declarations
//-----------------------------------------------------------------------------
PyTypeObject cxoPyTypeMsgProps = {
    PyVarObject_HEAD_INIT(NULL, 0)
    "cx_Oracle.MessageProperties",      // tp_name
    sizeof(cxoMsgProps),                // tp_basicsize
    0,                                  // tp_itemsize
    (destructor) cxoMsgProps_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
    cxoMsgPropsCalcMembers,             // 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
};


//-----------------------------------------------------------------------------
// cxoMsgProps_new()
//   Create a new message properties object.
//-----------------------------------------------------------------------------
cxoMsgProps *cxoMsgProps_new(cxoConnection *connection)
{
    cxoMsgProps *props;

    props = (cxoMsgProps*) cxoPyTypeMsgProps.tp_alloc(&cxoPyTypeMsgProps, 0);
    if (!props)
        return NULL;
    if (dpiConn_newMsgProps(connection->handle, &props->handle) < 0) {
        Py_DECREF(props);
        cxoError_raiseAndReturnNull();
        return NULL;
    }
    props->encoding = connection->encodingInfo.encoding;

    return props;
}


//-----------------------------------------------------------------------------
// cxoMsgProps_free()
//   Free the memory associated with the message properties object.
//-----------------------------------------------------------------------------
static void cxoMsgProps_free(cxoMsgProps *props)
{
    if (props->handle) {
        dpiMsgProps_release(props->handle);
        props->handle = NULL;
    }
    Py_TYPE(props)->tp_free((PyObject*) props);
}


//-----------------------------------------------------------------------------
// cxoMsgProps_getAttrInt32()
//   Get the value of the attribute as a 32-bit integer.
//-----------------------------------------------------------------------------
static PyObject *cxoMsgProps_getAttrInt32(cxoMsgProps *props,
        int (*func)(dpiMsgProps *props, int32_t *value))
{
    int32_t value;

    if ((*func)(props->handle, &value) < 0)
        return cxoError_raiseAndReturnNull();
    return PyInt_FromLong(value);
}


//-----------------------------------------------------------------------------
// cxoMsgProps_setAttrInt32()
//   Set the value of the attribute as a 32-bit integer.
//-----------------------------------------------------------------------------
static int cxoMsgProps_setAttrInt32(cxoMsgProps *props, PyObject *valueObj,
        int (*func)(dpiMsgProps *props, int32_t value))
{
    int32_t value;

    value = PyInt_AsLong(valueObj);
    if (PyErr_Occurred())
        return -1;
    if ((*func)(props->handle, value) < 0)
        return cxoError_raiseAndReturnInt();
    return 0;
}


//-----------------------------------------------------------------------------
// cxoMsgProps_getNumAttempts()
//   Get the value of the attempts property.
//-----------------------------------------------------------------------------
static PyObject *cxoMsgProps_getNumAttempts(cxoMsgProps *props, void *unused)
{
    return cxoMsgProps_getAttrInt32(props, dpiMsgProps_getNumAttempts);
}


//-----------------------------------------------------------------------------
// cxoMsgProps_getCorrelation()
//   Get the value of the correlation property.
//-----------------------------------------------------------------------------
static PyObject *cxoMsgProps_getCorrelation(cxoMsgProps *props, void *unused)
{
    uint32_t valueLength;
    const char *value;

    if (dpiMsgProps_getCorrelation(props->handle, &value, &valueLength) < 0)
        return cxoError_raiseAndReturnNull();
    if (!value)
        Py_RETURN_NONE;
    return cxoPyString_fromEncodedString(value, valueLength, props->encoding,
            NULL);
}


//-----------------------------------------------------------------------------
// cxoMsgProps_getDelay()
//   Get the value of the delay property.
//-----------------------------------------------------------------------------
static PyObject *cxoMsgProps_getDelay(cxoMsgProps *props, void *unused)
{
    return cxoMsgProps_getAttrInt32(props, dpiMsgProps_getDelay);
}


//-----------------------------------------------------------------------------
// cxoMsgProps_getDeliveryMode()
//   Get the value of the delivery mode property.
//-----------------------------------------------------------------------------
static PyObject *cxoMsgProps_getDeliveryMode(cxoMsgProps *props, void *unused)
{
    dpiMessageDeliveryMode value;

    if (dpiMsgProps_getDeliveryMode(props->handle, &value) < 0)
        return cxoError_raiseAndReturnNull();
    return PyInt_FromLong(value);
}


//-----------------------------------------------------------------------------
// cxoMsgProps_getEnqTime()
//   Get the value of the enqueue time property.
//-----------------------------------------------------------------------------
static PyObject *cxoMsgProps_getEnqTime(cxoMsgProps *props, void *unused)
{
    dpiDataBuffer buffer;

    if (dpiMsgProps_getEnqTime(props->handle, &buffer.asTimestamp) < 0)
        return cxoError_raiseAndReturnNull();
    return cxoTransform_toPython(CXO_TRANSFORM_DATETIME, NULL, NULL, &buffer,
            NULL);
}


//-----------------------------------------------------------------------------
// cxoMsgProps_getExceptionQ()
//   Get the value of the exception queue property.
//-----------------------------------------------------------------------------
static PyObject *cxoMsgProps_getExceptionQ(cxoMsgProps *props, void *unused)
{
    uint32_t valueLength;
    const char *value;

    if (dpiMsgProps_getExceptionQ(props->handle, &value, &valueLength) < 0)
        return cxoError_raiseAndReturnNull();
    if (!value)
        Py_RETURN_NONE;
    return cxoPyString_fromEncodedString(value, valueLength, props->encoding,
            NULL);
}


//-----------------------------------------------------------------------------
// cxoMsgProps_getExpiration()
//   Get the value of the expiration property.
//-----------------------------------------------------------------------------
static PyObject *cxoMsgProps_getExpiration(cxoMsgProps *props, void *unused)
{
    return cxoMsgProps_getAttrInt32(props, dpiMsgProps_getExpiration);
}


//-----------------------------------------------------------------------------
// cxoMsgProps_getOriginalMsgId()
//   Get the value of the expiration property.
//-----------------------------------------------------------------------------
static PyObject *cxoMsgProps_getOriginalMsgId(cxoMsgProps *props, void *unused)
{
    uint32_t valueLength;
    const char *value;

    if (dpiMsgProps_getOriginalMsgId(props->handle, &value, &valueLength) < 0)
        return cxoError_raiseAndReturnNull();
    if (!value)
        Py_RETURN_NONE;
    return PyBytes_FromStringAndSize(value, valueLength);
}


//-----------------------------------------------------------------------------
// cxoMsgProps_getPriority()
//   Get the value of the priority property.
//-----------------------------------------------------------------------------
static PyObject *cxoMsgProps_getPriority(cxoMsgProps *props, void *unused)
{
    return cxoMsgProps_getAttrInt32(props, dpiMsgProps_getPriority);
}


//-----------------------------------------------------------------------------
// cxoMsgProps_getState()
//   Get the value of the state property.
//-----------------------------------------------------------------------------
static PyObject *cxoMsgProps_getState(cxoMsgProps *props, void *unused)
{
    dpiMessageState value;

    if (dpiMsgProps_getState(props->handle, &value) < 0)
        return cxoError_raiseAndReturnNull();
    return PyInt_FromLong(value);
}


//-----------------------------------------------------------------------------
// cxoMsgProps_setCorrelation()
//   Set the value of the correlation property.
//-----------------------------------------------------------------------------
static int cxoMsgProps_setCorrelation(cxoMsgProps *props, PyObject *valueObj,
        void *unused)
{
    cxoBuffer buffer;
    int status;

    if (cxoBuffer_fromObject(&buffer, valueObj, props->encoding))
        return -1;
    status = dpiMsgProps_setCorrelation(props->handle, buffer.ptr,
            buffer.size);
    cxoBuffer_clear(&buffer);
    if (status < 0)
        return cxoError_raiseAndReturnInt();
    return 0;
}


//-----------------------------------------------------------------------------
// cxoMsgProps_setDelay()
//   Set the value of the delay property.
//-----------------------------------------------------------------------------
static int cxoMsgProps_setDelay(cxoMsgProps *props, PyObject *valueObj,
        void *unused)
{
    return cxoMsgProps_setAttrInt32(props, valueObj, dpiMsgProps_setDelay);
}


//-----------------------------------------------------------------------------
// cxoMsgProps_setExceptionQ()
//   Set the value of the exception queue property.
//-----------------------------------------------------------------------------
static int cxoMsgProps_setExceptionQ(cxoMsgProps *props, PyObject *valueObj,
        void *unused)
{
    cxoBuffer buffer;
    int status;

    if (cxoBuffer_fromObject(&buffer, valueObj, props->encoding))
        return -1;
    status = dpiMsgProps_setExceptionQ(props->handle, buffer.ptr, buffer.size);
    cxoBuffer_clear(&buffer);
    if (status < 0)
        return cxoError_raiseAndReturnInt();
    return 0;
}


//-----------------------------------------------------------------------------
// cxoMsgProps_setExpiration()
//   Set the value of the expiration property.
//-----------------------------------------------------------------------------
static int cxoMsgProps_setExpiration(cxoMsgProps *props, PyObject *valueObj,
        void *unused)
{
    return cxoMsgProps_setAttrInt32(props, valueObj, dpiMsgProps_setExpiration);
}


//-----------------------------------------------------------------------------
// cxoMsgProps_setOriginalMsgId()
//   Set the value of the original message id property.
//-----------------------------------------------------------------------------
static int cxoMsgProps_setOriginalMsgId(cxoMsgProps *props, PyObject *valueObj,
        void *unused)
{
    Py_ssize_t valueLength;
    char *value;

    if (PyBytes_AsStringAndSize(valueObj, &value, &valueLength) < 0)
        return -1;
    if (dpiMsgProps_setOriginalMsgId(props->handle, value,
            (uint32_t) valueLength) < 0)
        return cxoError_raiseAndReturnInt();
    return 0;
}


//-----------------------------------------------------------------------------
// cxoMsgProps_setPriority()
//   Set the value of the expiration property.
//-----------------------------------------------------------------------------
static int cxoMsgProps_setPriority(cxoMsgProps *props, PyObject *valueObj,
        void *unused)
{
    return cxoMsgProps_setAttrInt32(props, valueObj, dpiMsgProps_setPriority);
}