• Main Page
  • Modules
  • Data Structures
  • Files
  • File List

D:/Perso/dev/ocilib/ocilib/src/enqueue.c

00001 /*
00002     +-----------------------------------------------------------------------------------------+
00003     |                                                                                         |
00004     |                               OCILIB - C Driver for Oracle                              |
00005     |                                                                                         |
00006     |                                (C Wrapper for Oracle OCI)                               |
00007     |                                                                                         |
00008     |                              Website : http://www.ocilib.net                            |
00009     |                                                                                         |
00010     |             Copyright (c) 2007-2010 Vincent ROGIER <vince.rogier@ocilib.net>            |
00011     |                                                                                         |
00012     +-----------------------------------------------------------------------------------------+
00013     |                                                                                         |
00014     |             This library is free software; you can redistribute it and/or               |
00015     |             modify it under the terms of the GNU Lesser General Public                  |
00016     |             License as published by the Free Software Foundation; either                |
00017     |             version 2 of the License, or (at your option) any later version.            |
00018     |                                                                                         |
00019     |             This library is distributed in the hope that it will be useful,             |
00020     |             but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00021     |             MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU           |
00022     |             Lesser General Public License for more details.                             |
00023     |                                                                                         |
00024     |             You should have received a copy of the GNU Lesser General Public            |
00025     |             License along with this library; if not, write to the Free                  |
00026     |             Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.          |
00027     |                                                                                         |
00028     +-----------------------------------------------------------------------------------------+
00029 */
00030 
00031 /* --------------------------------------------------------------------------------------------- *
00032  * $Id: event.c, v 3.8.0 2010-10-24 21:53 Vincent Rogier $
00033  * --------------------------------------------------------------------------------------------- */
00034 
00035 #include "ocilib_internal.h"
00036 
00037 /* ********************************************************************************************* *
00038  *                            PUBLIC FUNCTIONS
00039  * ********************************************************************************************* */
00040 
00041 /* --------------------------------------------------------------------------------------------- *
00042  * OCI_EnqueueCreate
00043  * --------------------------------------------------------------------------------------------- */
00044 
00045 OCI_Enqueue * OCI_API OCI_EnqueueCreate
00046 (
00047     OCI_TypeInfo *typinf,
00048     const mtext  *name
00049 )
00050 {
00051     OCI_Enqueue *enqueue = NULL;
00052     boolean res          = TRUE;
00053 
00054     OCI_CHECK_INITIALIZED(NULL);
00055 
00056     OCI_CHECK_PTR(OCI_IPC_TYPE_INFO, typinf, NULL);
00057     OCI_CHECK_PTR(OCI_IPC_STRING, name, NULL);
00058 
00059     /* allocate enqueue structure */
00060 
00061     enqueue = (OCI_Enqueue *) OCI_MemAlloc(OCI_IPC_ENQUEUE, sizeof(*enqueue), (size_t) 1, TRUE);
00062 
00063     if (enqueue != NULL)
00064     {
00065         enqueue->typinf = typinf;
00066         enqueue->name   = mtsdup(name);
00067 
00068         /* get payload type */
00069 
00070         if (mtscmp(enqueue->typinf->name, OCI_RAW_OBJECT_TYPE) == 0)
00071         {
00072             enqueue->payload_type = OCI_CDT_RAW;
00073         }
00074         else
00075         {
00076             enqueue->payload_type = OCI_CDT_OBJECT;
00077         }
00078 
00079         /* allocate enqueue options descriptor */
00080 
00081         res = (OCI_SUCCESS == OCI_DescriptorAlloc((dvoid * ) OCILib.env,
00082                                                   (dvoid **) &enqueue->opth,
00083                                                   OCI_DTYPE_AQENQ_OPTIONS,
00084                                                   (size_t) 0, (dvoid **) NULL));
00085     }
00086     else
00087         res = FALSE;
00088 
00089     /* check for failure */
00090 
00091     if (res == FALSE)
00092     {
00093         OCI_EnqueueFree(enqueue);
00094         enqueue = NULL;
00095     }
00096 
00097     return enqueue;
00098 }
00099 
00100 /* --------------------------------------------------------------------------------------------- *
00101  * OCI_EnqueueFree
00102  * --------------------------------------------------------------------------------------------- */
00103 
00104 boolean OCI_API OCI_EnqueueFree
00105 (
00106     OCI_Enqueue *enqueue
00107 )
00108 {
00109     OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE);
00110 
00111     /* free OCI descriptor */
00112 
00113     OCI_DescriptorFree((dvoid *) enqueue->opth, OCI_DTYPE_AQENQ_OPTIONS);
00114 
00115     OCI_FREE(enqueue->name);
00116     OCI_FREE(enqueue);
00117 
00118     return TRUE;
00119 }
00120 
00121 /* --------------------------------------------------------------------------------------------- *
00122  * OCI_EnqueuePut
00123  * --------------------------------------------------------------------------------------------- */
00124 
00125 boolean OCI_API OCI_EnqueuePut
00126 (
00127     OCI_Enqueue *enqueue,
00128     OCI_Msg     *msg
00129 )
00130 {
00131     boolean res     = TRUE;
00132     void *ostr      = NULL;
00133     int osize       = -1;
00134 
00135     void *payload  = NULL;
00136     void *ind      = NULL;
00137 
00138     OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE);
00139     OCI_CHECK_PTR(OCI_IPC_MSG, msg, FALSE);
00140 
00141     OCI_CHECK_COMPAT(enqueue->typinf->con, enqueue->typinf == msg->typinf, FALSE);
00142 
00143     ostr = OCI_GetInputMetaString(enqueue->name, &osize);
00144 
00145     /* get payload */
00146 
00147     if (enqueue->payload_type == OCI_CDT_OBJECT)
00148     {
00149         OCI_Object *obj = (OCI_Object *) msg->payload;
00150 
00151         if (msg->ind != OCI_IND_NULL)
00152         {
00153 
00154             payload = obj->handle;
00155             ind     = obj->tab_ind;
00156         }
00157         else
00158         {
00159             payload = NULL;
00160             ind     = msg->payload_ind;
00161         }
00162     }
00163     else
00164     {
00165         payload = msg->payload;
00166         ind     = msg->payload_ind;
00167     }
00168 
00169     /* enqueue message */
00170 
00171     OCI_CALL2
00172     (
00173         res, enqueue->typinf->con,
00174 
00175         OCIAQEnq(enqueue->typinf->con->cxt, enqueue->typinf->con->err,
00176                  ostr, enqueue->opth, msg->proph, enqueue->typinf->tdo,
00177                  &payload, &ind, &msg->id, OCI_DEFAULT);
00178     )
00179 
00180     OCI_RESULT(res);
00181 
00182     return res;
00183 }
00184 
00185 /* --------------------------------------------------------------------------------------------- *
00186  * OCI_EnqueueGetVisibility
00187  * --------------------------------------------------------------------------------------------- */
00188 
00189 unsigned int OCI_API OCI_EnqueueGetVisibility
00190 (
00191     OCI_Enqueue *enqueue
00192 )
00193 {
00194     boolean res = TRUE;
00195     ub4 ret     = 0;
00196 
00197     OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE);
00198 
00199     OCI_CALL2
00200     (
00201         res, enqueue->typinf->con,
00202 
00203         OCIAttrGet((dvoid *) enqueue->opth,
00204                    (ub4    ) OCI_DTYPE_AQENQ_OPTIONS,
00205                    (dvoid *) &ret,
00206                    (ub4   *) NULL,
00207                    (ub4    ) OCI_ATTR_VISIBILITY,
00208                    enqueue->typinf->con->err)
00209     )
00210 
00211     OCI_RESULT(res);
00212 
00213     return (int) ret;
00214 }
00215 
00216 /* --------------------------------------------------------------------------------------------- *
00217  * OCI_EnqueueSetVisibility
00218  * --------------------------------------------------------------------------------------------- */
00219 
00220 boolean OCI_API OCI_EnqueueSetVisibility
00221 (
00222     OCI_Enqueue *enqueue,
00223     unsigned int visibility
00224 )
00225 {
00226     boolean res = TRUE;
00227     ub4 value   = (ub4) visibility;
00228 
00229     OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE);
00230 
00231     OCI_CALL2
00232     (
00233         res, enqueue->typinf->con,
00234 
00235         OCIAttrSet((dvoid *) enqueue->opth,
00236                    (ub4    ) OCI_DTYPE_AQENQ_OPTIONS,
00237                    (dvoid *) &value,
00238                    (ub4    ) 0,
00239                    (ub4    ) OCI_ATTR_VISIBILITY,
00240                    enqueue->typinf->con->err)
00241     )
00242 
00243     OCI_RESULT(res);
00244 
00245     return res;
00246 }
00247 
00248 /* --------------------------------------------------------------------------------------------- *
00249  * OCI_EnqueueGetSequenceDeviation
00250  * --------------------------------------------------------------------------------------------- */
00251 
00252 unsigned int OCI_API OCI_EnqueueGetSequenceDeviation
00253 (
00254     OCI_Enqueue *enqueue
00255 )
00256 {
00257     boolean res = TRUE;
00258     ub4 ret     = 0;
00259 
00260     OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE);
00261 
00262     OCI_CALL2
00263     (
00264         res, enqueue->typinf->con,
00265 
00266         OCIAttrGet((dvoid *) enqueue->opth,
00267                    (ub4    ) OCI_DTYPE_AQENQ_OPTIONS,
00268                    (dvoid *) &ret,
00269                    (ub4   *) NULL,
00270                    (ub4    ) OCI_ATTR_SEQUENCE_DEVIATION,
00271                    enqueue->typinf->con->err)
00272     )
00273 
00274     OCI_RESULT(res);
00275 
00276     return (int) ret;
00277 }
00278 
00279 /* --------------------------------------------------------------------------------------------- *
00280  * OCI_EnqueueSetDeviation
00281  * --------------------------------------------------------------------------------------------- */
00282 
00283 boolean OCI_API OCI_EnqueueSetSequenceDeviation
00284 (
00285     OCI_Enqueue *enqueue,
00286     unsigned int sequence
00287 )
00288 {
00289     boolean res = TRUE;
00290     ub4 value   = (ub4) sequence;
00291 
00292     OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE);
00293 
00294     OCI_CALL2
00295     (
00296         res, enqueue->typinf->con,
00297 
00298         OCIAttrSet((dvoid *) enqueue->opth,
00299                    (ub4    ) OCI_DTYPE_AQENQ_OPTIONS,
00300                    (dvoid *) &value,
00301                    (ub4    ) 0,
00302                    (ub4    ) OCI_ATTR_SEQUENCE_DEVIATION,
00303                    enqueue->typinf->con->err)
00304     )
00305 
00306     OCI_RESULT(res);
00307 
00308     return res;
00309 }
00310 
00311 /* --------------------------------------------------------------------------------------------- *
00312  * OCI_EnqueueSetRelativeMsgID
00313  * --------------------------------------------------------------------------------------------- */
00314 
00315 boolean OCI_API OCI_EnqueueGetRelativeMsgID
00316 (
00317     OCI_Enqueue  *enqueue,
00318     void         *id,
00319     unsigned int *len
00320 )
00321 {
00322     boolean res   = TRUE;
00323     OCIRaw *value = NULL;
00324 
00325     OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE);
00326     OCI_CHECK_PTR(OCI_IPC_VOID,    id,      FALSE);
00327     OCI_CHECK_PTR(OCI_IPC_VOID,    len,     FALSE);
00328 
00329     OCI_CALL2
00330     (
00331         res, enqueue->typinf->con,
00332 
00333         OCIAttrGet((dvoid *) enqueue->opth,
00334                    (ub4    ) OCI_DTYPE_AQENQ_OPTIONS,
00335                    (dvoid *) &value,
00336                    (ub4   *) NULL,
00337                    (ub4    ) OCI_ATTR_RELATIVE_MSGID,
00338                    enqueue->typinf->con->err)
00339     )
00340 
00341     if (value != NULL)
00342     {
00343         ub4 raw_len = 0;
00344 
00345         raw_len = OCIRawSize(OCILib.env, value);
00346 
00347         if (*len > raw_len)
00348             *len = raw_len;
00349 
00350         memcpy(id, OCIRawPtr(OCILib.env, value), (size_t) (*len));
00351     }
00352     else
00353     {
00354         *len = 0;
00355     }
00356 
00357     OCI_RESULT(res);
00358 
00359     return res;
00360 }
00361 
00362 /* --------------------------------------------------------------------------------------------- *
00363  * OCI_EnqueueSetRelativeMsgID
00364  * --------------------------------------------------------------------------------------------- */
00365 
00366 boolean OCI_API OCI_EnqueueSetRelativeMsgID
00367 (
00368     OCI_Enqueue  *enqueue,
00369     const void   *id,
00370     unsigned int  len
00371 )
00372 {
00373     boolean res   = TRUE;
00374     OCIRaw *value = NULL;
00375 
00376     OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE);
00377 
00378     OCI_CALL2
00379     (
00380         res, enqueue->typinf->con,
00381 
00382         OCIRawAssignBytes(OCILib.env, enqueue->typinf->con->err,
00383                           (ub1*) id, (ub4) len, (OCIRaw **) &value)
00384     )
00385 
00386     OCI_CALL2
00387     (
00388         res, enqueue->typinf->con,
00389 
00390         OCIAttrSet((dvoid *) enqueue->opth,
00391                    (ub4    ) OCI_DTYPE_AQENQ_OPTIONS,
00392                    (dvoid *) &value,
00393                    (ub4    ) 0,
00394                    (ub4    ) OCI_ATTR_RELATIVE_MSGID,
00395                    enqueue->typinf->con->err)
00396     )
00397 
00398     OCI_RESULT(res);
00399 
00400     return res;
00401 }
00402 

Generated on Sun Oct 24 2010 22:02:54 for OCILIB (C Driver for Oracle) by  doxygen 1.7.1