Files
arrayvec
async_attributes
async_channel
async_executor
async_global_executor
async_io
async_lock
async_mutex
async_process
async_rustbus
async_std
collections
fs
future
io
net
option
os
path
pin
result
rt
stream
string
sync
task
unit
vec
async_task
atomic_waker
bitflags
blocking
cache_padded
cfg_if
concurrent_queue
crossbeam_utils
ctor
derive_utils
event_listener
fastrand
find_crate
futures
futures_channel
futures_core
futures_enum
futures_executor
futures_io
futures_lite
futures_macro
futures_sink
futures_task
futures_util
async_await
future
io
lock
sink
stream
task
kv_log_macro
lazy_static
libc
log
memchr
nix
num_cpus
once_cell
parking
pin_project_lite
pin_utils
polling
proc_macro2
proc_macro_hack
proc_macro_nested
quote
rustable
rustbus
rustbus_derive
serde
signal_hook
signal_hook_registry
slab
socket2
syn
toml
unicode_xid
value_bag
void
waker_fn
xml
  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
//! Messages that have been completetly unmarshalled

use crate::message_builder::{DynamicHeader, HeaderFlags, MessageType};
use crate::params::*;
use crate::signature;

/// A message with all the different fields it may or may not have
/// and only Params as the body
#[derive(Debug, Clone)]
pub struct Message<'a, 'e> {
    pub typ: MessageType,
    pub flags: u8,

    // dynamic header
    pub dynheader: DynamicHeader,

    // body
    pub params: Vec<Param<'a, 'e>>,

    // out of band data
    pub raw_fds: Vec<crate::wire::UnixFd>,
}

impl<'a, 'e> Default for Message<'a, 'e> {
    fn default() -> Message<'a, 'e> {
        Self::new()
    }
}

impl<'a, 'e> Message<'a, 'e> {
    /// Create a new empty message
    pub fn new() -> Message<'a, 'e> {
        Message {
            dynheader: DynamicHeader::default(),
            flags: 0,
            raw_fds: Vec::new(),
            typ: MessageType::Invalid,
            params: Vec::new(),
        }
    }

    pub fn set_interface(&mut self, interface: String) {
        self.dynheader.interface = Some(interface);
    }
    pub fn set_member(&mut self, member: String) {
        self.dynheader.member = Some(member);
    }
    pub fn set_object(&mut self, object: String) {
        self.dynheader.object = Some(object);
    }
    pub fn set_destination(&mut self, dest: String) {
        self.dynheader.destination = Some(dest);
    }
    pub fn push_params<P: Into<Param<'a, 'e>>>(&mut self, params: Vec<P>) {
        self.params
            .extend(params.into_iter().map(std::convert::Into::into));
    }
    pub fn push_param<P: Into<Param<'a, 'e>>>(&mut self, param: P) {
        self.params.push(param.into());
    }

    /// Make a correctly addressed response with the correct response serial
    /// This is identical to calling [`self.dynheader.make_response()`].
    ///
    /// [`self.dynheader.make_response()`]: ./struct.DynamicHeader.html#method.make_response
    #[inline]
    pub fn make_response(&self) -> crate::message_builder::MarshalledMessage {
        self.dynheader.make_response()
    }

    pub fn set_flag(&mut self, flag: HeaderFlags) {
        flag.set(&mut self.flags)
    }
    pub fn unset_flag(&mut self, flag: HeaderFlags) {
        flag.unset(&mut self.flags)
    }
    pub fn toggle_flag(&mut self, flag: HeaderFlags) {
        flag.toggle(&mut self.flags)
    }

    pub fn sig(&self) -> Vec<signature::Type> {
        self.params.iter().map(|p| p.sig()).collect()
    }

    pub fn add_param<P: Into<Param<'a, 'e>>>(&mut self, p: P) {
        self.params.push(p.into());
    }
    pub fn add_param2<P1: Into<Param<'a, 'e>>, P2: Into<Param<'a, 'e>>>(&mut self, p1: P1, p2: P2) {
        self.params.push(p1.into());
        self.params.push(p2.into());
    }
    pub fn add_param3<P1: Into<Param<'a, 'e>>, P2: Into<Param<'a, 'e>>, P3: Into<Param<'a, 'e>>>(
        &mut self,
        p1: P1,
        p2: P2,
        p3: P3,
    ) {
        self.params.push(p1.into());
        self.params.push(p2.into());
        self.params.push(p3.into());
    }
}

pub type Result<T> = std::result::Result<T, crate::Error>;