data_source_configuration.c
Go to the documentation of this file.
1 
11 #include "mcl_core/mcl_memory.h"
13 
14 // This array is used to get the data source configuration version.
16 
18  mcl_data_source_configuration_t **data_source_configuration)
19 {
20  mcl_error_t code;
21 
22  MCL_DEBUG_ENTRY("E_MCL_DATA_SOURCE_CONFIGURATION_VERSION version = <%d>, mcl_data_source_configuration_t **data_source_configuration = <%p>",
23  version, data_source_configuration);
24 
25  // Null check.
26  MCL_ASSERT_NOT_NULL(data_source_configuration, code);
27 
28  // Check data source configuration version parameter.
29  MCL_ASSERT_CODE_MESSAGE(MCL_DATA_SOURCE_CONFIGURATION_1_0 <= version && MCL_DATA_SOURCE_CONFIGURATION_END > version, MCL_INVALID_PARAMETER,
30  "Invalid data source configuration version parameter.");
31 
32  // Allocate memory for data source configuration.
33  if (MCL_NULL != MCL_NEW(*data_source_configuration))
34  {
35  // Set initial values.
36  (*data_source_configuration)->item_base.preamble = MCL_ITEM_PREAMBLE;
37  (*data_source_configuration)->item_base.version = (mcl_uint32_t)version;
38  (*data_source_configuration)->item_base.type = MCL_ITEM_TYPE_DATA_SOURCE_CONFIGURATION;
39 
40  // Allocate memory for payload of data source configuration.
41  MCL_NEW((*data_source_configuration)->payload);
42  }
43 
44  if ((MCL_NULL != (*data_source_configuration)) && (MCL_NULL != (*data_source_configuration)->payload))
45  {
46  // Set initial values.
47  (*data_source_configuration)->payload->configuration_id = MCL_NULL;
48 
49  // Initialize list for data sources.
50  code = mcl_list_initialize(&(*data_source_configuration)->payload->data_sources);
51  }
52  else
53  {
54  code = MCL_OUT_OF_MEMORY;
55  }
56 
57  // Error check.
58  if (MCL_OK != code)
59  {
60  mcl_data_source_configuration_destroy(data_source_configuration);
61  }
62 
64  MCL_DEBUG_LEAVE("retVal = <%d>", code);
65  return code;
66 }
67 
69  E_MCL_DATA_SOURCE_CONFIGURATION_PARAMETER parameter, const void *value)
70 {
71  mcl_error_t code;
72 
73  MCL_DEBUG_ENTRY("mcl_data_source_configuration_t *data_source_configuration = <%p>, "\
74  "E_MCL_DATA_SOURCE_CONFIGURATION_PARAMETER parameter = <%d>, const void *value = <%p>", data_source_configuration, parameter, value);
75 
76  // Null check.
77  MCL_ASSERT_NOT_NULL(data_source_configuration, code);
78  MCL_ASSERT_NOT_NULL(value, code);
79 
81  {
82  code = mcl_string_util_reset(value, &data_source_configuration->payload->configuration_id);
83  }
84  else
85  {
86  code = MCL_INVALID_PARAMETER;
87  }
88 
90  MCL_DEBUG_LEAVE("retVal = <%d>", code);
91  return code;
92 }
93 
95 {
96  mcl_error_t code;
97 
98  MCL_DEBUG_ENTRY("mcl_data_source_configuration_t *data_source_configuration = <%p>, mcl_data_source_t *data_source = <%p>",
99  data_source_configuration, data_source);
100 
101  // Null check.
102  MCL_ASSERT_NOT_NULL(data_source_configuration, code);
103  MCL_ASSERT_NOT_NULL(data_source, code);
104 
105  // Add data source to data source configuration.
106  code = mcl_list_add(data_source_configuration->payload->data_sources, data_source);
107 
109  MCL_DEBUG_LEAVE("retVal = <%d>", code);
110  return code;
111 }
112 
114 {
115  mcl_error_t code = MCL_OK;
116  mcl_list_t *data_sources = data_source_configuration->payload->data_sources;
117  mcl_size_t index;
118 
119  MCL_DEBUG_ENTRY("data_source_configuration_t *data_source_configuration = <%p>", data_source_configuration);
120 
121  // Check configuration id.
122  if (MCL_NULL == data_source_configuration->payload->configuration_id)
123  {
124  code = MCL_INVALID_PARAMETER;
125  MCL_ERROR_STRING("Configuration id is not set.");
126  }
127  else if (0 == data_sources->count)
128  {
129  code = MCL_INVALID_PARAMETER;
130  MCL_ERROR_STRING("Data source configuration has no data source.");
131  }
132  else
133  {
134  mcl_list_reset(data_sources);
135  }
136 
137  // Validate each data source.
138  for (index = 0; (index < data_sources->count) && (MCL_OK == code); ++index)
139  {
140  mcl_list_node_t *node = MCL_NULL;
141 
142  (void) mcl_list_next(data_sources, &node);
143 
144  if ((MCL_NULL == node) || (MCL_OK != data_source_validate((data_source_t *) (node->data))))
145  {
146  code = MCL_INVALID_PARAMETER;
147  MCL_ERROR_STRING("Data source is not valid.");
148  }
149  }
150 
151  MCL_DEBUG_LEAVE("retVal = <%d>", code);
152  return code;
153 }
154 
156 {
157  MCL_DEBUG_ENTRY("mcl_data_source_configuration_t **data_source_configuration = <%p>", data_source_configuration);
158 
159  // Destroys the data source configuration data structure.
160  if ((MCL_NULL != data_source_configuration) && (MCL_NULL != *data_source_configuration))
161  {
162  if (MCL_NULL != (*data_source_configuration)->payload)
163  {
164  // Destroy payload.
165  MCL_FREE((*data_source_configuration)->payload->configuration_id);
166  mcl_list_destroy_with_content(&(*data_source_configuration)->payload->data_sources, (mcl_list_item_destroy_callback)mcl_data_source_destroy);
167  MCL_FREE((*data_source_configuration)->payload);
168  }
169 
170  MCL_FREE(*data_source_configuration);
171  }
172 
173  MCL_DEBUG_LEAVE("retVal = void");
174 }
E_MCL_DATA_SOURCE_CONFIGURATION_PARAMETER
#define MCL_FUNCTION_LEAVE_LABEL
Data source configuration module header file.
size_t mcl_size_t
mcl_error_t mcl_data_source_configuration_add_data_source(mcl_data_source_configuration_t *data_source_configuration, mcl_data_source_t *data_source)
Item type data source configuration.
Definition: item.h:28
MCL_OK
struct mcl_data_source_configuration_t mcl_data_source_configuration_t
struct mcl_data_source_t mcl_data_source_t
MCL_CORE_EXPORT mcl_error_t mcl_string_util_reset(const void *value, char **target)
mcl_int32_t mcl_error_t
#define MCL_DEBUG_ENTRY(...)
mcl_error_t data_source_configuration_validate(data_source_configuration_t *data_source_configuration)
void(* mcl_list_item_destroy_callback)(void **item)
uint32_t mcl_uint32_t
Data source configuration module interface header file.
MCL_CORE_EXPORT mcl_error_t mcl_list_next(mcl_list_t *list, mcl_list_node_t **node)
#define MCL_ERROR_STRING(string)
Data source configuration ID parameter as char*.
#define MCL_ASSERT_CODE_MESSAGE(condition, return_code,...)
#define MCL_NEW(p)
#define MCL_NULL
const char * mcl_data_source_configuration_versions[MCL_DATA_SOURCE_CONFIGURATION_END]
MCL_CONNECTIVITY_EXPORT void mcl_data_source_destroy(mcl_data_source_t **data_source)
Definition: data_source.c:147
MCL_CORE_EXPORT mcl_error_t mcl_list_add(mcl_list_t *list, void *data)
#define MCL_FREE(p)
MCL_CORE_EXPORT void mcl_list_destroy_with_content(mcl_list_t **list, mcl_list_item_destroy_callback callback)
data_source_configuration_payload_t * payload
E_MCL_DATA_SOURCE_CONFIGURATION_VERSION
mcl_error_t mcl_data_source_configuration_initialize(E_MCL_DATA_SOURCE_CONFIGURATION_VERSION version, mcl_data_source_configuration_t **data_source_configuration)
#define MCL_ASSERT_NOT_NULL(argument, return_variable)
mcl_error_t data_source_validate(data_source_t *data_source)
Definition: data_source.c:105
void mcl_data_source_configuration_destroy(mcl_data_source_configuration_t **data_source_configuration)
MCL_CORE_EXPORT void mcl_list_reset(mcl_list_t *list)
#define MCL_ITEM_PREAMBLE
Definition: item.h:17
MCL_OUT_OF_MEMORY
MCL_CORE_EXPORT mcl_error_t mcl_list_initialize(mcl_list_t **list)
mcl_size_t count
mcl_list_t * data_sources
List of data sources definitions.
End of data source configuration version.
MCL_INVALID_PARAMETER
#define MCL_DEBUG_LEAVE(...)
char * configuration_id
Unique identifier of the configuration.
mcl_error_t mcl_data_source_configuration_set_parameter(mcl_data_source_configuration_t *data_source_configuration, E_MCL_DATA_SOURCE_CONFIGURATION_PARAMETER parameter, const void *value)