OCILIB (C and C++ Driver for Oracle)  4.7.6
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
Dequeue.hpp
1 /*
2  * OCILIB - C Driver for Oracle (C Wrapper for Oracle OCI)
3  *
4  * Website: http://www.ocilib.net
5  *
6  * Copyright (c) 2007-2023 Vincent ROGIER <vince.rogier@ocilib.net>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #pragma once
22 
23 #include "ocilibcpp/types.hpp"
24 
25 // ReSharper disable CppClangTidyHicppUseAuto
26 // ReSharper disable CppClangTidyModernizeUseAuto
27 // ReSharper disable CppClangTidyMiscMisplacedConst
28 
29 namespace ocilib
30 {
31 
32 inline Dequeue::Dequeue(const TypeInfo &typeInfo, const ostring& queueName)
33 {
34  Connection connection = typeInfo.GetConnection();
35 
36  AcquireAllocated
37  (
38  core::Check(OCI_DequeueCreate(typeInfo, queueName.c_str())),
39  connection.GetHandle()
40  );
41 }
42 
43 inline Dequeue::Dequeue(OCI_Dequeue *pDequeue, core::Handle* parent)
44 {
45  AcquireTransient(pDequeue,parent);
46 }
47 
49 {
50  return Message(core::Check(OCI_DequeueGet(*this)), nullptr);
51 }
52 
53 inline Agent Dequeue::Listen(int timeout)
54 {
55  return Agent(core::Check(OCI_DequeueListen(*this, timeout)), nullptr);
56 }
57 
59 {
61 }
62 
63 inline void Dequeue::SetConsumer(const ostring& value)
64 {
65  core::Check(OCI_DequeueSetConsumer(*this, value.c_str()));
66 }
67 
69 {
71 }
72 
73 inline void Dequeue::SetCorrelation(const ostring& value)
74 {
75  core::Check(OCI_DequeueSetCorrelation(*this, value.c_str()));
76 }
77 
79 {
80  unsigned int size = OCI_SIZE_BUFFER;
81 
82  core::ManagedBuffer<unsigned char> buffer(size + 1);
83 
84  core::Check(OCI_DequeueGetRelativeMsgID(*this, static_cast<AnyPointer>(buffer), &size));
85 
86  return core::MakeRaw(buffer, size);
87 }
88 
89 inline void Dequeue::SetRelativeMsgID(const Raw &value)
90 {
91  const AnyPointer data = value.empty() ? nullptr : static_cast<AnyPointer>(const_cast<Raw::value_type*>(&value[0])) ;
92 
93  core::Check(OCI_DequeueSetRelativeMsgID(*this, data, static_cast<unsigned int>(value.size())));
94 }
95 
97 {
98  return DequeueVisibility(static_cast<DequeueVisibility::Type>(core::Check(OCI_DequeueGetVisibility(*this))));
99 }
100 
102 {
103  core::Check(OCI_DequeueSetVisibility(*this, value));
104 }
105 
107 {
108  return DequeueMode(static_cast<DequeueMode::Type>(core::Check(OCI_DequeueGetMode(*this))));
109 }
110 
111 inline void Dequeue::SetMode(DequeueMode value)
112 {
113  core::Check(OCI_DequeueSetMode(*this, value));
114 }
115 
117 {
118  return NavigationMode(static_cast<NavigationMode::Type>(core::Check(OCI_DequeueGetNavigation(*this))));
119 }
120 
122 {
123  core::Check(OCI_DequeueSetNavigation(*this, value));
124 }
125 
126 inline int Dequeue::GetWaitTime() const
127 {
128  return core::Check(OCI_DequeueGetWaitTime(*this));
129 }
130 
131 inline void Dequeue::SetWaitTime(int value)
132 {
133  core::Check(OCI_DequeueSetWaitTime(*this, value));
134 }
135 
136 inline void Dequeue::SetAgents(std::vector<Agent> &agents)
137 {
138  const size_t size = agents.size();
139  core::ManagedBuffer<OCI_Agent*> buffer(size);
140 
141  OCI_Agent ** pAgents = static_cast<OCI_Agent **>(buffer);
142 
143  for (size_t i = 0; i < size; ++i)
144  {
145  pAgents[i] = static_cast<const Agent &>(agents[i]);
146  }
147 
148  core::Check(OCI_DequeueSetAgentList(*this, pAgents, static_cast<unsigned int>(size)));
149 }
150 
151 inline void Dequeue::Subscribe(unsigned int port, unsigned int timeout, NotifyAQHandlerProc handler)
152 {
153  core::Check(OCI_DequeueSubscribe(*this, port, timeout, static_cast<POCI_NOTIFY_AQ>(handler != nullptr ? Environment::NotifyHandlerAQ : nullptr)));
154 
155  Environment::SetUserCallback<NotifyAQHandlerProc>(static_cast<OCI_Dequeue*>(*this), handler);
156 }
157 
158 inline void Dequeue::Unsubscribe()
159 {
161 }
162 
163 }
AQ identified agent for messages delivery.
Definition: types.hpp:7332
A connection or session with a specific database.
Definition: types.hpp:1580
Agent Listen(int timeout)
Listen for messages that match any recipient of the associated Agent list.
Definition: Dequeue.hpp:53
Message Get()
Dequeue messages from the given queue.
Definition: Dequeue.hpp:48
int GetWaitTime() const
Return the time that Get() waits for messages if no messages are currently available.
Definition: Dequeue.hpp:126
ostring GetCorrelation() const
Get the correlation identifier of the message to be dequeued.
Definition: Dequeue.hpp:68
DequeueVisibility GetVisibility() const
Get the dequeuing/locking behavior.
Definition: Dequeue.hpp:96
void Unsubscribe()
Unsubscribe for asynchronous messages notifications.
Definition: Dequeue.hpp:158
void Subscribe(unsigned int port, unsigned int timeout, NotifyAQHandlerProc handler)
Subscribe for asynchronous messages notifications.
Definition: Dequeue.hpp:151
DequeueMode GetMode() const
Get the dequeuing/locking behavior.
Definition: Dequeue.hpp:106
void SetAgents(std::vector< Agent > &agents)
Set the Agent list to listen to message for.
Definition: Dequeue.hpp:136
ostring GetConsumer() const
Get the current consumer name associated with the dequeuing process.
Definition: Dequeue.hpp:58
core::Enum< DequeueVisibilityValues > DequeueVisibility
Message visibility after begin dequeued.
Definition: types.hpp:7998
void SetConsumer(const ostring &value)
Set the current consumer name to retrieve message for.
Definition: Dequeue.hpp:63
void SetRelativeMsgID(const Raw &value)
Set the message identifier of the message to be dequeued.
Definition: Dequeue.hpp:89
void SetMode(DequeueMode value)
Set the dequeuing/locking behavior.
Definition: Dequeue.hpp:111
void SetCorrelation(const ostring &value)
set the correlation identifier of the message to be dequeued
Definition: Dequeue.hpp:73
Dequeue(const TypeInfo &typeInfo, const ostring &queueName)
Parametrized constructor.
Definition: Dequeue.hpp:32
void SetVisibility(DequeueVisibility value)
Set whether the new message is dequeued as part of the current transaction.
Definition: Dequeue.hpp:101
core::Enum< DequeueModeValues > DequeueMode
Dequeue mode.
Definition: types.hpp:7976
NavigationMode GetNavigation() const
Return the navigation position of messages to retrieve from the queue.
Definition: Dequeue.hpp:116
void SetNavigation(NavigationMode value)
Set the position of messages to be retrieved.
Definition: Dequeue.hpp:121
Raw GetRelativeMsgID() const
Get the message identifier of the message to be dequeued.
Definition: Dequeue.hpp:78
void SetWaitTime(int value)
Set the time that Get() waits for messages if no messages are currently available.
Definition: Dequeue.hpp:131
core::Enum< NavigationModeValues > NavigationMode
Navigation Mode.
Definition: types.hpp:8023
AQ message.
Definition: types.hpp:7422
Provides type information on Oracle Database objects.
Definition: types.hpp:4531
Connection GetConnection() const
Return the connection associated with a statement.
Definition: TypeInfo.hpp:52
Template Enumeration template class providing some type safety to some extends for manipulating enume...
Definition: core.hpp:118
Internal usage. Interface for handling ownership and relationship of a C API handle.
Definition: core.hpp:325
Internal usage. Provide a buffer class with RAII capabilities.
Definition: core.hpp:197
OCI_SYM_PUBLIC unsigned int OCI_API OCI_DequeueGetNavigation(OCI_Dequeue *dequeue)
Return the navigation position of messages to retrieve from the queue.
OCI_SYM_PUBLIC unsigned int OCI_API OCI_DequeueGetVisibility(OCI_Dequeue *dequeue)
Get the dequeuing/locking behavior.
OCI_SYM_PUBLIC OCI_Agent *OCI_API OCI_DequeueListen(OCI_Dequeue *dequeue, int timeout)
Listen for messages that match any recipient of the associated Agent list.
OCI_SYM_PUBLIC boolean OCI_API OCI_DequeueSetVisibility(OCI_Dequeue *dequeue, unsigned int visibility)
Set whether the new message is dequeued as part of the current transaction.
OCI_SYM_PUBLIC boolean OCI_API OCI_DequeueGetRelativeMsgID(OCI_Dequeue *dequeue, void *id, unsigned int *len)
Get the message identifier of the message to be dequeued.
OCI_SYM_PUBLIC const otext *OCI_API OCI_DequeueGetCorrelation(OCI_Dequeue *dequeue)
Get the correlation identifier of the message to be dequeued.
OCI_SYM_PUBLIC boolean OCI_API OCI_DequeueSetAgentList(OCI_Dequeue *dequeue, OCI_Agent **consumers, unsigned int count)
Set the Agent list to listen to message for.
OCI_SYM_PUBLIC const otext *OCI_API OCI_DequeueGetConsumer(OCI_Dequeue *dequeue)
Get the current consumer name associated with the dequeuing process.
OCI_SYM_PUBLIC OCI_Msg *OCI_API OCI_DequeueGet(OCI_Dequeue *dequeue)
Dequeue messages from the given queue.
OCI_SYM_PUBLIC boolean OCI_API OCI_DequeueUnsubscribe(OCI_Dequeue *dequeue)
Unsubscribe for asynchronous messages notifications.
OCI_SYM_PUBLIC unsigned int OCI_API OCI_DequeueGetMode(OCI_Dequeue *dequeue)
Get the dequeuing/locking behavior.
OCI_SYM_PUBLIC int OCI_API OCI_DequeueGetWaitTime(OCI_Dequeue *dequeue)
Return the time that OCIDequeueGet() waits for messages if no messages are currently available.
OCI_SYM_PUBLIC boolean OCI_API OCI_DequeueSetRelativeMsgID(OCI_Dequeue *dequeue, const void *id, unsigned int len)
Set the message identifier of the message to be dequeued.
OCI_SYM_PUBLIC OCI_Dequeue *OCI_API OCI_DequeueCreate(OCI_TypeInfo *typinf, const otext *name)
Create a Dequeue object for the given queue.
OCI_SYM_PUBLIC boolean OCI_API OCI_DequeueSetConsumer(OCI_Dequeue *dequeue, const otext *consumer)
Set the current consumer name to retrieve message for.
OCI_SYM_PUBLIC boolean OCI_API OCI_DequeueSetMode(OCI_Dequeue *dequeue, unsigned int mode)
Set the dequeuing/locking behavior.
OCI_SYM_PUBLIC boolean OCI_API OCI_DequeueSubscribe(OCI_Dequeue *dequeue, unsigned int port, unsigned int timeout, POCI_NOTIFY_AQ callback)
Subscribe for asynchronous messages notifications.
OCI_SYM_PUBLIC boolean OCI_API OCI_DequeueSetCorrelation(OCI_Dequeue *dequeue, const otext *pattern)
set the correlation identifier of the message to be dequeued
OCI_SYM_PUBLIC boolean OCI_API OCI_DequeueSetNavigation(OCI_Dequeue *dequeue, unsigned int position)
Set the position of messages to be retrieved.
OCI_SYM_PUBLIC boolean OCI_API OCI_DequeueSetWaitTime(OCI_Dequeue *dequeue, int timeout)
set the time that OCIDequeueGet() waits for messages if no messages are currently available
struct OCI_Dequeue OCI_Dequeue
OCILIB encapsulation of A/Q dequeuing operations.
Definition: types.h:470
void(* POCI_NOTIFY_AQ)(OCI_Dequeue *dequeue)
AQ notification callback prototype.
Definition: types.h:555
struct OCI_Agent OCI_Agent
OCILIB encapsulation of A/Q Agent.
Definition: types.h:460
static T Check(T result)
Internal usage. Checks if the last OCILIB function call has raised an error. If so,...
Definition: Utils.hpp:53
ostring MakeString(const otext *result, int size=-1)
Internal usage. Constructs a C++ string object from the given OCILIB string pointer.
Definition: Utils.hpp:65
Raw MakeRaw(AnyPointer result, unsigned int size)
Internal usage. Constructs a C++ Raw object from the given OCILIB raw buffer.
Definition: Utils.hpp:70
OCILIB ++ Namespace.
std::basic_string< otext, std::char_traits< otext >, std::allocator< otext > > ostring
string class wrapping the OCILIB otext * type and OTEXT() macros ( see Character sets )
Definition: config.hpp:120
std::vector< unsigned char > Raw
C++ counterpart of SQL RAW data type.
Definition: config.hpp:138
void * AnyPointer
Alias for the generic void pointer.
Definition: config.hpp:129