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 */
68  stClosing
70 
71 /* Request types */
72 typedef enum
73 {
74  SOPC_REQUEST_TYPE_UNKNOWN = 0, /* Unknown Request */
75  SOPC_REQUEST_TYPE_USER, /* User Crafted Request */
76  SOPC_REQUEST_TYPE_PUBLISH, /* PublishRequest */
77  SOPC_REQUEST_TYPE_CREATE_SUBSCRIPTION, /* CreateSubscriptionRequest */
78  SOPC_REQUEST_TYPE_CREATE_MONITORED_ITEMS, /* CreateMonitoredItemsRequest */
79  SOPC_REQUEST_TYPE_DELETE_SUBSCRIPTION, /* DeleteSubscriptionRequest */
80  SOPC_REQUEST_TYPE_GET_ENDPOINTS /* GetEndpointsRequest */
82 
83 /* Request scopes */
84 typedef enum
85 {
92 
93 typedef struct
94 {
95  uintptr_t appCtx; /* Application context, chosen outside of the state machine */
96  SOPC_StaMac_RequestScope requestScope; /* Whether the request is started by the state machine or the applicative */
97  SOPC_StaMac_RequestType requestType; /* the type of request */
99 
100 /* Machine content is private to the implementation */
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 char* szPath_cert_x509_token,
140  const char* szPath_key_x509_token,
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 
209 
214 {
215  OpcUa_CreateMonitoredItemsResponse* Results; /* might be NULL if not necessary for application. */
216  uintptr_t outCtxId; /* Contains unique identifier filled by ::SOPC_StaMac_CreateMonitoredItem */
218 
238  char const* const* lszNodeId,
239  const uint32_t* liAttrId,
240  int32_t nElems,
242  uint32_t* lCliHndl);
243 
250 
257 
262 
267 
272 
277 
280 
285 
289 void SOPC_StaMac_SetUserContext(SOPC_StaMac_Machine* pSM, uintptr_t userContext);
290 
312  uintptr_t* pAppCtx,
313  SOPC_App_Com_Event event,
314  uint32_t arg,
315  void* pParam,
316  uintptr_t appCtx);
317 
318 #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:136
SOPC_CreateMonitoredItem_Ctx::outCtxId
uintptr_t outCtxId
Definition: state_machine.h:216
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 char *szPath_cert_x509_token, const char *szPath_key_x509_token, 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_types.h
SOPC_StaMac_ReqCtx::requestType
SOPC_StaMac_RequestType requestType
Definition: state_machine.h:97
SOPC_StaMac_HasMonItByAppCtx
bool SOPC_StaMac_HasMonItByAppCtx(SOPC_StaMac_Machine *pSM, SOPC_CreateMonitoredItem_Ctx *pAppCtx)
Returns whether the machine has created the MonitoredItem with the given appCtx or not.
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_CreateMonitoredItem_Ctx::Results
OpcUa_CreateMonitoredItemsResponse * Results
Definition: state_machine.h:215
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:255
SOPC_REQUEST_TYPE_GET_ENDPOINTS
@ SOPC_REQUEST_TYPE_GET_ENDPOINTS
Definition: state_machine.h:80
stError
@ stError
Definition: state_machine.h:61
SOPC_REQUEST_TYPE_UNKNOWN
@ SOPC_REQUEST_TYPE_UNKNOWN
Definition: state_machine.h:74
SOPC_REQUEST_TYPE_DELETE_SUBSCRIPTION
@ SOPC_REQUEST_TYPE_DELETE_SUBSCRIPTION
Definition: state_machine.h:79
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:54
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.
libs2opc_client_cmds.h
Interface of a library supporting the subscription management, read/write operation and browse.
stClosing
@ stClosing
Definition: state_machine.h:68
SOPC_StaMac_ReqCtx::appCtx
uintptr_t appCtx
Definition: state_machine.h:95
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:231
stDeletingSubscr
@ stDeletingSubscr
Definition: state_machine.h:67
SOPC_StaMac_ConfigureDataChangeCallback
SOPC_ReturnStatus SOPC_StaMac_ConfigureDataChangeCallback(SOPC_StaMac_Machine *pSM, SOPC_ClientHelper_DataChangeCbk *pCbkClientHelper)
sopc_builtintypes.h
SOPC_REQUEST_TYPE_CREATE_SUBSCRIPTION
@ SOPC_REQUEST_TYPE_CREATE_SUBSCRIPTION
Definition: state_machine.h:77
stActivating
@ stActivating
Definition: state_machine.h:63
sopc_log_manager.h
A log manager providing circular logging, multiple logging categories and levels with thread-safe acc...
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 synchroneous calls.
SOPC_StaMac_RequestScope
SOPC_StaMac_RequestScope
Definition: state_machine.h:85
SOPC_StaMac_RequestType
SOPC_StaMac_RequestType
Definition: state_machine.h:73
SOPC_StaMac_ReqCtx
Definition: state_machine.h:94
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:96
SOPC_StaMac_CreateSubscription
SOPC_ReturnStatus SOPC_StaMac_CreateSubscription(SOPC_StaMac_Machine *pSM)
SOPC_REQUEST_SCOPE_DISCOVERY
@ SOPC_REQUEST_SCOPE_DISCOVERY
Definition: state_machine.h:89
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().
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:86
SOPC_REQUEST_SCOPE_APPLICATION
@ SOPC_REQUEST_SCOPE_APPLICATION
Definition: state_machine.h:87
SOPC_REQUEST_TYPE_CREATE_MONITORED_ITEMS
@ SOPC_REQUEST_TYPE_CREATE_MONITORED_ITEMS
Definition: state_machine.h:78
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:283
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_CreateMonitoredItem_Ctx *pAppCtx, uint32_t *lCliHndl)
Creates a MonitoredItem asynchronously.
SOPC_CreateMonitoredItem_Ctx
struct SOPC_CreateMonitoredItem_Ctx SOPC_CreateMonitoredItem_Ctx
Context structure to be provided when using SOPC_StaMac_CreateMonitoredItem.
_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:76
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_CreateMonitoredItem_Ctx
Context structure to be provided when using SOPC_StaMac_CreateMonitoredItem.
Definition: state_machine.h:214
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_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:75
SOPC_StaMac_Machine
struct SOPC_StaMac_Machine SOPC_StaMac_Machine
Definition: state_machine.h:101
SOPC_ReturnStatus
SOPC_ReturnStatus
Definition: libs2opc_client.h:61