ua_client_config.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. *
  5. * Copyright 2018 (c) Stefan Profanter, fortiss GmbH
  6. * Copyright 2018 (c) Thomas Stalder, Blue Time Concept SA
  7. */
  8. #ifndef UA_CLIENT_CONFIG_H
  9. #define UA_CLIENT_CONFIG_H
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. #include "ua_plugin_network.h"
  14. /**
  15. * .. _client-config:
  16. *
  17. * Client Configuration
  18. * --------------------
  19. *
  20. * The client configuration is used for setting connection parameters and
  21. * additional settings used by the client.
  22. * The configuration should not be modified after it is passed to a client.
  23. * Currently, only one client can use a configuration at a time.
  24. *
  25. * Examples for configurations are provided in the ``/plugins`` folder.
  26. * The usual usage is as follows:
  27. *
  28. * 1. Create a client configuration with default settings as a starting point
  29. * 2. Modifiy the configuration, e.g. modifying the timeout
  30. * 3. Instantiate a client with it
  31. * 4. After shutdown of the client, clean up the configuration (free memory)
  32. *
  33. * The :ref:`tutorials` provide a good starting point for this. */
  34. typedef enum {
  35. UA_CLIENTSTATE_DISCONNECTED, /* The client is disconnected */
  36. UA_CLIENTSTATE_WAITING_FOR_ACK, /* The Client has sent HEL and waiting */
  37. UA_CLIENTSTATE_CONNECTED, /* A TCP connection to the server is open */
  38. UA_CLIENTSTATE_SECURECHANNEL, /* A SecureChannel to the server is open */
  39. UA_CLIENTSTATE_SESSION, /* A session with the server is open */
  40. UA_CLIENTSTATE_SESSION_DISCONNECTED, /* Disconnected vs renewed? */
  41. UA_CLIENTSTATE_SESSION_RENEWED /* A session with the server is open (renewed) */
  42. } UA_ClientState;
  43. struct UA_Client;
  44. typedef struct UA_Client UA_Client;
  45. typedef void (*UA_ClientAsyncServiceCallback)(UA_Client *client, void *userdata,
  46. UA_UInt32 requestId, void *response);
  47. /*
  48. * Repeated Callbacks
  49. * ------------------ */
  50. typedef UA_StatusCode (*UA_ClientCallback)(UA_Client *client, void *data);
  51. UA_StatusCode
  52. UA_Client_addRepeatedCallback(UA_Client *Client, UA_ClientCallback callback,
  53. void *data, UA_UInt32 interval, UA_UInt64 *callbackId);
  54. UA_StatusCode
  55. UA_Client_changeRepeatedCallbackInterval(UA_Client *Client,
  56. UA_UInt64 callbackId, UA_UInt32 interval);
  57. UA_StatusCode UA_Client_removeRepeatedCallback(UA_Client *Client,
  58. UA_UInt64 callbackId);
  59. /**
  60. * Client Lifecycle callback
  61. * ^^^^^^^^^^^^^^^^^^^^^^^^^ */
  62. typedef void (*UA_ClientStateCallback)(UA_Client *client, UA_ClientState clientState);
  63. /**
  64. * Subscription Inactivity callback
  65. * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */
  66. #ifdef UA_ENABLE_SUBSCRIPTIONS
  67. typedef void (*UA_SubscriptionInactivityCallback)(UA_Client *client, UA_UInt32 subscriptionId, void *subContext);
  68. #endif
  69. /**
  70. * Inactivity callback
  71. * ^^^^^^^^^^^^^^^^^^^ */
  72. typedef void (*UA_InactivityCallback)(UA_Client *client);
  73. /**
  74. * Client Configuration Data
  75. * ^^^^^^^^^^^^^^^^^^^^^^^^^ */
  76. typedef struct UA_ClientConfig {
  77. UA_UInt32 timeout; /* ASync + Sync response timeout in ms */
  78. UA_UInt32 secureChannelLifeTime; /* Lifetime in ms (then the channel needs
  79. to be renewed) */
  80. UA_Logger logger;
  81. UA_ConnectionConfig localConnectionConfig;
  82. UA_ConnectClientConnection connectionFunc;
  83. UA_ConnectClientConnection initConnectionFunc;
  84. UA_ClientCallback pollConnectionFunc;
  85. /* Custom DataTypes */
  86. size_t customDataTypesSize;
  87. const UA_DataType *customDataTypes;
  88. /* Callback function */
  89. UA_ClientStateCallback stateCallback;
  90. #ifdef UA_ENABLE_SUBSCRIPTIONS
  91. /**
  92. * When outStandingPublishRequests is greater than 0,
  93. * the server automatically create publishRequest when
  94. * UA_Client_runAsync is called. If the client don't receive
  95. * a publishResponse after :
  96. * (sub->publishingInterval * sub->maxKeepAliveCount) +
  97. * client->config.timeout)
  98. * then, the client call subscriptionInactivityCallback
  99. * The connection can be closed, this in an attempt to
  100. * recreate a healthy connection. */
  101. UA_SubscriptionInactivityCallback subscriptionInactivityCallback;
  102. #endif
  103. /**
  104. * When connectivityCheckInterval is greater than 0,
  105. * every connectivityCheckInterval (in ms), a async read request
  106. * is performed on the server. inactivityCallback is called
  107. * when the client receive no response for this read request
  108. * The connection can be closed, this in an attempt to
  109. * recreate a healthy connection. */
  110. UA_InactivityCallback inactivityCallback;
  111. void *clientContext;
  112. #ifdef UA_ENABLE_SUBSCRIPTIONS
  113. /* number of PublishResponse standing in the sever */
  114. /* 0 = background task disabled */
  115. UA_UInt16 outStandingPublishRequests;
  116. #endif
  117. /**
  118. * connectivity check interval in ms
  119. * 0 = background task disabled */
  120. UA_UInt32 connectivityCheckInterval;
  121. } UA_ClientConfig;
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. #endif /* UA_CLIENT_CONFIG_H */