store.c
Go to the documentation of this file.
1 /*!**********************************************************************
2  *
3  * @copyright Copyright (C) 2016 Siemens Aktiengesellschaft.\n
4  * All rights reserved.
5  *
6  *************************************************************************
7  *
8  * @file store.c
9  * @date Jul 18, 2016
10  * @brief This file implements MCL Store Interface.
11  *
12  ************************************************************************/
13 
14 #include "store.h"
15 #include "time_series.h"
16 #include "custom_data.h"
17 #include "stream_data.h"
19 #include "event_list.h"
20 #include "file.h"
21 #include "log_util.h"
22 #include "memory.h"
23 #include "definitions.h"
24 #include "mcl/mcl_store.h"
25 #include "time_util.h"
26 
28 {
32 
33 typedef struct
34 {
35  char *type;
36  char *version;
38 
39 typedef enum E_EVENT_VERSION
40 {
45 
47 {
50 };
51 
53 {
54  {1, 2, 3},
55  {20, 30, 40}
56 };
57 
58 // custom list destroyer ( destroys based on the type of the item ) for destroying high and low priority lists.
59 void _store_list_destroy_callback(void **item);
60 
61 static E_MCL_ERROR_CODE _store_add_data(mcl_store_t *store, void *data, E_STORE_DATA_TYPE data_type, E_STORE_DATA_PRIORITY priority);
62 static E_MCL_ERROR_CODE _compare_item_meta_of_event(void *data, const item_meta_payload_local_t *item_meta_payload);
63 
64 // Checks version format.
65 static mcl_bool_t _is_valid_version(const char *version);
66 static mcl_bool_t _is_positive_integer(const char *version, mcl_size_t start_index, mcl_size_t end_index);
67 
69 {
70  DEBUG_ENTRY("mcl_bool_t streamable = <%u>, mcl_store_t **store = <%p>", streamable, store)
71 
72  E_MCL_ERROR_CODE code;
73 
74  ASSERT_NOT_NULL(store);
75 
76 #if !MCL_STREAM_ENABLED
77  ASSERT_CODE_MESSAGE(MCL_FALSE == streamable, MCL_OPERATION_IS_NOT_SUPPORTED, "Streamable store is not supported currently.");
78 #endif
79 
80  // Allocate store
81  MCL_NEW(*store);
82  ASSERT_CODE_MESSAGE(MCL_NULL != *store, MCL_OUT_OF_MEMORY, "Memory for store could not be allocated!");
83 
84  // Initialize lists containing mcl data types
85  code = list_initialize(&((*store)->high_priority_list));
86  code = (MCL_OK == code) ? list_initialize(&((*store)->low_priority_list)) : MCL_FAIL;
87  ASSERT_STATEMENT_CODE_MESSAGE(MCL_OK == code, mcl_store_destroy(store), MCL_FAIL, "Initialization of store lists failed!");
88 
89  // set streamable property :
90  (*store)->streamable = streamable;
91 
92  MCL_DEBUG("High and Low priority lists has been successfully initialized.");
93 
94  DEBUG_LEAVE("retVal = <%d>", MCL_OK);
95  return MCL_OK;
96 }
97 
98 E_MCL_ERROR_CODE mcl_store_new_time_series(mcl_store_t *store, const char *version, const char *configuration_id, const char *routing, mcl_time_series_t **time_series)
99 {
100  DEBUG_ENTRY("mcl_store_t *store = <%p>, const char *version = <%p>, const char *configuration_id = <%p>, const char *routing = <%p>, mcl_time_series_t **time_series = <%p>",
101  store, version, configuration_id, routing, time_series)
102 
103  E_MCL_ERROR_CODE code;
104 
105  ASSERT_NOT_NULL(store);
106  ASSERT_NOT_NULL(version);
107  ASSERT_NOT_NULL(configuration_id);
108  ASSERT_NOT_NULL(time_series);
109 
110  // Check version format.
111  ASSERT_CODE_MESSAGE(MCL_TRUE == _is_valid_version(version), MCL_INVALID_PARAMETER, "Version format is not correct.");
112 
113  // Initialize a new time series.
114  code = time_series_initialize(version, configuration_id, routing, time_series);
115  ASSERT_CODE_MESSAGE(MCL_OK == code, code, "Creation of new time_series store failed!");
116 
117  // Add new time_series to list, or if failed destroy it
118  code = _store_add_data(store, (void *)*time_series, STORE_DATA_TIME_SERIES, PRIORITY_HIGH);
119  ASSERT_STATEMENT_CODE_MESSAGE(MCL_OK == code, time_series_destroy(time_series), code, "Adding time_series to list failed!");
120 
121  DEBUG_LEAVE("retVal = <%d>", code);
122  return code;
123 }
124 
125 E_MCL_ERROR_CODE mcl_store_new_event(mcl_store_t *store, const char *version, const char *type, const char *type_version, E_MCL_EVENT_SEVERITY severity, const char *timestamp, mcl_event_t **event)
126 {
127  DEBUG_ENTRY("mcl_store_t *store = <%p>, const char *version = <%p>, const char *type = <%p>, const char *type_version = <%p>, E_MCL_EVENT_SEVERITY severity = <%d>, const char *timestamp = <%p>, mcl_event_t **event = <%p>", store, version, type, type_version, severity, timestamp, event)
128 
129  E_MCL_ERROR_CODE code;
130  E_MCL_ERROR_CODE event_list_exists;
131  item_meta_payload_local_t item_meta_payload_local;
132  event_list_t *event_list = MCL_NULL;
133  mcl_size_t index;
134  store_data_t *store_data;
135 
136  ASSERT_NOT_NULL(store);
137  ASSERT_NOT_NULL(version);
138  ASSERT_NOT_NULL(type);
139  ASSERT_NOT_NULL(type_version);
140  ASSERT_NOT_NULL(timestamp);
141  ASSERT_NOT_NULL(event);
142  ASSERT_CODE_MESSAGE(severity >= MCL_EVENT_SEVERITY_ERROR && severity < MCL_EVENT_SEVERITY_END, MCL_INVALID_PARAMETER, "Invalid severity.");
143 
144  // Check version.
145  for (index = 0; index < (mcl_size_t)EVENT_VERSION_END; index++)
146  {
147  if (MCL_OK == string_compare_with_cstr(&_event_versions[(E_EVENT_VERSION)index], version))
148  {
149  break;
150  }
151  }
152 
153  ASSERT_CODE_MESSAGE(EVENT_VERSION_END != index, MCL_INVALID_PARAMETER, "Version is not correct.");
154 
155  // Validate timestamp.
156  ASSERT_CODE_MESSAGE(MCL_TRUE == time_util_validate_timestamp(timestamp), MCL_INVALID_PARAMETER, "Timestamp format is not correct.");
157 
158  // Set event type.
160 
161  // Set event version.
162  item_meta_payload_local.version = (char *)version;
163 
164  // Check if the necessary event set exists.
165  event_list_exists = list_exist(store->high_priority_list, (const void *)(&item_meta_payload_local), (list_compare_callback)_compare_item_meta_of_event,
166  (void **)(&store_data));
167 
168  // If the event set does not exist, initialize the event and add to store.
169  if (MCL_FAIL == event_list_exists)
170  {
171  // event set initialize
172  code = event_list_initialize(version, &event_list);
173  ASSERT_CODE_MESSAGE(MCL_OK == code, code, "Creation of new event set failed!");
174 
175  // Add a new event set to store list.
176  code = _store_add_data(store, (void *)event_list, STORE_DATA_EVENT_LIST, PRIORITY_HIGH);
177  ASSERT_STATEMENT_CODE_MESSAGE(MCL_OK == code, event_list_destroy(&event_list), code, "Adding event set to store list failed!");
178  }
179  else
180  {
181  event_list = store_data->data;
182  }
183 
184  // Initialize a new event.
185  code = event_initialize(event_list->meta, type, type_version, _event_severity_values[index][severity], timestamp, event);
186  ASSERT_CODE_MESSAGE(MCL_OK == code, code, "Creation of new event store failed!");
187 
188  // add event to event set
189  code = event_list_add_event(*event, event_list);
190  ASSERT_STATEMENT_CODE_MESSAGE(MCL_OK == code, event_destroy(event), code, "Creation of new event store failed!");
191 
192  DEBUG_LEAVE("retVal = <%d>", MCL_OK);
193  return MCL_OK;
194 }
195 
196 E_MCL_ERROR_CODE mcl_store_new_file(mcl_store_t *store, const char *version, const char *file_path, const char *file_name, const char *file_type, const char *routing, mcl_file_t **file)
197 {
198  DEBUG_ENTRY("mcl_store_t *store = <%p>, const char *version = <%p>, const char *file_path = <%p>, const char *file_name = <%p>, const char *file_type = <%p>, const char *routing = <%p>, mcl_file_t **file = <%p>", store, version, file_path, file_name, file_type, routing, file)
199 
200 #if MCL_FILE_EXCHANGE_ENABLED
201 
202  E_MCL_ERROR_CODE code;
203 
204  ASSERT_NOT_NULL(store);
205  ASSERT_NOT_NULL(version);
206  ASSERT_NOT_NULL(file_path);
207  ASSERT_NOT_NULL(file);
208  ASSERT_NOT_NULL(file_name);
209 
210  // Check version format.
211  ASSERT_CODE_MESSAGE(MCL_TRUE == _is_valid_version(version), MCL_INVALID_PARAMETER, "Version format is not correct.");
212 
213  // Initialize a file item.
214  code = file_initialize(version, file_path, file_name, file_type, routing, file);
215  ASSERT_CODE_MESSAGE(MCL_OK == code, code, "Creation of a new file item failed!");
216 
217  // Add new file item to store.
218  code = _store_add_data(store, (void *)*file, STORE_DATA_FILE, PRIORITY_HIGH);
219  ASSERT_STATEMENT_CODE_MESSAGE(MCL_OK == code, file_destroy(file), code, "Adding file item to store failed!");
220 
221  DEBUG_LEAVE("retVal = <%d>", MCL_OK);
222  return MCL_OK;
223 #else
224  MCL_ERROR("File exchange feature is not enabled.");
225  DEBUG_LEAVE("retVal = <%d>", MCL_FAIL);
226  return MCL_FAIL;
227 #endif
228 }
229 
230 E_MCL_ERROR_CODE mcl_store_new_custom_data(mcl_store_t *store, const char *version, const char *type, const char *routing, mcl_custom_data_t **custom_data)
231 {
232  DEBUG_ENTRY("mcl_store_t *store = <%p>, const char *version = <%p>, const char *type = <%p>, const char *routing = <%p>, mcl_custom_data_t **custom_data = <%p>", store,
233  version, type, routing, custom_data)
234 
235  E_MCL_ERROR_CODE code;
236 
237  ASSERT_NOT_NULL(store);
238  ASSERT_NOT_NULL(custom_data);
239  ASSERT_NOT_NULL(version);
240  ASSERT_NOT_NULL(type);
241 
242  // Initialize a new custom data
243  code = custom_data_initialize(version, type, routing, custom_data);
244  ASSERT_CODE_MESSAGE(MCL_OK == code, code, "Creation of new custom data store failed!");
245 
246  // Add new custom data to list, or if failed destroy it
247  // TODO : Currently adding only to the high priority list
248  code = _store_add_data(store, (void *)*custom_data, STORE_DATA_CUSTOM, PRIORITY_HIGH);
249  ASSERT_STATEMENT_CODE_MESSAGE(MCL_OK == code, custom_data_destroy(custom_data), code, "Adding custom data to list failed!");
250 
251  DEBUG_LEAVE("retVal = <%d>", code);
252  return code;
253 }
254 
255 E_MCL_ERROR_CODE mcl_store_new_stream_data(mcl_store_t *store, const char *version, const char *type, const char *routing,
256  mcl_stream_data_read_callback_t stream_data_read_callback, void *user_context, mcl_stream_data_t **stream_data)
257 {
258  DEBUG_ENTRY("mcl_store_t *store = <%p>, const char *version = <%p>, const char *type = <%p>, const char *routing = <%p>, stream_data_read_callback_t stream_data_read_callback = <%p>, void *user_context = <%p>, mcl_stream_data_t **stream_data = <%p>",
259  store, version, type, routing, stream_data_read_callback, user_context, stream_data)
260 
261  E_MCL_ERROR_CODE code;
262 
263  ASSERT_NOT_NULL(store);
264  ASSERT_CODE_MESSAGE(MCL_TRUE == store->streamable, MCL_INVALID_PARAMETER, "Store must be streamable to add this type of item!");
265  ASSERT_NOT_NULL(stream_data);
266  ASSERT_NOT_NULL(version);
267  ASSERT_NOT_NULL(type);
268  ASSERT_NOT_NULL(stream_data_read_callback);
269 
270  // Check version format.
271  ASSERT_CODE_MESSAGE(MCL_TRUE == _is_valid_version(version), MCL_INVALID_PARAMETER, "Version format is not correct.");
272 
273  // Initialize a new stream data
274  code = stream_data_initialize(version, type, routing, stream_data_read_callback, user_context, stream_data);
275  ASSERT_CODE_MESSAGE(MCL_OK == code, code, "Creation of new stream data store failed!");
276 
277  // Add new stream data to list, or if failed destroy it
278  // TODO : Currently adding only to the high priority list
279  code = _store_add_data(store, (void *)*stream_data, STORE_DATA_STREAM, PRIORITY_HIGH);
280  ASSERT_STATEMENT_CODE_MESSAGE(MCL_OK == code, stream_data_destroy(stream_data), code, "Adding stream data to list failed!");
281 
282  DEBUG_LEAVE("retVal = <%d>", code);
283  return code;
284 }
285 
287 {
288  DEBUG_ENTRY("mcl_store_t *store = <%p>, const char *version = <%p>, mcl_data_source_configuration_t **data_source_configuration = <%p>", store, version, data_source_configuration)
289 
290  E_MCL_ERROR_CODE code;
291 
292  ASSERT_NOT_NULL(store);
293  ASSERT_NOT_NULL(version);
294  ASSERT_NOT_NULL(data_source_configuration);
295 
296  // Check version format.
297  ASSERT_CODE_MESSAGE(MCL_TRUE == _is_valid_version(version), MCL_INVALID_PARAMETER, "Version format is not correct.");
298 
299  // Initialize a new data_source_configuration
300  code = data_source_configuration_initialize(version, data_source_configuration);
301  ASSERT_CODE_MESSAGE(MCL_OK == code, code, "Creation of new data source configuration failed!");
302 
303  // Add new data_source_configuration to list, or if failed destroy it
304  // TODO : Currently adding only to the high priority list
305  code = _store_add_data(store, (void *)*data_source_configuration, STORE_DATA_DATA_SOURCE_CONFIGURATION, PRIORITY_HIGH);
306  ASSERT_STATEMENT_CODE_MESSAGE(MCL_OK == code, data_source_configuration_destroy(data_source_configuration), code, "Adding data source configuration to list failed!");
307 
308  DEBUG_LEAVE("retVal = <%d>", code);
309  return code;
310 }
311 
313 {
314  DEBUG_ENTRY("mcl_store_t **store = <%p>", store)
315 
316  // Make sure input argument is not NULL.
317  ASSERT_NOT_NULL(store);
318 
319  if (MCL_NULL != *store)
320  {
321  list_destroy_with_content(&(*store)->high_priority_list, _store_list_destroy_callback);
322  list_destroy_with_content(&(*store)->low_priority_list, _store_list_destroy_callback);
323  MCL_FREE(*store);
324  }
325  else
326  {
327  MCL_DEBUG("Store is already NULL. Nothing will be destroyed.");
328  }
329 
330  DEBUG_LEAVE("retVal = <%d>", MCL_OK);
331  return MCL_OK;
332 }
333 
335 {
336  DEBUG_ENTRY("store_data_t *store_data = <%p>, E_STORE_DATA_STATE state = <%d>", store_data, state)
337 
338  MCL_DEBUG("Updating state : %d --> %d", store_data->state, state);
339  store_data->state = state;
340 
341  DEBUG_LEAVE("retVal = <void>");
342  return;
343 }
344 
346 {
347  DEBUG_ENTRY("store_data_t *store_data = <%p>", store_data)
348 
349  MCL_DEBUG("Current state is <%d>", store_data->state);
350 
351  DEBUG_LEAVE("retVal = <%d>", store_data->state);
352  return store_data->state;
353 }
354 
355 E_MCL_ERROR_CODE store_data_remove(list_t *store_list, list_node_t *store_data_node)
356 {
357  DEBUG_ENTRY("list_t *store_list = <%p>, list_node_t *store_data_node = <%p>", store_list, store_data_node)
358 
359  // first remove the item from the list :
360  E_MCL_ERROR_CODE result = list_remove_with_content(store_list, store_data_node, _store_list_destroy_callback);
361 
362  DEBUG_LEAVE("retVal = <%d>", result);
363  return result;
364 }
365 
367 {
368  DEBUG_ENTRY("store_t *store = <%p>", store)
369 
370  DEBUG_LEAVE("retVal = <%u>", store->high_priority_list->count + store->low_priority_list->count);
371  return store->high_priority_list->count + store->low_priority_list->count;
372 }
373 
374 // Private Functions:
376 {
377  DEBUG_ENTRY("mcl_store_t *store = <%p>, void *data = <%p>, E_STORE_DATA_TYPE data_type = <%d>, E_STORE_DATA_PRIORITY priority = <%d>", store, data, data_type, priority)
378 
379  E_MCL_ERROR_CODE code;
380  store_data_t *store_data;
381  list_t *list_to_add;
382 
383  MCL_NEW(store_data);
384  ASSERT_CODE_MESSAGE(MCL_NULL != store_data, MCL_OUT_OF_MEMORY, "Not enough memory to create store_data!");
385 
386  store_data->data = data;
387  store_data->type = data_type;
388  store_data->meta = MCL_NULL;
389  store_data->payload_buffer = MCL_NULL;
390  store_data->payload_size = 0;
391  store_data->stream_info = MCL_NULL;
392  store_data->state = DATA_STATE_INITIAL;
393 
394  list_to_add = (PRIORITY_HIGH == priority) ? store->high_priority_list : store->low_priority_list;
395 
396  code = list_add(list_to_add, store_data);
397  ASSERT_STATEMENT_CODE_MESSAGE(MCL_OK == code, MCL_FREE(store_data), code, "Add to list failed!");
398 
399  DEBUG_LEAVE("retVal = <%d>", MCL_OK);
400  return MCL_OK;
401 }
402 
404 {
405  DEBUG_ENTRY("void **item = <%p>", item)
406 
407  // common destroy :
408  store_data_t *store_data = (store_data_t *)*item;
409 
410  // destroy meta string :
411  string_destroy(&store_data->meta);
412 
413  // destroy payload string ( only if it is not file or custom or stream. payload for those is just a pointer to their payload and it will be freed by them ):
414  if ((MCL_NULL != store_data->payload_buffer)
415  && ((STORE_DATA_FILE != store_data->type) && (STORE_DATA_CUSTOM != store_data->type) && (STORE_DATA_STREAM != store_data->type)))
416  {
417  MCL_FREE(store_data->payload_buffer);
418  }
419 
420  // type based data destroy :
421  if (STORE_DATA_TIME_SERIES == store_data->type)
422  {
423  MCL_DEBUG("Item type is time_series, calling its destroy function.");
424  time_series_destroy((time_series_t **)&(store_data->data));
425  }
426  else if (STORE_DATA_EVENT_LIST == store_data->type)
427  {
428  MCL_DEBUG("Item type is event, calling its destroy function.");
429  event_list_destroy((event_list_t **)&(store_data->data));
430  }
431  else if (STORE_DATA_FILE == store_data->type)
432  {
433  MCL_DEBUG("Item type is file, calling its destroy function.");
434  file_destroy((file_t **)&(store_data->data));
435  }
436  else if (STORE_DATA_CUSTOM == store_data->type)
437  {
438  MCL_DEBUG("Item type is custom data, calling its destroy function.");
439  custom_data_destroy((custom_data_t **)&(store_data->data));
440  }
441  else if (STORE_DATA_STREAM == store_data->type)
442  {
443  MCL_DEBUG("Item type is stream data, calling its destroy function.");
444  stream_data_destroy((stream_data_t **)&(store_data->data));
445  }
446  else if (STORE_DATA_DATA_SOURCE_CONFIGURATION == store_data->type)
447  {
448  MCL_DEBUG("Item type is data source configuration, calling its destroy function.");
450  }
451  else
452  {
453  MCL_FATAL("Received type of store list item is unknown!");
454  }
455 
456  // clean up stream info :
457  if (MCL_NULL != store_data->stream_info)
458  {
460  MCL_FREE(store_data->stream_info);
461  }
462 
463  MCL_FREE(store_data);
464 
465  DEBUG_LEAVE("retVal = void");
466 }
467 
468 static E_MCL_ERROR_CODE _compare_item_meta_of_event(void *data, const item_meta_payload_local_t *item_meta_payload)
469 {
470  DEBUG_ENTRY("void *data = <%p>, const item_meta_payload_local_t *item_meta_payload = <%p>", data, item_meta_payload)
471 
472  store_data_t *store_data = data;
473 
474  if (STORE_DATA_EVENT_LIST == store_data->type)
475  {
476  event_list_t *event_list = store_data->data;
477 
478  if ((MCL_OK == string_compare_with_cstr(event_list->meta->payload.type, item_meta_payload->type))
479  && (MCL_OK == string_compare_with_cstr(event_list->meta->payload.version, item_meta_payload->version)))
480  {
481  MCL_DEBUG("There is an event set already created with the same type and version in the list.");
482  DEBUG_LEAVE("retVal = <%d>", MCL_OK);
483  return MCL_OK;
484  }
485  }
486 
487  DEBUG_LEAVE("retVal = <%d>", MCL_FAIL);
488  return MCL_FAIL;
489 }
490 
491 static mcl_bool_t _is_valid_version(const char *version)
492 {
493  DEBUG_ENTRY("const char *version = <%p>", version)
494 
495  mcl_bool_t ok;
496  mcl_size_t dot_index = 0;
497  mcl_size_t version_length = string_util_strlen(version);
498 
499  // Search dot.
500  ok = string_util_find(version, ".", &dot_index);
501 
502  // Make sure there is major version and minor version strings.
503  ok = ok && (dot_index > 0 && dot_index < version_length - 1);
504 
505  // Make sure major version is a positive integer.
506  ok = ok && _is_positive_integer(version, 0, dot_index);
507 
508  // Make sure minor version is a positive integer.
509  ok = ok && _is_positive_integer(version, dot_index + 1, version_length);
510 
511  DEBUG_LEAVE("retVal = <%d>", ok);
512  return ok;
513 }
514 
515 static mcl_bool_t _is_positive_integer(const char *version, mcl_size_t start_index, mcl_size_t end_index)
516 {
517  DEBUG_ENTRY("const char *version = <%p>, mcl_size_t start_index = <%u>, mcl_size_t end_index = <%u>", version, start_index, end_index)
518 
519  mcl_size_t index;
520  mcl_bool_t status = MCL_TRUE;
521 
522  for (index = start_index; index < end_index; index++)
523  {
524  if (version[index] < '0' || version[index] > '9')
525  {
526  status = MCL_FALSE;
527  }
528  }
529 
530  DEBUG_LEAVE("retVal = <%d>", status);
531  return status;
532 }
#define MCL_FATAL(...)
Definition: log_util.h:102
store_data_stream_info_t * stream_info
Stream information.
Definition: store.h:71
static mcl_int32_t _event_severity_values[EVENT_VERSION_END][MCL_EVENT_SEVERITY_END]
Definition: store.c:52
void string_destroy(string_t **string)
Destroys the allocated resources of the string.
Definition: string_type.c:326
Data source configuration module header file.
void data_source_configuration_destroy(data_source_configuration_t **data_source_configuration)
E_MCL_ERROR_CODE event_list_add_event(event_t *event, event_list_t *event_list)
This function adds event to event_list.
Definition: event_list.c:60
string_t * version
Version of payload.
Definition: data_types.h:77
Internal failure in MCL.
Definition: mcl_common.h:141
string_t * type
Type of payload.
Definition: data_types.h:76
static E_MCL_ERROR_CODE _compare_item_meta_of_event(void *data, const item_meta_payload_local_t *item_meta_payload)
Definition: store.c:468
Memory module header file.
E_MCL_ERROR_CODE mcl_store_new_event(mcl_store_t *store, const char *version, const char *type, const char *type_version, E_MCL_EVENT_SEVERITY severity, const char *timestamp, mcl_event_t **event)
Definition: store.c:125
list_t * high_priority_list
Contains high priority store_data_t data.
Definition: store.h:81
void file_destroy(file_t **file)
Definition: file.c:163
struct mcl_data_source_configuration_t mcl_data_source_configuration_t
#define DEBUG_LEAVE(...)
Definition: log_util.h:81
Type of the data in the store is time series.
Definition: store.h:23
#define DEBUG_ENTRY(...)
Definition: log_util.h:80
static const string_t _event_versions[EVENT_VERSION_END]
Definition: store.c:46
Type of the data in the store is stream.
Definition: store.h:27
#define MCL_NEW(p)
Definition: memory.h:121
E_MCL_ERROR_CODE mcl_store_new_time_series(mcl_store_t *store, const char *version, const char *configuration_id, const char *routing, mcl_time_series_t **time_series)
Definition: store.c:98
Represents the low priority data to be sent to MindSphere.
Definition: store.c:30
If a particular operation is not supported.
Definition: mcl_common.h:148
mcl_size_t(* mcl_stream_data_read_callback_t)(void *destination, void *source, mcl_size_t size, void *user_context)
Stream data read callback function definition.
#define MCL_TRUE
Definition: mcl_common.h:54
char * buffer
Buffer of string handle.
Definition: string_type.h:45
Severity level of event is ERROR.
Definition: mcl_common.h:116
Business event type of meta field payload.
Definition: data_types.h:287
This struct is used for building the complete message of time series event.
Definition: time_series.h:22
mcl_bool_t string_util_find(const char *source, const char *target, mcl_size_t *start_index)
Finds the first occurence of target in source and puts it&#39;s first index to start_index.
Definition: string_util.c:156
Type of the data in the store is data source configuration.
Definition: store.h:28
list_t * low_priority_list
Contains low priority store_data_t data.
Definition: store.h:83
Store module header file.
Initial state of a store data. Means this data is not processed before.
Definition: store.h:36
E_MCL_ERROR_CODE custom_data_initialize(const char *version, const char *type, const char *routing, custom_data_t **custom_data)
Initializes custom_data.
Definition: custom_data.c:24
E_MCL_ERROR_CODE list_exist(list_t *list, const void *item_to_find, list_compare_callback compare_function, void **item)
Searches item_to_find in the list.
Definition: list.c:346
#define MCL_DEBUG(...)
Definition: log_util.h:70
mcl_list_compare_callback list_compare_callback
Definition: list.h:23
#define ASSERT_NOT_NULL(argument)
Definition: definitions.h:129
#define MCL_FALSE
MCL bool type.
Definition: mcl_common.h:53
E_MCL_ERROR_CODE file_initialize(const char *version, const char *file_path, const char *file_name, const char *file_type, const char *routing, file_t **file)
Definition: file.c:22
File module header file.
E_MCL_ERROR_CODE string_compare_with_cstr(const string_t *string, const char *other)
Compare the contents of string_t with a C string.
Definition: string_type.c:139
struct mcl_event_t mcl_event_t
This struct is used for building only one message of event.
Definition: mcl_event.h:27
Log utility module header file.
E_MCL_ERROR_CODE list_initialize(list_t **list)
Initializes the list.
Definition: list.c:139
static mcl_bool_t _is_valid_version(const char *version)
Definition: store.c:491
E_MCL_ERROR_CODE
MCL Error code definitions. Every function returning an error code uses this enum values...
Definition: mcl_common.h:137
Type of the data in the store is custom data.
Definition: store.h:26
struct mcl_time_series_t mcl_time_series_t
This struct is used for building the time series type.
Type of the data in the store is file.
Definition: store.h:25
struct mcl_custom_data_t mcl_custom_data_t
This struct is used for building the custom data type.
#define MCL_FREE(p)
Definition: memory.h:125
E_STORE_DATA_TYPE type
Type of data in the store.
Definition: store.h:66
void time_series_destroy(time_series_t **time_series)
To destroy the time_series_t data struct.
Definition: time_series.c:123
void store_data_set_state(store_data_t *store_data, E_STORE_DATA_STATE state)
Definition: store.c:334
item_meta_payload_t payload
Information describing the payload part following this meta or a collection of tuples referencing it...
Definition: data_types.h:91
struct mcl_store_t mcl_store_t
Definition: mcl_store.h:34
#define ASSERT_STATEMENT_CODE_MESSAGE(condition, statement, return_code,...)
Definition: definitions.h:121
Definition: store.h:77
E_MCL_ERROR_CODE event_initialize(item_meta_t *meta, const char *type, const char *version, mcl_int32_t severity, const char *timestamp, event_t **event)
This function creates and initializes a data struct of event_t.
Definition: event.c:23
Type of the data in the store is event list.
Definition: store.h:24
This struct is used for building the complete message of file.
Definition: file.h:24
E_MCL_ERROR_CODE mcl_store_new_data_source_configuration(mcl_store_t *store, const char *version, mcl_data_source_configuration_t **data_source_configuration)
Definition: store.c:286
General invalid parameter fail.
Definition: mcl_common.h:144
item_meta_t * meta
Meta of event list.
Definition: event_list.h:27
Stream data module header file.
mcl_uint8_t * payload_buffer
Payload of the store.
Definition: store.h:69
string_t * meta
Meta of the store as json string.
Definition: store.h:68
E_MCL_ERROR_CODE mcl_store_initialize(mcl_bool_t streamable, mcl_store_t **store)
Definition: store.c:68
void event_destroy(event_t **event)
To destroy the event_t data struct.
Definition: event.c:108
char * version
Version of payload.
Definition: store.c:36
#define ASSERT_CODE_MESSAGE(condition, return_code,...)
Definition: definitions.h:105
Definitions module header file.
E_STORE_DATA_PRIORITY
Definition: store.c:27
E_MCL_ERROR_CODE list_remove_with_content(list_t *list, list_node_t *node, list_item_destroy_callback callback)
Removes a node from the list and destroys the removed item with the provided callback function...
Definition: list.c:195
This struct is used for building the event.
Definition: event_list.h:25
mcl_bool_t time_util_validate_timestamp(const char *timestamp)
Definition: time_util.c:71
void stream_data_destroy(stream_data_t **stream_data)
Destroys stream_data.
Definition: stream_data.c:57
E_MCL_ERROR_CODE mcl_store_new_custom_data(mcl_store_t *store, const char *version, const char *type, const char *routing, mcl_custom_data_t **custom_data)
Definition: store.c:230
Time series module header file.
struct mcl_stream_data_t mcl_stream_data_t
This struct is used for building the stream data type.
void event_list_destroy(event_list_t **event_list)
To destroy the event_list data struct.
Definition: event_list.c:98
This struct is used for building the custom data type.
Definition: custom_data.h:24
E_STORE_DATA_TYPE
Definition: store.h:21
This struct is used for building the complete message of stream data.
Definition: stream_data.h:26
E_STORE_DATA_STATE store_data_get_state(store_data_t *store_data)
Definition: store.c:345
mcl_size_t store_get_data_count(store_t *store)
Definition: store.c:366
string_t meta_field_values[META_FIELD_VALUES_END]
Definition: data_types.c:36
size_t mcl_size_t
Definition: mcl_common.h:38
void _store_list_destroy_callback(void **item)
Definition: store.c:403
mcl_uint8_t mcl_bool_t
Definition: mcl_common.h:47
Success.
Definition: mcl_common.h:140
Represents the high priority data to be sent to MindSphere.
Definition: store.c:29
static E_MCL_ERROR_CODE _store_add_data(mcl_store_t *store, void *data, E_STORE_DATA_TYPE data_type, E_STORE_DATA_PRIORITY priority)
Definition: store.c:375
static mcl_bool_t _is_positive_integer(const char *version, mcl_size_t start_index, mcl_size_t end_index)
Definition: store.c:515
Custom data module header file.
char * type
Type of payload.
Definition: store.c:35
void list_destroy_with_content(list_t **list, list_item_destroy_callback callback)
To destroy the list and its items with a given callback function.
Definition: list.c:373
E_EVENT_VERSION
Definition: store.c:39
#define MCL_ERROR(...)
Definition: log_util.h:97
Store module interface header file.
E_MCL_ERROR_CODE data_source_configuration_initialize(const char *version, data_source_configuration_t **data_source_configuration)
void * data
Data to be added to the store.
Definition: store.h:65
void custom_data_destroy(custom_data_t **custom_data)
Destroys custom_data.
Definition: custom_data.c:72
mcl_size_t count
Node count of the list.
Definition: mcl_list.h:45
E_MCL_ERROR_CODE mcl_store_destroy(mcl_store_t **store)
Definition: store.c:312
E_MCL_ERROR_CODE mcl_store_new_file(mcl_store_t *store, const char *version, const char *file_path, const char *file_name, const char *file_type, const char *routing, mcl_file_t **file)
Definition: store.c:196
E_STORE_DATA_STATE state
State of data in the store.
Definition: store.h:67
E_MCL_ERROR_CODE list_add(list_t *list, void *data)
Adds a new list item.
Definition: list.c:159
Event list module header file.
Memory allocation fail.
Definition: mcl_common.h:143
E_MCL_ERROR_CODE time_series_initialize(const char *version, const char *configuration_id, const char *routing, time_series_t **time_series)
This function creates and initializes a data struct of time_series_t.
Definition: time_series.c:26
string_t * tuple_subboundary
Subboundary of tuple.
Definition: store.h:47
struct mcl_file_t mcl_file_t
This struct is used for building the complete message of file.
Definition: mcl_store.h:39
#define MCL_NULL
Definition: definitions.h:24
E_MCL_EVENT_SEVERITY
Severity values for events.
Definition: mcl_common.h:114
E_MCL_ERROR_CODE store_data_remove(list_t *store_list, list_node_t *store_data_node)
Definition: store.c:355
E_MCL_ERROR_CODE mcl_store_new_stream_data(mcl_store_t *store, const char *version, const char *type, const char *routing, mcl_stream_data_read_callback_t stream_data_read_callback, void *user_context, mcl_stream_data_t **stream_data)
Definition: store.c:255
int32_t mcl_int32_t
Definition: mcl_common.h:41
E_MCL_ERROR_CODE stream_data_initialize(const char *version, const char *type, const char *routing, mcl_stream_data_read_callback_t stream_data_read_callback, void *user_context, stream_data_t **stream_data)
Initializes stream_data.
Definition: stream_data.c:21
mcl_size_t string_util_strlen(const char *buffer)
Standard library strlen wrapper.
Definition: string_util.c:24
E_STORE_DATA_STATE
Definition: store.h:34
Time utility module header file.
E_MCL_ERROR_CODE event_list_initialize(const char *version, event_list_t **event_list)
This function creates and initializes a data struct of event_list.
Definition: event_list.c:23
mcl_size_t payload_size
Size of the payload in the store.
Definition: store.h:70
Strings with this type will NOT allocate its buffer during initialization (buffer only points of the ...
Definition: string_type.h:37