S2OPC OPCUA Toolkit
state_machine.h
Go to the documentation of this file.
1 /*
2  * Licensed to Systerel under one or more contributor license
3  * agreements. See the NOTICE file distributed with this work
4  * for additional information regarding copyright ownership.
5  * Systerel licenses this file to you under the Apache
6  * License, Version 2.0 (the "License"); you may not use this
7  * file except in compliance with the License. You may obtain
8  * a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
39 #ifndef STATE_MACHINE_H_
40 #define STATE_MACHINE_H_
41 
42 /* Machine static parameters, MonitoredItem parameters */
43 #define MONIT_TIMESTAMPS_TO_RETURN OpcUa_TimestampsToReturn_Both
44 #define MONIT_QSIZE 10
45 
46 #include <stdbool.h>
47 
48 /* The following includes are required to fetch the SOPC_LibSub_DataChangeCbk type */
49 #include "sopc_builtintypes.h"
50 #include "sopc_crypto_profiles.h"
51 #include "sopc_log_manager.h"
52 #include "sopc_types.h"
53 #include "sopc_user_app_itf.h"
54 #define SKIP_S2OPC_DEFINITIONS
56 #include "libs2opc_client_cmds.h"
57 
58 /* Machine states */
59 typedef enum
60 {
61  stError, /* stError is both error and closed state */
69  stClosing
71 
72 /* Request types */
73 typedef enum
74 {
75  SOPC_REQUEST_TYPE_UNKNOWN = 0, /* Unknown Request */
76  SOPC_REQUEST_TYPE_USER, /* User Crafted Request */
77  SOPC_REQUEST_TYPE_PUBLISH, /* PublishRequest */
78  SOPC_REQUEST_TYPE_SUBSCRIPTION, /* Other internally managed Subscription related request */
79  SOPC_REQUEST_TYPE_GET_ENDPOINTS /* GetEndpointsRequest */
81 
82 /* Request scopes */
83 typedef enum
84 {
91 
92 /* Machine content is private to the implementation */
94 
95 typedef struct
96 {
97  SOPC_StaMac_Machine* pSM; /* The state machine that issued the request */
98  uintptr_t appCtx; /* Application context, chosen outside of the state machine */
99  SOPC_StaMac_RequestScope requestScope; /* Whether the request is started by the state machine or the applicative */
100  SOPC_StaMac_RequestType requestType; /* the type of request */
102 
103 /* Machine lifecycle */
104 
134  SOPC_ReverseEndpointConfigIdx reverseConfigIdx,
135  uint32_t iCliId,
136  const char* szPolicyId,
137  const char* szUsername,
138  const char* szPassword,
139  const SOPC_SerializedCertificate* pUserCertX509,
140  const SOPC_SerializedAsymmetricKey* pUserKey,
141  SOPC_LibSub_DataChangeCbk* cbkLibSubDataChanged,
142  double fPublishInterval,
143  uint32_t iCntMaxKeepAlive,
144  uint32_t iCntLifetime,
145  uint32_t iTokenTarget,
146  int64_t iTimeoutMs,
147  SOPC_LibSub_EventCbk* cbkGenericEvent,
148  uintptr_t userContext,
149  SOPC_StaMac_Machine** ppSM);
150 
151 /*
152  * \brief Changes the callback for data change notifications on subscription
153  */
155  SOPC_ClientHelper_DataChangeCbk* pCbkClientHelper);
156 
161 
171 
178 
195  void* requestStruct,
196  uintptr_t appCtx,
197  SOPC_StaMac_RequestScope requestScope,
198  SOPC_StaMac_RequestType requestType);
199 
200 /*
201  * \brief Create subscription associated to the given state machine
202  */
204 
205 /*
206  * \brief Create subscription associated to the given state machine using the subscription request (new API)
207  */
210  uintptr_t userAppContext);
211 
216 
217 /*
218  * \brief Retrieve the subscription parameters revised by the server (for non-NULL params only)
219  */
221  double* revisedPublishingInterval,
222  uint32_t* revisedLifetimeCount,
223  uint32_t* revisedMaxKeepAliveCount);
224 
225 /*
226  * \brief Set the number of tokens for the subscription associated to the given state machine
227  */
229 
234 
240 {
241  OpcUa_CreateMonitoredItemsResponse* Results; /* It shall be allocated if response expected
242  or might be NULL if not necessary for application. */
243  uintptr_t outCtxId; /* Contains unique identifier filled by ::SOPC_StaMac_CreateMonitoredItem or
244  ::SOPC_StaMac_NewCreateMonitoredItems*/
246  req; /* Contains the request sent to the server (internal use only, freed during treatment)*/
248 
268  char const* const* lszNodeId,
269  const uint32_t* liAttrId,
270  int32_t nElems,
272  uint32_t* lCliHndl);
273 
291 typedef void SOPC_StaMacNotification_Fct(uintptr_t subscriptionAppCtx,
292  SOPC_StatusCode status,
293  SOPC_EncodeableType* notificationType,
294  uint32_t nbNotifElts,
295  const void* notification,
296  uintptr_t* monitoredItemCtxArray);
297 /*
298  * \brief Changes the callback for data change notifications on subscription
299  *
300  * \param pSM The state machine with a subscription used to create monitored items
301  * \param pNotificationCb The callback to be called on data change notifications on created monitored items
302  *
303  * \return SOPC_STATUS_OK if the callback was successfully set,
304  * otherwise SOPC_STATUS_INVALID_PARAMETER if one of the parameters is NULL or
305  * SOPC_STATUS_INVALID_STATE if a data change notification callback is already set.
306  */
308  SOPC_StaMacNotification_Fct* pNotificationCb);
309 
326  const uintptr_t* userAppCtxArray,
328 
333 {
334  OpcUa_DeleteMonitoredItemsResponse* Results; /* It shall be allocated if response expected
335  or might be NULL if not necessary for application. */
336  uintptr_t outCtxId; /* Contains unique identifier filled by ::SOPC_StaMac_NewDeleteMonitoredItems */
338  req; /* Contains the request sent to the server (internal use only, freed during treatment)*/
340 
354  SOPC_DeleteMonitoredItems_Ctx* outAppCtx);
355 
362 
369 
374 
379 
384 
389 
395 
401 
404 
409 
413 void SOPC_StaMac_SetUserContext(SOPC_StaMac_Machine* pSM, uintptr_t userContext);
414 
436  uintptr_t* pAppCtx,
437  SOPC_App_Com_Event event,
438  uint32_t arg,
439  void* pParam,
440  uintptr_t appCtx);
441 
442 #endif /* STATE_MACHINE_H_ */
SOPC_StaMac_SetUserContext
void SOPC_StaMac_SetUserContext(SOPC_StaMac_Machine *pSM, uintptr_t userContext)
Overwrite the user content in the given state machine.
SOPC_ReverseEndpointConfigIdx
uint32_t SOPC_ReverseEndpointConfigIdx
Index type for reverse endpoint configuration, 0 is an invalid index.
Definition: sopc_toolkit_config.h:142
_OpcUa_CreateSubscriptionRequest
Definition: sopc_types.h:5868
sopc_types.h
SOPC_StaMac_ReqCtx::requestType
SOPC_StaMac_RequestType requestType
Definition: state_machine.h:100
SOPC_StaMac_GetUserContext
uintptr_t SOPC_StaMac_GetUserContext(SOPC_StaMac_Machine *pSM)
Returns the user context provided to SOPC_StaMac_Create or modified through SOPC_StaMac_SetUserContex...
SOPC_StatusCode
uint32_t SOPC_StatusCode
Definition: libs2opc_client.h:60
SOPC_StaMac_NewCreateSubscription
SOPC_ReturnStatus SOPC_StaMac_NewCreateSubscription(SOPC_StaMac_Machine *pSM, OpcUa_CreateSubscriptionRequest *req, uintptr_t userAppContext)
SOPC_CreateMonitoredItems_Ctx::Results
OpcUa_CreateMonitoredItemsResponse * Results
Definition: state_machine.h:241
stActivated
@ stActivated
Definition: state_machine.h:64
SOPC_LibSub_EventCbk
void SOPC_LibSub_EventCbk(SOPC_LibSub_ConnectionId c_id, SOPC_LibSub_ApplicativeEvent event, SOPC_StatusCode status, const void *response, uintptr_t responseContext)
Callback for generic responses to a call to SOPC_LibSub_AsyncSendRequestOnSession().
Definition: libs2opc_client.h:272
SOPC_StaMac_Create
SOPC_ReturnStatus SOPC_StaMac_Create(uint32_t iscConfig, SOPC_ReverseEndpointConfigIdx reverseConfigIdx, uint32_t iCliId, const char *szPolicyId, const char *szUsername, const char *szPassword, const SOPC_SerializedCertificate *pUserCertX509, const SOPC_SerializedAsymmetricKey *pUserKey, SOPC_LibSub_DataChangeCbk *cbkLibSubDataChanged, double fPublishInterval, uint32_t iCntMaxKeepAlive, uint32_t iCntLifetime, uint32_t iTokenTarget, int64_t iTimeoutMs, SOPC_LibSub_EventCbk *cbkGenericEvent, uintptr_t userContext, SOPC_StaMac_Machine **ppSM)
Creates a new state machine, initialized in state stInit.
SOPC_REQUEST_TYPE_GET_ENDPOINTS
@ SOPC_REQUEST_TYPE_GET_ENDPOINTS
Definition: state_machine.h:79
stError
@ stError
Definition: state_machine.h:61
SOPC_REQUEST_TYPE_UNKNOWN
@ SOPC_REQUEST_TYPE_UNKNOWN
Definition: state_machine.h:75
_OpcUa_DeleteMonitoredItemsRequest
Definition: sopc_types.h:5818
SOPC_ClientHelper_DataChangeCbk
void SOPC_ClientHelper_DataChangeCbk(const int32_t connectionId, const char *nodeId, const SOPC_DataValue *value)
Callback type for data change event (related to a subscription)
Definition: libs2opc_client_cmds.h:59
SOPC_StaMac_State
SOPC_StaMac_State
Definition: state_machine.h:60
SOPC_StaMac_IsError
bool SOPC_StaMac_IsError(SOPC_StaMac_Machine *pSM)
Returns a bool whether the machine is in stError or not.
SOPC_DeleteMonitoredItems_Ctx::Results
OpcUa_DeleteMonitoredItemsResponse * Results
Definition: state_machine.h:334
SOPC_StaMac_PopDeleteMonItByAppCtx
bool SOPC_StaMac_PopDeleteMonItByAppCtx(SOPC_StaMac_Machine *pSM, SOPC_DeleteMonitoredItems_Ctx *pAppCtx)
Returns whether the machine has deleted the MonitoredItems with the given appCtx or not....
libs2opc_client_cmds.h
Interface of a library supporting the subscription management, read/write operation and browse.
stClosing
@ stClosing
Definition: state_machine.h:69
SOPC_REQUEST_TYPE_SUBSCRIPTION
@ SOPC_REQUEST_TYPE_SUBSCRIPTION
Definition: state_machine.h:78
SOPC_StaMac_ReqCtx::appCtx
uintptr_t appCtx
Definition: state_machine.h:98
SOPC_StaMac_NewDeleteMonitoredItems
SOPC_ReturnStatus SOPC_StaMac_NewDeleteMonitoredItems(SOPC_StaMac_Machine *pSM, OpcUa_DeleteMonitoredItemsRequest *req, SOPC_DeleteMonitoredItems_Ctx *outAppCtx)
Deletes created monitored items for the state machine subscription using the request (new API)
SOPC_SerializedAsymmetricKey
SOPC_SecretBuffer SOPC_SerializedAsymmetricKey
A serialized representation of an asymmetric key.
Definition: sopc_crypto_decl.h:70
SOPC_StaMac_Delete
void SOPC_StaMac_Delete(SOPC_StaMac_Machine **ppSM)
Deletes and deallocate the machine.
SOPC_StaMac_EventDispatcher
bool SOPC_StaMac_EventDispatcher(SOPC_StaMac_Machine *pSM, uintptr_t *pAppCtx, SOPC_App_Com_Event event, uint32_t arg, void *pParam, uintptr_t appCtx)
Handles the events from the Toolkit and changes the state machine state.
SOPC_LibSub_DataChangeCbk
void SOPC_LibSub_DataChangeCbk(const SOPC_LibSub_ConnectionId c_id, const SOPC_LibSub_DataId d_id, const SOPC_LibSub_Value *value)
Callback type for data change event (related to a subscription)
Definition: libs2opc_client.h:247
stDeletingSubscr
@ stDeletingSubscr
Definition: state_machine.h:68
SOPC_Buffer
Bytes buffer structure.
Definition: sopc_buffer.h:38
SOPC_StaMac_ReqCtx::pSM
SOPC_StaMac_Machine * pSM
Definition: state_machine.h:97
SOPC_DeleteMonitoredItems_Ctx::outCtxId
uintptr_t outCtxId
Definition: state_machine.h:336
SOPC_StaMac_SetSubscriptionNbTokens
SOPC_ReturnStatus SOPC_StaMac_SetSubscriptionNbTokens(SOPC_StaMac_Machine *pSM, uint32_t nbTokens)
SOPC_StaMac_NewCreateMonitoredItems
SOPC_ReturnStatus SOPC_StaMac_NewCreateMonitoredItems(SOPC_StaMac_Machine *pSM, OpcUa_CreateMonitoredItemsRequest *req, const uintptr_t *userAppCtxArray, SOPC_CreateMonitoredItems_Ctx *pAppCtx)
Creates new monitored items for the state machine subscription using the request (new API)
stDeletingMonIt
@ stDeletingMonIt
Definition: state_machine.h:67
SOPC_StaMac_ConfigureDataChangeCallback
SOPC_ReturnStatus SOPC_StaMac_ConfigureDataChangeCallback(SOPC_StaMac_Machine *pSM, SOPC_ClientHelper_DataChangeCbk *pCbkClientHelper)
sopc_builtintypes.h
stActivating
@ stActivating
Definition: state_machine.h:63
SOPC_DeleteMonitoredItems_Ctx
Context structure to be provided when using SOPC_StaMac_NewDeleteMonitoredItems.
Definition: state_machine.h:333
SOPC_StaMacNotification_Fct
void SOPC_StaMacNotification_Fct(uintptr_t subscriptionAppCtx, SOPC_StatusCode status, SOPC_EncodeableType *notificationType, uint32_t nbNotifElts, const void *notification, uintptr_t *monitoredItemCtxArray)
Type of callback called on Subscription Notification.
Definition: state_machine.h:291
sopc_log_manager.h
Provide circular logging.
SOPC_StaMac_GetSubscriptionCtx
uintptr_t SOPC_StaMac_GetSubscriptionCtx(SOPC_StaMac_Machine *pSM)
return the context provided in SOPC_StaMac_NewCreateSubscription
SOPC_StaMac_SetError
void SOPC_StaMac_SetError(SOPC_StaMac_Machine *pSM)
Put the state machine in error state (without closing). This avoids additional notifications.
SOPC_StaMac_GetTimeout
int64_t SOPC_StaMac_GetTimeout(SOPC_StaMac_Machine *pSM)
Returns the timeout of the machine, used for the synchronous calls.
SOPC_CreateMonitoredItems_Ctx::req
OpcUa_CreateMonitoredItemsRequest * req
Definition: state_machine.h:246
SOPC_StaMac_RequestScope
SOPC_StaMac_RequestScope
Definition: state_machine.h:84
SOPC_StaMac_RequestType
SOPC_StaMac_RequestType
Definition: state_machine.h:74
SOPC_StaMac_ReqCtx
Definition: state_machine.h:96
SOPC_StaMac_IsConnectable
bool SOPC_StaMac_IsConnectable(SOPC_StaMac_Machine *pSM)
Returns a bool whether the machine is configured and ready for a new SecureChannel.
SOPC_StaMac_ReqCtx::requestScope
SOPC_StaMac_RequestScope requestScope
Definition: state_machine.h:99
SOPC_StaMac_CreateSubscription
SOPC_ReturnStatus SOPC_StaMac_CreateSubscription(SOPC_StaMac_Machine *pSM)
SOPC_CreateMonitoredItems_Ctx
Context structure to be provided when using SOPC_StaMac_CreateMonitoredItem or SOPC_StaMac_NewCreateM...
Definition: state_machine.h:240
SOPC_REQUEST_SCOPE_DISCOVERY
@ SOPC_REQUEST_SCOPE_DISCOVERY
Definition: state_machine.h:88
SOPC_StaMac_SendRequest
SOPC_ReturnStatus SOPC_StaMac_SendRequest(SOPC_StaMac_Machine *pSM, void *requestStruct, uintptr_t appCtx, SOPC_StaMac_RequestScope requestScope, SOPC_StaMac_RequestType requestType)
Sends a request, wraps SOPC_ToolkitClient_AsyncSendRequestOnSession().
_OpcUa_DeleteMonitoredItemsResponse
Definition: sopc_types.h:5841
SOPC_CreateMonitoredItems_Ctx::outCtxId
uintptr_t outCtxId
Definition: state_machine.h:243
SOPC_StaMac_StopSession
SOPC_ReturnStatus SOPC_StaMac_StopSession(SOPC_StaMac_Machine *pSM)
Closes the session.
SOPC_REQUEST_SCOPE_STATE_MACHINE
@ SOPC_REQUEST_SCOPE_STATE_MACHINE
Definition: state_machine.h:85
SOPC_REQUEST_SCOPE_APPLICATION
@ SOPC_REQUEST_SCOPE_APPLICATION
Definition: state_machine.h:86
sopc_user_app_itf.h
Contains the types to be used by the user application to use the Toolkit.
SOPC_App_Com_Event
SOPC_App_Com_Event
Client and Server communication events to be managed by applicative code.
Definition: sopc_user_app_itf.h:381
SOPC_StaMac_GetSubscriptionRevisedParams
SOPC_ReturnStatus SOPC_StaMac_GetSubscriptionRevisedParams(SOPC_StaMac_Machine *pSM, double *revisedPublishingInterval, uint32_t *revisedLifetimeCount, uint32_t *revisedMaxKeepAliveCount)
SOPC_StaMac_HasSubscription
bool SOPC_StaMac_HasSubscription(SOPC_StaMac_Machine *pSM)
Returns a bool whether the machine has an active subscription or not.
stInit
@ stInit
Definition: state_machine.h:62
SOPC_StaMac_CreateMonitoredItem
SOPC_ReturnStatus SOPC_StaMac_CreateMonitoredItem(SOPC_StaMac_Machine *pSM, char const *const *lszNodeId, const uint32_t *liAttrId, int32_t nElems, SOPC_CreateMonitoredItems_Ctx *pAppCtx, uint32_t *lCliHndl)
Creates a MonitoredItem asynchronously.
SOPC_CreateMonitoredItems_Ctx
struct SOPC_CreateMonitoredItems_Ctx SOPC_CreateMonitoredItems_Ctx
Context structure to be provided when using SOPC_StaMac_CreateMonitoredItem or SOPC_StaMac_NewCreateM...
_OpcUa_CreateMonitoredItemsRequest
Definition: sopc_types.h:5562
SOPC_DeleteMonitoredItems_Ctx
struct SOPC_DeleteMonitoredItems_Ctx SOPC_DeleteMonitoredItems_Ctx
Context structure to be provided when using SOPC_StaMac_NewDeleteMonitoredItems.
_OpcUa_CreateMonitoredItemsResponse
Definition: sopc_types.h:5586
SOPC_StaMac_IsConnected
bool SOPC_StaMac_IsConnected(SOPC_StaMac_Machine *pSM)
Returns a bool whether the machine is in a connected state or not.
SOPC_REQUEST_TYPE_PUBLISH
@ SOPC_REQUEST_TYPE_PUBLISH
Definition: state_machine.h:77
libs2opc_client.h
Interface of an example client library supporting the subscription management.
stCreatingMonIt
@ stCreatingMonIt
Definition: state_machine.h:66
stCreatingSubscr
@ stCreatingSubscr
Definition: state_machine.h:65
SOPC_StaMac_PopMonItByAppCtx
bool SOPC_StaMac_PopMonItByAppCtx(SOPC_StaMac_Machine *pSM, SOPC_CreateMonitoredItems_Ctx *pAppCtx)
Returns whether the machine has created the MonitoredItems with the given appCtx or not....
SOPC_StaMac_NewConfigureNotificationCallback
SOPC_ReturnStatus SOPC_StaMac_NewConfigureNotificationCallback(SOPC_StaMac_Machine *pSM, SOPC_StaMacNotification_Fct *pNotificationCb)
SOPC_EncodeableType_Struct
Encodeable object type structure definition. It provides all the services functions associated with t...
Definition: sopc_encodeabletype.h:161
sopc_crypto_profiles.h
Defines the cryptographic profiles: constants and struct.
SOPC_StaMac_StartSession
SOPC_ReturnStatus SOPC_StaMac_StartSession(SOPC_StaMac_Machine *pSM)
Creates a session asynchronously.
SOPC_StaMac_HasSubscriptionId
uint32_t SOPC_StaMac_HasSubscriptionId(SOPC_StaMac_Machine *pSM)
Returns subscription Id whether the machine has an active subscription or not (id = 0).
SOPC_DeleteMonitoredItems_Ctx::req
OpcUa_DeleteMonitoredItemsRequest * req
Definition: state_machine.h:338
SOPC_StaMac_DeleteSubscription
SOPC_ReturnStatus SOPC_StaMac_DeleteSubscription(SOPC_StaMac_Machine *pSM)
Delete subscription associated to the given state machine.
SOPC_REQUEST_TYPE_USER
@ SOPC_REQUEST_TYPE_USER
Definition: state_machine.h:76
SOPC_StaMac_Machine
struct SOPC_StaMac_Machine SOPC_StaMac_Machine
Definition: state_machine.h:93
SOPC_ReturnStatus
SOPC_ReturnStatus
Definition: libs2opc_client.h:64