1use crate::chkerr;
104use crate::connection::Conn;
105use crate::sql_type::Object;
106use crate::sql_type::ObjectType;
107use crate::sql_type::OracleType;
108use crate::sql_type::Timestamp;
109use crate::to_rust_slice;
110use crate::Connection;
111use crate::Context;
112use crate::DpiMsgProps;
113use crate::DpiObject;
114use crate::DpiQueue;
115use crate::Error;
116use crate::OdpiStr;
117use crate::Result;
118use odpic_sys::*;
119use std::borrow::ToOwned;
120use std::fmt;
121use std::marker::PhantomData;
122use std::os::raw::c_char;
123use std::ptr;
124use std::time::Duration;
125
126pub trait Payload: ToOwned {
130 type TypeInfo;
131 fn payload_type(payload_type: &Self::TypeInfo) -> Result<Option<ObjectType>>;
132 fn get(props: &MsgProps<Self>) -> Result<Self::Owned>;
133 fn set(&self, props: &mut MsgProps<Self>) -> Result<()>;
134}
135
136impl Payload for [u8] {
137 type TypeInfo = ();
138
139 fn payload_type(_payload_type: &Self::TypeInfo) -> Result<Option<ObjectType>> {
140 Ok(None)
141 }
142
143 fn get(props: &MsgProps<Self>) -> Result<Vec<u8>> {
144 let mut ptr = ptr::null();
145 let mut len = 0;
146 chkerr!(
147 props.ctxt(),
148 dpiMsgProps_getPayload(props.handle.raw, ptr::null_mut(), &mut ptr, &mut len)
149 );
150 Ok(to_rust_slice(ptr, len).to_vec())
151 }
152
153 fn set(&self, props: &mut MsgProps<Self>) -> Result<()> {
154 chkerr!(
155 props.ctxt(),
156 dpiMsgProps_setPayloadBytes(
157 props.handle.raw,
158 self.as_ptr() as *const c_char,
159 self.len() as u32
160 )
161 );
162 props.payload_type = None;
163 Ok(())
164 }
165}
166
167impl Payload for Object {
168 type TypeInfo = ObjectType;
169
170 fn payload_type(payload_type: &Self::TypeInfo) -> Result<Option<ObjectType>> {
171 Ok(Some(payload_type.clone()))
172 }
173
174 fn get(props: &MsgProps<Self>) -> Result<Object> {
175 let objtype = props
176 .payload_type
177 .as_ref()
178 .ok_or_else(Error::no_data_found)?;
179 let mut obj_handle = DpiObject::null();
180 chkerr!(
181 props.ctxt(),
182 dpiMsgProps_getPayload(
183 props.handle.raw,
184 &mut obj_handle.raw,
185 ptr::null_mut(),
186 ptr::null_mut()
187 )
188 );
189 Ok(Object::new(props.conn.clone(), obj_handle, objtype.clone()))
190 }
191
192 fn set(&self, props: &mut MsgProps<Self>) -> Result<()> {
193 chkerr!(
194 props.ctxt(),
195 dpiMsgProps_setPayloadObject(props.handle.raw, self.handle())
196 );
197 props.payload_type = Some(self.object_type().clone());
198 Ok(())
199 }
200}
201
202pub struct Queue<T>
206where
207 T: Payload + ?Sized,
208{
209 conn: Conn,
210 handle: DpiQueue,
211 payload_type: Option<ObjectType>,
212 enq_options: Option<EnqOptions>,
213 deq_options: Option<DeqOptions>,
214 phantom: PhantomData<T>,
215}
216
217impl<T> Queue<T>
218where
219 T: Payload + ?Sized,
220{
221 fn handle(&self) -> *mut dpiQueue {
222 self.handle.raw
223 }
224
225 fn ctxt(&self) -> &Context {
226 self.conn.ctxt()
227 }
228
229 pub fn new(
232 conn: &Connection,
233 queue_name: &str,
234 payload_type: &T::TypeInfo,
235 ) -> Result<Queue<T>> {
236 let mut handle = ptr::null_mut();
237 let name = OdpiStr::new(queue_name);
238 let payload_type = T::payload_type(payload_type)?;
239 let objtype = payload_type
240 .as_ref()
241 .map(|t| t.handle().raw)
242 .unwrap_or(ptr::null_mut());
243 chkerr!(
244 conn.ctxt(),
245 dpiConn_newQueue(conn.handle(), name.ptr, name.len, objtype, &mut handle)
246 );
247 Ok(Queue {
248 conn: conn.conn.clone(),
249 handle: DpiQueue::new(handle),
250 payload_type,
251 enq_options: None,
252 deq_options: None,
253 phantom: PhantomData,
254 })
255 }
256
257 pub fn dequeue(&self) -> Result<MsgProps<T>> {
259 let mut props = ptr::null_mut();
260 chkerr!(self.ctxt(), dpiQueue_deqOne(self.handle(), &mut props));
261 Ok(MsgProps::from_dpi_msg_props(
262 self.conn.clone(),
263 DpiMsgProps::new(props),
264 self.payload_type.clone(),
265 ))
266 }
267
268 pub fn dequeue_many(&self, max_size: u32) -> Result<Vec<MsgProps<T>>> {
270 let mut num_props = max_size;
271 let mut handles = Vec::<DpiMsgProps>::with_capacity(max_size as usize);
272 chkerr!(
273 self.ctxt(),
274 dpiQueue_deqMany(
275 self.handle(),
276 &mut num_props,
277 handles.as_mut_ptr() as *mut *mut dpiMsgProps
280 )
281 );
282 let num_props = num_props as usize;
283 unsafe {
284 handles.set_len(num_props);
285 }
286 let props: Vec<_> = handles
287 .into_iter()
288 .map(|handle| {
289 MsgProps::from_dpi_msg_props(self.conn.clone(), handle, self.payload_type.clone())
290 })
291 .collect();
292 Ok(props)
293 }
294
295 pub fn enqueue(&self, props: &MsgProps<T>) -> Result<()> {
297 chkerr!(self.ctxt(), dpiQueue_enqOne(self.handle(), props.handle()));
298 Ok(())
299 }
300
301 pub fn enqueue_many<'a, I>(&'a self, props: I) -> Result<()>
313 where
314 I: IntoIterator<Item = &'a MsgProps<T>>,
315 {
316 let iter = props.into_iter();
317 let (lower, _) = iter.size_hint();
318 let mut raw_props = Vec::with_capacity(lower);
319 for msg in iter {
320 let handle = msg.handle();
321 raw_props.push(handle);
322 unsafe {
323 dpiMsgProps_addRef(handle);
324 }
325 }
326 chkerr!(
327 self.ctxt(),
328 dpiQueue_enqMany(
329 self.handle(),
330 raw_props.len() as u32,
331 raw_props.as_mut_ptr()
332 ),
333 for handle in raw_props {
334 unsafe {
335 dpiMsgProps_release(handle);
336 }
337 }
338 );
339 for handle in raw_props {
340 unsafe {
341 dpiMsgProps_release(handle);
342 }
343 }
344 Ok(())
345 }
346
347 pub fn deq_options(&mut self) -> Result<&mut DeqOptions> {
350 if self.deq_options.is_none() {
351 let mut handle = ptr::null_mut();
352 chkerr!(
353 self.ctxt(),
354 dpiQueue_getDeqOptions(self.handle(), &mut handle)
355 );
356 self.deq_options = Some(DeqOptions::new(self.ctxt().clone(), handle));
357 }
358 Ok(self.deq_options.as_mut().unwrap())
359 }
360
361 pub fn enq_options(&mut self) -> Result<&mut EnqOptions> {
364 if self.enq_options.is_none() {
365 let mut handle = ptr::null_mut();
366 chkerr!(
367 self.ctxt(),
368 dpiQueue_getEnqOptions(self.handle(), &mut handle)
369 );
370 self.enq_options = Some(EnqOptions::new(self.ctxt().clone(), handle));
371 }
372 Ok(self.enq_options.as_mut().unwrap())
373 }
374}
375
376#[derive(Clone, Debug, PartialEq, Eq)]
377pub enum MessageDeliveryMode {
381 Persistent,
383 Buffered,
385 PersistentOrBuffered,
387}
388
389impl MessageDeliveryMode {
390 fn from_dpi_value(val: dpiMessageDeliveryMode) -> Result<MessageDeliveryMode> {
391 match val {
392 DPI_MODE_MSG_PERSISTENT => Ok(MessageDeliveryMode::Persistent),
393 DPI_MODE_MSG_BUFFERED => Ok(MessageDeliveryMode::Buffered),
394 DPI_MODE_MSG_PERSISTENT_OR_BUFFERED => Ok(MessageDeliveryMode::PersistentOrBuffered),
395 _ => Err(Error::internal_error(format!(
396 "unknown dpiMessageDeliveryMode {}",
397 val
398 ))),
399 }
400 }
401
402 fn to_dpi_value(&self) -> dpiMessageDeliveryMode {
403 match self {
404 MessageDeliveryMode::Persistent => DPI_MODE_MSG_PERSISTENT as dpiMessageDeliveryMode,
405 MessageDeliveryMode::Buffered => DPI_MODE_MSG_PERSISTENT as dpiMessageDeliveryMode,
406 MessageDeliveryMode::PersistentOrBuffered => {
407 DPI_MODE_MSG_PERSISTENT as dpiMessageDeliveryMode
408 }
409 }
410 }
411}
412
413#[derive(Clone, Debug, PartialEq, Eq)]
414pub enum MessageState {
418 Ready,
420 Waiting,
422 Processed,
424 Expired,
426}
427
428impl MessageState {
429 fn from_dpi_value(val: dpiMessageState) -> Result<MessageState> {
430 match val {
431 DPI_MSG_STATE_READY => Ok(MessageState::Ready),
432 DPI_MSG_STATE_WAITING => Ok(MessageState::Waiting),
433 DPI_MSG_STATE_PROCESSED => Ok(MessageState::Processed),
434 DPI_MSG_STATE_EXPIRED => Ok(MessageState::Expired),
435 _ => Err(Error::internal_error(format!(
436 "unknown dpiMessageState {}",
437 val
438 ))),
439 }
440 }
441}
442
443#[derive(Clone, Debug, PartialEq, Eq)]
444pub enum DeqMode {
448 Browse,
451 Locked,
455 Remove,
460 RemoveNoData,
463}
464
465impl DeqMode {
466 fn from_dpi_value(val: dpiDeqMode) -> Result<DeqMode> {
467 match val {
468 DPI_MODE_DEQ_BROWSE => Ok(DeqMode::Browse),
469 DPI_MODE_DEQ_LOCKED => Ok(DeqMode::Locked),
470 DPI_MODE_DEQ_REMOVE => Ok(DeqMode::Remove),
471 DPI_MODE_DEQ_REMOVE_NO_DATA => Ok(DeqMode::RemoveNoData),
472 _ => Err(Error::internal_error(format!("unknown dpiDeqMode {}", val))),
473 }
474 }
475
476 fn to_dpi_value(&self) -> dpiDeqMode {
477 match self {
478 DeqMode::Browse => DPI_MODE_DEQ_BROWSE,
479 DeqMode::Locked => DPI_MODE_DEQ_LOCKED,
480 DeqMode::Remove => DPI_MODE_DEQ_REMOVE,
481 DeqMode::RemoveNoData => DPI_MODE_DEQ_REMOVE_NO_DATA,
482 }
483 }
484}
485
486#[derive(Clone, Debug, PartialEq, Eq)]
487pub enum DeqNavigation {
491 FirstMessage,
495 NextTransaction,
501 NextMessage,
504}
505
506impl DeqNavigation {
507 fn from_dpi_value(val: dpiDeqNavigation) -> Result<DeqNavigation> {
508 match val {
509 DPI_DEQ_NAV_FIRST_MSG => Ok(DeqNavigation::FirstMessage),
510 DPI_DEQ_NAV_NEXT_TRANSACTION => Ok(DeqNavigation::NextTransaction),
511 DPI_DEQ_NAV_NEXT_MSG => Ok(DeqNavigation::NextMessage),
512 _ => Err(Error::internal_error(format!(
513 "unknown dpiDeqNavigation {}",
514 val
515 ))),
516 }
517 }
518
519 fn to_dpi_value(&self) -> dpiDeqNavigation {
520 match self {
521 DeqNavigation::FirstMessage => DPI_DEQ_NAV_FIRST_MSG,
522 DeqNavigation::NextTransaction => DPI_DEQ_NAV_NEXT_TRANSACTION,
523 DeqNavigation::NextMessage => DPI_DEQ_NAV_NEXT_MSG,
524 }
525 }
526}
527
528#[derive(Clone, Debug, PartialEq, Eq)]
529pub enum Visibility {
533 Immediate,
536 OnCommit,
539}
540
541impl Visibility {
542 fn from_dpi_value(val: dpiVisibility) -> Result<Visibility> {
543 match val {
544 DPI_VISIBILITY_IMMEDIATE => Ok(Visibility::Immediate),
545 DPI_VISIBILITY_ON_COMMIT => Ok(Visibility::OnCommit),
546 _ => Err(Error::internal_error(format!(
547 "unknown dpiVisibility {}",
548 val
549 ))),
550 }
551 }
552
553 fn to_dpi_value(&self) -> dpiVisibility {
554 match self {
555 Visibility::Immediate => DPI_VISIBILITY_IMMEDIATE,
556 Visibility::OnCommit => DPI_VISIBILITY_ON_COMMIT,
557 }
558 }
559}
560
561pub struct DeqOptions {
565 ctxt: Context,
566 handle: *mut dpiDeqOptions,
567}
568
569impl DeqOptions {
570 fn new(ctxt: Context, handle: *mut dpiDeqOptions) -> DeqOptions {
571 DeqOptions { ctxt, handle }
572 }
573
574 fn ctxt(&self) -> &Context {
575 &self.ctxt
576 }
577
578 pub fn condition(&self) -> Result<String> {
583 let mut s = OdpiStr::new("");
584 chkerr!(
585 self.ctxt(),
586 dpiDeqOptions_getCondition(self.handle, &mut s.ptr, &mut s.len)
587 );
588 Ok(s.to_string())
589 }
590
591 pub fn consumer_name(&self) -> Result<String> {
595 let mut s = OdpiStr::new("");
596 chkerr!(
597 self.ctxt(),
598 dpiDeqOptions_getConsumerName(self.handle, &mut s.ptr, &mut s.len)
599 );
600 Ok(s.to_string())
601 }
602
603 pub fn correlation(&self) -> Result<String> {
607 let mut s = OdpiStr::new("");
608 chkerr!(
609 self.ctxt(),
610 dpiDeqOptions_getCorrelation(self.handle, &mut s.ptr, &mut s.len)
611 );
612 Ok(s.to_string())
613 }
614
615 pub fn mode(&self) -> Result<DeqMode> {
617 let mut val = 0;
618 chkerr!(self.ctxt(), dpiDeqOptions_getMode(self.handle, &mut val));
619 DeqMode::from_dpi_value(val)
620 }
621
622 pub fn message_id(&self) -> Result<Vec<u8>> {
624 let mut msg = OdpiStr::new("");
625 chkerr!(
626 self.ctxt(),
627 dpiDeqOptions_getMsgId(self.handle, &mut msg.ptr, &mut msg.len)
628 );
629 Ok(msg.to_vec())
630 }
631
632 pub fn navigation(&self) -> Result<DeqNavigation> {
634 let mut val = 0;
635 chkerr!(
636 self.ctxt(),
637 dpiDeqOptions_getNavigation(self.handle, &mut val)
638 );
639 DeqNavigation::from_dpi_value(val)
640 }
641
642 pub fn transformation(&self) -> Result<String> {
646 let mut s = OdpiStr::new("");
647 chkerr!(
648 self.ctxt(),
649 dpiDeqOptions_getTransformation(self.handle, &mut s.ptr, &mut s.len)
650 );
651 Ok(s.to_string())
652 }
653
654 pub fn visibility(&self) -> Result<Visibility> {
657 let mut val = 0;
658 chkerr!(
659 self.ctxt(),
660 dpiDeqOptions_getVisibility(self.handle, &mut val)
661 );
662 Visibility::from_dpi_value(val)
663 }
664
665 pub fn wait(&self) -> Result<Duration> {
668 let mut val = 0;
669 chkerr!(self.ctxt(), dpiDeqOptions_getWait(self.handle, &mut val));
670 Ok(Duration::from_secs(val as u64))
671 }
672
673 pub fn set_condition(&mut self, val: &str) -> Result<()> {
681 let val = OdpiStr::new(val);
682 chkerr!(
683 self.ctxt(),
684 dpiDeqOptions_setCondition(self.handle, val.ptr, val.len)
685 );
686 Ok(())
687 }
688
689 pub fn set_consumer_name(&mut self, val: &str) -> Result<()> {
692 let val = OdpiStr::new(val);
693 chkerr!(
694 self.ctxt(),
695 dpiDeqOptions_setConsumerName(self.handle, val.ptr, val.len)
696 );
697 Ok(())
698 }
699
700 pub fn set_correlation(&mut self, val: &str) -> Result<()> {
707 let val = OdpiStr::new(val);
708 chkerr!(
709 self.ctxt(),
710 dpiDeqOptions_setCorrelation(self.handle, val.ptr, val.len)
711 );
712 Ok(())
713 }
714
715 pub fn set_delivery_mode(&mut self, val: &MessageDeliveryMode) -> Result<()> {
717 chkerr!(
718 self.ctxt(),
719 dpiDeqOptions_setDeliveryMode(self.handle, val.to_dpi_value())
720 );
721 Ok(())
722 }
723
724 pub fn set_mode(&mut self, val: &DeqMode) -> Result<()> {
726 chkerr!(
727 self.ctxt(),
728 dpiDeqOptions_setMode(self.handle, val.to_dpi_value())
729 );
730 Ok(())
731 }
732
733 pub fn set_message_id(&mut self, val: &[u8]) -> Result<()> {
735 let ptr = if val.is_empty() {
736 ptr::null()
737 } else {
738 val.as_ptr() as *const c_char
739 };
740 let len = val.len() as u32;
741 chkerr!(self.ctxt(), dpiDeqOptions_setMsgId(self.handle, ptr, len));
742 Ok(())
743 }
744
745 pub fn set_navigation(&mut self, val: &DeqNavigation) -> Result<()> {
747 chkerr!(
748 self.ctxt(),
749 dpiDeqOptions_setNavigation(self.handle, val.to_dpi_value())
750 );
751 Ok(())
752 }
753
754 pub fn set_transformation(&mut self, val: &str) -> Result<()> {
760 let val = OdpiStr::new(val);
761 chkerr!(
762 self.ctxt(),
763 dpiDeqOptions_setTransformation(self.handle, val.ptr, val.len)
764 );
765 Ok(())
766 }
767
768 pub fn set_visibility(&mut self, val: &Visibility) -> Result<()> {
771 chkerr!(
772 self.ctxt(),
773 dpiDeqOptions_setVisibility(self.handle, val.to_dpi_value())
774 );
775 Ok(())
776 }
777
778 pub fn set_wait(&mut self, val: &Duration) -> Result<()> {
781 let secs = val.as_secs().try_into().unwrap_or(u32::MAX);
782 chkerr!(self.ctxt(), dpiDeqOptions_setWait(self.handle, secs));
783 Ok(())
784 }
785}
786
787impl fmt::Debug for DeqOptions {
788 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
789 write!(f, "DeqOptions {{ handle: {:?} }}", self.handle)
790 }
791}
792
793pub struct EnqOptions {
797 ctxt: Context,
798 handle: *mut dpiEnqOptions,
799}
800
801impl EnqOptions {
802 fn new(ctxt: Context, handle: *mut dpiEnqOptions) -> EnqOptions {
803 EnqOptions { ctxt, handle }
804 }
805
806 fn ctxt(&self) -> &Context {
807 &self.ctxt
808 }
809
810 pub fn transformation(&self) -> Result<String> {
814 let mut s = OdpiStr::new("");
815 chkerr!(
816 self.ctxt(),
817 dpiEnqOptions_getTransformation(self.handle, &mut s.ptr, &mut s.len)
818 );
819 Ok(s.to_string())
820 }
821
822 pub fn visibility(&self) -> Result<Visibility> {
825 let mut val = 0;
826 chkerr!(
827 self.ctxt(),
828 dpiEnqOptions_getVisibility(self.handle, &mut val)
829 );
830 Visibility::from_dpi_value(val)
831 }
832
833 pub fn set_delivery_mode(&mut self, val: &MessageDeliveryMode) -> Result<()> {
835 chkerr!(
836 self.ctxt(),
837 dpiEnqOptions_setDeliveryMode(self.handle, val.to_dpi_value())
838 );
839 Ok(())
840 }
841
842 pub fn set_transformation(&mut self, val: &str) -> Result<()> {
848 let val = OdpiStr::new(val);
849 chkerr!(
850 self.ctxt(),
851 dpiEnqOptions_setTransformation(self.handle, val.ptr, val.len)
852 );
853 Ok(())
854 }
855
856 pub fn set_visibility(&mut self, val: &Visibility) -> Result<()> {
859 chkerr!(
860 self.ctxt(),
861 dpiEnqOptions_setVisibility(self.handle, val.to_dpi_value())
862 );
863 Ok(())
864 }
865}
866
867impl fmt::Debug for EnqOptions {
868 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
869 write!(f, "EnqOptions {{ handle: {:?} }}", self.handle)
870 }
871}
872
873#[derive(Clone)]
877pub struct MsgProps<T>
878where
879 T: Payload + ?Sized,
880{
881 conn: Conn,
882 handle: DpiMsgProps,
883 payload_type: Option<ObjectType>,
884 phantom: PhantomData<T>,
885}
886
887impl<T> MsgProps<T>
888where
889 T: Payload + ?Sized,
890{
891 fn handle(&self) -> *mut dpiMsgProps {
892 self.handle.raw()
893 }
894
895 fn ctxt(&self) -> &Context {
896 self.conn.ctxt()
897 }
898
899 pub fn new(conn: &Connection) -> Result<MsgProps<T>> {
901 let mut handle = ptr::null_mut();
902 chkerr!(conn.ctxt(), dpiConn_newMsgProps(conn.handle(), &mut handle));
903 Ok(MsgProps {
904 conn: conn.conn.clone(),
905 handle: DpiMsgProps::new(handle),
906 payload_type: None,
907 phantom: PhantomData,
908 })
909 }
910
911 fn from_dpi_msg_props(
912 conn: Conn,
913 handle: DpiMsgProps,
914 payload_type: Option<ObjectType>,
915 ) -> MsgProps<T> {
916 MsgProps {
917 conn,
918 handle,
919 payload_type,
920 phantom: PhantomData,
921 }
922 }
923
924 pub fn num_attempts(&self) -> Result<i32> {
926 let mut val = 0;
927 chkerr!(
928 self.ctxt(),
929 dpiMsgProps_getNumAttempts(self.handle(), &mut val)
930 );
931 Ok(val)
932 }
933
934 pub fn correlation(&self) -> Result<String> {
937 let mut s = OdpiStr::new("");
938 chkerr!(
939 self.ctxt(),
940 dpiMsgProps_getCorrelation(self.handle(), &mut s.ptr, &mut s.len)
941 );
942 Ok(s.to_string())
943 }
944
945 pub fn delay(&self) -> Result<Duration> {
947 let mut secs = 0;
948 chkerr!(self.ctxt(), dpiMsgProps_getDelay(self.handle(), &mut secs));
949 Ok(Duration::from_secs(secs as u64))
950 }
951
952 pub fn delivery_mode(&self) -> Result<MessageDeliveryMode> {
954 let mut val = 0;
955 chkerr!(
956 self.ctxt(),
957 dpiMsgProps_getDeliveryMode(self.handle(), &mut val)
958 );
959 MessageDeliveryMode::from_dpi_value(val)
960 }
961
962 pub fn enq_time(&self) -> Result<Timestamp> {
964 let mut val = Default::default();
965 chkerr!(self.ctxt(), dpiMsgProps_getEnqTime(self.handle(), &mut val));
966 Ok(Timestamp::from_dpi_timestamp(&val, &OracleType::Date))
967 }
968
969 pub fn exception_queue(&self) -> Result<String> {
974 let mut s = OdpiStr::new("");
975 chkerr!(
976 self.ctxt(),
977 dpiMsgProps_getExceptionQ(self.handle(), &mut s.ptr, &mut s.len)
978 );
979 Ok(s.to_string())
980 }
981
982 pub fn expiration(&self) -> Result<Duration> {
986 let mut val = 0;
987 chkerr!(
988 self.ctxt(),
989 dpiMsgProps_getExpiration(self.handle(), &mut val)
990 );
991 Ok(Duration::from_secs(val as u64))
992 }
993
994 pub fn message_id(&self) -> Result<Vec<u8>> {
997 let mut msg = OdpiStr::new("");
998 chkerr!(
999 self.ctxt(),
1000 dpiMsgProps_getMsgId(self.handle(), &mut msg.ptr, &mut msg.len)
1001 );
1002 Ok(msg.to_vec())
1003 }
1004
1005 pub fn original_message_id(&self) -> Result<Vec<u8>> {
1010 let mut msg = OdpiStr::new("");
1011 chkerr!(
1012 self.ctxt(),
1013 dpiMsgProps_getOriginalMsgId(self.handle(), &mut msg.ptr, &mut msg.len)
1014 );
1015 Ok(msg.to_vec())
1016 }
1017
1018 pub fn payload(&self) -> Result<T::Owned> {
1026 T::get(self)
1027 }
1028
1029 pub fn priority(&self) -> Result<i32> {
1033 let mut val = 0;
1034 chkerr!(
1035 self.ctxt(),
1036 dpiMsgProps_getPriority(self.handle(), &mut val)
1037 );
1038 Ok(val)
1039 }
1040
1041 pub fn state(&self) -> Result<MessageState> {
1043 let mut val = 0;
1044 chkerr!(self.ctxt(), dpiMsgProps_getState(self.handle(), &mut val));
1045 MessageState::from_dpi_value(val)
1046 }
1047
1048 pub fn set_correlation(&mut self, val: &str) -> Result<()> {
1055 let val = OdpiStr::new(val);
1056 chkerr!(
1057 self.ctxt(),
1058 dpiMsgProps_setCorrelation(self.handle(), val.ptr, val.len)
1059 );
1060 Ok(())
1061 }
1062
1063 pub fn set_delay(&mut self, val: &Duration) -> Result<()> {
1074 let secs = val
1075 .as_secs()
1076 .try_into()
1077 .map_err(|_| Error::out_of_range(format!("too long duration {:?}", val)))?;
1078 chkerr!(self.ctxt(), dpiMsgProps_setDelay(self.handle(), secs));
1079 Ok(())
1080 }
1081
1082 pub fn set_exception_queue(&mut self, val: &str) -> Result<()> {
1092 let val = OdpiStr::new(val);
1093 chkerr!(
1094 self.ctxt(),
1095 dpiMsgProps_setExceptionQ(self.handle(), val.ptr, val.len)
1096 );
1097 Ok(())
1098 }
1099
1100 pub fn set_expiration(&mut self, val: &Duration) -> Result<()> {
1110 let secs = val
1111 .as_secs()
1112 .try_into()
1113 .map_err(|_| Error::out_of_range(format!("too long duration {:?}", val)))?;
1114 chkerr!(self.ctxt(), dpiMsgProps_setExpiration(self.handle(), secs));
1115 Ok(())
1116 }
1117
1118 pub fn set_original_message_id(&mut self, val: &[u8]) -> Result<()> {
1121 let ptr = if val.is_empty() {
1122 ptr::null()
1123 } else {
1124 val.as_ptr() as *const c_char
1125 };
1126 let len = val.len() as u32;
1127 chkerr!(
1128 self.ctxt(),
1129 dpiMsgProps_setOriginalMsgId(self.handle(), ptr, len)
1130 );
1131 Ok(())
1132 }
1133
1134 pub fn set_payload(&mut self, val: &T) -> Result<()> {
1142 val.set(self)
1143 }
1144
1145 pub fn set_priority(&mut self, val: i32) -> Result<()> {
1150 chkerr!(self.ctxt(), dpiMsgProps_setPriority(self.handle(), val));
1151 Ok(())
1152 }
1153}
1154
1155impl<T> fmt::Debug for MsgProps<T>
1156where
1157 T: Payload,
1158{
1159 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1160 write!(f, "MsgProps {{ handle: {:?} }}", self.handle())
1161 }
1162}