connectivity_configuration.c
Go to the documentation of this file.
1 
11 #include "mcl_core/mcl_memory.h"
13 
14 // Connectivity exchange api.
15 static const char _connectivity_exchange_uri[] = "/api/mindconnect/v3/exchange";
16 static const char _connectivity_mapping_url[] = "/api/mindconnect/v3/dataPointMappings";
17 
18 // This function sets core parameter of connectivity configuration.
20 
22 {
23  mcl_error_t code = MCL_OK;
24 
25  MCL_DEBUG_ENTRY("connectivity_configuration_t *configuration = <%p>", configuration);
26 
27  // Null check.
28  MCL_ASSERT_NOT_NULL(configuration, code);
29 
30  MCL_NEW(*configuration);
31 
32  if (MCL_NULL == *configuration)
33  {
34  code = MCL_OUT_OF_MEMORY;
35  }
36  else
37  {
38  // Initialize connectivity configuration.
39  (*configuration)->core = MCL_NULL;
40  (*configuration)->exchange_url = MCL_NULL;
41  (*configuration)->mapping_url = MCL_NULL;
42  (*configuration)->max_http_payload_size = MCL_CONNECTIVITY_DEFAULT_MAX_HTTP_PAYLOAD_SIZE;
43  }
44 
46  MCL_DEBUG_LEAVE("retVal = <%d>", code);
47  return code;
48 }
49 
51  E_MCL_CONNECTIVITY_CONFIGURATION_PARAMETER parameter, const void *value)
52 {
53  mcl_error_t code = MCL_OK;
54 
55  MCL_DEBUG_ENTRY("mcl_connectivity_configuration_t *configuration = <%p>, E_MCL_CONNECTIVITY_CONFIGURATION_PARAMETER parameter = <%d>, "\
56  "const void *value = <%p>", configuration, parameter, value);
57 
58  MCL_ASSERT_NOT_NULL(configuration, code);
59  MCL_ASSERT_NOT_NULL(value, code);
60 
61  switch (parameter)
62  {
64  code = _set_connectivity_configuration_core_parameter(configuration, (mcl_core_t *) value);
65  break;
66 
68 
69  if ((MCL_CONNECTIVITY_MIN_HTTP_PAYLOAD_SIZE <= *((const mcl_size_t *) value)) &&
70  (MCL_CONNECTIVITY_MAX_HTTP_PAYLOAD_SIZE >= *((const mcl_size_t *) value)))
71  {
72  configuration->max_http_payload_size = *((const mcl_size_t *) value);
73  }
74  else
75  {
76  code = MCL_INVALID_PARAMETER;
77  }
78  break;
79 
80  default:
81  code = MCL_INVALID_PARAMETER;
82  break;
83  }
84 
86  MCL_DEBUG_LEAVE("retVal = <%d>", code);
87  return code;
88 }
89 
91 {
92  MCL_DEBUG_ENTRY("mcl_connectivity_configuration_t **configuration = <%p>", configuration);
93 
94  if ((MCL_NULL != configuration) && (MCL_NULL != *configuration))
95  {
96  MCL_FREE((*configuration)->exchange_url);
97  MCL_FREE((*configuration)->mapping_url);
98  MCL_FREE(*configuration);
99  }
100 
101  MCL_DEBUG_LEAVE("retVal = void");
102 }
103 
105 {
106  mcl_error_t code = MCL_OK;
107 
108  MCL_DEBUG_ENTRY("connectivity_configuration_t *configuration = <%p>", configuration);
109 
110  if (MCL_NULL == configuration->core)
111  {
112  code = MCL_INVALID_PARAMETER;
113  }
114 
115  MCL_DEBUG_LEAVE("retVal = <%d>", code);
116  return code;
117 }
118 
120 {
121  mcl_error_t code;
122  const char *hostname;
123 
124  MCL_DEBUG_ENTRY("mcl_connectivity_configuration_t *configuration = <%p>, mcl_core_t *core = <%p>", configuration, core);
125 
126  MCL_FREE(configuration->exchange_url);
127  MCL_FREE(configuration->mapping_url);
128 
129  // Get hostname.
130  hostname = mcl_core_get_host_name(core);
131 
132  if (MCL_NULL != hostname)
133  {
134  code = mcl_string_util_concatenate(hostname, _connectivity_exchange_uri, &(configuration->exchange_url));
135 
136  if (MCL_OK == code)
137  {
138  code = mcl_string_util_concatenate(hostname, _connectivity_mapping_url, &(configuration->mapping_url));
139 
140  if (MCL_OK != code)
141  {
142  MCL_FREE(configuration->exchange_url);
143  }
144  else
145  {
146  configuration->core = core;
147  }
148  }
149  }
150  else
151  {
152  code = MCL_INVALID_PARAMETER;
153  }
154 
155  MCL_DEBUG_LEAVE("retVal = <%d>", code);
156  return code;
157 }
#define MCL_FUNCTION_LEAVE_LABEL
size_t mcl_size_t
mcl_error_t mcl_connectivity_configuration_set_parameter(mcl_connectivity_configuration_t *configuration, E_MCL_CONNECTIVITY_CONFIGURATION_PARAMETER parameter, const void *value)
MCL_OK
mcl_int32_t mcl_error_t
E_MCL_CONNECTIVITY_CONFIGURATION_PARAMETER
#define MCL_DEBUG_ENTRY(...)
struct mcl_connectivity_configuration_t mcl_connectivity_configuration_t
MCL_CORE_EXPORT const char * mcl_core_get_host_name(mcl_core_t *core)
static const char _connectivity_mapping_url[]
#define MCL_CONNECTIVITY_DEFAULT_MAX_HTTP_PAYLOAD_SIZE
#define MCL_CONNECTIVITY_MIN_HTTP_PAYLOAD_SIZE
#define MCL_NEW(p)
mcl_error_t connectivity_configuration_validate(connectivity_configuration_t *configuration)
#define MCL_NULL
static const char _connectivity_exchange_uri[]
struct mcl_core_t mcl_core_t
MCL_CORE_EXPORT mcl_error_t mcl_string_util_concatenate(const char *string_1, const char *string_2, char **result)
#define MCL_FREE(p)
Connectivity configuration module header file.
mcl_error_t mcl_connectivity_configuration_initialize(mcl_connectivity_configuration_t **configuration)
#define MCL_ASSERT_NOT_NULL(argument, return_variable)
#define MCL_CONNECTIVITY_MAX_HTTP_PAYLOAD_SIZE
void mcl_connectivity_configuration_destroy(mcl_connectivity_configuration_t **configuration)
MCL_OUT_OF_MEMORY
MCL_INVALID_PARAMETER
#define MCL_DEBUG_LEAVE(...)
Connectivity configuration module header file.
static mcl_error_t _set_connectivity_configuration_core_parameter(mcl_connectivity_configuration_t *configuration, mcl_core_t *core)