S2OPC OPCUA Toolkit
Loading...
Searching...
No Matches
libs2opc_server_internal.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
29#ifndef LIBS2OPC_SERVER_CONFIG_INTERNAL_H_
30#define LIBS2OPC_SERVER_CONFIG_INTERNAL_H_
31
32#include <inttypes.h>
33#include <stdbool.h>
34
35#include "sopc_address_space.h"
36#include "sopc_event_manager.h"
37#include "sopc_mutexes.h"
39#include "sopc_user_app_itf.h"
40
41#include "libs2opc_server.h"
44
45#ifndef SOPC_HELPER_LOCAL_RESPONSE_TIMEOUT_MS
46#define SOPC_HELPER_LOCAL_RESPONSE_TIMEOUT_MS 5000
47#endif
48
49#ifndef SOPC_DEFAULT_SHUTDOWN_PHASE_IN_SECONDS
50#define SOPC_DEFAULT_SHUTDOWN_PHASE_IN_SECONDS 5
51#endif
52
53#ifndef SOPC_DEFAULT_CURRENT_TIME_REFERSH_FREQ_MS
54#define SOPC_DEFAULT_CURRENT_TIME_REFERSH_FREQ_MS 1000
55#endif
56
57typedef enum
58{
59 SOPC_SERVER_STATE_INITIALIZING = 0,
60 SOPC_SERVER_STATE_CONFIGURING = 1,
61 SOPC_SERVER_STATE_CONFIGURED = 2,
62 SOPC_SERVER_STATE_STARTED = 3,
63 SOPC_SERVER_STATE_SHUTDOWN_PHASE = 4,
64 SOPC_SERVER_STATE_STOPPING = 5,
65 SOPC_SERVER_STATE_STOPPED = 6,
66} SOPC_HelperServer_State;
67
68// The server helper dedicated configuration in addition to configuration ::SOPC_S2OPC_Config
69typedef struct SOPC_ServerHelper_Config
70{
71 // Flag atomically set when the structure is initialized during call to SOPC_ServerConfigHelper_Initialize
72 // and singleton config is initialized
73 int32_t initialized;
74 // Server state
75 SOPC_Mutex stateMutex;
76 SOPC_HelperServer_State state;
77
78 // Address space instance
79 SOPC_AddressSpace* addressSpace;
80
81 // Application write notification callback record
82 SOPC_WriteNotif_Fct* writeNotifCb;
83 // Application node availability for CreateMonitoreItem callback
84 SOPC_CreateMI_NodeAvail_Fct* nodeAvailCb;
85 // Application asynchronous local service response callback record
87 // Application server private key password callback
89 getServerKeyPassword; /* If it is defined and if the serverKey is encrypted,
90 then the callback is called during call to
91 ::SOPC_ServerConfigHelper_SetKeyCertPairFromPath
92 or ::SOPC_ServerConfigHelper_ConfigureFromXML.
93 The callback allows to retrieve the password for decryption */
94
95 // Synchronous local service response management
96 SOPC_Condition syncLocalServiceCond;
97 SOPC_Mutex syncLocalServiceMutex;
98 uint32_t syncLocalServiceId;
99 bool syncCalled;
100 void* syncResp;
101
102 // Stop server management:
103
104 // Manage server stopping when server is running synchronously using SOPC_ServerHelper_Serve.
105 struct
106 {
107 SOPC_Condition serverStoppedCond;
108 SOPC_Mutex serverStoppedMutex;
109 int32_t serverRequestedToStop;
110 bool serverAllEndpointsClosed;
111 } syncServeStopData;
112
113 // Server stopped notification callback record
114 SOPC_ServerStopped_Fct* stoppedCb;
115 // Server stopped notification callback data
116 SOPC_ReturnStatus serverStoppedStatus;
117
118 // Server shutdown phase duration configuration
119 uint16_t configuredSecondsTillShutdown;
120 // Server status current time refresh interval
121 uint16_t configuredCurrentTimeRefreshIntervalMs;
122 uint32_t currentTimeRefreshTimerId;
123
124 // Server build info
125 OpcUa_BuildInfo* buildInfo;
126
127 // Configured endpoint indexes and opened state arrays
128 uint8_t nbEndpoints;
129 SOPC_Endpoint_Config* endpoints[SOPC_MAX_ENDPOINT_DESCRIPTION_CONFIGURATIONS]; // we do not use config.endpoints to
130 // avoid pre-allocating structure
131 uint32_t* endpointIndexes; // array of endpoint indexes provided by toolkit
132 bool* endpointClosed; // array of closed endpoint to keep track of endpoints notified closed by toolkit
133
134 // Runtime variables
135 SOPC_Server_RuntimeVariables runtimeVariables;
136
137} SOPC_ServerHelper_Config;
138
139// Define the structure used as context for asynchronous calls
140typedef struct SOPC_HelperConfigInternal_Ctx
141{
142 // actual context for helper user (user application)
143 uintptr_t userContext;
144
145 // Discriminant
146 SOPC_App_Com_Event event;
147 union
148 {
149 struct LocalServiceCtx
150 {
151 // sync call management
152 bool isSyncCall;
153 uint32_t syncId;
154 // internal use of local services (runtime variables)
155 bool isHelperInternal;
156 // message to display in case of internal local service failure (response NOK)
157 const char* internalErrorMsg;
158 } localService;
159 } eventCtx;
160} SOPC_HelperConfigInternal_Ctx;
161
162// The singleton configuration structure
163extern SOPC_ServerHelper_Config sopc_server_helper_config;
164
165// Returns true if the server is in configuring state, false otherwise
166bool SOPC_ServerInternal_IsConfiguring(void);
167
168// Returns true if the server is in started state, false otherwise
169bool SOPC_ServerInternal_IsStarted(void);
170
171// Returns true if the server is in stopped state, false otherwise
172bool SOPC_ServerInternal_IsStopped(void);
173
174// Returns true if the server is in stopped state or in a state previous to started state, false otherwise
175// Note: server configuration is not clearable in shutdown or stopping states
176bool SOPC_ServerInternal_IsConfigClearable(void);
177
178// Check for configuration issues and set server state as configured in case of success
179bool SOPC_ServerInternal_CheckConfigAndSetConfiguredState(void);
180
181// Check current state and set server state as started in case of success
182bool SOPC_ServerInternal_SetStartedState(void);
183
184// Check current state and set server state as stopping in case of success
185bool SOPC_ServerInternal_SetStoppingState(void);
186
187// Set server state as stopped
188void SOPC_ServerInternal_SetStoppedState(void);
189
190// Get password to decrypt server private key from internal callback
191bool SOPC_ServerInternal_GetKeyPassword(char** outPassword);
192
193// Local service synchronous internal callback
194void SOPC_ServerInternal_SyncLocalServiceCb(SOPC_EncodeableType* encType,
195 void* response,
196 SOPC_HelperConfigInternal_Ctx* helperCtx);
197
198// Local service asynchronous internal callback
199void SOPC_ServerInternal_AsyncLocalServiceCb(SOPC_EncodeableType* encType,
200 void* response,
201 SOPC_HelperConfigInternal_Ctx* helperCtx);
202
203// Endpoint closed asynchronous callback
204void SOPC_ServerInternal_ClosedEndpoint(uint32_t epConfigIdx, SOPC_ReturnStatus status);
205
206// Clear low level endpoint config (clear strings, do not clear user managers)
207void SOPC_ServerInternal_ClearEndpoint(SOPC_Endpoint_Config* epConfig);
208
209// Callback instance to be used on client application key / certificate pair update
210void SOPC_ServerInternal_KeyCertPairUpdateCb(uintptr_t updateParam);
211
212// Callback instance to be used on server PKI update
213void SOPC_ServerInternal_PKIProviderUpdateCb(uintptr_t updateParam);
214
215#endif
High level interface to run an OPC UA server.
void SOPC_ServerStopped_Fct(SOPC_ReturnStatus status)
Type of callback called when server stopped.
Definition libs2opc_server.h:55
High level interface to configure an OPC UA server.
bool SOPC_CreateMI_NodeAvail_Fct(const SOPC_NodeId *nodeId, OpcUa_NodeClass *outNodeClass, SOPC_StatusCode *outBadStatus)
Type of the callback called by CreateMonitoredItem service when a NodeId is not already part of serve...
Definition libs2opc_server_config.h:206
bool SOPC_GetServerKeyPassword_Fct(char **outPassword)
Type of callback to retrieve password for decryption of the server private key.
Definition libs2opc_server_config.h:110
void SOPC_WriteNotif_Fct(const SOPC_CallContext *callCtxPtr, OpcUa_WriteValue *writeValue, SOPC_StatusCode writeStatus)
Type of callback to provide to receive write notification on address space.
Definition libs2opc_server_config.h:161
void SOPC_LocalServiceAsyncResp_Fct(SOPC_EncodeableType *type, void *response, uintptr_t userContext)
Type of callback to provide to receive asynchronous local service response.
Definition libs2opc_server_config.h:252
Internal module used to manage the server runtime node variable changes (Server information nodes)
struct _SOPC_AddressSpace SOPC_AddressSpace
Definition sopc_address_space.h:68
enum _SOPC_ReturnStatus SOPC_ReturnStatus
Common enumerations for S2OPC.
Contains the interface to configure events in the server. This interface is intended to be used by th...
Contains the configuration constants used by the Tookit. Those constants could be modified for specif...
#define SOPC_MAX_ENDPOINT_DESCRIPTION_CONFIGURATIONS
Maximum number of classic endpoint descriptions configured (same as number of connection listeners)....
Definition sopc_toolkit_config_constants.h:68
Contains the types to be used by the user application to use the Toolkit.
enum _SOPC_App_Com_Event SOPC_App_Com_Event
Client and Server communication events to be managed by applicative code.
Definition p_sopc_synchronisation.h:57
Encodeable object type structure definition. It provides all the services functions associated with t...
Definition sopc_encodeabletype.h:177
Server configuration of a Endpoint connection listener.
Definition sopc_user_app_itf.h:140
Definition p_sopc_synchronisation.h:64
Definition sopc_types.h:6403