OCILIB (C and C++ Driver for Oracle)  4.7.3
Open source and cross platform Oracle Driver delivering efficient access to Oracle databases.
Message.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 Message::Message(const TypeInfo &typeInfo)
33 {
34  Acquire(core::Check(OCI_MsgCreate(typeInfo)), reinterpret_cast<HandleFreeFunc>(OCI_MsgFree), nullptr, nullptr);
35 }
36 
37 inline Message::Message(OCI_Msg *pMessage, core::Handle *parent)
38 {
39  Acquire(pMessage, nullptr, nullptr, parent);
40 }
41 
42 inline void Message::Reset()
43 {
44  core::Check(OCI_MsgReset(*this));
45 }
46 
47 template<>
48 inline Object Message::GetPayload<Object>()
49 {
50  return Object(core::Check(OCI_MsgGetObject(*this)), nullptr);
51 }
52 
53 template<>
54 inline void Message::SetPayload<Object>(const Object &value)
55 {
56  core::Check(OCI_MsgSetObject(*this, value));
57 }
58 
59 template<>
60 inline Raw Message::GetPayload<Raw>()
61 {
62  unsigned int size = 0;
63 
64  core::ManagedBuffer<unsigned char> buffer(static_cast<size_t>(size + 1));
65 
66  core::Check(OCI_MsgGetRaw(*this, static_cast<AnyPointer>(buffer), &size));
67 
68  return core::MakeRaw(buffer, size);
69 }
70 
71 template<>
72 inline void Message::SetPayload<Raw>(const Raw &value)
73 {
74  const AnyPointer data = value.empty() ? nullptr : static_cast<AnyPointer>(const_cast<Raw::value_type*>(&value[0])) ;
75 
76  core::Check(OCI_MsgSetRaw(*this, data, static_cast<unsigned int>(value.size())));
77 }
78 
80 {
81  return Date(core::Check(OCI_MsgGetEnqueueTime(*this)), nullptr);
82 }
83 
84 inline int Message::GetAttemptCount() const
85 {
86  return core::Check(OCI_MsgGetAttemptCount(*this));
87 }
88 
90 {
91  return MessageState(static_cast<MessageState::Type>(core::Check(OCI_MsgGetState(*this))));
92 }
93 
94 inline Raw Message::GetID() const
95 {
96  unsigned int size = OCI_SIZE_BUFFER;
97 
98  core::ManagedBuffer<unsigned char> buffer(static_cast<size_t>(size + 1));
99 
100  core::Check(OCI_MsgGetID(*this, static_cast<AnyPointer>(buffer), &size));
101 
102  return core::MakeRaw(buffer, size);
103 }
104 
105 inline int Message::GetExpiration() const
106 {
107  return core::Check(OCI_MsgGetExpiration(*this));
108 }
109 
110 inline void Message::SetExpiration(int value)
111 {
112  core::Check(OCI_MsgSetExpiration(*this, value));
113 }
114 
115 inline int Message::GetEnqueueDelay() const
116 {
117  return core::Check(OCI_MsgGetEnqueueDelay(*this));
118 }
119 
120 inline void Message::SetEnqueueDelay(int value)
121 {
122  core::Check(OCI_MsgSetEnqueueDelay(*this, value));
123 }
124 
125 inline int Message::GetPriority() const
126 {
127  return core::Check(OCI_MsgGetPriority(*this));
128 }
129 
130 inline void Message::SetPriority(int value)
131 {
132  core::Check(OCI_MsgSetPriority(*this, value));
133 }
134 
136 {
137  unsigned int size = OCI_SIZE_BUFFER;
138 
139  core::ManagedBuffer<unsigned char> buffer(static_cast<size_t>(size + 1));
140 
141  core::Check(OCI_MsgGetOriginalID(*this, static_cast<AnyPointer>(buffer), &size));
142 
143  return core::MakeRaw(buffer, size);
144 }
145 
146 inline void Message::SetOriginalID(const Raw &value)
147 {
148  const AnyPointer data = value.empty() ? nullptr : static_cast<AnyPointer>(const_cast<Raw::value_type*>(&value[0])) ;
149 
150  core::Check(OCI_MsgSetOriginalID(*this, data, static_cast<unsigned int>(value.size())));
151 }
152 
154 {
156 }
157 
158 inline void Message::SetCorrelation(const ostring& value)
159 {
160  core::Check(OCI_MsgSetCorrelation(*this, value.c_str()));
161 }
162 
164 {
166 }
167 
168 inline void Message::SetExceptionQueue(const ostring& value)
169 {
170  core::Check(OCI_MsgSetExceptionQueue(*this, value.c_str()));
171 }
172 
173 inline Agent Message::GetSender() const
174 {
175  return Agent(core::Check(OCI_MsgGetSender(*this)), nullptr);
176 }
177 
178 inline void Message::SetSender(const Agent &agent)
179 {
180  core::Check(OCI_MsgSetSender(*this, agent));
181 }
182 
183 inline void Message::SetConsumers(std::vector<Agent> &agents)
184 {
185  const size_t size = agents.size();
186  core::ManagedBuffer<OCI_Agent*> buffer(size);
187 
188  OCI_Agent ** pAgents = static_cast<OCI_Agent **>(buffer);
189 
190  for (size_t i = 0; i < size; ++i)
191  {
192  pAgents[i] = static_cast<const Agent &>(agents[i]);
193  }
194 
195  core::Check(OCI_MsgSetConsumers(*this, pAgents, static_cast<unsigned int>(size)));
196 }
197 
198 }
struct OCI_Agent OCI_Agent
OCILIB encapsulation of A/Q Agent.
Definition: types.h:448
Internal usage. Interface for handling ownership and relationship of a C API handle.
Definition: core.hpp:312
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetSender(OCI_Msg *msg, OCI_Agent *sender)
Set the original sender of a message.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetEnqueueDelay(OCI_Msg *msg, int value)
set the number of seconds to delay the enqueued message
OCILIB ++ Namespace.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgGetRaw(OCI_Msg *msg, void *raw, unsigned int *size)
Get the RAW payload of the given message.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetExceptionQueue(OCI_Msg *msg, const otext *queue)
Set the name of the queue to which the message is moved to if it cannot be processed successfully...
Raw MakeRaw(AnyPointer result, unsigned int size)
Internal usage. Constructs a C++ Raw object from the given OCILIB raw buffer.
Definition: Utils.hpp:70
OCI_SYM_PUBLIC OCI_Agent *OCI_API OCI_MsgGetSender(OCI_Msg *msg)
Return the original sender of a message.
OCI_SYM_PUBLIC OCI_Date *OCI_API OCI_MsgGetEnqueueTime(OCI_Msg *msg)
return the time the message was enqueued
void SetExceptionQueue(const ostring &value)
Set the name of the queue to which the message is moved to if it cannot be processed successfully...
Definition: Message.hpp:168
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
AQ identified agent for messages delivery.
Definition: types.hpp:7309
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetRaw(OCI_Msg *msg, const void *raw, unsigned int size)
Set the RAW payload of the given message.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetCorrelation(OCI_Msg *msg, const otext *correlation)
set the correlation identifier of the message
int GetPriority() const
Return the priority of the message.
Definition: Message.hpp:125
void Reset()
Reset all attributes of the message.
Definition: Message.hpp:42
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetObject(OCI_Msg *msg, OCI_Object *obj)
Set the object payload of the given message.
OCI_SYM_PUBLIC OCI_Msg *OCI_API OCI_MsgCreate(OCI_TypeInfo *typinf)
Create a message object based on the given payload type.
struct OCI_Msg OCI_Msg
OCILIB encapsulation of A/Q message.
Definition: types.h:438
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgFree(OCI_Msg *msg)
Free a message object.
OCI_SYM_PUBLIC OCI_Object *OCI_API OCI_MsgGetObject(OCI_Msg *msg)
Get the object payload of the given message.
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
ostring GetExceptionQueue() const
Get the Exception queue name of the message.
Definition: Message.hpp:163
OCI_SYM_PUBLIC const otext *OCI_API OCI_MsgGetCorrelation(OCI_Msg *msg)
Get the correlation identifier of the message.
OCI_SYM_PUBLIC const otext *OCI_API OCI_MsgGetExceptionQueue(OCI_Msg *msg)
Get the Exception queue name of the message.
void SetCorrelation(const ostring &value)
Set the correlation identifier of the message.
Definition: Message.hpp:158
void * AnyPointer
Alias for the generic void pointer.
Definition: config.hpp:129
Template Enumeration template class providing some type safety to some extends for manipulating enume...
Definition: core.hpp:117
void SetPriority(int value)
Set the priority of the message.
Definition: Message.hpp:130
Internal usage. Provide a buffer class with RAII capabilities.
Definition: core.hpp:196
Message(const TypeInfo &typeInfo)
Create a message object based on the given payload type.
Definition: Message.hpp:32
OCI_SYM_PUBLIC int OCI_API OCI_MsgGetEnqueueDelay(OCI_Msg *msg)
Return the number of seconds that a message is delayed for dequeuing.
MessageState GetState() const
Return the state of the message at the time of the dequeue.
Definition: Message.hpp:89
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetConsumers(OCI_Msg *msg, OCI_Agent **consumers, unsigned int count)
Set the recipient list of a message to enqueue.
OCI_SYM_PUBLIC int OCI_API OCI_MsgGetPriority(OCI_Msg *msg)
Return the priority of the message.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgGetOriginalID(OCI_Msg *msg, void *id, unsigned int *len)
Return the original ID of the message in the last queue that generated this message.
void SetOriginalID(const Raw &value)
Set the original ID of the message in the last queue that generated this message. ...
Definition: Message.hpp:146
ostring GetCorrelation() const
Get the correlation identifier of the message.
Definition: Message.hpp:153
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetPriority(OCI_Msg *msg, int value)
Set the priority of the message.
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgGetID(OCI_Msg *msg, void *id, unsigned int *len)
Return the ID of the message.
void SetConsumers(std::vector< Agent > &agents)
Set the recipient list of a message to enqueue.
Definition: Message.hpp:183
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgReset(OCI_Msg *msg)
Reset all attributes of a message object.
OCI_SYM_PUBLIC int OCI_API OCI_MsgGetExpiration(OCI_Msg *msg)
Return the duration that the message is available for dequeuing.
std::vector< unsigned char > Raw
C++ counterpart of SQL RAW data type.
Definition: config.hpp:138
Agent GetSender() const
Return the original sender of the message.
Definition: Message.hpp:173
Raw GetID() const
Return the ID of the message.
Definition: Message.hpp:94
Provides type information on Oracle Database objects.
Definition: types.hpp:4508
int GetEnqueueDelay() const
Return the number of seconds that a message is delayed for dequeuing.
Definition: Message.hpp:115
void SetSender(const Agent &agent)
Set the original sender of the message.
Definition: Message.hpp:178
void SetEnqueueDelay(int value)
set the number of seconds to delay the enqueued message
Definition: Message.hpp:120
OCI_SYM_PUBLIC unsigned int OCI_API OCI_MsgGetState(OCI_Msg *msg)
Return the state of the message at the time of the dequeue.
void SetExpiration(int value)
set the duration that the message is available for dequeuing
Definition: Message.hpp:110
OCI_SYM_PUBLIC int OCI_API OCI_MsgGetAttemptCount(OCI_Msg *msg)
Return the number of attempts that have been made to dequeue the message.
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
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetOriginalID(OCI_Msg *msg, const void *id, unsigned int len)
Set the original ID of the message in the last queue that generated this message. ...
Date GetEnqueueTime() const
return the time the message was enqueued
Definition: Message.hpp:79
int GetAttemptCount() const
Return the number of attempts that have been made to dequeue the message.
Definition: Message.hpp:84
int GetExpiration() const
Return the duration that the message is available for dequeuing.
Definition: Message.hpp:105
core::Enum< MessageStateValues > MessageState
Message state.
Definition: types.hpp:7429
Object identifying the SQL data type OBJECT.
Definition: types.hpp:4645
Raw GetOriginalID() const
Return the original ID of the message in the last queue that generated this message.
Definition: Message.hpp:135
OCI_SYM_PUBLIC boolean OCI_API OCI_MsgSetExpiration(OCI_Msg *msg, int value)
set the duration that the message is available for dequeuing
Object identifying the SQL data type DATE.
Definition: types.hpp:2655