S2OPC OPCUA Toolkit
Loading...
Searching...
No Matches
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#include "sopc_builtintypes.h"
49#include "sopc_types.h"
50
61
82typedef void SOPC_StaMac_EventCbk(uint32_t c_id,
84 SOPC_StatusCode status,
85 const void* response,
86 uintptr_t responseContext);
87
88/* Machine states */
101
102/* Request types */
103typedef enum
104{
105 SOPC_REQUEST_TYPE_UNKNOWN = 0, /* Unknown Request */
106 SOPC_REQUEST_TYPE_USER, /* User Crafted Request */
107 SOPC_REQUEST_TYPE_PUBLISH, /* PublishRequest */
108 SOPC_REQUEST_TYPE_SUBSCRIPTION, /* Other internally managed Subscription related request */
109 SOPC_REQUEST_TYPE_GET_ENDPOINTS /* GetEndpointsRequest */
111
112/* Request scopes */
121
122/* Machine content is private to the implementation */
124
125typedef struct
126{
127 SOPC_StaMac_Machine* pSM; /* The state machine that issued the request */
128 uintptr_t appCtx; /* Application context, chosen outside of the state machine */
129 SOPC_StaMac_RequestScope requestScope; /* Whether the request is started by the state machine or the applicative */
130 SOPC_StaMac_RequestType requestType; /* the type of request */
132
133/* Machine lifecycle */
134
157 SOPC_ReverseEndpointConfigIdx reverseConfigIdx,
158 uint32_t iCliId,
159 const char* szPolicyId,
160 const char* szUsername,
161 const char* szPassword,
162 const SOPC_SerializedCertificate* pUserCertX509,
163 const SOPC_SerializedAsymmetricKey* pUserKey,
164 uint32_t iTokenTarget,
165 SOPC_StaMac_EventCbk* cbkGenericEvent,
166 uintptr_t userContext,
167 SOPC_StaMac_Machine** ppSM);
168
173
183
190
207 void* requestStruct,
208 uintptr_t appCtx,
209 SOPC_StaMac_RequestScope requestScope,
210 SOPC_StaMac_RequestType requestType);
211
212/*
213 * \brief Create subscription associated to the given state machine using the subscription request (new API)
214 */
217 uintptr_t userAppContext);
218
223
224/*
225 * \brief Retrieve the subscription parameters revised by the server (for non-NULL params only)
226 */
228 double* revisedPublishingInterval,
229 uint32_t* revisedLifetimeCount,
230 uint32_t* revisedMaxKeepAliveCount);
231
232/*
233 * \brief Set the number of tokens for the subscription associated to the given state machine
234 */
236
241
246{
247 OpcUa_CreateMonitoredItemsResponse* Results; /* It shall be allocated if response expected
248 or might be NULL if not necessary for application. */
249 uintptr_t outCtxId; /* Contains unique identifier filled by ::SOPC_StaMac_NewCreateMonitoredItems*/
251 req; /* Contains the request sent to the server (internal use only, freed during treatment)*/
253
271typedef void SOPC_StaMacNotification_Fct(uintptr_t subscriptionAppCtx,
272 SOPC_StatusCode status,
273 SOPC_EncodeableType* notificationType,
274 uint32_t nbNotifElts,
275 const void* notification,
276 uintptr_t* monitoredItemCtxArray);
277/*
278 * \brief Changes the callback for data change notifications on subscription
279 *
280 * \param pSM The state machine with a subscription used to create monitored items
281 * \param pNotificationCb The callback to be called on data change notifications on created monitored items
282 *
283 * \return SOPC_STATUS_OK if the callback was successfully set,
284 * otherwise SOPC_STATUS_INVALID_PARAMETER if one of the parameters is NULL or
285 * SOPC_STATUS_INVALID_STATE if a data change notification callback is already set.
286 */
288 SOPC_StaMacNotification_Fct* pNotificationCb);
289
306 const uintptr_t* userAppCtxArray,
308
313{
314 OpcUa_DeleteMonitoredItemsResponse* Results; /* It shall be allocated if response expected
315 or might be NULL if not necessary for application. */
316 uintptr_t outCtxId; /* Contains unique identifier filled by ::SOPC_StaMac_NewDeleteMonitoredItems */
318 req; /* Contains the request sent to the server (internal use only, freed during treatment)*/
320
335
342
349
354
359
364
369
375
381
386
390void SOPC_StaMac_SetUserContext(SOPC_StaMac_Machine* pSM, uintptr_t userContext);
391
413 uintptr_t* pAppCtx,
414 SOPC_App_Com_Event event,
415 uint32_t arg,
416 void* pParam,
417 uintptr_t appCtx);
418
419#endif /* STATE_MACHINE_H_ */
uint32_t SOPC_StatusCode
Definition sopc_builtintypes.h:36
SOPC_SecretBuffer SOPC_SerializedAsymmetricKey
A serialized representation of an asymmetric key.
Definition sopc_crypto_decl.h:70
enum _SOPC_ReturnStatus SOPC_ReturnStatus
Common enumerations for S2OPC.
uint32_t SOPC_ReverseEndpointConfigIdx
Index type for reverse endpoint configuration, 0 is an invalid index.
Definition sopc_toolkit_config.h:142
enum _SOPC_App_Com_Event SOPC_App_Com_Event
Client and Server communication events to be managed by applicative code.
SOPC_ReturnStatus SOPC_StaMac_NewCreateSubscription(SOPC_StaMac_Machine *pSM, OpcUa_CreateSubscriptionRequest *req, uintptr_t userAppContext)
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, uint32_t iTokenTarget, SOPC_StaMac_EventCbk *cbkGenericEvent, uintptr_t userContext, SOPC_StaMac_Machine **ppSM)
Creates a new state machine, initialized in state stInit.
uintptr_t SOPC_StaMac_GetUserContext(SOPC_StaMac_Machine *pSM)
Returns the user context provided to SOPC_StaMac_Create or modified through SOPC_StaMac_SetUserContex...
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.
struct SOPC_CreateMonitoredItems_Ctx SOPC_CreateMonitoredItems_Ctx
Context structure to be provided when using SOPC_StaMac_NewCreateMonitoredItems.
bool SOPC_StaMac_IsError(SOPC_StaMac_Machine *pSM)
Returns a bool whether the machine is in stError or not.
struct SOPC_StaMac_Machine SOPC_StaMac_Machine
Definition state_machine.h:123
SOPC_ReturnStatus SOPC_StaMac_NewConfigureNotificationCallback(SOPC_StaMac_Machine *pSM, SOPC_StaMacNotification_Fct *pNotificationCb)
SOPC_ReturnStatus SOPC_StaMac_SetSubscriptionNbTokens(SOPC_StaMac_Machine *pSM, uint32_t nbTokens)
void SOPC_StaMac_SetError(SOPC_StaMac_Machine *pSM)
Put the state machine in error state (without closing). This avoids additional notifications.
SOPC_ReturnStatus SOPC_StaMac_StopSession(SOPC_StaMac_Machine *pSM)
Closes the session.
uintptr_t SOPC_StaMac_GetSubscriptionCtx(SOPC_StaMac_Machine *pSM)
return the context provided in SOPC_StaMac_NewCreateSubscription
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_ApplicativeEvent
The event passed to the connection SOPC_LibSub_EventCbk. Either an error or a valid response notifica...
Definition state_machine.h:57
@ SOPC_StaMac_ApplicativeEvent_SendFailed
Definition state_machine.h:58
@ SOPC_StaMac_ApplicativeEvent_Response
Definition state_machine.h:59
void SOPC_StaMac_SetUserContext(SOPC_StaMac_Machine *pSM, uintptr_t userContext)
Overwrite the user content in the given state machine.
SOPC_StaMac_RequestScope
Definition state_machine.h:114
@ SOPC_REQUEST_SCOPE_STATE_MACHINE
Definition state_machine.h:115
@ SOPC_REQUEST_SCOPE_APPLICATION
Definition state_machine.h:116
@ SOPC_REQUEST_SCOPE_DISCOVERY
Definition state_machine.h:118
bool SOPC_StaMac_HasSubscription(SOPC_StaMac_Machine *pSM)
Returns a bool whether the machine has an active subscription or not.
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....
SOPC_StaMac_RequestType
Definition state_machine.h:104
@ SOPC_REQUEST_TYPE_PUBLISH
Definition state_machine.h:107
@ SOPC_REQUEST_TYPE_USER
Definition state_machine.h:106
@ SOPC_REQUEST_TYPE_GET_ENDPOINTS
Definition state_machine.h:109
@ SOPC_REQUEST_TYPE_UNKNOWN
Definition state_machine.h:105
@ SOPC_REQUEST_TYPE_SUBSCRIPTION
Definition state_machine.h:108
SOPC_ReturnStatus SOPC_StaMac_StartSession(SOPC_StaMac_Machine *pSM)
Creates a session asynchronously.
void SOPC_StaMac_Delete(SOPC_StaMac_Machine **ppSM)
Deletes and deallocate the machine.
bool SOPC_StaMac_IsConnectable(SOPC_StaMac_Machine *pSM)
Returns a bool whether the machine is configured and ready for a new SecureChannel.
uint32_t SOPC_StaMac_HasSubscriptionId(SOPC_StaMac_Machine *pSM)
Returns subscription Id whether the machine has an active subscription or not (id = 0).
SOPC_ReturnStatus SOPC_StaMac_DeleteSubscription(SOPC_StaMac_Machine *pSM)
Delete subscription associated to the given state machine.
struct SOPC_DeleteMonitoredItems_Ctx SOPC_DeleteMonitoredItems_Ctx
Context structure to be provided when using SOPC_StaMac_NewDeleteMonitoredItems.
enum _SOPC_StaMac_ApplicativeEvent SOPC_StaMac_ApplicativeEvent
The event passed to the connection SOPC_LibSub_EventCbk. Either an error or a valid response notifica...
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)
SOPC_ReturnStatus SOPC_StaMac_GetSubscriptionRevisedParams(SOPC_StaMac_Machine *pSM, double *revisedPublishingInterval, uint32_t *revisedLifetimeCount, uint32_t *revisedMaxKeepAliveCount)
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:271
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().
bool SOPC_StaMac_IsConnected(SOPC_StaMac_Machine *pSM)
Returns a bool whether the machine is in a connected state or not.
SOPC_StaMac_State
Definition state_machine.h:90
@ stActivated
Definition state_machine.h:94
@ stCreatingSubscr
Definition state_machine.h:95
@ stActivating
Definition state_machine.h:93
@ stDeletingMonIt
Definition state_machine.h:97
@ stInit
Definition state_machine.h:92
@ stClosing
Definition state_machine.h:99
@ stDeletingSubscr
Definition state_machine.h:98
@ stError
Definition state_machine.h:91
@ stCreatingMonIt
Definition state_machine.h:96
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)
void SOPC_StaMac_EventCbk(uint32_t c_id, SOPC_StaMac_ApplicativeEvent event, SOPC_StatusCode status, const void *response, uintptr_t responseContext)
Callback for generic responses to a call to SOPC_StaMac_SendRequest().
Definition state_machine.h:82
Bytes buffer structure.
Definition sopc_buffer.h:38
Context structure to be provided when using SOPC_StaMac_NewCreateMonitoredItems.
Definition state_machine.h:246
uintptr_t outCtxId
Definition state_machine.h:249
OpcUa_CreateMonitoredItemsResponse * Results
Definition state_machine.h:247
OpcUa_CreateMonitoredItemsRequest * req
Definition state_machine.h:251
Context structure to be provided when using SOPC_StaMac_NewDeleteMonitoredItems.
Definition state_machine.h:313
OpcUa_DeleteMonitoredItemsResponse * Results
Definition state_machine.h:314
OpcUa_DeleteMonitoredItemsRequest * req
Definition state_machine.h:318
uintptr_t outCtxId
Definition state_machine.h:316
Encodeable object type structure definition. It provides all the services functions associated with t...
Definition sopc_encodeabletype.h:177
Definition state_machine.h:126
SOPC_StaMac_RequestType requestType
Definition state_machine.h:130
SOPC_StaMac_Machine * pSM
Definition state_machine.h:127
SOPC_StaMac_RequestScope requestScope
Definition state_machine.h:129
uintptr_t appCtx
Definition state_machine.h:128
Definition sopc_types.h:5562
Definition sopc_types.h:5586
Definition sopc_types.h:5868
Definition sopc_types.h:5818
Definition sopc_types.h:5841