pub struct Channel<'session>(/* private fields */);Implementations§
Source§impl<'a> Channel<'a>
impl<'a> Channel<'a>
Sourcepub fn set_private<T>(&self, key: &CStr, data: T) -> Result<()>where
T: IntoChannelValue + Clone + 'a,
pub fn set_private<T>(&self, key: &CStr, data: T) -> Result<()>where
T: IntoChannelValue + Clone + 'a,
Set private data on channel. See: switch_channel_set_private.
Sourcepub fn get_private<T>(&self, key: &CStr) -> Option<T>where
T: IntoChannelValue + Clone + 'a,
pub fn get_private<T>(&self, key: &CStr) -> Option<T>where
T: IntoChannelValue + Clone + 'a,
Retrieve private data from a given channel for the given key. See: switch_channel_get_private.
Sourcepub fn remove_private<T: IntoChannelValue>(&self, key: &CStr) -> Result<()>
pub fn remove_private<T: IntoChannelValue>(&self, key: &CStr) -> Result<()>
Remove private data from channel for the given key. See: switch_channel_set_private.
Sourcepub unsafe fn set_private_raw_ptr<T>(
&self,
key: &CStr,
data: *const T,
) -> Result<()>
pub unsafe fn set_private_raw_ptr<T>( &self, key: &CStr, data: *const T, ) -> Result<()>
Set private data on channel. See: switch_channel_set_private.
§Safety
Channels do not own or cleanup their data, so caller must ensure
rust allocated structs are cleaned up IF required ie anything on the heap
normally by using [add_state_handler]
§Examples
#[switch_state_handler]
pub fn cleanup(s: &Session) -> switch_status_t {
unsafe {
let ptr = s.get_channel().map(|c| c.get_private_raw_ptr());
// Cast and drop ...
}
}Sourcepub unsafe fn get_private_raw_ptr<T>(&self, key: &CStr) -> Option<*mut T>
pub unsafe fn get_private_raw_ptr<T>(&self, key: &CStr) -> Option<*mut T>
Retrieve private data from a given channel for the given key. See: switch_channel_get_private.
§Safety
Care must be taken to not invalidate the stored pointer whilst the channel holds the value ie ensure T is not dropped
Sourcepub fn add_state_handler(
&self,
table: &'static switch_state_handler_table_t,
) -> Result<usize>
pub fn add_state_handler( &self, table: &'static switch_state_handler_table_t, ) -> Result<usize>
Add a state handler table to a given channel. Returns the index number/priority of the table.
See: switch_channel_add_state_handler.
§Examples
#[switch_state_handler]
pub fn cleanup(s: &Session) -> switch_status_t {
// cleanup ...
}
const STATE_HANDLERS: StateHandlerTable = StateHandlerTable {
on_destroy: Some(cleanup),
..DEFAULT_STATE_HANDLER_TABLE
}