1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
use chrono::{DateTime, Utc};
use error::{ErrorKind, Result};
use odpi::opaque::ODPIMsgProps;
use odpi::structs::ODPITimestamp;
use odpi::{enums, externs};
use std::convert::TryFrom;
use std::ptr;
use util::ODPIStr;
#[derive(Clone)]
pub struct Properties {
inner: *mut ODPIMsgProps,
}
impl Properties {
#[doc(hidden)]
pub fn inner(&self) -> *mut ODPIMsgProps {
self.inner
}
pub fn get_num_attempts(&self) -> Result<i32> {
let mut attempts = 0;
try_dpi!(
externs::dpiMsgProps_getNumAttempts(self.inner, &mut attempts),
Ok(attempts),
ErrorKind::MsgProps("dpiMsgProps_getNumAttempts".to_string())
)
}
pub fn get_correlation(&self) -> Result<String> {
let mut corr_ptr = ptr::null();
let mut corr_len = 0;
try_dpi!(
externs::dpiMsgProps_getCorrelation(self.inner, &mut corr_ptr, &mut corr_len),
{
let correlation = if corr_ptr.is_null() {
"".to_string()
} else {
let corr_s = ODPIStr::new(corr_ptr, corr_len);
corr_s.into()
};
Ok(correlation)
},
ErrorKind::Lob("dpiMsgProps_getCorrelation".to_string())
)
}
pub fn get_delay(&self) -> Result<i32> {
let mut delay = 0;
try_dpi!(
externs::dpiMsgProps_getDelay(self.inner, &mut delay),
Ok(delay),
ErrorKind::MsgProps("dpiMsgProps_getDelay".to_string())
)
}
pub fn get_delivery_mode(&self) -> Result<enums::ODPIMessageDeliveryMode> {
let mut del_mode_ptr = enums::ODPIMessageDeliveryMode::NotSet;
try_dpi!(
externs::dpiMsgProps_getDeliveryMode(self.inner, &mut del_mode_ptr),
Ok(del_mode_ptr),
ErrorKind::MsgProps("dpiEnqOptions_getMode".to_string())
)
}
pub fn get_enq_time(&self) -> Result<DateTime<Utc>> {
let mut timestamp: ODPITimestamp = Default::default();
try_dpi!(
externs::dpiMsgProps_getEnqTime(self.inner, &mut timestamp),
Ok(timestamp.into()),
ErrorKind::MsgProps("dpiMsgProps_getEnqTime".to_string())
)
}
pub fn get_exception_q(&self) -> Result<String> {
let mut exception_q_ptr = ptr::null();
let mut exception_q_len = 0;
try_dpi!(
externs::dpiMsgProps_getExceptionQ(
self.inner,
&mut exception_q_ptr,
&mut exception_q_len
),
{
let exception_q = ODPIStr::new(exception_q_ptr, exception_q_len);
Ok(exception_q.into())
},
ErrorKind::MsgProps("dpiMsgProps_getExceptionQ".to_string())
)
}
pub fn get_expiration(&self) -> Result<i32> {
let mut seconds = 0;
try_dpi!(
externs::dpiMsgProps_getExpiration(self.inner, &mut seconds),
Ok(seconds),
ErrorKind::MsgProps("dpiMsgProps_getExpiration".to_string())
)
}
pub fn get_original_msg_id(&self) -> Result<String> {
let mut orig_msg_id_ptr = ptr::null();
let mut orig_msg_id_len = 0;
try_dpi!(
externs::dpiMsgProps_getOriginalMsgId(
self.inner,
&mut orig_msg_id_ptr,
&mut orig_msg_id_len
),
{
let orig_msg_id = ODPIStr::new(orig_msg_id_ptr, orig_msg_id_len);
Ok(orig_msg_id.into())
},
ErrorKind::MsgProps("dpiMsgProps_getOriginalMsgId".to_string())
)
}
pub fn get_priority(&self) -> Result<i32> {
let mut priority = 0;
try_dpi!(
externs::dpiMsgProps_getPriority(self.inner, &mut priority),
Ok(priority),
ErrorKind::MsgProps("dpiMsgProps_getPriority".to_string())
)
}
pub fn get_state(&self) -> Result<enums::ODPIMessageState> {
let mut state = enums::ODPIMessageState::Ready;
try_dpi!(
externs::dpiMsgProps_getState(self.inner, &mut state),
Ok(state),
ErrorKind::MsgProps("dpiMsgProps_getState".to_string())
)
}
pub fn set_correlation(&self, correlation: &str) -> Result<()> {
let correlation_s: ODPIStr = TryFrom::try_from(correlation)?;
try_dpi!(
externs::dpiMsgProps_setCorrelation(
self.inner,
correlation_s.ptr(),
correlation_s.len()
),
Ok(()),
ErrorKind::MsgProps("dpiMsgProps_setCorrelation".to_string())
)
}
pub fn set_delay(&self, delay: i32) -> Result<()> {
try_dpi!(
externs::dpiMsgProps_setDelay(self.inner, delay),
Ok(()),
ErrorKind::MsgProps("dpiMsgProps_setDelay".to_string())
)
}
pub fn set_exception_q(&self, queue_name: &str) -> Result<()> {
let queue_name_s: ODPIStr = TryFrom::try_from(queue_name)?;
try_dpi!(
externs::dpiMsgProps_setExceptionQ(self.inner, queue_name_s.ptr(), queue_name_s.len()),
Ok(()),
ErrorKind::MsgProps("dpiMsgProps_setExceptionQ".to_string())
)
}
pub fn set_expiration(&self, seconds: i32) -> Result<()> {
try_dpi!(
externs::dpiMsgProps_setExpiration(self.inner, seconds),
Ok(()),
ErrorKind::MsgProps("dpiMsgProps_setExpiration".to_string())
)
}
pub fn set_original_msg_id(&self, id: &str) -> Result<()> {
let id_s: ODPIStr = TryFrom::try_from(id)?;
try_dpi!(
externs::dpiMsgProps_setOriginalMsgId(self.inner, id_s.ptr(), id_s.len()),
Ok(()),
ErrorKind::MsgProps("dpiMsgProps_setOriginalMsgId".to_string())
)
}
pub fn set_priority(&self, priority: i32) -> Result<()> {
try_dpi!(
externs::dpiMsgProps_setPriority(self.inner, priority),
Ok(()),
ErrorKind::MsgProps("dpiMsgProps_setPriority".to_string())
)
}
}
impl From<*mut ODPIMsgProps> for Properties {
fn from(inner: *mut ODPIMsgProps) -> Self {
Self { inner }
}
}
impl Drop for Properties {
fn drop(&mut self) {
if !self.inner.is_null() {
unsafe {
externs::dpiMsgProps_release(self.inner);
}
}
}
}