Struct opcua_client::prelude::Session
source · [−]pub struct Session { /* private fields */ }
Expand description
A session of the client. The session is associated with an endpoint and maintains a state
when it is active. The Session
struct provides functions for all the supported
request types in the API.
Note that not all servers may support all client side requests and calling an unsupported API may cause the connection to be dropped. Your client is expected to know the capabilities of the server it is calling to avoid this.
Implementations
sourceimpl Session
impl Session
sourcepub fn connect_and_activate(&mut self) -> Result<(), StatusCode>
pub fn connect_and_activate(&mut self) -> Result<(), StatusCode>
Connects to the server, creates and activates a session. If there is a failure, it will be communicated by the status code in the result.
Returns
Ok(())
- connection has happened and the session is activatedErr(StatusCode)
- reason for failure
sourcepub fn set_session_retry_policy(
&mut self,
session_retry_policy: SessionRetryPolicy
)
pub fn set_session_retry_policy(
&mut self,
session_retry_policy: SessionRetryPolicy
)
Sets the session retry policy that dictates what this session will do if the connection fails or goes down. The retry policy enables the session to retry a connection on an interval up to a maxmimum number of times.
Arguments
session_retry_policy
- the session retry policy to use
sourcepub fn set_session_closed_callback<CB>(&mut self, session_closed_callback: CB) where
CB: OnSessionClosed + Send + Sync + 'static,
pub fn set_session_closed_callback<CB>(&mut self, session_closed_callback: CB) where
CB: OnSessionClosed + Send + Sync + 'static,
Register a callback to be notified when the session has been closed.
Arguments
session_closed_callback
- the session closed callback
sourcepub fn set_connection_status_callback<CB>(
&mut self,
connection_status_callback: CB
) where
CB: OnConnectionStatusChange + Send + Sync + 'static,
pub fn set_connection_status_callback<CB>(
&mut self,
connection_status_callback: CB
) where
CB: OnConnectionStatusChange + Send + Sync + 'static,
Registers a callback to be notified when the session connection status has changed. This will be called if connection status changes from connected to disconnected or vice versa.
Arguments
connection_status_callback
- the connection status callback.
sourcepub fn reconnect_and_activate(&mut self) -> Result<(), StatusCode>
pub fn reconnect_and_activate(&mut self) -> Result<(), StatusCode>
Reconnects to the server and tries to activate the existing session. If there is a failure, it will be communicated by the status code in the result. You should not call this if there is a session retry policy associated with the session.
Reconnecting will attempt to transfer or recreate subscriptions that were on the old session before it terminated.
Returns
Ok(())
- reconnection has happened and the session is activatedErr(StatusCode)
- reason for failure
sourcepub fn connect(&self) -> Result<(), StatusCode>
pub fn connect(&self) -> Result<(), StatusCode>
Connects to the server using the retry policy to repeat connecting until such time as it succeeds or the policy says to give up. If there is a failure, it will be communicated by the status code in the result.
sourcepub fn connect_no_retry(&self) -> Result<(), StatusCode>
pub fn connect_no_retry(&self) -> Result<(), StatusCode>
Connects to the server using the configured session arguments. No attempt is made to retry the connection if the attempt fails. If there is a failure, it will be communicated by the status code in the result.
Returns
Ok(())
- connection has happenedErr(StatusCode)
- reason for failure
sourcepub fn disconnect(&self)
pub fn disconnect(&self)
Disconnect from the server. Disconnect is an explicit command to drop the socket and throw away all state information. If you disconnect you cannot reconnect to your existing session or retrieve any existing subscriptions.
sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Test if the session is in a connected state
Returns
true
- Session is connectedfalse
- Session is not connected
sourcepub fn run(session: Arc<RwLock<Session>>)
pub fn run(session: Arc<RwLock<Session>>)
Synchronously runs a polling loop over the supplied session. Running a session performs periodic actions such as receiving messages, processing subscriptions, and recovering from connection errors. The run function will return if the session is disconnected and cannot be reestablished.
Arguments
session
- the session to run ynchronously
sourcepub fn run_async(session: Arc<RwLock<Session>>) -> Sender<SessionCommand>
pub fn run_async(session: Arc<RwLock<Session>>) -> Sender<SessionCommand>
Runs the session asynchronously on a new thread. The function returns immediately
and gives a caller a Sender
that can be used to send a message to the session
to cause it to terminate. Do not drop this sender (i.e. make sure to bind it to a variable with
sufficient lifetime) or the session will terminate as soon as you do.
Running a session performs periodic actions such as receiving messages, processing subscriptions, and recovering from. connection errors. The session will terminate by itself if it is disconnected and cannot be reestablished. It will terminate if the sender is dropped or if sent a ClientCommand to terminate. caller to this function can monitor the status of the session through state calls to know when this happens.
Arguments
session
- the session to run asynchronously
Returns
oneshot::Sender<ClientCommand>
- A sender that allows the caller to send a message to the run loop to cause it to stop. Note that dropping the sender, i.e. not binding it to a variable will also cause the loop to stop.
sourcepub async fn session_task(
session: Arc<RwLock<Session>>,
sleep_interval: u64,
rx: Receiver<SessionCommand>
)
pub async fn session_task(
session: Arc<RwLock<Session>>,
sleep_interval: u64,
rx: Receiver<SessionCommand>
)
The asynchronous main session loop. This is the function that processes responses and
keeps the session alive. Note that while the client normally calls run()
or run_loop()
to invoke this, there may be situations where the client wishes to directly use this
function, for example if the client has its own Tokio runtime and prefers to spawn the task
with that.
sourcepub fn run_loop(
session: Arc<RwLock<Session>>,
sleep_interval: u64,
rx: Receiver<SessionCommand>
)
pub fn run_loop(
session: Arc<RwLock<Session>>,
sleep_interval: u64,
rx: Receiver<SessionCommand>
)
The main running loop for a session. This is used by run()
and run_async()
to run
continuously until a signal is received to terminate.
Arguments
session
- The sessionsleep_interval
- An internal polling timer in msrx
- A receiver that the task uses to receive a quit command directly from the caller.
sourcepub fn poll(&mut self) -> Result<bool, ()>
pub fn poll(&mut self) -> Result<bool, ()>
Polls on the session which basically dispatches any pending async responses, attempts to reconnect if the client is disconnected from the client and sleeps a little bit if nothing needed to be done.
Arguments
sleep_for
- the period of time in milliseconds that poll should sleep for if it performed no action.
Returns
true
- if an action was performed during the pollfalse
- if no action was performed during the poll and the poll slept
sourcepub fn delete_all_subscriptions(
&self
) -> Result<Vec<(u32, StatusCode)>, StatusCode>
pub fn delete_all_subscriptions(
&self
) -> Result<Vec<(u32, StatusCode)>, StatusCode>
Deletes all subscriptions by sending a DeleteSubscriptionsRequest
to the server with
ids for all subscriptions.
Returns
Ok(Vec<(u32, StatusCode)>)
- List of (id, status code) result for delete action on each id,Good
orBadSubscriptionIdInvalid
Err(StatusCode)
- Status code reason for failure
sourcepub fn close_session_and_delete_subscriptions(&self) -> Result<(), StatusCode>
pub fn close_session_and_delete_subscriptions(&self) -> Result<(), StatusCode>
Closes the session and deletes all subscriptions
Returns
Ok(())
- if the session was closedErr(StatusCode)
- Status code reason for failure
sourcepub fn subscription_state(&self) -> Arc<RwLock<SubscriptionState>>
pub fn subscription_state(&self) -> Arc<RwLock<SubscriptionState>>
Returns the subscription state object
Trait Implementations
sourceimpl AttributeService for Session
impl AttributeService for Session
sourcefn read(
&self,
nodes_to_read: &[ReadValueId],
timestamps_to_return: TimestampsToReturn,
max_age: f64
) -> Result<Vec<DataValue>, StatusCode>
fn read(
&self,
nodes_to_read: &[ReadValueId],
timestamps_to_return: TimestampsToReturn,
max_age: f64
) -> Result<Vec<DataValue>, StatusCode>
Reads the value of nodes by sending a ReadRequest
to the server. Read more
sourcefn history_read(
&self,
history_read_details: HistoryReadAction,
timestamps_to_return: TimestampsToReturn,
release_continuation_points: bool,
nodes_to_read: &[HistoryReadValueId]
) -> Result<Vec<HistoryReadResult>, StatusCode>
fn history_read(
&self,
history_read_details: HistoryReadAction,
timestamps_to_return: TimestampsToReturn,
release_continuation_points: bool,
nodes_to_read: &[HistoryReadValueId]
) -> Result<Vec<HistoryReadResult>, StatusCode>
Reads historical values or events of one or more nodes. The caller is expected to provide a HistoryReadAction enum which must be one of the following: Read more
sourcefn write(
&self,
nodes_to_write: &[WriteValue]
) -> Result<Vec<StatusCode>, StatusCode>
fn write(
&self,
nodes_to_write: &[WriteValue]
) -> Result<Vec<StatusCode>, StatusCode>
Writes values to nodes by sending a WriteRequest
to the server. Note that some servers may reject DataValues
containing source or server timestamps. Read more
sourcefn history_update(
&self,
history_update_details: &[HistoryUpdateAction]
) -> Result<Vec<HistoryUpdateResult>, StatusCode>
fn history_update(
&self,
history_update_details: &[HistoryUpdateAction]
) -> Result<Vec<HistoryUpdateResult>, StatusCode>
Updates historical values. The caller is expected to provide one or more history update operations in a slice of HistoryUpdateAction enums which are one of the following: Read more
sourceimpl DiscoveryService for Session
impl DiscoveryService for Session
sourcefn find_servers<T>(
&self,
endpoint_url: T
) -> Result<Vec<ApplicationDescription>, StatusCode> where
T: Into<UAString>,
fn find_servers<T>(
&self,
endpoint_url: T
) -> Result<Vec<ApplicationDescription>, StatusCode> where
T: Into<UAString>,
Sends a FindServersRequest
to the server denoted by the discovery url. Read more
sourcefn get_endpoints(&self) -> Result<Vec<EndpointDescription>, StatusCode>
fn get_endpoints(&self) -> Result<Vec<EndpointDescription>, StatusCode>
Obtain the list of endpoints supported by the server by sending it a GetEndpointsRequest
. Read more
sourcefn register_server(&self, server: RegisteredServer) -> Result<(), StatusCode>
fn register_server(&self, server: RegisteredServer) -> Result<(), StatusCode>
This function is used by servers that wish to register themselves with a discovery server.
i.e. one server is the client to another server. The server sends a RegisterServerRequest
to the discovery server to register itself. Servers are expected to re-register themselves periodically
with the discovery server, with a maximum of 10 minute intervals. Read more
sourceimpl MethodService for Session
impl MethodService for Session
sourcefn call<T>(&self, method: T) -> Result<CallMethodResult, StatusCode> where
T: Into<CallMethodRequest>,
fn call<T>(&self, method: T) -> Result<CallMethodResult, StatusCode> where
T: Into<CallMethodRequest>,
Calls a single method on an object on the server by sending a CallRequest
to the server. Read more
sourceimpl MonitoredItemService for Session
impl MonitoredItemService for Session
sourcefn create_monitored_items(
&self,
subscription_id: u32,
timestamps_to_return: TimestampsToReturn,
items_to_create: &[MonitoredItemCreateRequest]
) -> Result<Vec<MonitoredItemCreateResult>, StatusCode>
fn create_monitored_items(
&self,
subscription_id: u32,
timestamps_to_return: TimestampsToReturn,
items_to_create: &[MonitoredItemCreateRequest]
) -> Result<Vec<MonitoredItemCreateResult>, StatusCode>
Creates monitored items on a subscription by sending a CreateMonitoredItemsRequest
to the server. Read more
sourcefn modify_monitored_items(
&self,
subscription_id: u32,
timestamps_to_return: TimestampsToReturn,
items_to_modify: &[MonitoredItemModifyRequest]
) -> Result<Vec<MonitoredItemModifyResult>, StatusCode>
fn modify_monitored_items(
&self,
subscription_id: u32,
timestamps_to_return: TimestampsToReturn,
items_to_modify: &[MonitoredItemModifyRequest]
) -> Result<Vec<MonitoredItemModifyResult>, StatusCode>
Modifies monitored items on a subscription by sending a ModifyMonitoredItemsRequest
to the server. Read more
sourcefn set_monitoring_mode(
&self,
subscription_id: u32,
monitoring_mode: MonitoringMode,
monitored_item_ids: &[u32]
) -> Result<Vec<StatusCode>, StatusCode>
fn set_monitoring_mode(
&self,
subscription_id: u32,
monitoring_mode: MonitoringMode,
monitored_item_ids: &[u32]
) -> Result<Vec<StatusCode>, StatusCode>
Sets the monitoring mode on one or more monitored items by sending a SetMonitoringModeRequest
to the server. Read more
sourcefn set_triggering(
&self,
subscription_id: u32,
triggering_item_id: u32,
links_to_add: &[u32],
links_to_remove: &[u32]
) -> Result<(Option<Vec<StatusCode>>, Option<Vec<StatusCode>>), StatusCode>
fn set_triggering(
&self,
subscription_id: u32,
triggering_item_id: u32,
links_to_add: &[u32],
links_to_remove: &[u32]
) -> Result<(Option<Vec<StatusCode>>, Option<Vec<StatusCode>>), StatusCode>
Sets a monitored item so it becomes the trigger that causes other monitored items to send
change events in the same update. Sends a SetTriggeringRequest
to the server.
Note that items_to_remove
is applied before items_to_add
. Read more
sourcefn delete_monitored_items(
&self,
subscription_id: u32,
items_to_delete: &[u32]
) -> Result<Vec<StatusCode>, StatusCode>
fn delete_monitored_items(
&self,
subscription_id: u32,
items_to_delete: &[u32]
) -> Result<Vec<StatusCode>, StatusCode>
Deletes monitored items from a subscription by sending a DeleteMonitoredItemsRequest
to the server. Read more
sourceimpl NodeManagementService for Session
impl NodeManagementService for Session
sourcefn add_nodes(
&self,
nodes_to_add: &[AddNodesItem]
) -> Result<Vec<AddNodesResult>, StatusCode>
fn add_nodes(
&self,
nodes_to_add: &[AddNodesItem]
) -> Result<Vec<AddNodesResult>, StatusCode>
Add nodes by sending a AddNodesRequest
to the server. Read more
sourcefn add_references(
&self,
references_to_add: &[AddReferencesItem]
) -> Result<Vec<StatusCode>, StatusCode>
fn add_references(
&self,
references_to_add: &[AddReferencesItem]
) -> Result<Vec<StatusCode>, StatusCode>
Add references by sending a AddReferencesRequest
to the server. Read more
sourcefn delete_nodes(
&self,
nodes_to_delete: &[DeleteNodesItem]
) -> Result<Vec<StatusCode>, StatusCode>
fn delete_nodes(
&self,
nodes_to_delete: &[DeleteNodesItem]
) -> Result<Vec<StatusCode>, StatusCode>
Delete nodes by sending a DeleteNodesRequest
to the server. Read more
sourcefn delete_references(
&self,
references_to_delete: &[DeleteReferencesItem]
) -> Result<Vec<StatusCode>, StatusCode>
fn delete_references(
&self,
references_to_delete: &[DeleteReferencesItem]
) -> Result<Vec<StatusCode>, StatusCode>
Delete references by sending a DeleteReferencesRequest
to the server. Read more
sourceimpl SecureChannelService for Session
impl SecureChannelService for Session
sourcefn open_secure_channel(&self) -> Result<(), StatusCode>
fn open_secure_channel(&self) -> Result<(), StatusCode>
Sends an OpenSecureChannelRequest
to the server Read more
sourcefn close_secure_channel(&self) -> Result<(), StatusCode>
fn close_secure_channel(&self) -> Result<(), StatusCode>
Sends a CloseSecureChannelRequest
to the server which will cause the server to drop
the connection. Read more
sourceimpl Service for Session
impl Service for Session
sourcefn make_request_header(&self) -> RequestHeader
fn make_request_header(&self) -> RequestHeader
Construct a request header for the session. All requests after create session are expected to supply an authentication token.
sourcefn send_request<T>(&self, request: T) -> Result<SupportedMessage, StatusCode> where
T: Into<SupportedMessage>,
fn send_request<T>(&self, request: T) -> Result<SupportedMessage, StatusCode> where
T: Into<SupportedMessage>,
Synchronously sends a request. The return value is the response to the request
sourcefn async_send_request<T>(
&self,
request: T,
sender: Option<SyncSender<SupportedMessage>>
) -> Result<u32, StatusCode> where
T: Into<SupportedMessage>,
fn async_send_request<T>(
&self,
request: T,
sender: Option<SyncSender<SupportedMessage>>
) -> Result<u32, StatusCode> where
T: Into<SupportedMessage>,
Asynchronously sends a request. The return value is the request handle of the request
sourceimpl SessionService for Session
impl SessionService for Session
sourcefn create_session(&self) -> Result<NodeId, StatusCode>
fn create_session(&self) -> Result<NodeId, StatusCode>
Sends a CreateSessionRequest
to the server, returning the session id of the created
session. Internally, the session will store the authentication token which is used for requests
subsequent to this call. Read more
sourcefn activate_session(&self) -> Result<(), StatusCode>
fn activate_session(&self) -> Result<(), StatusCode>
Sends an ActivateSessionRequest
to the server to activate this session Read more
sourcefn cancel(&self, request_handle: IntegerId) -> Result<u32, StatusCode>
fn cancel(&self, request_handle: IntegerId) -> Result<u32, StatusCode>
Cancels an outstanding service request by sending a CancelRequest
to the server. Read more
sourceimpl SubscriptionService for Session
impl SubscriptionService for Session
sourcefn create_subscription<CB>(
&self,
publishing_interval: f64,
lifetime_count: u32,
max_keep_alive_count: u32,
max_notifications_per_publish: u32,
priority: u8,
publishing_enabled: bool,
callback: CB
) -> Result<u32, StatusCode> where
CB: OnSubscriptionNotification + Send + Sync + 'static,
fn create_subscription<CB>(
&self,
publishing_interval: f64,
lifetime_count: u32,
max_keep_alive_count: u32,
max_notifications_per_publish: u32,
priority: u8,
publishing_enabled: bool,
callback: CB
) -> Result<u32, StatusCode> where
CB: OnSubscriptionNotification + Send + Sync + 'static,
Create a subscription by sending a CreateSubscriptionRequest
to the server. Read more
sourcefn modify_subscription(
&self,
subscription_id: u32,
publishing_interval: f64,
lifetime_count: u32,
max_keep_alive_count: u32,
max_notifications_per_publish: u32,
priority: u8
) -> Result<(), StatusCode>
fn modify_subscription(
&self,
subscription_id: u32,
publishing_interval: f64,
lifetime_count: u32,
max_keep_alive_count: u32,
max_notifications_per_publish: u32,
priority: u8
) -> Result<(), StatusCode>
Modifies a subscription by sending a ModifySubscriptionRequest
to the server. Read more
sourcefn set_publishing_mode(
&self,
subscription_ids: &[u32],
publishing_enabled: bool
) -> Result<Vec<StatusCode>, StatusCode>
fn set_publishing_mode(
&self,
subscription_ids: &[u32],
publishing_enabled: bool
) -> Result<Vec<StatusCode>, StatusCode>
Changes the publishing mode of subscriptions by sending a SetPublishingModeRequest
to the server. Read more
sourcefn transfer_subscriptions(
&self,
subscription_ids: &[u32],
send_initial_values: bool
) -> Result<Vec<TransferResult>, StatusCode>
fn transfer_subscriptions(
&self,
subscription_ids: &[u32],
send_initial_values: bool
) -> Result<Vec<TransferResult>, StatusCode>
Transfers Subscriptions and their MonitoredItems from one Session to another. For example, a Client may need to reopen a Session and then transfer its Subscriptions to that Session. It may also be used by one Client to take over a Subscription from another Client by transferring the Subscription to its Session. Read more
sourcefn delete_subscription(
&self,
subscription_id: u32
) -> Result<StatusCode, StatusCode>
fn delete_subscription(
&self,
subscription_id: u32
) -> Result<StatusCode, StatusCode>
Deletes a subscription by sending a DeleteSubscriptionsRequest
to the server. Read more
sourcefn delete_subscriptions(
&self,
subscription_ids: &[u32]
) -> Result<Vec<StatusCode>, StatusCode>
fn delete_subscriptions(
&self,
subscription_ids: &[u32]
) -> Result<Vec<StatusCode>, StatusCode>
Deletes subscriptions by sending a DeleteSubscriptionsRequest
to the server with the list
of subscriptions to delete. Read more
sourceimpl ViewService for Session
impl ViewService for Session
sourcefn browse(
&self,
nodes_to_browse: &[BrowseDescription]
) -> Result<Option<Vec<BrowseResult>>, StatusCode>
fn browse(
&self,
nodes_to_browse: &[BrowseDescription]
) -> Result<Option<Vec<BrowseResult>>, StatusCode>
Discover the references to the specified nodes by sending a BrowseRequest
to the server. Read more
sourcefn browse_next(
&self,
release_continuation_points: bool,
continuation_points: &[ByteString]
) -> Result<Option<Vec<BrowseResult>>, StatusCode>
fn browse_next(
&self,
release_continuation_points: bool,
continuation_points: &[ByteString]
) -> Result<Option<Vec<BrowseResult>>, StatusCode>
Continue to discover references to nodes by sending continuation points in a BrowseNextRequest
to the server. This function may have to be called repeatedly to process the initial query. Read more
sourcefn translate_browse_paths_to_node_ids(
&self,
browse_paths: &[BrowsePath]
) -> Result<Vec<BrowsePathResult>, StatusCode>
fn translate_browse_paths_to_node_ids(
&self,
browse_paths: &[BrowsePath]
) -> Result<Vec<BrowsePathResult>, StatusCode>
Translate browse paths to NodeIds by sending a TranslateBrowsePathsToNodeIdsRequest
request to the Server
Each BrowsePath
is constructed of a starting node and a RelativePath
. The specified starting node
identifies the node from which the RelativePath is based. The RelativePath contains a sequence of
ReferenceTypes and BrowseNames. Read more
sourcefn register_nodes(
&self,
nodes_to_register: &[NodeId]
) -> Result<Vec<NodeId>, StatusCode>
fn register_nodes(
&self,
nodes_to_register: &[NodeId]
) -> Result<Vec<NodeId>, StatusCode>
Register nodes on the server by sending a RegisterNodesRequest
. The purpose of this
call is server-dependent but allows a client to ask a server to create nodes which are
otherwise expensive to set up or maintain, e.g. nodes attached to hardware. Read more
sourcefn unregister_nodes(
&self,
nodes_to_unregister: &[NodeId]
) -> Result<(), StatusCode>
fn unregister_nodes(
&self,
nodes_to_unregister: &[NodeId]
) -> Result<(), StatusCode>
Unregister nodes on the server by sending a UnregisterNodesRequest
. This indicates to
the server that the client relinquishes any need for these nodes. The server will ignore
unregistered nodes. Read more
Auto Trait Implementations
impl RefUnwindSafe for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnwindSafe for Session
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more