ua_client_config.h 5.0 KB

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