S2OPC OPCUA Toolkit
libs2opc_client.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 
30 #ifndef LIBS2OPC_CLIENT_H_
31 #define LIBS2OPC_CLIENT_H_
32 /*
33  Notes:
34  This header is designed so as to make it possible to generate automatically an Ada specification package (.ads)
35  for any application that would have to link the staticC library S2OPC_CLIENT.
36  The Generation of .ADS file can be done using the following command:
37  g++ -c -std=gnu++11 -fdump-ada-spec -C libs2opc_client.h
38  gcc also works but loses parameter names in function prototypes, that is why the g++ and 'extern "C"' are used.
39 */
40 
41 #include <stdint.h>
42 
43 /*
44  =================
45  TYPES DEFINITION
46  ================= */
47 
48 /* S2OPC types: define them except when SKIP_S2OPC_DEFINITIONS is defined.
49  * To use the LibSub with other parts of the S2OPC Toolkit, you shall define SKIP_S2OPC_DEFINITIONS
50  * and includes the following files before including this header:
51  * sopc_builtintypes.h
52  * sopc_user_app_itf.h
53  */
54 #ifndef SKIP_S2OPC_DEFINITIONS
55 
56 /*
57  Data value quality
58  TBD? Masks for BAD and UNCERTAIN quality?
59  Taken from sop "sopc_builtintypes.h" */
60 typedef uint32_t SOPC_StatusCode;
61 
62 /* Result, taken from "sopc_enums.h" */
63 typedef enum SOPC_ReturnStatus
64 {
76 
77 /* Log levels, taken from "sopc_user_app_itf.h" */
78 typedef enum
79 {
85 
86 /* SecurityMode, directly compatible with the encoded OPC-UA type,
87  * taken from "sopc_types.h" */
88 typedef enum
89 {
95 
96 /* Security policies, taken from "sopc_crypto_profiles.h" */
97 #define SOPC_SecurityPolicy_None_URI "http://opcfoundation.org/UA/SecurityPolicy#None"
98 #define SOPC_SecurityPolicy_Basic256_URI "http://opcfoundation.org/UA/SecurityPolicy#Basic256"
99 #define SOPC_SecurityPolicy_Basic256Sha256_URI "http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256"
100 #define SOPC_SecurityPolicy_Aes128Sha256RsaOaep_URI "http://opcfoundation.org/UA/SecurityPolicy#Aes128_Sha256_RsaOaep"
101 #define SOPC_SecurityPolicy_Aes256Sha256RsaPss_URI "http://opcfoundation.org/UA/SecurityPolicy#Aes256_Sha256_RsaPss"
102 
103 typedef enum
104 {
108 
109 void SOPC_Sleep(unsigned int milliseconds);
110 #endif
111 
112 /* C String type */
114 typedef char* SOPC_LibSub_String;
115 
116 /* C Const String type */
118 typedef const char* SOPC_LibSub_CstString;
119 
120 /* Connnection configuration identifier */
123 
124 /* Connection identifier */
126 typedef uint32_t SOPC_LibSub_ConnectionId;
127 
128 /* Data identifier (used for subscription change notification) */
130 typedef uint32_t SOPC_LibSub_DataId;
131 
132 /* Timestamp (NTP Format) */
134 typedef uint64_t SOPC_LibSub_Timestamp;
135 
136 /* Data value type */
138 typedef enum
139 {
146 
164 typedef struct
165 {
168  void* value;
169  int32_t length;
172  void* raw_value;
174 
179 typedef uint32_t SOPC_LibSub_AttributeId;
180 
181 #define SOPC_LibSub_AttributeId_NodeId 1
182 #define SOPC_LibSub_AttributeId_NodeClass 2
183 #define SOPC_LibSub_AttributeId_BrowseName 3
184 #define SOPC_LibSub_AttributeId_DisplayName 4
185 #define SOPC_LibSub_AttributeId_Description 5
186 #define SOPC_LibSub_AttributeId_WriteMask 6
187 #define SOPC_LibSub_AttributeId_UserWriteMask 7
188 #define SOPC_LibSub_AttributeId_IsAbstract 8
189 #define SOPC_LibSub_AttributeId_Symmetric 9
190 #define SOPC_LibSub_AttributeId_InverseName 10
191 #define SOPC_LibSub_AttributeId_ContainsNoLoops 11
192 #define SOPC_LibSub_AttributeId_EventNotifier 12
193 #define SOPC_LibSub_AttributeId_Value 13
194 #define SOPC_LibSub_AttributeId_DataType 14
195 #define SOPC_LibSub_AttributeId_ValueRank 15
196 #define SOPC_LibSub_AttributeId_ArrayDimensions 16
197 #define SOPC_LibSub_AttributeId_AccessLevel 17
198 #define SOPC_LibSub_AttributeId_UserAccessLevel 18
199 #define SOPC_LibSub_AttributeId_MinimumSamplingInterval 19
200 #define SOPC_LibSub_AttributeId_Historizing 20
201 #define SOPC_LibSub_AttributeId_Executable 21
202 #define SOPC_LibSub_AttributeId_UserExecutable 22
203 
211 {
215 
224 typedef void SOPC_LibSub_LogCbk(const SOPC_Log_Level log_level, SOPC_LibSub_CstString text);
225 
233 
248  const SOPC_LibSub_DataId d_id,
249  const SOPC_LibSub_Value* value);
250 
274  SOPC_StatusCode status,
275  const void* response,
276  uintptr_t responseContext);
277 // TODO: the const constraint on response should be released since it is not necessary and by-passed
278 
279 /*
280  =====================
281  STRUCTURES DEFINITION
282  ===================== */
283 
293 typedef struct
294 {
297  struct
298  {
300  const char* log_path;
301  uint32_t maxBytes;
302  uint16_t maxFiles;
303  } toolkit_logger;
305 
383 typedef struct
384 {
386 
404  uint32_t n_max_keepalive;
405  uint32_t n_max_lifetime;
407  int64_t timeout_ms;
408  uint32_t sc_lifetime;
409  uint16_t token_target;
411  const void* expected_endpoints;
413 
414 /*
415  ===================
416  SERVICES DEFINITION
417  =================== */
418 
424 
438 
444 void SOPC_LibSub_Clear(void);
445 
460 
472 
492 
518  const SOPC_LibSub_CstString* lszNodeId,
519  const SOPC_LibSub_AttributeId* lattrId,
520  int32_t nElements,
521  SOPC_LibSub_DataId* lDataId);
522 
537  void* requestStruct,
538  uintptr_t requestContext);
552 
553 /*--------------------------------
554  TBC??
555  - delete_subscription
556  - delete_from_subscription
557 --------------------------------*/
558 
564 void Helpers_Log(const SOPC_Log_Level log_level, const char* format, ...);
565 
571 
572 #endif /* LIBS2OPC_CLIENT_H_ */
SOPC_LibSub_Value
Structure defining the value of a node.
Definition: libs2opc_client.h:165
OpcUa_MessageSecurityMode_SignAndEncrypt
@ OpcUa_MessageSecurityMode_SignAndEncrypt
Definition: libs2opc_client.h:93
SOPC_LibSub_StaticCfg::disconnect_callback
SOPC_LibSub_DisconnectCbk * disconnect_callback
Definition: libs2opc_client.h:296
SOPC_LOG_LEVEL_WARNING
@ SOPC_LOG_LEVEL_WARNING
Definition: libs2opc_client.h:81
SOPC_LibSub_ConnectionCfg::password
SOPC_LibSub_CstString password
Definition: libs2opc_client.h:399
SOPC_LibSub_Value::raw_value
void * raw_value
Definition: libs2opc_client.h:172
SOPC_StatusCode
uint32_t SOPC_StatusCode
Definition: libs2opc_client.h:60
SOPC_LibSub_ConnectionCfg::security_mode
OpcUa_MessageSecurityMode security_mode
Definition: libs2opc_client.h:390
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_UserPolicyId
SOPC_UserPolicyId
Definition: libs2opc_client.h:104
SOPC_LibSub_Value::type
SOPC_LibSub_DataType type
Definition: libs2opc_client.h:166
OpcUa_MessageSecurityMode_Sign
@ OpcUa_MessageSecurityMode_Sign
Definition: libs2opc_client.h:92
SOPC_LibSub_ConnectionCfg::n_max_keepalive
uint32_t n_max_keepalive
Definition: libs2opc_client.h:404
SOPC_LibSub_ConnectionCfg::publish_period_ms
int64_t publish_period_ms
Definition: libs2opc_client.h:403
SOPC_LibSub_Value::server_timestamp
SOPC_LibSub_Timestamp server_timestamp
Definition: libs2opc_client.h:171
SOPC_LibSub_StaticCfg::maxBytes
uint32_t maxBytes
Definition: libs2opc_client.h:301
SOPC_STATUS_WOULD_BLOCK
@ SOPC_STATUS_WOULD_BLOCK
Definition: libs2opc_client.h:70
SOPC_LibSub_DataType_string
@ SOPC_LibSub_DataType_string
Definition: libs2opc_client.h:142
SOPC_LibSub_ConnectionCfg::security_policy
SOPC_LibSub_CstString security_policy
Definition: libs2opc_client.h:389
OpcUa_MessageSecurityMode
OpcUa_MessageSecurityMode
Definition: libs2opc_client.h:89
SOPC_STATUS_ENCODING_ERROR
@ SOPC_STATUS_ENCODING_ERROR
Definition: libs2opc_client.h:69
SOPC_LibSub_ConfigurationId
uint32_t SOPC_LibSub_ConfigurationId
Definition: libs2opc_client.h:122
Helpers_LoggerStdout
void Helpers_LoggerStdout(const SOPC_Log_Level log_level, const SOPC_LibSub_CstString text)
Helper logger, prints a log message to stdout, with the following format "# log_level: text\n".
SOPC_LibSub_ConnectionCfg::path_key_cli
SOPC_LibSub_CstString path_key_cli
Definition: libs2opc_client.h:396
SOPC_LibSub_Value::value
void * value
Definition: libs2opc_client.h:168
SOPC_STATUS_INVALID_STATE
@ SOPC_STATUS_INVALID_STATE
Definition: libs2opc_client.h:68
SOPC_LibSub_ConnectionCfg::generic_response_callback
SOPC_LibSub_EventCbk * generic_response_callback
Definition: libs2opc_client.h:410
SOPC_LibSub_CstString
const char * SOPC_LibSub_CstString
Definition: libs2opc_client.h:118
SOPC_LibSub_Connect
SOPC_ReturnStatus SOPC_LibSub_Connect(const SOPC_LibSub_ConfigurationId cfgId, SOPC_LibSub_ConnectionId *pCliId)
Creates a new connection to a remote OPC server from configuration id cfg_id. The connection represen...
SOPC_USER_POLICY_ID_USERNAME
@ SOPC_USER_POLICY_ID_USERNAME
Definition: libs2opc_client.h:106
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
SOPC_LibSub_StaticCfg
Static configuration of OPC client library.
Definition: libs2opc_client.h:294
SOPC_LibSub_StaticCfg::log_path
const char * log_path
Definition: libs2opc_client.h:300
SOPC_LibSub_ConnectionId
uint32_t SOPC_LibSub_ConnectionId
Definition: libs2opc_client.h:126
SOPC_STATUS_OUT_OF_MEMORY
@ SOPC_STATUS_OUT_OF_MEMORY
Definition: libs2opc_client.h:72
SOPC_LibSub_AttributeId
uint32_t SOPC_LibSub_AttributeId
AttributeIds, as defined in the OPC UA Reference, Part 6 Annex A.
Definition: libs2opc_client.h:179
SOPC_LibSub_ConnectionCfg::timeout_ms
int64_t timeout_ms
Definition: libs2opc_client.h:407
SOPC_LibSub_ConfigureConnection
SOPC_ReturnStatus SOPC_LibSub_ConfigureConnection(const SOPC_LibSub_ConnectionCfg *pCfg, SOPC_LibSub_ConfigurationId *pCfgId)
Configure a future connection. This function shall be called once per connection before a call to SOP...
SOPC_STATUS_INVALID_PARAMETERS
@ SOPC_STATUS_INVALID_PARAMETERS
Definition: libs2opc_client.h:67
SOPC_LibSub_DataType_other
@ SOPC_LibSub_DataType_other
Definition: libs2opc_client.h:144
SOPC_LibSub_StaticCfg::maxFiles
uint16_t maxFiles
Definition: libs2opc_client.h:302
SOPC_LibSub_DataType
SOPC_LibSub_DataType
Definition: libs2opc_client.h:139
OpcUa_MessageSecurityMode_None
@ OpcUa_MessageSecurityMode_None
Definition: libs2opc_client.h:91
SOPC_LibSub_ConnectionCfg::n_max_lifetime
uint32_t n_max_lifetime
Definition: libs2opc_client.h:405
SOPC_Log_Level
SOPC_Log_Level
Definition: libs2opc_client.h:79
SOPC_LOG_LEVEL_ERROR
@ SOPC_LOG_LEVEL_ERROR
Definition: libs2opc_client.h:80
SOPC_LibSub_StaticCfg::host_log_callback
SOPC_LibSub_LogCbk * host_log_callback
Definition: libs2opc_client.h:295
SOPC_LibSub_Clear
void SOPC_LibSub_Clear(void)
Clears the connections, configurations, and clears the Toolkit.
SOPC_Sleep
void SOPC_Sleep(unsigned int milliseconds)
SOPC_LibSub_LogCbk
void SOPC_LibSub_LogCbk(const SOPC_Log_Level log_level, SOPC_LibSub_CstString text)
Log callback type.
Definition: libs2opc_client.h:224
SOPC_LibSub_DataType_bool
@ SOPC_LibSub_DataType_bool
Definition: libs2opc_client.h:140
SOPC_LibSub_AddToSubscription
SOPC_ReturnStatus SOPC_LibSub_AddToSubscription(const SOPC_LibSub_ConnectionId cliId, const SOPC_LibSub_CstString *lszNodeId, const SOPC_LibSub_AttributeId *lattrId, int32_t nElements, SOPC_LibSub_DataId *lDataId)
Add variables to the subscription of the connection. This call is synchroneous: it waits for the serv...
SOPC_LibSub_ConnectionCfg::path_cert_x509_token
SOPC_LibSub_CstString path_cert_x509_token
Definition: libs2opc_client.h:400
SOPC_STATUS_TIMEOUT
@ SOPC_STATUS_TIMEOUT
Definition: libs2opc_client.h:71
SOPC_LibSub_DataType_integer
@ SOPC_LibSub_DataType_integer
Definition: libs2opc_client.h:141
Helpers_Log
void Helpers_Log(const SOPC_Log_Level log_level, const char *format,...)
Buffers a log message, then calls the callback configured with the LibSub.
SOPC_STATUS_NOK
@ SOPC_STATUS_NOK
Definition: libs2opc_client.h:66
SOPC_LibSub_ConnectionCfg::path_cert_auth
SOPC_LibSub_CstString path_cert_auth
Definition: libs2opc_client.h:392
SOPC_LibSub_ConnectionCfg::server_uri
SOPC_LibSub_CstString server_uri
Definition: libs2opc_client.h:387
SOPC_LibSub_AsyncSendRequestOnSession
SOPC_ReturnStatus SOPC_LibSub_AsyncSendRequestOnSession(SOPC_LibSub_ConnectionId cliId, void *requestStruct, uintptr_t requestContext)
Sends a generic request on the connection. The request must be accepted by the SOPC encoders (OpcUa_<...
SOPC_LibSub_ConnectionCfg::reverse_config_idx
uint32_t reverse_config_idx
Definition: libs2opc_client.h:385
SOPC_LibSub_StaticCfg::level
SOPC_Log_Level level
Definition: libs2opc_client.h:299
SOPC_LibSub_ConnectionCfg::policyId
SOPC_LibSub_CstString policyId
Definition: libs2opc_client.h:397
SOPC_STATUS_NOT_SUPPORTED
@ SOPC_STATUS_NOT_SUPPORTED
Definition: libs2opc_client.h:74
SOPC_LibSub_ConnectionCfg::key_x509_token_encrypted
bool key_x509_token_encrypted
Definition: libs2opc_client.h:402
SOPC_USER_POLICY_ID_ANONYMOUS
@ SOPC_USER_POLICY_ID_ANONYMOUS
Definition: libs2opc_client.h:105
SOPC_LibSub_ConnectionCfg::server_url
SOPC_LibSub_CstString server_url
Definition: libs2opc_client.h:388
SOPC_LibSub_DisconnectCbk
void SOPC_LibSub_DisconnectCbk(const SOPC_LibSub_ConnectionId c_id)
Callback type for disconnect event.
Definition: libs2opc_client.h:232
SOPC_LibSub_Initialize
SOPC_ReturnStatus SOPC_LibSub_Initialize(const SOPC_LibSub_StaticCfg *pCfg)
Configure the library. This function shall be called once by the host application before any other se...
SOPC_STATUS_CLOSED
@ SOPC_STATUS_CLOSED
Definition: libs2opc_client.h:73
SOPC_LibSub_ConnectionCfg::path_crl
SOPC_LibSub_CstString path_crl
Definition: libs2opc_client.h:393
SOPC_LibSub_ConnectionCfg::disable_certificate_verification
uint8_t disable_certificate_verification
Definition: libs2opc_client.h:391
SOPC_LibSub_ApplicativeEvent_Response
@ SOPC_LibSub_ApplicativeEvent_Response
Definition: libs2opc_client.h:213
SOPC_LibSub_DataId
uint32_t SOPC_LibSub_DataId
Definition: libs2opc_client.h:130
SOPC_LibSub_ConnectionCfg::path_cert_srv
SOPC_LibSub_CstString path_cert_srv
Definition: libs2opc_client.h:394
SOPC_LOG_LEVEL_INFO
@ SOPC_LOG_LEVEL_INFO
Definition: libs2opc_client.h:82
SOPC_LibSub_ConnectionCfg::path_key_x509_token
SOPC_LibSub_CstString path_key_x509_token
Definition: libs2opc_client.h:401
SOPC_LibSub_ApplicativeEvent
SOPC_LibSub_ApplicativeEvent
The event passed to the connection SOPC_LibSub_EventCbk. Either an error or a valid response notifica...
Definition: libs2opc_client.h:211
OpcUa_MessageSecurityMode_Invalid
@ OpcUa_MessageSecurityMode_Invalid
Definition: libs2opc_client.h:90
SOPC_LibSub_ConnectionCfg::path_cert_cli
SOPC_LibSub_CstString path_cert_cli
Definition: libs2opc_client.h:395
SOPC_LibSub_Value::quality
SOPC_StatusCode quality
Definition: libs2opc_client.h:167
SOPC_LibSub_String
char * SOPC_LibSub_String
Definition: libs2opc_client.h:114
SOPC_STATUS_OK
@ SOPC_STATUS_OK
Definition: libs2opc_client.h:65
SOPC_LibSub_DataType_bytestring
@ SOPC_LibSub_DataType_bytestring
Definition: libs2opc_client.h:143
SOPC_LibSub_GetVersion
SOPC_LibSub_CstString SOPC_LibSub_GetVersion(void)
Return the current version of the library.
SOPC_LibSub_Value::source_timestamp
SOPC_LibSub_Timestamp source_timestamp
Definition: libs2opc_client.h:170
SOPC_LibSub_ConnectionCfg
Connection configuration to a remote OPC server.
Definition: libs2opc_client.h:384
SOPC_LibSub_Value::length
int32_t length
Definition: libs2opc_client.h:169
SOPC_LibSub_ConnectionCfg::username
SOPC_LibSub_CstString username
Definition: libs2opc_client.h:398
SOPC_LibSub_Configured
SOPC_ReturnStatus SOPC_LibSub_Configured(void)
Mark the library as configured. All calls to SOPC_LibSub_ConfigureConnection() shall be done prior to...
SOPC_LibSub_ConnectionCfg::data_change_callback
SOPC_LibSub_DataChangeCbk * data_change_callback
Definition: libs2opc_client.h:406
SOPC_LOG_LEVEL_DEBUG
@ SOPC_LOG_LEVEL_DEBUG
Definition: libs2opc_client.h:83
SOPC_LibSub_ConnectionCfg::expected_endpoints
const void * expected_endpoints
Definition: libs2opc_client.h:411
SOPC_LibSub_ApplicativeEvent_SendFailed
@ SOPC_LibSub_ApplicativeEvent_SendFailed
Definition: libs2opc_client.h:212
SOPC_LibSub_Disconnect
SOPC_ReturnStatus SOPC_LibSub_Disconnect(const SOPC_LibSub_ConnectionId cliId)
Disconnect from a remote OPC server. The function waits until the client is effectively disconnected,...
SOPC_LibSub_ConnectionCfg::token_target
uint16_t token_target
Definition: libs2opc_client.h:409
SOPC_LibSub_Timestamp
uint64_t SOPC_LibSub_Timestamp
Definition: libs2opc_client.h:134
SOPC_LibSub_ConnectionCfg::sc_lifetime
uint32_t sc_lifetime
Definition: libs2opc_client.h:408
SOPC_ReturnStatus
SOPC_ReturnStatus
Definition: libs2opc_client.h:64