OCI_Msg * OCI_API OCI_MsgCreate ( OCI_TypeInfo *typinf ) { OCI_Msg *msg = NULL; boolean res = TRUE; OCI_CHECK_INITIALIZED(NULL); OCI_CHECK_PTR(OCI_IPC_TYPE_INFO, typinf, NULL); /* allocate message structure */ msg = (OCI_Msg *) OCI_MemAlloc(OCI_IPC_MSG, sizeof(*msg), (size_t) 1, TRUE); if (msg != NULL) { msg->typinf = typinf; msg->ind = OCI_IND_NULL; /* allocate message properties descriptor */ res = (OCI_SUCCESS == OCI_DescriptorAlloc((dvoid * ) msg->typinf->con->env, (dvoid **) &msg->proph, OCI_DTYPE_AQMSG_PROPERTIES, (size_t) 0, (dvoid **) NULL)); if (res == TRUE) { /* allocate internal OCI_Object handle if payload is not RAW */ if (msg->typinf->tcode != OCI_UNKNOWN) { msg->obj = OCI_ObjectCreate(typinf->con, typinf); res = (msg->obj != NULL); } } } else { res = FALSE; } /* check for failure */ if (res == FALSE) { OCI_MsgFree(msg); msg = NULL; } return msg; }
OCI_Msg * OCI_API OCI_MsgCreate ( OCI_TypeInfo *typinf ) { OCI_Msg *msg = NULL; OCI_CALL_ENTER(OCI_Msg*, NULL) OCI_CALL_CHECK_PTR(OCI_IPC_TYPE_INFO, typinf) OCI_CALL_CONTEXT_SET_FROM_CONN(typinf->con) /* allocate message structure */ msg = (OCI_Msg *) OCI_MemAlloc(OCI_IPC_MSG, sizeof(*msg), (size_t) 1, TRUE); OCI_STATUS = (NULL != msg); if (OCI_STATUS) { msg->typinf = typinf; msg->ind = OCI_IND_NULL; /* allocate message properties descriptor */ OCI_STATUS = OCI_DescriptorAlloc((dvoid *)msg->typinf->con->env, (dvoid **)&msg->proph, OCI_DTYPE_AQMSG_PROPERTIES); if (OCI_STATUS) { /* allocate internal OCI_Object handle if payload is not RAW */ if (OCI_UNKNOWN != msg->typinf->typecode) { msg->obj = OCI_ObjectCreate(typinf->con, typinf); OCI_STATUS = (NULL != msg->obj); } } } /* check for failure */ if (OCI_STATUS) { OCI_RETVAL = msg; } else if (msg) { OCI_MsgFree(msg); msg = NULL; } OCI_CALL_EXIT() }
int main(int argc, char *argv[]) { OCI_Connection *con; OCI_Enqueue *enq; OCI_Dequeue *deq; OCI_Msg *msg; OCI_TypeInfo *inf; OCI_Object *obj; OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT); con = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); inf = OCI_TypeInfoGet(con, "MY_MESSAGE", OCI_TIF_TYPE); enq = OCI_EnqueueCreate(inf, "my_queue"); deq = OCI_DequeueCreate(inf, "my_queue"); msg = OCI_MsgCreate(inf); obj = OCI_ObjectCreate(con, inf); OCI_ObjectSetString(obj, "TITLE", "NEXT MEETING"); OCI_ObjectSetString(obj, "CONTENT", "12:00 PM IN STARBUCKS"); OCI_MsgSetObject(msg, obj); OCI_EnqueuePut(enq, msg); OCI_MsgFree(msg); OCI_ObjectFree(obj); OCI_Commit(con); msg = OCI_DequeueGet(deq); obj = OCI_MsgGetObject(msg); printf("MSG '%s' => %s\n", OCI_ObjectGetString(obj, "TITLE"), OCI_ObjectGetString(obj, "CONTENT")); OCI_EnqueueFree(enq); OCI_DequeueFree(deq); OCI_ConnectionFree(con); OCI_Cleanup(); return EXIT_SUCCESS; }
boolean OCI_API OCI_DequeueFree ( OCI_Dequeue *dequeue ) { OCI_CHECK_PTR(OCI_IPC_DEQUEUE, dequeue, FALSE); /* Unsubscribe notification if needed */ if (dequeue->subhp != NULL) { OCI_DequeueUnsubscribe(dequeue); } /* free local message */ if (dequeue->msg != NULL) { OCI_MsgFree(dequeue->msg); } /* free local agent */ if (dequeue->agent != NULL) { OCI_AgentFree(dequeue->agent); } /* free OCI descriptor */ OCI_DescriptorFree((dvoid *) dequeue->opth, OCI_DTYPE_AQDEQ_OPTIONS); /* free strings */ OCI_FREE(dequeue->name); OCI_FREE(dequeue->pattern); OCI_FREE(dequeue->consumer); /* free misc. */ OCI_FREE(dequeue->agent_list); OCI_FREE(dequeue); return TRUE; }
int main(int argc, char *argv[]) { OCI_Connection *con; OCI_Enqueue *enq; OCI_Dequeue *deq1; OCI_Dequeue *deq2; OCI_Msg *msg; OCI_TypeInfo *inf; OCI_Object *obj; OCI_Agent *agents[2]; OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT | OCI_ENV_THREADED |OCI_ENV_EVENTS); con = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); OCI_Immediate(con, "create type my_message as object (title varchar2(50), content varchar2(50)) "); OCI_QueueTableCreate(con, "my_queue_table", "my_message", NULL, NULL, TRUE, FALSE, NULL, 0,0,NULL); OCI_QueueCreate(con, "my_queue", "my_queue_table", OCIT_NORMAL, 0, 0, 0, 0, NULL); OCI_QueueStart(con, "my_queue", TRUE, TRUE); agents[0] = OCI_AgentCreate(con, "C1", NULL); agents[1] = OCI_AgentCreate(con, "C2", NULL); inf = OCI_TypeInfoGet(con, "MY_MESSAGE", OCI_TIF_TYPE); enq = OCI_EnqueueCreate(inf, "my_queue"); deq1 = OCI_DequeueCreate(inf, "my_queue"); deq2 = OCI_DequeueCreate(inf, "my_queue"); OCI_DequeueSetConsumer(deq1, "C1"); OCI_DequeueSetNavigation(deq1, OCI_ADN_FIRST_MSG); OCI_DequeueSetConsumer(deq2, "C2"); OCI_DequeueSetNavigation(deq2, OCI_ADN_FIRST_MSG); OCI_DequeueSubscribe(deq1, 9998, 0, on_message); OCI_DequeueSubscribe(deq2, 9999, 0, on_message); msg = OCI_MsgCreate(inf); obj = OCI_ObjectCreate(con, inf); OCI_ObjectSetString(obj, "TITLE", "NEXT MEETING"); OCI_ObjectSetString(obj, "CONTENT", "12:00 PM IN STARBUCKS"); OCI_MsgSetObject(msg, obj); OCI_MsgSetConsumers(msg, agents, 2); OCI_EnqueuePut(enq, msg); OCI_MsgFree(msg); OCI_ObjectFree(obj); OCI_Commit(con); getchar(); OCI_DequeueUnsubscribe(deq1); OCI_DequeueUnsubscribe(deq2); OCI_AgentFree(agents[0]); OCI_AgentFree(agents[1]); OCI_EnqueueFree(enq); OCI_DequeueFree(deq1); OCI_DequeueFree(deq2); OCI_QueueStop(con, "my_queue", TRUE, TRUE, 0); OCI_QueueDrop(con, "my_queue"); OCI_QueueTableDrop(con, "my_queue_table", TRUE); OCI_Immediate(con, "drop type my_message"); OCI_ConnectionFree(con); OCI_Cleanup(); return EXIT_SUCCESS; }