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 
27 #ifndef LIBS2OPC_CLIENT_H_
28 #define LIBS2OPC_CLIENT_H_
29 /*
30  Notes:
31  This header is designed so as to make it possible to generate automatically an Ada specification package (.ads)
32  for any application that would have to link the staticC library S2OPC_CLIENT.
33  The Generation of .ADS file can be done using the following command:
34  g++ -c -std=gnu++11 -fdump-ada-spec -C libs2opc_client.h
35  gcc also works but loses parameter names in function prototypes, that is why the g++ and 'extern "C"' are used.
36 */
37 
38 #include <stdint.h>
39 
40 /*
41  =================
42  TYPES DEFINITION
43  ================= */
44 
45 /* S2OPC types: define them except when SKIP_S2OPC_DEFINITIONS is defined.
46  * To use the LibSub with other parts of the S2OPC Toolkit, you shall define SKIP_S2OPC_DEFINITIONS
47  * and includes the following files before including this header:
48  * sopc_builtintypes.h
49  * sopc_user_app_itf.h
50  */
51 #ifndef SKIP_S2OPC_DEFINITIONS
52 
53 /*
54  Data value quality
55  TBD? Masks for BAD and UNCERTAIN quality?
56  Taken from sop "sopc_builtintypes.h" */
57 typedef uint32_t SOPC_StatusCode;
58 
59 /* Result, taken from "sopc_enums.h" */
60 typedef enum SOPC_ReturnStatus
61 {
73 
74 /* Log levels, taken from "sopc_user_app_itf.h" */
75 typedef enum
76 {
82 
83 /* SecurityMode, directly compatible with the encoded OPC-UA type,
84  * taken from "sopc_types.h" */
85 typedef enum
86 {
92 
93 /* Security policies, taken from "sopc_crypto_profiles.h" */
94 #define SOPC_SecurityPolicy_None_URI "http://opcfoundation.org/UA/SecurityPolicy#None"
95 #define SOPC_SecurityPolicy_Basic256_URI "http://opcfoundation.org/UA/SecurityPolicy#Basic256"
96 #define SOPC_SecurityPolicy_Basic256Sha256_URI "http://opcfoundation.org/UA/SecurityPolicy#Basic256Sha256"
97 #define SOPC_SecurityPolicy_Aes128Sha256RsaOaep_URI "http://opcfoundation.org/UA/SecurityPolicy#Aes128_Sha256_RsaOaep"
98 #define SOPC_SecurityPolicy_Aes256Sha256RsaPss_URI "http://opcfoundation.org/UA/SecurityPolicy#Aes256_Sha256_RsaPss"
99 
100 typedef enum
101 {
105 
106 void SOPC_Sleep(unsigned int milliseconds);
107 #endif
108 
109 /* C String type */
110 typedef char* SOPC_LibSub_String;
111 
112 /* C Const String type */
113 typedef const char* SOPC_LibSub_CstString;
114 
115 /* Connnection configuration identifier */
117 
118 /* Connection identifier */
119 typedef uint32_t SOPC_LibSub_ConnectionId;
120 
121 /* Data identifier (used for subscription change notification) */
122 typedef uint32_t SOPC_LibSub_DataId;
123 
124 /* Timestamp (NTP Format) */
125 typedef uint64_t SOPC_LibSub_Timestamp;
126 
127 /* Data value type */
128 typedef enum
129 {
136 
153 typedef struct
154 {
157  void* value;
158  int32_t length;
161  void* raw_value;
163 
167 typedef uint32_t SOPC_LibSub_AttributeId;
168 
169 #define SOPC_LibSub_AttributeId_NodeId 1
170 #define SOPC_LibSub_AttributeId_NodeClass 2
171 #define SOPC_LibSub_AttributeId_BrowseName 3
172 #define SOPC_LibSub_AttributeId_DisplayName 4
173 #define SOPC_LibSub_AttributeId_Description 5
174 #define SOPC_LibSub_AttributeId_WriteMask 6
175 #define SOPC_LibSub_AttributeId_UserWriteMask 7
176 #define SOPC_LibSub_AttributeId_IsAbstract 8
177 #define SOPC_LibSub_AttributeId_Symmetric 9
178 #define SOPC_LibSub_AttributeId_InverseName 10
179 #define SOPC_LibSub_AttributeId_ContainsNoLoops 11
180 #define SOPC_LibSub_AttributeId_EventNotifier 12
181 #define SOPC_LibSub_AttributeId_Value 13
182 #define SOPC_LibSub_AttributeId_DataType 14
183 #define SOPC_LibSub_AttributeId_ValueRank 15
184 #define SOPC_LibSub_AttributeId_ArrayDimensions 16
185 #define SOPC_LibSub_AttributeId_AccessLevel 17
186 #define SOPC_LibSub_AttributeId_UserAccessLevel 18
187 #define SOPC_LibSub_AttributeId_MinimumSamplingInterval 19
188 #define SOPC_LibSub_AttributeId_Historizing 20
189 #define SOPC_LibSub_AttributeId_Executable 21
190 #define SOPC_LibSub_AttributeId_UserExecutable 22
191 
198 {
202 
210 typedef void SOPC_LibSub_LogCbk(const SOPC_Log_Level log_level, SOPC_LibSub_CstString text);
211 
218 
232  const SOPC_LibSub_DataId d_id,
233  const SOPC_LibSub_Value* value);
234 
257  SOPC_StatusCode status,
258  const void* response,
259  uintptr_t responseContext);
260 // TODO: the const constraint on response should be released since it is not necessary and by-passed
261 
262 /*
263  =====================
264  STRUCTURES DEFINITION
265  ===================== */
266 
275 typedef struct
276 {
279  struct
280  {
282  const char* log_path;
283  uint32_t maxBytes;
284  uint16_t maxFiles;
285  } toolkit_logger;
287 
364 typedef struct
365 {
367 
384  uint32_t n_max_keepalive;
385  uint32_t n_max_lifetime;
387  int64_t timeout_ms;
388  uint32_t sc_lifetime;
389  uint16_t token_target;
391  const void* expected_endpoints;
393 
394 /*
395  ===================
396  SERVICES DEFINITION
397  =================== */
398 
403 
416 
422 void SOPC_LibSub_Clear(void);
423 
437 
448 
467 
492  const SOPC_LibSub_CstString* lszNodeId,
493  const SOPC_LibSub_AttributeId* lattrId,
494  int32_t nElements,
495  SOPC_LibSub_DataId* lDataId);
496 
510  void* requestStruct,
511  uintptr_t requestContext);
524 
525 /*--------------------------------
526  TBC??
527  - delete_subscription
528  - delete_from_subscription
529 --------------------------------*/
530 
535 void Helpers_Log(const SOPC_Log_Level log_level, const char* format, ...);
536 
541 
542 #endif /* LIBS2OPC_CLIENT_H_ */
SOPC_LibSub_Value
Structure defining the value of a node.
Definition: libs2opc_client.h:154
OpcUa_MessageSecurityMode_SignAndEncrypt
@ OpcUa_MessageSecurityMode_SignAndEncrypt
Definition: libs2opc_client.h:90
SOPC_LibSub_StaticCfg::disconnect_callback
SOPC_LibSub_DisconnectCbk * disconnect_callback
Definition: libs2opc_client.h:278
SOPC_LOG_LEVEL_WARNING
@ SOPC_LOG_LEVEL_WARNING
Definition: libs2opc_client.h:78
SOPC_LibSub_ConnectionCfg::password
SOPC_LibSub_CstString password
Definition: libs2opc_client.h:380
SOPC_LibSub_Value::raw_value
void * raw_value
Definition: libs2opc_client.h:161
SOPC_StatusCode
uint32_t SOPC_StatusCode
Definition: libs2opc_client.h:57
SOPC_LibSub_ConnectionCfg::security_mode
OpcUa_MessageSecurityMode security_mode
Definition: libs2opc_client.h:371
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_UserPolicyId
SOPC_UserPolicyId
Definition: libs2opc_client.h:101
SOPC_LibSub_Value::type
SOPC_LibSub_DataType type
Definition: libs2opc_client.h:155
OpcUa_MessageSecurityMode_Sign
@ OpcUa_MessageSecurityMode_Sign
Definition: libs2opc_client.h:89
SOPC_LibSub_ConnectionCfg::n_max_keepalive
uint32_t n_max_keepalive
Definition: libs2opc_client.h:384
SOPC_LibSub_ConnectionCfg::publish_period_ms
int64_t publish_period_ms
Definition: libs2opc_client.h:383
SOPC_LibSub_Value::server_timestamp
SOPC_LibSub_Timestamp server_timestamp
Definition: libs2opc_client.h:160
SOPC_LibSub_StaticCfg::maxBytes
uint32_t maxBytes
Definition: libs2opc_client.h:283
SOPC_STATUS_WOULD_BLOCK
@ SOPC_STATUS_WOULD_BLOCK
Definition: libs2opc_client.h:67
SOPC_LibSub_DataType_string
@ SOPC_LibSub_DataType_string
Definition: libs2opc_client.h:132
SOPC_LibSub_ConnectionCfg::security_policy
SOPC_LibSub_CstString security_policy
Definition: libs2opc_client.h:370
OpcUa_MessageSecurityMode
OpcUa_MessageSecurityMode
Definition: libs2opc_client.h:86
SOPC_STATUS_ENCODING_ERROR
@ SOPC_STATUS_ENCODING_ERROR
Definition: libs2opc_client.h:66
SOPC_LibSub_ConfigurationId
uint32_t SOPC_LibSub_ConfigurationId
Definition: libs2opc_client.h:116
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:377
SOPC_LibSub_Value::value
void * value
Definition: libs2opc_client.h:157
SOPC_STATUS_INVALID_STATE
@ SOPC_STATUS_INVALID_STATE
Definition: libs2opc_client.h:65
SOPC_LibSub_ConnectionCfg::generic_response_callback
SOPC_LibSub_EventCbk * generic_response_callback
Definition: libs2opc_client.h:390
SOPC_LibSub_CstString
const char * SOPC_LibSub_CstString
Definition: libs2opc_client.h:113
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:103
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
SOPC_LibSub_StaticCfg
Static configuration of OPC client library.
Definition: libs2opc_client.h:276
SOPC_LibSub_StaticCfg::log_path
const char * log_path
Definition: libs2opc_client.h:282
SOPC_LibSub_ConnectionId
uint32_t SOPC_LibSub_ConnectionId
Definition: libs2opc_client.h:119
SOPC_STATUS_OUT_OF_MEMORY
@ SOPC_STATUS_OUT_OF_MEMORY
Definition: libs2opc_client.h:69
SOPC_LibSub_AttributeId
uint32_t SOPC_LibSub_AttributeId
AttributeIds, as defined in the OPC UA Reference, Part 6 Annex A.
Definition: libs2opc_client.h:167
SOPC_LibSub_ConnectionCfg::timeout_ms
int64_t timeout_ms
Definition: libs2opc_client.h:387
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:64
SOPC_LibSub_DataType_other
@ SOPC_LibSub_DataType_other
Definition: libs2opc_client.h:134
SOPC_LibSub_StaticCfg::maxFiles
uint16_t maxFiles
Definition: libs2opc_client.h:284
SOPC_LibSub_DataType
SOPC_LibSub_DataType
Definition: libs2opc_client.h:129
OpcUa_MessageSecurityMode_None
@ OpcUa_MessageSecurityMode_None
Definition: libs2opc_client.h:88
SOPC_LibSub_ConnectionCfg::n_max_lifetime
uint32_t n_max_lifetime
Definition: libs2opc_client.h:385
SOPC_Log_Level
SOPC_Log_Level
Definition: libs2opc_client.h:76
SOPC_LOG_LEVEL_ERROR
@ SOPC_LOG_LEVEL_ERROR
Definition: libs2opc_client.h:77
SOPC_LibSub_StaticCfg::host_log_callback
SOPC_LibSub_LogCbk * host_log_callback
Definition: libs2opc_client.h:277
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:210
SOPC_LibSub_DataType_bool
@ SOPC_LibSub_DataType_bool
Definition: libs2opc_client.h:130
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:381
SOPC_STATUS_TIMEOUT
@ SOPC_STATUS_TIMEOUT
Definition: libs2opc_client.h:68
SOPC_LibSub_DataType_integer
@ SOPC_LibSub_DataType_integer
Definition: libs2opc_client.h:131
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:63
SOPC_LibSub_ConnectionCfg::path_cert_auth
SOPC_LibSub_CstString path_cert_auth
Definition: libs2opc_client.h:373
SOPC_LibSub_ConnectionCfg::server_uri
SOPC_LibSub_CstString server_uri
Definition: libs2opc_client.h:368
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:366
SOPC_LibSub_StaticCfg::level
SOPC_Log_Level level
Definition: libs2opc_client.h:281
SOPC_LibSub_ConnectionCfg::policyId
SOPC_LibSub_CstString policyId
Definition: libs2opc_client.h:378
SOPC_STATUS_NOT_SUPPORTED
@ SOPC_STATUS_NOT_SUPPORTED
Definition: libs2opc_client.h:71
SOPC_USER_POLICY_ID_ANONYMOUS
@ SOPC_USER_POLICY_ID_ANONYMOUS
Definition: libs2opc_client.h:102
SOPC_LibSub_ConnectionCfg::server_url
SOPC_LibSub_CstString server_url
Definition: libs2opc_client.h:369
SOPC_LibSub_DisconnectCbk
void SOPC_LibSub_DisconnectCbk(const SOPC_LibSub_ConnectionId c_id)
Callback type for disconnect event.
Definition: libs2opc_client.h:217
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:70
SOPC_LibSub_ConnectionCfg::path_crl
SOPC_LibSub_CstString path_crl
Definition: libs2opc_client.h:374
SOPC_LibSub_ConnectionCfg::disable_certificate_verification
uint8_t disable_certificate_verification
Definition: libs2opc_client.h:372
SOPC_LibSub_ApplicativeEvent_Response
@ SOPC_LibSub_ApplicativeEvent_Response
Definition: libs2opc_client.h:200
SOPC_LibSub_DataId
uint32_t SOPC_LibSub_DataId
Definition: libs2opc_client.h:122
SOPC_LibSub_ConnectionCfg::path_cert_srv
SOPC_LibSub_CstString path_cert_srv
Definition: libs2opc_client.h:375
SOPC_LOG_LEVEL_INFO
@ SOPC_LOG_LEVEL_INFO
Definition: libs2opc_client.h:79
SOPC_LibSub_ConnectionCfg::path_key_x509_token
SOPC_LibSub_CstString path_key_x509_token
Definition: libs2opc_client.h:382
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:198
OpcUa_MessageSecurityMode_Invalid
@ OpcUa_MessageSecurityMode_Invalid
Definition: libs2opc_client.h:87
SOPC_LibSub_ConnectionCfg::path_cert_cli
SOPC_LibSub_CstString path_cert_cli
Definition: libs2opc_client.h:376
SOPC_LibSub_Value::quality
SOPC_StatusCode quality
Definition: libs2opc_client.h:156
SOPC_LibSub_String
char * SOPC_LibSub_String
Definition: libs2opc_client.h:110
SOPC_STATUS_OK
@ SOPC_STATUS_OK
Definition: libs2opc_client.h:62
SOPC_LibSub_DataType_bytestring
@ SOPC_LibSub_DataType_bytestring
Definition: libs2opc_client.h:133
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:159
SOPC_LibSub_ConnectionCfg
Connection configuration to a remote OPC server.
Definition: libs2opc_client.h:365
SOPC_LibSub_Value::length
int32_t length
Definition: libs2opc_client.h:158
SOPC_LibSub_ConnectionCfg::username
SOPC_LibSub_CstString username
Definition: libs2opc_client.h:379
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:386
SOPC_LOG_LEVEL_DEBUG
@ SOPC_LOG_LEVEL_DEBUG
Definition: libs2opc_client.h:80
SOPC_LibSub_ConnectionCfg::expected_endpoints
const void * expected_endpoints
Definition: libs2opc_client.h:391
SOPC_LibSub_ApplicativeEvent_SendFailed
@ SOPC_LibSub_ApplicativeEvent_SendFailed
Definition: libs2opc_client.h:199
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:389
SOPC_LibSub_Timestamp
uint64_t SOPC_LibSub_Timestamp
Definition: libs2opc_client.h:125
SOPC_LibSub_ConnectionCfg::sc_lifetime
uint32_t sc_lifetime
Definition: libs2opc_client.h:388
SOPC_ReturnStatus
SOPC_ReturnStatus
Definition: libs2opc_client.h:61