OCILIB (C and C++ Driver for Oracle)  4.7.3
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-2021 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  Acquire(core::Check(OCI_DequeueCreate(typeInfo, queueName.c_str())), reinterpret_cast<HandleFreeFunc>(OCI_DequeueFree), nullptr, nullptr);
35 }
36 
37 inline Dequeue::Dequeue(OCI_Dequeue *pDequeue)
38 {
39  Acquire(pDequeue, nullptr, nullptr, nullptr);
40 }
41 
43 {
44  return Message(core::Check(OCI_DequeueGet(*this)), nullptr);
45 }
46 
47 inline Agent Dequeue::Listen(int timeout)
48 {
49  return Agent(core::Check(OCI_DequeueListen(*this, timeout)), nullptr);
50 }
51 
53 {
55 }
56 
57 inline void Dequeue::SetConsumer(const ostring& value)
58 {
59  core::Check(OCI_DequeueSetConsumer(*this, value.c_str()));
60 }
61 
63 {
65 }
66 
67 inline void Dequeue::SetCorrelation(const ostring& value)
68 {
69  core::Check(OCI_DequeueSetCorrelation(*this, value.c_str()));
70 }
71 
73 {
74  unsigned int size = OCI_SIZE_BUFFER;
75 
76  core::ManagedBuffer<unsigned char> buffer(size + 1);
77 
78  core::Check(OCI_DequeueGetRelativeMsgID(*this, static_cast<AnyPointer>(buffer), &size));
79 
80  return core::MakeRaw(buffer, size);
81 }
82 
83 inline void Dequeue::SetRelativeMsgID(const Raw &value)
84 {
85  const AnyPointer data = value.empty() ? nullptr : static_cast<AnyPointer>(const_cast<Raw::value_type*>(&value[0])) ;
86 
87  core::Check(OCI_DequeueSetRelativeMsgID(*this, data, static_cast<unsigned int>(value.size())));
88 }
89 
91 {
92  return DequeueVisibility(static_cast<DequeueVisibility::Type>(core::Check(OCI_DequeueGetVisibility(*this))));
93 }
94 
96 {
98 }
99 
101 {
102  return DequeueMode(static_cast<DequeueMode::Type>(core::Check(OCI_DequeueGetMode(*this))));
103 }
104 
105 inline void Dequeue::SetMode(DequeueMode value)
106 {
107  core::Check(OCI_DequeueSetMode(*this, value));
108 }
109 
111 {
112  return NavigationMode(static_cast<NavigationMode::Type>(core::Check(OCI_DequeueGetNavigation(*this))));
113 }
114 
116 {
117  core::Check(OCI_DequeueSetNavigation(*this, value));
118 }
119 
120 inline int Dequeue::GetWaitTime() const
121 {
122  return core::Check(OCI_DequeueGetWaitTime(*this));
123 }
124 
125 inline void Dequeue::SetWaitTime(int value)
126 {
127  core::Check(OCI_DequeueSetWaitTime(*this, value));
128 }
129 
130 inline void Dequeue::SetAgents(std::vector<Agent> &agents)
131 {
132  const size_t size = agents.size();
133  core::ManagedBuffer<OCI_Agent*> buffer(size);
134 
135  OCI_Agent ** pAgents = static_cast<OCI_Agent **>(buffer);
136 
137  for (size_t i = 0; i < size; ++i)
138  {
139  pAgents[i] = static_cast<const Agent &>(agents[i]);
140  }
141 
142  core::Check(OCI_DequeueSetAgentList(*this, pAgents, static_cast<unsigned int>(size)));
143 }
144 
145 inline void Dequeue::Subscribe(unsigned int port, unsigned int timeout, NotifyAQHandlerProc handler)
146 {
147  core::Check(OCI_DequeueSubscribe(*this, port, timeout, static_cast<POCI_NOTIFY_AQ>(handler != nullptr ? Environment::NotifyHandlerAQ : nullptr)));
148 
149  Environment::SetUserCallback<NotifyAQHandlerProc>(static_cast<OCI_Dequeue*>(*this), handler);
150 }
151 
152 inline void Dequeue::Unsubscribe()
153 {
155 }
156 
157 }
struct OCI_Agent OCI_Agent
OCILIB encapsulation of A/Q Agent.
Definition: types.h:448
Agent Listen(int timeout)
Listen for messages that match any recipient of the associated Agent list.
Definition: Dequeue.hpp:47
void(* NotifyAQHandlerProc)(Dequeue &dequeue)
User callback for dequeue event notifications.
Definition: types.hpp:7928
OCI_SYM_PUBLIC boolean OCI_API OCI_DequeueFree(OCI_Dequeue *dequeue)
Free a Dequeue object.
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_DequeueSetAgentList(OCI_Dequeue *dequeue, OCI_Agent **consumers, unsigned int count)
Set the Agent list to listen to message for.
OCILIB ++ Namespace.
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 OCI_Msg *OCI_API OCI_DequeueGet(OCI_Dequeue *dequeue)
Dequeue messages from the given queue.
Raw MakeRaw(AnyPointer result, unsigned int size)
Internal usage. Constructs a C++ Raw object from the given OCILIB raw buffer.
Definition: Utils.hpp:70
core::Enum< DequeueModeValues > DequeueMode
Dequeue mode.
Definition: types.hpp:7954
OCI_SYM_PUBLIC unsigned int OCI_API OCI_DequeueGetMode(OCI_Dequeue *dequeue)
Get the dequeuing/locking behavior.
DequeueVisibility GetVisibility() const
Get the dequeuing/locking behavior.
Definition: Dequeue.hpp:90
NavigationMode GetNavigation() const
Return the navigation position of messages to retrieve from the queue.
Definition: Dequeue.hpp:110
OCI_SYM_PUBLIC const otext *OCI_API OCI_DequeueGetConsumer(OCI_Dequeue *dequeue)
Get the current consumer name associated with the dequeuing process.
struct OCI_Dequeue OCI_Dequeue
OCILIB encapsulation of A/Q dequeuing operations.
Definition: types.h:458
static T Check(T result)
Internal usage. Checks if the last OCILIB function call has raised an error. If so, it raises a C++ exception using the retrieved error handle.
Definition: Utils.hpp:53
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.
AQ identified agent for messages delivery.
Definition: types.hpp:7309
OCI_SYM_PUBLIC unsigned int OCI_API OCI_DequeueGetVisibility(OCI_Dequeue *dequeue)
Get the dequeuing/locking behavior.
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 boolean OCI_API OCI_DequeueSetNavigation(OCI_Dequeue *dequeue, unsigned int position)
Set the position of messages to be retrieved.
void SetConsumer(const ostring &value)
Set the current consumer name to retrieve message for.
Definition: Dequeue.hpp:57
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
OCI_SYM_PUBLIC boolean OCI_API OCI_DequeueSetConsumer(OCI_Dequeue *dequeue, const otext *consumer)
Set the current consumer name to retrieve message for.
ostring GetConsumer() const
Get the current consumer name associated with the dequeuing process.
Definition: Dequeue.hpp:52
core::Enum< DequeueVisibilityValues > DequeueVisibility
Message visibility after begin dequeued.
Definition: types.hpp:7976
OCI_SYM_PUBLIC const otext *OCI_API OCI_DequeueGetCorrelation(OCI_Dequeue *dequeue)
Get the correlation identifier of the message to be dequeued.
void SetCorrelation(const ostring &value)
set the correlation identifier of the message to be dequeued
Definition: Dequeue.hpp:67
Message Get()
Dequeue messages from the given queue.
Definition: Dequeue.hpp:42
void SetRelativeMsgID(const Raw &value)
Set the message identifier of the message to be dequeued.
Definition: Dequeue.hpp:83
void SetAgents(std::vector< Agent > &agents)
Set the Agent list to listen to message for.
Definition: Dequeue.hpp:130
OCI_SYM_PUBLIC boolean OCI_API OCI_DequeueSetMode(OCI_Dequeue *dequeue, unsigned int mode)
Set the dequeuing/locking behavior.
void * AnyPointer
Alias for the generic void pointer.
Definition: config.hpp:129
void Subscribe(unsigned int port, unsigned int timeout, NotifyAQHandlerProc handler)
Subscribe for asynchronous messages notifications.
Definition: Dequeue.hpp:145
Template Enumeration template class providing some type safety to some extends for manipulating enume...
Definition: core.hpp:117
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...
Internal usage. Provide a buffer class with RAII capabilities.
Definition: core.hpp:196
void SetMode(DequeueMode value)
Set the dequeuing/locking behavior.
Definition: Dequeue.hpp:105
OCI_SYM_PUBLIC OCI_Dequeue *OCI_API OCI_DequeueCreate(OCI_TypeInfo *typinf, const otext *name)
Create a Dequeue object for the given queue.
void SetVisibility(DequeueVisibility value)
Set whether the new message is dequeued as part of the current transaction.
Definition: Dequeue.hpp:95
Dequeue(const TypeInfo &typeInfo, const ostring &queueName)
Parametrized constructor.
Definition: Dequeue.hpp:32
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.
DequeueMode GetMode() const
Get the dequeuing/locking behavior.
Definition: Dequeue.hpp:100
core::Enum< NavigationModeValues > NavigationMode
Navigation Mode.
Definition: types.hpp:8001
void Unsubscribe()
Unsubscribe for asynchronous messages notifications.
Definition: Dequeue.hpp:152
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.
std::vector< unsigned char > Raw
C++ counterpart of SQL RAW data type.
Definition: config.hpp:138
void SetWaitTime(int value)
Set the time that Get() waits for messages if no messages are currently available.
Definition: Dequeue.hpp:125
Provides type information on Oracle Database objects.
Definition: types.hpp:4508
OCI_SYM_PUBLIC unsigned int OCI_API OCI_DequeueGetNavigation(OCI_Dequeue *dequeue)
Return the navigation position of messages to retrieve from the queue.
ostring GetCorrelation() const
Get the correlation identifier of the message to be dequeued.
Definition: Dequeue.hpp:62
OCI_SYM_PUBLIC boolean OCI_API OCI_DequeueUnsubscribe(OCI_Dequeue *dequeue)
Unsubscribe for asynchronous messages notifications.
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 ...
AQ message.
Definition: types.hpp:7399
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
int GetWaitTime() const
Return the time that Get() waits for messages if no messages are currently available.
Definition: Dequeue.hpp:120
Raw GetRelativeMsgID() const
Get the message identifier of the message to be dequeued.
Definition: Dequeue.hpp:72
void SetNavigation(NavigationMode value)
Set the position of messages to be retrieved.
Definition: Dequeue.hpp:115