S2OPC OPCUA Toolkit
|
High level interface to run an OPC UA client. More...
#include <stdbool.h>
#include <stdint.h>
#include "sopc_types.h"
#include "libs2opc_client_config.h"
Go to the source code of this file.
Typedefs | |
typedef struct SOPC_ClientConnection | SOPC_ClientConnection |
Structure representing a secure connection to a server. | |
typedef void | SOPC_ClientConnectionEvent_Fct(SOPC_ClientConnection *conn, SOPC_ClientConnectionEvent event, SOPC_StatusCode status) |
Type of callback called on client connection event. | |
typedef struct SOPC_ClientHelper_Subscription | SOPC_ClientHelper_Subscription |
typedef void | SOPC_ClientSubscriptionNotification_Fct(const SOPC_ClientHelper_Subscription *subscription, SOPC_StatusCode status, SOPC_EncodeableType *notificationType, uint32_t nbNotifElts, const void *notification, uintptr_t *monitoredItemCtxArray) |
Type of callback called on Subscription Notification. | |
Enumerations | |
enum | SOPC_ClientConnectionEvent { SOPC_ClientConnectionEvent_Disconnected , SOPC_ClientConnectionEvent_Connected , SOPC_ClientConnectionEvent_Reconnecting } |
Functions | |
SOPC_ReturnStatus | SOPC_ClientHelper_DiscoveryServiceAsync (SOPC_SecureConnection_Config *secConnConfig, void *request, uintptr_t userContext) |
Sends a discovery request without user session creation and activation and retrieve response asynchronously. Service response callback configured through SOPC_ClientConfigHelper_SetServiceAsyncResponse will be called on service response or in case of service request sending failure. | |
SOPC_ReturnStatus | SOPC_ClientHelper_DiscoveryServiceSync (SOPC_SecureConnection_Config *secConnConfig, void *request, void **response) |
Sends a discovery request without user session creation and activation and retrieve response synchronously. | |
SOPC_ReturnStatus | SOPC_ClientHelper_Connect (SOPC_SecureConnection_Config *secConnConfig, SOPC_ClientConnectionEvent_Fct *connectEventCb, SOPC_ClientConnection **secureConnection) |
Establishes the connection in a blocking way (synchronously). | |
SOPC_ReturnStatus | SOPC_ClientHelper_Disconnect (SOPC_ClientConnection **secureConnection) |
Disconnects the connection established with SOPC_ClientHelper_Connect in a blocking way (synchronously). | |
SOPC_ReturnStatus | SOPC_ClientHelper_ServiceAsync (SOPC_ClientConnection *secureConnection, void *request, uintptr_t userContext) |
Executes an OPC UA service on server (read, write, browse, discovery service, etc.) asynchronously. Service response callback configured through SOPC_ClientConfigHelper_SetServiceAsyncResponse will be called on service response or in case of service request sending failure. | |
SOPC_ReturnStatus | SOPC_ClientHelper_ServiceSync (SOPC_ClientConnection *secureConnection, void *request, void **response) |
Executes an OPC UA service on server (read, write, browse, discovery service, etc.) synchronously. | |
SOPC_ClientHelper_Subscription * | SOPC_ClientHelper_CreateSubscription (SOPC_ClientConnection *secureConnection, OpcUa_CreateSubscriptionRequest *subParams, SOPC_ClientSubscriptionNotification_Fct *subNotifCb, uintptr_t userParam) |
Creates a subscription on the server. | |
SOPC_ReturnStatus | SOPC_ClientHelper_DeleteSubscription (SOPC_ClientHelper_Subscription **subscription) |
Deletes a subscription on the server. | |
SOPC_ReturnStatus | SOPC_ClientHelper_Subscription_SetAvailableTokens (SOPC_ClientHelper_Subscription *subscription, uint32_t nbPublishTokens) |
Sets the number of publish tokens to be used for the subscription. This number shall be greater than 0 and indicates the number of publish request sent to the server that might be used to send back notifications. | |
SOPC_ReturnStatus | SOPC_ClientHelper_Subscription_GetRevisedParameters (SOPC_ClientHelper_Subscription *subscription, double *revisedPublishingInterval, uint32_t *revisedLifetimeCount, uint32_t *revisedMaxKeepAliveCount) |
Gets the created subscription parameters values revised by the server. | |
uintptr_t | SOPC_ClientHelper_Subscription_GetUserParam (const SOPC_ClientHelper_Subscription *subscription) |
Returns the user parameter defined in SOPC_ClientHelper_CreateSubscription. | |
SOPC_ClientConnection * | SOPC_ClientHelper_GetSecureConnection (const SOPC_ClientHelper_Subscription *subscription) |
Gets the secure connection on which the subscription rely on. | |
SOPC_ReturnStatus | SOPC_ClientHelper_GetSubscriptionId (const SOPC_ClientHelper_Subscription *subscription, uint32_t *pSubscriptionId) |
Gets the subscription Id associated to the subscription. It should only be used in the context of server method calls (ConditionRefresh, etc.) and is not referenced by the rest of this client API. | |
SOPC_ReturnStatus | SOPC_ClientHelper_Subscription_CreateMonitoredItems (const SOPC_ClientHelper_Subscription *subscription, OpcUa_CreateMonitoredItemsRequest *monitoredItemsReq, const uintptr_t *monitoredItemCtxArray, OpcUa_CreateMonitoredItemsResponse *monitoredItemsResp) |
Creates new monitored items on the given subscription. A context array might be provided and context will be provided on notification for corresponding monitored item in notification callback. A pointer to empty message response might be provided to retrieve the creation result and monitored item id affected by the server (needed to modify or delete monitored items prior to subscription deletion) | |
SOPC_ReturnStatus | SOPC_ClientHelper_Subscription_DeleteMonitoredItems (const SOPC_ClientHelper_Subscription *subscription, OpcUa_DeleteMonitoredItemsRequest *delMonitoredItemsReq, OpcUa_DeleteMonitoredItemsResponse *delMonitoredItemsResp) |
Deletes monitored items on the given subscription using the server monitored item ids. A pointer to empty message response might be provided to retrieve the deletion result. | |
SOPC_ReturnStatus | SOPC_ClientHelper_Subscription_SyncService (const SOPC_ClientHelper_Subscription *subscription, void *subOrMIrequest, void **subOrMIresponse) |
Executes an OPC UA service on server related to the given subscription synchronously. | |
SOPC_ReturnStatus | SOPC_ClientHelper_Subscription_AsyncService (const SOPC_ClientHelper_Subscription *subscription, void *subOrMIrequest, uintptr_t userContext) |
Executes an OPC UA service on server related to the given subscription asynchronously. Service response callback configured through SOPC_ClientConfigHelper_SetServiceAsyncResponse will be called on service response or in case of service request sending failure. | |
High level interface to run an OPC UA client.
Once the client is configured using functions of libs2opc_client_config.h, the client should establish connection using SOPC_ClientHelper_Connect or call a discovery service using SOPC_ClientHelper_DiscoveryServiceAsync (or SOPC_ClientHelper_DiscoveryServiceSync). Until connection is stopped by a call to SOPC_ClientHelper_Disconnect or due to an error (socket closed, etc.), the client application might use the connections. This is done using OPC UA services using SOPC_ClientHelper_ServiceAsync (or SOPC_ClientHelper_ServiceSync). The request messages can be built using the helper functions of libs2opc_request_builder.h (e.g.: SOPC_ReadRequest_Create, SOPC_ReadRequest_SetReadValue, etc.).
Dedicated functions are provided to handle subscriptions: SOPC_ClientHelper_CreateSubscription (SOPC_ClientHelper_DeleteSubscription) to create (delete) a unique subscription instance for the connection. SOPC_ClientHelper_Subscription_CreateMonitoredItems (SOPC_ClientHelper_Subscription_DeleteMonitoredItems) to create (delete) monitored items in a subscription instance. SOPC_ClientHelper_Subscription_AsyncService and SOPC_ClientHelper_Subscription_SyncService to call other subscription related services on the subscription instance.
typedef struct SOPC_ClientConnection SOPC_ClientConnection |
Structure representing a secure connection to a server.
typedef void SOPC_ClientConnectionEvent_Fct(SOPC_ClientConnection *conn, SOPC_ClientConnectionEvent event, SOPC_StatusCode status) |
Type of callback called on client connection event.
conn | Indicates the connection concerned by the event |
event | The event that occurred on the connection |
status | Indicates the return status of client connection |
typedef struct SOPC_ClientHelper_Subscription SOPC_ClientHelper_Subscription |
typedef void SOPC_ClientSubscriptionNotification_Fct(const SOPC_ClientHelper_Subscription *subscription, SOPC_StatusCode status, SOPC_EncodeableType *notificationType, uint32_t nbNotifElts, const void *notification, uintptr_t *monitoredItemCtxArray) |
Type of callback called on Subscription Notification.
subscription | Indicates the subscription concerned by the notification |
status | OPC UA status code for the subscription, notification is only valid when SOPC_IsGoodStatus |
notificationType | Type of notification received (OpcUa_DataChangeNotification_EncodeableType or OpcUa_EventNotificationList_EncodeableType) or NULL (if status is not good) |
nbNotifElts | Number of elements in notification received and in monitoredItemCtxArray |
notification | Notification of the type indicated by notificationType , either pointer to a OpcUa_DataChangeNotification or OpcUa_EventNotificationList. Or NULL if status is not good. Content is freed after callback return, thus any content to record shall be copied. |
monitoredItemCtxArray | Array of context for monitored items for which notification were received in notification . Notification element and monitored item context have the same index in the array. |
Enumerator | |
---|---|
SOPC_ClientConnectionEvent_Disconnected | Connection terminated unexpectedly, it will not be established again unless a new connection attempt is done. To do a new attempt the following functions shall be called:
|
SOPC_ClientConnectionEvent_Connected | (NOT IMPLEMENTED YET) Connection established (SC & session), only triggered when asynchronous SOPC_ClientHelper_StartConnection is used or in case of reconnection. |
SOPC_ClientConnectionEvent_Reconnecting | (NOT IMPLEMENTED YET) Connection temporarily interrupted, attempt to re-establish connection on-going. Do not use connection until Connected event received |
SOPC_ReturnStatus SOPC_ClientHelper_DiscoveryServiceAsync | ( | SOPC_SecureConnection_Config * | secConnConfig, |
void * | request, | ||
uintptr_t | userContext ) |
Sends a discovery request without user session creation and activation and retrieve response asynchronously. Service response callback configured through SOPC_ClientConfigHelper_SetServiceAsyncResponse will be called on service response or in case of service request sending failure.
secConnConfig | The secure connection configuration. |
request | An instance of one of the following OPC UA request: |
The request messages can be built using the helper functions of libs2opc_request_builder.h (e.g.: SOPC_GetEndpointsRequest_Create, SOPC_GetEndpointsRequest_SetPreferredLocales, etc.).
Note: it shall be allocated on heap since it will be freed by S2OPC library during treatment.
userContext | User defined context that will be provided with the corresponding response in SOPC_LocalServiceAsyncResp_Fct |
request
memory is managed by the function after this call (even in case of error) and shall not be accessed nor freed after call.SOPC_ReturnStatus SOPC_ClientHelper_DiscoveryServiceSync | ( | SOPC_SecureConnection_Config * | secConnConfig, |
void * | request, | ||
void ** | response ) |
Sends a discovery request without user session creation and activation and retrieve response synchronously.
secConnConfig | The secure connection configuration. |
request | An instance of one of the following OPC UA request: |
The request messages can be built using the helper functions of libs2opc_request_builder.h (e.g.: SOPC_GetEndpointsRequest_Create, SOPC_GetEndpointsRequest_SetPreferredLocales, etc.).
Note: it shall be allocated on heap since it will be freed by S2OPC library during treatment.
[out] | response | Pointer into which instance of response complying with the OPC UA request is provided:
response.encodeableType points to OpcUa_ServiceFault_EncodeableType and SOPC_IsGoodStatus(response.ResponseHeader.ServiceResult ) is false . |
request
memory is managed by the function after this call (even in case of error) and shall not be accessed nor freed after call. response
memory after successful callSOPC_ReturnStatus SOPC_ClientHelper_Connect | ( | SOPC_SecureConnection_Config * | secConnConfig, |
SOPC_ClientConnectionEvent_Fct * | connectEventCb, | ||
SOPC_ClientConnection ** | secureConnection ) |
Establishes the connection in a blocking way (synchronously).
secConnConfig
.secConnConfig | The secure connection configuration to establish | |
connectEventCb | Callback called on connection event, it is only used in case of further unexpected disconnection | |
[out] | secureConnection | Pointer to the secure connection established when returned value is SOPC_STATUS_OK |
SOPC_ReturnStatus SOPC_ClientHelper_Disconnect | ( | SOPC_ClientConnection ** | secureConnection | ) |
Disconnects the connection established with SOPC_ClientHelper_Connect in a blocking way (synchronously).
secureConnection
is currently in use for any other operation and shall be prevented to be used for other operation. Internal references to secureConnection
should have been cleared prior to this call.secureConnection | Pointer to the secure connection reference to stop, set to NULL during successful call. |
SOPC_ReturnStatus SOPC_ClientHelper_ServiceAsync | ( | SOPC_ClientConnection * | secureConnection, |
void * | request, | ||
uintptr_t | userContext ) |
Executes an OPC UA service on server (read, write, browse, discovery service, etc.) asynchronously. Service response callback configured through SOPC_ClientConfigHelper_SetServiceAsyncResponse will be called on service response or in case of service request sending failure.
secureConnection | The client connection instance to use to execute the service |
request | An instance of one of the following OPC UA request: |
The request messages can be built using the helper functions of libs2opc_request_builder.h (e.g.: SOPC_ReadRequest_Create, SOPC_ReadRequest_SetReadValue, etc.).
Note: it shall be allocated on heap since it will be freed by S2OPC library during treatment.
userContext | User defined context that will be provided with the corresponding response in SOPC_LocalServiceAsyncResp_Fct |
request
memory is managed by the function after this call (even in case of error) and shall not be accessed nor freed after call.SOPC_ReturnStatus SOPC_ClientHelper_ServiceSync | ( | SOPC_ClientConnection * | secureConnection, |
void * | request, | ||
void ** | response ) |
Executes an OPC UA service on server (read, write, browse, discovery service, etc.) synchronously.
secureConnection | The client connection instance to use to execute the service |
request | An instance of OPC UA request: |
The request messages can be built using the helper functions of libs2opc_request_builder.h (e.g.: SOPC_ReadRequest_Create, SOPC_ReadRequest_SetReadValue, etc.).
Note: it shall be allocated on heap since it will be freed by S2OPC library during treatment.
[out] | response | Pointer into which instance of response complying with the OPC UA request is provided:
response.encodeableType points to OpcUa_ServiceFault_EncodeableType and SOPC_IsGoodStatus(response.ResponseHeader.ServiceResult ) is false . |
request
memory is managed by the function after this call (even in case of error) and shall not be accessed nor freed after call. SOPC_ClientHelper_Subscription * SOPC_ClientHelper_CreateSubscription | ( | SOPC_ClientConnection * | secureConnection, |
OpcUa_CreateSubscriptionRequest * | subParams, | ||
SOPC_ClientSubscriptionNotification_Fct * | subNotifCb, | ||
uintptr_t | userParam ) |
Creates a subscription on the server.
secureConnection | The client connection instance to use to execute the service |
subParams | The subscription creation request containing subscription parameters (created using SOPC_CreateSubscriptionRequest_CreateDefault or :: SOPC_CreateSubscriptionRequest_Create) Note: it shall be allocated on heap since it will be freed by S2OPC library during treatment. |
subNotifCb | The callback to be called on subscription notification |
userParam | The user parameter associated to the subscription that can be accessed using SOPC_ClientHelper_Subscription_GetUserParam |
subParams
memory is managed by the function after this call (even in case of error) and shall not be accessed nor freed after call. SOPC_ReturnStatus SOPC_ClientHelper_DeleteSubscription | ( | SOPC_ClientHelper_Subscription ** | subscription | ) |
Deletes a subscription on the server.
subscription | Pointer to the subscription pointer returned by SOPC_ClientHelper_CreateSubscription and to be deleted. |
SOPC_ReturnStatus SOPC_ClientHelper_Subscription_SetAvailableTokens | ( | SOPC_ClientHelper_Subscription * | subscription, |
uint32_t | nbPublishTokens ) |
Sets the number of publish tokens to be used for the subscription. This number shall be greater than 0 and indicates the number of publish request sent to the server that might be used to send back notifications.
subscription | The subscription instance |
nbPublishTokens | The number of publish tokens to be used by the client |
SOPC_ReturnStatus SOPC_ClientHelper_Subscription_GetRevisedParameters | ( | SOPC_ClientHelper_Subscription * | subscription, |
double * | revisedPublishingInterval, | ||
uint32_t * | revisedLifetimeCount, | ||
uint32_t * | revisedMaxKeepAliveCount ) |
Gets the created subscription parameters values revised by the server.
subscription | The subscription instance | |
[out] | revisedPublishingInterval | Pointer for the revised publishing interval output value (optional) |
[out] | revisedLifetimeCount | Pointer for the revised lifetime count output value (optional) |
[out] | revisedMaxKeepAliveCount | Pointer for the revised max keep alive count output value (optional) |
uintptr_t SOPC_ClientHelper_Subscription_GetUserParam | ( | const SOPC_ClientHelper_Subscription * | subscription | ) |
Returns the user parameter defined in SOPC_ClientHelper_CreateSubscription.
subscription | The subscription instance |
subscription
SOPC_ClientConnection * SOPC_ClientHelper_GetSecureConnection | ( | const SOPC_ClientHelper_Subscription * | subscription | ) |
Gets the secure connection on which the subscription rely on.
subscription | The subscription instance |
SOPC_ReturnStatus SOPC_ClientHelper_GetSubscriptionId | ( | const SOPC_ClientHelper_Subscription * | subscription, |
uint32_t * | pSubscriptionId ) |
Gets the subscription Id associated to the subscription. It should only be used in the context of server method calls (ConditionRefresh, etc.) and is not referenced by the rest of this client API.
subscription | The subscription instance | |
[out] | pSubscriptionId | The subscription Id associated to the subscription by server |
SOPC_ReturnStatus SOPC_ClientHelper_Subscription_CreateMonitoredItems | ( | const SOPC_ClientHelper_Subscription * | subscription, |
OpcUa_CreateMonitoredItemsRequest * | monitoredItemsReq, | ||
const uintptr_t * | monitoredItemCtxArray, | ||
OpcUa_CreateMonitoredItemsResponse * | monitoredItemsResp ) |
Creates new monitored items on the given subscription. A context array might be provided and context will be provided on notification for corresponding monitored item in notification callback. A pointer to empty message response might be provided to retrieve the creation result and monitored item id affected by the server (needed to modify or delete monitored items prior to subscription deletion)
subscription | The subscription instance on which monitored items shall be created | |
monitoredItemsReq | The create monitored items requests to use for creation parameters. SubscriptionId and ClientHandle parameters are ignored and set automatically. Simplified way to create it is to use SOPC_CreateMonitoredItemsRequest_CreateDefault or SOPC_CreateMonitoredItemsRequest_CreateDefaultFromStrings. Note: it shall be allocated on heap since it will be freed by S2OPC library during treatment. | |
monitoredItemCtxArray | (optional) The array of context for monitored items to be created (might be freed by caller after call only content is recorded in subscription) | |
[out] | monitoredItemsResp | (optional) Pointer to the empty response that will be filled with the response received from the server and containing the status result and server monitored items ids. |
monitoredItemsReq
memory is managed by the function after this call (even in case of error) and shall not be accessed nor freed after call. SOPC_ReturnStatus SOPC_ClientHelper_Subscription_DeleteMonitoredItems | ( | const SOPC_ClientHelper_Subscription * | subscription, |
OpcUa_DeleteMonitoredItemsRequest * | delMonitoredItemsReq, | ||
OpcUa_DeleteMonitoredItemsResponse * | delMonitoredItemsResp ) |
Deletes monitored items on the given subscription using the server monitored item ids. A pointer to empty message response might be provided to retrieve the deletion result.
subscription | The subscription instance on which monitored items shall be created | |
delMonitoredItemsReq | The delete monitored items requests to use for creation parameters. SubscriptionId parameter is ignored and set automatically. Note: it shall be allocated on heap since it will be freed by S2OPC library during treatment. | |
[out] | delMonitoredItemsResp | (optional) Pointer to the empty response that will be filled with the response received from the server and containing the status result. |
delMonitoredItemsReq
memory is managed by the function after this call (even in case of error) and shall not be accessed nor freed after call. SOPC_ReturnStatus SOPC_ClientHelper_Subscription_SyncService | ( | const SOPC_ClientHelper_Subscription * | subscription, |
void * | subOrMIrequest, | ||
void ** | subOrMIresponse ) |
Executes an OPC UA service on server related to the given subscription synchronously.
subscription | The subscription instance for which the service shall be executed | |
subOrMIrequest | An instance of one of the following OPC UA request:
| |
[out] | subOrMIresponse | Pointer into which instance of response complying with the OPC UA request is provided:
response.encodeableType points to OpcUa_ServiceFault_EncodeableType and SOPC_IsGoodStatus(response.ResponseHeader.ServiceResult ) is false . |
subOrMIrequest
memory is managed by the function after this call (even in case of error) and shall not be accessed nor freed after call. SOPC_ReturnStatus SOPC_ClientHelper_Subscription_AsyncService | ( | const SOPC_ClientHelper_Subscription * | subscription, |
void * | subOrMIrequest, | ||
uintptr_t | userContext ) |
Executes an OPC UA service on server related to the given subscription asynchronously. Service response callback configured through SOPC_ClientConfigHelper_SetServiceAsyncResponse will be called on service response or in case of service request sending failure.
subscription | The subscription instance for which the service shall be executed |
subOrMIrequest | An instance of one of the following OPC UA request:
|
userContext | User defined context that will be provided with the corresponding response in SOPC_LocalServiceAsyncResp_Fct |
subOrMIrequest
memory is managed by the function after this call (even in case of error) and shall not be accessed nor freed after call.