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

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 activated
  • Err(StatusCode) - reason for failure

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

Register a callback to be notified when the session has been closed.

Arguments
  • session_closed_callback - the session closed callback

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.

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 activated
  • Err(StatusCode) - reason for failure

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.

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 happened
  • Err(StatusCode) - reason for failure

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.

Test if the session is in a connected state

Returns
  • true - Session is connected
  • false - Session is not connected

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

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.

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.

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 session
  • sleep_interval - An internal polling timer in ms
  • rx - A receiver that the task uses to receive a quit command directly from the caller.

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 poll
  • false - if no action was performed during the poll and the poll slept

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 or BadSubscriptionIdInvalid
  • Err(StatusCode) - Status code reason for failure

Closes the session and deletes all subscriptions

Returns
  • Ok(()) - if the session was closed
  • Err(StatusCode) - Status code reason for failure

Returns the subscription state object

Trait Implementations

Reads the value of nodes by sending a ReadRequest to the server. Read more

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

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

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

Sends a FindServersRequest to the server denoted by the discovery url. Read more

Obtain the list of endpoints supported by the server by sending it a GetEndpointsRequest. Read more

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

Executes the destructor for this type. Read more

Calls a single method on an object on the server by sending a CallRequest to the server. Read more

Calls GetMonitoredItems via call_method(), putting a sane interface on the input / output. Read more

Creates monitored items on a subscription by sending a CreateMonitoredItemsRequest to the server. Read more

Modifies monitored items on a subscription by sending a ModifyMonitoredItemsRequest to the server. Read more

Sets the monitoring mode on one or more monitored items by sending a SetMonitoringModeRequest to the server. Read more

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

Deletes monitored items from a subscription by sending a DeleteMonitoredItemsRequest to the server. Read more

Add nodes by sending a AddNodesRequest to the server. Read more

Add references by sending a AddReferencesRequest to the server. Read more

Delete nodes by sending a DeleteNodesRequest to the server. Read more

Delete references by sending a DeleteReferencesRequest to the server. Read more

Sends an OpenSecureChannelRequest to the server Read more

Sends a CloseSecureChannelRequest to the server which will cause the server to drop the connection. Read more

Construct a request header for the session. All requests after create session are expected to supply an authentication token.

Synchronously sends a request. The return value is the response to the request

Asynchronously sends a request. The return value is the request handle of the request

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

Sends an ActivateSessionRequest to the server to activate this session Read more

Cancels an outstanding service request by sending a CancelRequest to the server. Read more

Create a subscription by sending a CreateSubscriptionRequest to the server. Read more

Modifies a subscription by sending a ModifySubscriptionRequest to the server. Read more

Changes the publishing mode of subscriptions by sending a SetPublishingModeRequest to the server. Read more

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

Deletes a subscription by sending a DeleteSubscriptionsRequest to the server. Read more

Deletes subscriptions by sending a DeleteSubscriptionsRequest to the server with the list of subscriptions to delete. Read more

Discover the references to the specified nodes by sending a BrowseRequest to the server. Read more

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

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

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

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.