• 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.1 2010-12-13 00:00 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         /* allocate enqueue options descriptor */
00069 
00070         res = (OCI_SUCCESS == OCI_DescriptorAlloc((dvoid * ) OCILib.env,
00071                                                   (dvoid **) &enqueue->opth,
00072                                                   OCI_DTYPE_AQENQ_OPTIONS,
00073                                                   (size_t) 0, (dvoid **) NULL));
00074     }
00075     else
00076         res = FALSE;
00077 
00078     /* check for failure */
00079 
00080     if (res == FALSE)
00081     {
00082         OCI_EnqueueFree(enqueue);
00083         enqueue = NULL;
00084     }
00085 
00086     return enqueue;
00087 }
00088 
00089 /* --------------------------------------------------------------------------------------------- *
00090  * OCI_EnqueueFree
00091  * --------------------------------------------------------------------------------------------- */
00092 
00093 boolean OCI_API OCI_EnqueueFree
00094 (
00095     OCI_Enqueue *enqueue
00096 )
00097 {
00098     OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE);
00099 
00100     /* free OCI descriptor */
00101 
00102     OCI_DescriptorFree((dvoid *) enqueue->opth, OCI_DTYPE_AQENQ_OPTIONS);
00103 
00104     OCI_FREE(enqueue->name);
00105     OCI_FREE(enqueue);
00106 
00107     return TRUE;
00108 }
00109 
00110 /* --------------------------------------------------------------------------------------------- *
00111  * OCI_EnqueuePut
00112  * --------------------------------------------------------------------------------------------- */
00113 
00114 boolean OCI_API OCI_EnqueuePut
00115 (
00116     OCI_Enqueue *enqueue,
00117     OCI_Msg     *msg
00118 )
00119 {
00120     boolean res     = TRUE;
00121     void *ostr      = NULL;
00122     int osize       = -1;
00123 
00124     void *payload  = NULL;
00125     void *ind      = NULL;
00126 
00127     OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE);
00128     OCI_CHECK_PTR(OCI_IPC_MSG, msg, FALSE);
00129 
00130     OCI_CHECK_COMPAT(enqueue->typinf->con, enqueue->typinf->tdo == msg->typinf->tdo, FALSE);
00131 
00132     ostr = OCI_GetInputMetaString(enqueue->name, &osize);
00133 
00134     /* get payload */
00135 
00136     if (enqueue->typinf->tcode != OCI_UNKNOWN)
00137     {
00138         if (msg->ind != OCI_IND_NULL)
00139         {
00140             payload = msg->obj->handle;
00141             ind     = msg->obj->tab_ind;
00142         }
00143     }
00144     else
00145     {
00146         payload =  msg->payload;
00147         ind     = &msg->ind;
00148     }
00149 
00150     /* enqueue message */
00151 
00152     OCI_CALL2
00153     (
00154         res, enqueue->typinf->con,
00155 
00156         OCIAQEnq(enqueue->typinf->con->cxt, enqueue->typinf->con->err,
00157                  ostr, enqueue->opth, msg->proph, enqueue->typinf->tdo,
00158                  &payload, &ind, NULL, OCI_DEFAULT);
00159     )
00160 
00161     OCI_ReleaseMetaString(ostr);
00162 
00163     OCI_RESULT(res);
00164 
00165     return res;
00166 }
00167 
00168 /* --------------------------------------------------------------------------------------------- *
00169  * OCI_EnqueueGetVisibility
00170  * --------------------------------------------------------------------------------------------- */
00171 
00172 unsigned int OCI_API OCI_EnqueueGetVisibility
00173 (
00174     OCI_Enqueue *enqueue
00175 )
00176 {
00177     boolean res = TRUE;
00178     ub4 ret     = 0;
00179 
00180     OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE);
00181 
00182     OCI_CALL2
00183     (
00184         res, enqueue->typinf->con,
00185 
00186         OCIAttrGet((dvoid *) enqueue->opth,
00187                    (ub4    ) OCI_DTYPE_AQENQ_OPTIONS,
00188                    (dvoid *) &ret,
00189                    (ub4   *) NULL,
00190                    (ub4    ) OCI_ATTR_VISIBILITY,
00191                    enqueue->typinf->con->err)
00192     )
00193 
00194     OCI_RESULT(res);
00195 
00196     return (int) ret;
00197 }
00198 
00199 /* --------------------------------------------------------------------------------------------- *
00200  * OCI_EnqueueSetVisibility
00201  * --------------------------------------------------------------------------------------------- */
00202 
00203 boolean OCI_API OCI_EnqueueSetVisibility
00204 (
00205     OCI_Enqueue *enqueue,
00206     unsigned int visibility
00207 )
00208 {
00209     boolean res = TRUE;
00210     ub4 value   = (ub4) visibility;
00211 
00212     OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE);
00213 
00214     OCI_CALL2
00215     (
00216         res, enqueue->typinf->con,
00217 
00218         OCIAttrSet((dvoid *) enqueue->opth,
00219                    (ub4    ) OCI_DTYPE_AQENQ_OPTIONS,
00220                    (dvoid *) &value,
00221                    (ub4    ) 0,
00222                    (ub4    ) OCI_ATTR_VISIBILITY,
00223                    enqueue->typinf->con->err)
00224     )
00225 
00226     OCI_RESULT(res);
00227 
00228     return res;
00229 }
00230 
00231 /* --------------------------------------------------------------------------------------------- *
00232  * OCI_EnqueueGetSequenceDeviation
00233  * --------------------------------------------------------------------------------------------- */
00234 
00235 unsigned int OCI_API OCI_EnqueueGetSequenceDeviation
00236 (
00237     OCI_Enqueue *enqueue
00238 )
00239 {
00240     boolean res = TRUE;
00241     ub4 ret     = 0;
00242 
00243     OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE);
00244 
00245     OCI_CALL2
00246     (
00247         res, enqueue->typinf->con,
00248 
00249         OCIAttrGet((dvoid *) enqueue->opth,
00250                    (ub4    ) OCI_DTYPE_AQENQ_OPTIONS,
00251                    (dvoid *) &ret,
00252                    (ub4   *) NULL,
00253                    (ub4    ) OCI_ATTR_SEQUENCE_DEVIATION,
00254                    enqueue->typinf->con->err)
00255     )
00256 
00257     OCI_RESULT(res);
00258 
00259     return (int) ret;
00260 }
00261 
00262 /* --------------------------------------------------------------------------------------------- *
00263  * OCI_EnqueueSetDeviation
00264  * --------------------------------------------------------------------------------------------- */
00265 
00266 boolean OCI_API OCI_EnqueueSetSequenceDeviation
00267 (
00268     OCI_Enqueue *enqueue,
00269     unsigned int sequence
00270 )
00271 {
00272     boolean res = TRUE;
00273     ub4 value   = (ub4) sequence;
00274 
00275     OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE);
00276 
00277     OCI_CALL2
00278     (
00279         res, enqueue->typinf->con,
00280 
00281         OCIAttrSet((dvoid *) enqueue->opth,
00282                    (ub4    ) OCI_DTYPE_AQENQ_OPTIONS,
00283                    (dvoid *) &value,
00284                    (ub4    ) 0,
00285                    (ub4    ) OCI_ATTR_SEQUENCE_DEVIATION,
00286                    enqueue->typinf->con->err)
00287     )
00288 
00289     OCI_RESULT(res);
00290 
00291     return res;
00292 }
00293 
00294 /* --------------------------------------------------------------------------------------------- *
00295  * OCI_EnqueueSetRelativeMsgID
00296  * --------------------------------------------------------------------------------------------- */
00297 
00298 boolean OCI_API OCI_EnqueueGetRelativeMsgID
00299 (
00300     OCI_Enqueue  *enqueue,
00301     void         *id,
00302     unsigned int *len
00303 )
00304 {
00305     boolean res   = TRUE;
00306     OCIRaw *value = NULL;
00307 
00308     OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE);
00309     OCI_CHECK_PTR(OCI_IPC_VOID,    id,      FALSE);
00310     OCI_CHECK_PTR(OCI_IPC_VOID,    len,     FALSE);
00311 
00312     OCI_CALL2
00313     (
00314         res, enqueue->typinf->con,
00315 
00316         OCIAttrGet((dvoid *) enqueue->opth,
00317                    (ub4    ) OCI_DTYPE_AQENQ_OPTIONS,
00318                    (dvoid *) &value,
00319                    (ub4   *) NULL,
00320                    (ub4    ) OCI_ATTR_RELATIVE_MSGID,
00321                    enqueue->typinf->con->err)
00322     )
00323 
00324     if (value != NULL)
00325     {
00326         ub4 raw_len = 0;
00327 
00328         raw_len = OCIRawSize(OCILib.env, value);
00329 
00330         if (*len > raw_len)
00331             *len = raw_len;
00332 
00333         memcpy(id, OCIRawPtr(OCILib.env, value), (size_t) (*len));
00334     }
00335     else
00336     {
00337         *len = 0;
00338     }
00339 
00340     OCI_RESULT(res);
00341 
00342     return res;
00343 }
00344 
00345 /* --------------------------------------------------------------------------------------------- *
00346  * OCI_EnqueueSetRelativeMsgID
00347  * --------------------------------------------------------------------------------------------- */
00348 
00349 boolean OCI_API OCI_EnqueueSetRelativeMsgID
00350 (
00351     OCI_Enqueue  *enqueue,
00352     const void   *id,
00353     unsigned int  len
00354 )
00355 {
00356     boolean res   = TRUE;
00357     OCIRaw *value = NULL;
00358 
00359     OCI_CHECK_PTR(OCI_IPC_ENQUEUE, enqueue, FALSE);
00360 
00361     OCI_CALL2
00362     (
00363         res, enqueue->typinf->con,
00364 
00365         OCIRawAssignBytes(OCILib.env, enqueue->typinf->con->err,
00366                           (ub1*) id, (ub4) len, (OCIRaw **) &value)
00367     )
00368 
00369     OCI_CALL2
00370     (
00371         res, enqueue->typinf->con,
00372 
00373         OCIAttrSet((dvoid *) enqueue->opth,
00374                    (ub4    ) OCI_DTYPE_AQENQ_OPTIONS,
00375                    (dvoid *) &value,
00376                    (ub4    ) 0,
00377                    (ub4    ) OCI_ATTR_RELATIVE_MSGID,
00378                    enqueue->typinf->con->err)
00379     )
00380 
00381     OCI_RESULT(res);
00382 
00383     return res;
00384 }
00385 

Generated on Mon Dec 13 2010 22:32:01 for OCILIB (C Driver for Oracle) by  doxygen 1.7.2