json.c
Go to the documentation of this file.
1 
9 #include "json.h"
11 #include "mcl_core/mcl_memory.h"
13 #include "event.h"
15 #include "timeseries.h"
16 #include "file.h"
17 #include "custom_data.h"
19 
20 #define ITEM_TYPE "item"
21 #define ITEM_VERSION "1.0"
22 
23 #define DOUBLE_BRACE_SIZE 2
24 #define DELIMITER_SIZE 1
25 
26 // Definitions to calculate item size. It is better to make them all compile-time constants.
27 
28 // {"type":"ITEM_TYPE","version":"ITEM_VERSION","payload":<meta_payload_json>}
29 #define ITEM_META_BASE_SIZE (sizeof("{\"type\":\""ITEM_TYPE"\",\"version\":\""ITEM_VERSION"\",\"payload\":}") - MCL_NULL_CHAR_SIZE)
30 
31 // {"type":"standardTimeSeries","version":"1.0","details":{"configurationId":"<configuration_id>"}}
32 #define ITEM_TIMESERIES_META_PAYLOAD_BASE_SIZE \
33  (sizeof("{\"type\":\"standardTimeSeries\",\"version\":\"\",\"details\":{\"configurationId\":\"\"}}") - MCL_NULL_CHAR_SIZE)
34 
35 // {"dataPointId":"<data_point_id>","value":"<value>","qualityCode":"<quality_code>"}
36 #define ITEM_TIMESERIES_VALUE_BASE_SIZE (sizeof("{\"dataPointId\":\"\",\"value\":\"\",\"qualityCode\":\"\"}") - MCL_NULL_CHAR_SIZE)
37 
38 // {"timestamp":"<timestamp>","values":[<values>]}
39 #define ITEM_TIMESERIES_VALUE_LIST_BASE_SIZE (sizeof("{\"timestamp\":\"\",\"values\":[]}") + MCL_TIMESTAMP_LENGTH - 2 * MCL_NULL_CHAR_SIZE)
40 
41 // {"type":"businessEvent","version":"<version>"}
42 #define ITEM_EVENT_META_PAYLOAD_BASE_SIZE (sizeof("{\"type\":\"businessEvent\",\"version\":\"\"}") - MCL_NULL_CHAR_SIZE)
43 
44 // {"id":"<id>","timestamp":"<timestamp>","severity":<severity>,"type":"<type>","version":"<version>","details":<details_json>}
45 #define ITEM_EVENT_PAYLOAD_BASE_SIZE \
46  (sizeof("{\"id\":\"\",\"timestamp\":\"\",\"severity\":,\"type\":\"\",\"version\":\"\",\"details\":}") + MCL_TIMESTAMP_LENGTH - 2 * MCL_NULL_CHAR_SIZE)
47 
48 // Correlation ID is optional for event.
49 #define ITEM_EVENT_PAYLOAD_CORRELATION_ID_SIZE (sizeof(",\"correlationId\":\"\"") - MCL_NULL_CHAR_SIZE)
50 
51 // Description is optional for event.
52 #define ITEM_EVENT_PAYLOAD_DESCRIPTION_SIZE (sizeof(",\"description\":\"\"") - MCL_NULL_CHAR_SIZE)
53 
54 // {"type":"file","version":"1.0","details":{"fileName":"<fileName>","creationDate":"<creationDate>"}}
55 #define ITEM_FILE_META_PAYLOAD_BASE_SIZE \
56  (sizeof("{\"type\":\"file\",\"version\":\"\",\"details\":{\"fileName\":\"\",\"creationDate\":\"\"}}") + MCL_TIMESTAMP_LENGTH - 2 * MCL_NULL_CHAR_SIZE)
57 
58 // File type is optional for file meta payload.
59 #define ITEM_FILE_META_PAYLOAD_FILE_TYPE_SIZE (sizeof(",\"fileType\":\"\"") - MCL_NULL_CHAR_SIZE)
60 
61 // {"type":"<type>","version":"<version>"}
62 #define ITEM_CUSTOM_DATA_META_PAYLOAD_BASE_SIZE (sizeof("{\"type\":\"\",\"version\":\"\"}") - MCL_NULL_CHAR_SIZE)
63 
64 // Json object can be added for custom data as details.
65 #define ITEM_CUSTOM_DATA_META_PAYLOAD_DETAILS_SIZE (sizeof(",\"details\":") - MCL_NULL_CHAR_SIZE)
66 
67 // {\"type\":\"dataSourceConfiguration\",\"version\":\"<version>\"}
68 #define ITEM_DATA_SOURCE_CONFIGURATION_META_PAYLOAD_BASE_SIZE (sizeof("{\"type\":\"dataSourceConfiguration\",\"version\":\"\"}") - MCL_NULL_CHAR_SIZE)
69 
70 // {"configurationId":"<configurationId>","dataSources":[<dataSources>]}
71 #define ITEM_DATA_SOURCE_CONFIGURATION_PAYLOAD_BASE_SIZE (sizeof("{\"configurationId\":\"\",\"dataSources\":[]}") - MCL_NULL_CHAR_SIZE)
72 
73 // {"name":"<name>","description":"<description>","dataPoints":[<dataPoints>]}
74 #define ITEM_DATA_SOURCE_BASE_SIZE (sizeof("{\"name\":\"\",\"description\":\"\",\"dataPoints\":[]}") - MCL_NULL_CHAR_SIZE)
75 
76 // {"id":"<id>","name":"<name>","description":"<description>","type":"<type>","unit":"<unit>"}
77 #define ITEM_DATA_POINT_BASE_SIZE (sizeof("{\"id\":\"\",\"name\":\"\",\"description\":\"\",\"type\":\"\",\"unit\":\"\"}") - MCL_NULL_CHAR_SIZE)
78 
79 // Json object can be added to data source and data point as custom data.
80 #define ITEM_DATA_SOURCE_CONFIGURATION_PAYLOAD_CUSTOM_DATA_SIZE (sizeof(",\"customData\":") - MCL_NULL_CHAR_SIZE)
81 
86 typedef enum E_META_FIELD_NAMES
87 {
105 
112 {
119 
125 {
161 
166 {
167  "type",
168  "version",
169  "meta",
170  "payload",
171  "type",
172  "version",
173  "details",
174  "configurationId",
175  "details",
176  "fileName",
177  "fileType",
178  "creationDate",
179  "totalItems",
180  "timestamp",
181  "duration"
182 };
183 
188 {
189  "standardTimeSeries",
190  "businessEvent",
191  "file",
192  "dataSourceConfiguration"
193 };
194 
199 {
200  "timestamp",
201  "values",
202  "dataPointId",
203  "value",
204  "qualityCode",
205  "id",
206  "customEventId",
207  "correlationId",
208  "sourceType",
209  "sourceId",
210  "severity",
211  "description",
212  "status",
213  "type",
214  "version",
215  "customData",
216  "details",
217  "message",
218  "errorCode",
219  "details",
220  "value",
221  "download_link",
222  "name",
223  "version",
224  "description",
225  "configurationId",
226  "dataSources",
227  "name",
228  "dataPoints",
229  "id",
230  "name",
231  "type",
232  "unit"
233 };
234 
235 // Function pointer definition for _fill_array_using_list.
236 typedef mcl_error_t (*json_converter_callback)(void *any_struct, mcl_json_t **json);
237 
238 // Function pointer definition for _fill_list_using_json_array.
239 typedef mcl_error_t (*json_parser_callback)(mcl_json_t *json, void **any_struct);
240 
241 // Convert nodes in the list to json object via callback function and add them to the json array.
243 
244 // Fill list of structures using json array.
245 static mcl_error_t _fill_list_using_json_array(mcl_json_t *json_array, json_parser_callback parser_callback,
246  mcl_list_item_destroy_callback destroy_callback, mcl_list_t *list);
247 
248 // Add item meta payload to root json.
250 
251 // Add item meta payload details to the payload json.
253 
254 // Add item meta details to root json.
256 
257 // Convert event to json and add to event payload array.
258 static mcl_error_t _add_event_to_payload_array(event_t *event, mcl_json_t *event_payload_array);
259 
260 // Get json string (which is a json array containing one item) from event payload.
261 static mcl_error_t _json_from_event_payload(event_t *event, char **json_string);
262 
263 // Get json string from data source configuration payload.
264 static mcl_error_t _json_from_data_source_configuration_payload(data_source_configuration_t *data_source_configuration, char **json_string);
265 
266 // Get json string from timeseries payload.
267 static mcl_error_t _json_from_timeseries_payload(timeseries_t *timeseries, char **json_string);
268 
269 // Convert data point to json object.
270 static mcl_error_t _json_from_data_point(data_point_t *data_point, mcl_json_t **json);
271 
272 // Convert data source to json object.
273 static mcl_error_t _json_from_data_source(data_source_t *data_source, mcl_json_t **json);
274 
275 // Convert timeseries value to json object.
276 static mcl_error_t _json_from_timeseries_value(timeseries_value_t *timeseries_value, mcl_json_t **json);
277 
278 // Convert timeseries value list to json object.
280 
281 // Returns item meta size of an item.
283 
284 // Returns item meta size of a custom data.
285 static mcl_size_t _custom_data_meta_size(custom_data_t *custom_data);
286 
287 // Returns item payload size of a timeseries.
289 
290 // Returns item payload size of a timeseries value list.
292 
293 // Returns item payload size of a timeseries value.
295 
296 // Returns item payload size of an event.
298 
299 // Returns item payload size of a data source configuration.
301 
302 // Returns item payload size of a data source.
304 
305 // Returns item payload size of a data point.
307 
308 // Add item meta payload timeseries details.
310 
311 // Add item meta payload file details.
313 
314 // Parse and get string value.
315 static mcl_error_t _parse_and_get_string_value(mcl_json_t *json, const char *field_name, char **string);
316 
317 // Parse data point.
318 static mcl_error_t _parse_data_point(mcl_json_t *json, data_point_t **data_point);
319 
320 // Parse data source.
321 static mcl_error_t _parse_data_source(mcl_json_t *json, data_source_t **data_source);
322 
323 // Parse data source configuration.
325 
326 mcl_error_t json_from_item_meta(void *item, char **json_string)
327 {
328  mcl_error_t code;
329  mcl_json_t *root = MCL_NULL;
330  *json_string = MCL_NULL;
331 
332  MCL_DEBUG_ENTRY("void *item = <%p>, char **json_string = <%p>", item, json_string);
333 
335 
336  // Add item type.
337  if (MCL_OK == code)
338  {
340  }
341 
342  // Add item version.
343  if (MCL_OK == code)
344  {
346  }
347 
348  // Add details.
349  if (MCL_OK == code)
350  {
351  code = _add_item_meta_details((mcl_item_t *) item, root);
352  }
353 
354  if (MCL_OK == code)
355  {
356  code = _add_item_meta_payload((mcl_item_t *) item, root);
357  }
358 
359  if (MCL_OK == code)
360  {
361  code = mcl_json_util_to_string(root, json_string);
362  }
363 
364  mcl_json_util_destroy(&root);
365 
366  MCL_DEBUG_LEAVE("retVal = <%d>", code);
367  return code;
368 }
369 
370 mcl_error_t json_from_item_payload(void *item, char **json_string)
371 {
372  mcl_error_t code;
373 
374  MCL_DEBUG_ENTRY("void *item = <%p>, char **json_string = <%p>", item, json_string);
375 
376  switch (((mcl_item_t *) item)->type)
377  {
378  case MCL_ITEM_TYPE_EVENT:
379  code = _json_from_event_payload((event_t *) item, json_string);
380  break;
381 
384  break;
385 
387  code = _json_from_timeseries_payload((timeseries_t *) item, json_string);
388  break;
389 
390  default:
391  code = MCL_FAIL;
392  break;
393  }
394 
395  MCL_DEBUG_LEAVE("retVal = <%d>", code);
396  return code;
397 }
398 
399 static mcl_error_t _json_from_event_payload(event_t *event, char **json_string)
400 {
401  mcl_error_t code;
402  mcl_json_t *json_array = MCL_NULL;
403  *json_string = MCL_NULL;
404 
405  MCL_DEBUG_ENTRY("event_t *event = <%p>, char **json_string = <%p>", event, json_string);
406 
407  // Initialize a json array.
408  code = mcl_json_util_initialize(MCL_JSON_ARRAY, &json_array);
409 
410  // Add event payload to json array.
411  if (MCL_OK == code)
412  {
413  code = _add_event_to_payload_array(event, json_array);
414  }
415 
416  // Convert json array to string.
417  if (MCL_OK == code)
418  {
419  code = mcl_json_util_to_string(json_array, json_string);
420  }
421 
422  // Destroy json array.
423  mcl_json_util_destroy(&json_array);
424 
425  MCL_DEBUG_LEAVE("retVal = <%d>", code);
426  return code;
427 }
428 
430 {
431  mcl_size_t size;
432 
433  MCL_DEBUG_ENTRY("void *item = <%p>", item);
434 
435  size = _item_meta_size((mcl_item_t *) item);
436 
437  switch (((mcl_item_t *) item)->type)
438  {
441  break;
442 
443  case MCL_ITEM_TYPE_EVENT:
444  size += _item_payload_size_for_event((event_t *) item);
445  break;
446 
447  case MCL_ITEM_TYPE_FILE:
448  size += ((file_t *) item)->payload->size;
449  break;
450 
452  size += ((custom_data_t *) item)->payload->size;
453  break;
454 
457  break;
458 
459  default:
460  break;
461  }
462 
463  MCL_DEBUG_LEAVE("retVal = <%lu>", size);
464  return size;
465 }
466 
467 mcl_error_t json_parse_item(const char *json_string, mcl_size_t string_length, void **item)
468 {
469  mcl_error_t code;
470  mcl_json_t *json = MCL_NULL;
471 
472  MCL_DEBUG_ENTRY("const char *json_string = <%p>, mcl_size_t string_length = <%lu>, void **item = <%p>", json_string, (long unsigned) string_length, item);
473 
474  code = mcl_json_util_parse(json_string, string_length, &json);
475 
476  if (MCL_OK == code)
477  {
478  // Currently, only data source configuration is parsed.
480  }
481 
482  mcl_json_util_destroy(&json);
483 
484  MCL_DEBUG_LEAVE("retVal = <%d>", code);
485  return code;
486 }
487 
489 {
490  mcl_error_t code = MCL_OK;
491  mcl_json_t *payload = MCL_NULL;
492  const char *payload_type = MCL_NULL;
493  const char *payload_version = MCL_NULL;
494 
495  MCL_DEBUG_ENTRY("mcl_item_t *item = <%p>, mcl_json_t *root = <%p>", item, root);
496 
497  switch (item->type)
498  {
499  case MCL_ITEM_TYPE_EVENT:
501  payload_version = mcl_event_versions[item->version];
502  break;
503 
506  payload_version = mcl_data_source_configuration_versions[item->version];
507  break;
508 
511  payload_version = mcl_timeseries_versions[item->version];
512  break;
513 
514  case MCL_ITEM_TYPE_FILE:
516  payload_version = mcl_file_versions[item->version];
517  break;
518 
520  payload_type = ((custom_data_t *) item)->payload->type;
521  payload_version = ((custom_data_t *) item)->payload->version;
522  break;
523 
524  default:
525  code = MCL_FAIL;
526  break;
527  }
528 
529  if (MCL_OK == code)
530  {
532  }
533 
534  if (MCL_OK == code)
535  {
536  code = mcl_json_util_add_string(payload, meta_field_names[META_FIELD_PAYLOAD_TYPE], payload_type);
537  }
538  else
539  {
540  // payload is not added to root parent. So destroy payload struct with root_handle in it.
541  mcl_json_util_destroy(&payload);
542  }
543 
544  if (MCL_OK == code)
545  {
546  code = mcl_json_util_add_string(payload, meta_field_names[META_FIELD_PAYLOAD_VERSION], payload_version);
547  }
548 
549  if (MCL_OK == code)
550  {
551  code = _add_item_meta_payload_details(item, payload);
552  }
553 
554  MCL_DEBUG_LEAVE("retVal = <%d>", code);
555  return code;
556 }
557 
559 {
560  mcl_error_t code = MCL_OK;
561 
562  MCL_DEBUG_ENTRY("mcl_item_t *item = <%p>, mcl_json_t *payload = <%p>", item, payload);
563 
564  switch (item->type)
565  {
566  // There is no meta payload details for event, data source configuration.
567  case MCL_ITEM_TYPE_EVENT:
569  break;
570 
573  break;
574 
575  case MCL_ITEM_TYPE_FILE:
576  code = _add_item_meta_payload_file_details((file_t *) item, payload);
577  break;
578 
580  if (MCL_NULL != ((custom_data_t *) item)->payload->details)
581  {
582  mcl_json_t *details_json = MCL_NULL;
583  code = mcl_json_util_duplicate(((custom_data_t *) item)->payload->details, &details_json);
584 
585  if (MCL_OK == code)
586  {
588  }
589 
590  if (MCL_OK != code)
591  {
592  mcl_json_util_destroy(&details_json);
593  }
594  }
595  break;
596 
597  default:
598  code = MCL_FAIL;
599  break;
600  }
601 
602  MCL_DEBUG_LEAVE("retVal = <%d>", code);
603  return code;
604 }
605 
606 static mcl_error_t _add_event_to_payload_array(event_t *event, mcl_json_t *event_payload_array)
607 {
608  mcl_error_t code;
609  mcl_json_t *details_json = MCL_NULL;
610  mcl_json_t *event_payload_json = MCL_NULL;
611 
612  MCL_DEBUG_ENTRY("event_t *event = <%p>, mcl_json_t *event_payload_array = <%p>", event, event_payload_array);
613 
614  // Initialize new json object to add to json array.
615  code = mcl_json_util_initialize(MCL_JSON_OBJECT, &event_payload_json);
616 
617  // Add id.
618  if (MCL_OK == code)
619  {
620  code = mcl_json_util_add_string(event_payload_json, payload_field_names[PAYLOAD_FIELD_ID], event->payload->id);
621  }
622 
623  // Add correlationId.
624  if ((MCL_OK == code) && (MCL_NULL != event->payload->correlation_id) && (MCL_NULL_CHAR != event->payload->correlation_id[0]))
625  {
627  }
628 
629  // Add timestamp.
630  if (MCL_OK == code)
631  {
633  }
634 
635  // Add severity.
636  if (MCL_OK == code)
637  {
639  }
640 
641  // Add description.
642  if ((MCL_OK == code) && (MCL_NULL != event->payload->description) && (MCL_NULL_CHAR != event->payload->description[0]))
643  {
645  }
646 
647  // Add type.
648  if (MCL_OK == code)
649  {
650  code = mcl_json_util_add_string(event_payload_json, payload_field_names[PAYLOAD_FIELD_TYPE], event->payload->type);
651  }
652 
653  // Add version.
654  if (MCL_OK == code)
655  {
657  }
658 
659  // Create details.
660  if ((MCL_OK == code) && (MCL_NULL != event->payload->details))
661  {
662  code = mcl_json_util_duplicate(event->payload->details, &details_json);
663  }
664  else
665  {
666  code = mcl_json_util_initialize(MCL_JSON_OBJECT, &details_json);
667  }
668 
669  // Add details even if it is empty.
670  if (MCL_OK == code)
671  {
672  code = mcl_json_util_add_object(event_payload_json, payload_field_names[PAYLOAD_FIELD_DETAILS], details_json);
673  }
674 
675  // Add json object to json array.
676  if (MCL_OK == code)
677  {
678  code = mcl_json_util_add_item_to_array(event_payload_array, event_payload_json);
679 
680  if (MCL_OK != code)
681  {
682  mcl_json_util_destroy(&event_payload_json);
683  }
684  }
685  else
686  {
687  mcl_json_util_destroy(&details_json);
688  mcl_json_util_destroy(&event_payload_json);
689  }
690 
691  MCL_DEBUG_LEAVE("retVal = <%d>", code);
692  return code;
693 }
694 
696 {
697  mcl_error_t code = MCL_OK;
698 
699  MCL_DEBUG_ENTRY("mcl_item_t *item = <%p>, mcl_json_t *root = <%p>", item, root);
700 
701  // Unused parameter.
702  (void) root;
703 
704  switch (item->type)
705  {
706  // There is no meta details for event, data source configuration, timeseries, file.
707  case MCL_ITEM_TYPE_EVENT:
710  case MCL_ITEM_TYPE_FILE:
712  break;
713 
714  default:
715  code = MCL_FAIL;
716  break;
717  }
718 
719  MCL_DEBUG_LEAVE("retVal = <%d>", code);
720  return code;
721 }
722 
723 static mcl_error_t _json_from_data_source_configuration_payload(data_source_configuration_t *data_source_configuration, char **json_string)
724 {
725  mcl_error_t code;
726  mcl_json_t *json_object = MCL_NULL;
727  *json_string = MCL_NULL;
728 
729  MCL_DEBUG_ENTRY("data_source_configuration_t *data_source_configuration = <%p>, char **json_string = <%p>", data_source_configuration, json_string);
730 
731  // Initialize a json object.
732  code = mcl_json_util_initialize(MCL_JSON_OBJECT, &json_object);
733 
734  // Add configuration id.
735  if (MCL_OK == code)
736  {
738  }
739 
740  // Add data sources
741  if (MCL_OK == code)
742  {
743  mcl_json_t *data_sources_array = MCL_NULL;
744 
745  // Initialize a json array.
746  code = mcl_json_util_start_array(json_object, payload_field_names[PAYLOAD_FIELD_DATA_SOURCES], &data_sources_array);
747 
748  // Fill data sources array.
749  if (MCL_OK == code)
750  {
751  code = _fill_array_using_list(data_sources_array, data_source_configuration->payload->data_sources,
753  }
754  }
755 
756  // Get json string from json object.
757  if (MCL_OK == code)
758  {
759  code = mcl_json_util_to_string(json_object, json_string);
760  }
761 
762  mcl_json_util_destroy(&json_object);
763 
764  MCL_DEBUG_LEAVE("retVal = <%d>", code);
765  return code;
766 }
767 
768 static mcl_error_t _json_from_timeseries_payload(timeseries_t *timeseries, char **json_string)
769 {
770  mcl_error_t code;
771  mcl_json_t *value_list_array = MCL_NULL;
772  *json_string = MCL_NULL;
773 
774  MCL_DEBUG_ENTRY("timeseries_t *timeseries = <%p>, char **json_string = <%p>", timeseries, json_string);
775 
776  // Initialize a json array.
777  code = mcl_json_util_initialize(MCL_JSON_ARRAY, &value_list_array);
778 
779  // Fill value list array.
780  if (MCL_OK == code)
781  {
783  }
784 
785  // Get json string from json object.
786  if (MCL_OK == code)
787  {
788  code = mcl_json_util_to_string(value_list_array, json_string);
789  }
790 
791  mcl_json_util_destroy(&value_list_array);
792 
793  MCL_DEBUG_LEAVE("retVal = <%d>", code);
794  return code;
795 }
796 
798 {
799  mcl_error_t code = MCL_OK;
800  mcl_size_t index;
801 
802  MCL_DEBUG_ENTRY("mcl_json_t *json_array = <%p>, mcl_list_t *list = <%p>, json_converter_callback callback = <%p>", json_array, list, callback);
803 
804  // Reset list to iterate from the first node.
805  mcl_list_reset(list);
806 
807  for (index = 0; index < list->count; ++index)
808  {
809  mcl_list_node_t *node = MCL_NULL;
810  mcl_json_t *json_object = MCL_NULL;
811  code = mcl_list_next(list, &node);
812 
813  // Convert struct to json object via callback function.
814  if (MCL_OK == code)
815  {
816  code = callback(node->data, &json_object);
817  }
818 
819  // Add json item to json array.
820  if (MCL_OK == code)
821  {
822  code = mcl_json_util_add_item_to_array(json_array, json_object);
823  }
824 
825  if (MCL_OK != code)
826  {
827  // Destroy all content.
828  mcl_json_util_destroy(&json_object);
829  break;
830  }
831  }
832 
833  MCL_DEBUG_LEAVE("retVal = <%d>", code);
834  return code;
835 }
836 
838 {
839  mcl_error_t code;
840 
841  MCL_DEBUG_ENTRY("data_point_t *data_point = <%p>, mcl_json_t **json = <%p>", data_point, json);
842 
843  // Initialize a json object.
845 
846  // Add ID.
847  if (MCL_OK == code)
848  {
850  }
851 
852  // Add name.
853  if (MCL_OK == code)
854  {
856  }
857 
858  // Add description.
859  if ((MCL_OK == code) && (MCL_NULL != data_point->description))
860  {
862  }
863 
864  // Add type.
865  if (MCL_OK == code)
866  {
868  }
869 
870  // Add unit.
871  if (MCL_OK == code)
872  {
874  }
875 
876  // Add custom data.
877  if ((MCL_OK == code) && (MCL_NULL != data_point->custom_data))
878  {
879  mcl_json_t *duplicate_custom_data = MCL_NULL;
880 
881  code = mcl_json_util_duplicate(data_point->custom_data, &duplicate_custom_data);
882 
883  if (MCL_OK == code)
884  {
885  code = mcl_json_util_add_object(*json, payload_field_names[PAYLOAD_FIELD_CUSTOM_DATA], duplicate_custom_data);
886  }
887 
888  if (MCL_OK != code)
889  {
890  mcl_json_util_destroy(&duplicate_custom_data);
891  }
892  }
893 
894  if (MCL_OK != code)
895  {
896  mcl_json_util_destroy(json);
897  }
898 
899  MCL_DEBUG_LEAVE("retVal = <%d>", code);
900  return code;
901 }
902 
904 {
905  mcl_error_t code;
906 
907  MCL_DEBUG_ENTRY("data_source *data_source = <%p>, mcl_json_t **json = <%p>", data_source, json);
908 
909  // Initialize a json object.
911 
912  // Add name.
913  if (MCL_OK == code)
914  {
916  }
917 
918  // Add description.
919  if ((MCL_OK == code) && (MCL_NULL != data_source->description))
920  {
922  }
923 
924  // Add data points.
925  if (MCL_OK == code)
926  {
927  mcl_json_t *data_points_array = MCL_NULL;
928 
929  // Initialize a json array.
931 
932  // Fill data points array.
933  if (MCL_OK == code)
934  {
935  code = _fill_array_using_list(data_points_array, data_source->data_points, (json_converter_callback)_json_from_data_point);
936  }
937  }
938 
939  // Add custom data.
940  if ((MCL_OK == code) && (MCL_NULL != data_source->custom_data))
941  {
942  mcl_json_t *duplicate_custom_data = MCL_NULL;
943 
944  code = mcl_json_util_duplicate(data_source->custom_data, &duplicate_custom_data);
945 
946  if (MCL_OK == code)
947  {
948  code = mcl_json_util_add_object(*json, payload_field_names[PAYLOAD_FIELD_CUSTOM_DATA], duplicate_custom_data);
949  }
950 
951  if (MCL_OK != code)
952  {
953  mcl_json_util_destroy(&duplicate_custom_data);
954  }
955  }
956 
957  if (MCL_OK != code)
958  {
959  mcl_json_util_destroy(json);
960  }
961 
962  MCL_DEBUG_LEAVE("retVal = <%d>", code);
963  return code;
964 }
965 
967 {
968  mcl_error_t code;
969 
970  MCL_DEBUG_ENTRY("timeseries_value_t *timeseries_value = <%p>, mcl_json_t **json = <%p>", timeseries_value, json);
971 
972  // Initialize a json object.
974 
975  // Add dataPointId.
976  if (MCL_OK == code)
977  {
979  }
980 
981  // Add value.
982  if (MCL_OK == code)
983  {
985  }
986 
987  // Add qualityCode.
988  if (MCL_OK == code)
989  {
991  }
992 
993  if (MCL_OK != code)
994  {
995  mcl_json_util_destroy(json);
996  }
997 
998  MCL_DEBUG_LEAVE("retVal = <%d>", code);
999  return code;
1000 }
1001 
1003 {
1004  mcl_error_t code;
1005 
1006  MCL_DEBUG_ENTRY("timeseries_value_list_t *value_list = <%p>, mcl_json_t **json = <%p>", value_list, json);
1007 
1008  // Initialize a json object.
1010 
1011  // Add timestamp.
1012  if (MCL_OK == code)
1013  {
1015  }
1016 
1017  // Add values.
1018  if (MCL_OK == code)
1019  {
1020  mcl_json_t *value_array = MCL_NULL;
1021 
1022  // Initialize a json array.
1024 
1025  // Fill value array.
1026  if (MCL_OK == code)
1027  {
1029  }
1030  }
1031 
1032  if (MCL_OK != code)
1033  {
1034  mcl_json_util_destroy(json);
1035  }
1036 
1037  MCL_DEBUG_LEAVE("retVal = <%d>", code);
1038  return code;
1039 }
1040 
1042 {
1043  // Timeseries payload is array of timeseries lists.
1045  mcl_size_t list_count = timeseries->payload->value_lists->count;
1046  mcl_size_t index;
1047 
1048  MCL_VERBOSE_ENTRY("timeseries_t *timeseries = <%p>", timeseries);
1049 
1050  // Add size of timeseries value list(s).
1051  mcl_list_reset(timeseries->payload->value_lists);
1052 
1053  for (index = 0; index < list_count; ++index)
1054  {
1055  mcl_list_node_t *node;
1056  mcl_list_next(timeseries->payload->value_lists, &node);
1057 
1059  }
1060 
1061  // Add delimiter (',') size.
1062  size += (list_count - 1) * DELIMITER_SIZE;
1063 
1064  MCL_VERBOSE_LEAVE("retVal = <%lu>", size);
1065  return size;
1066 }
1067 
1069 {
1071  mcl_size_t list_count = timeseries_value_list->values->count;
1072  mcl_size_t index;
1073 
1074  MCL_VERBOSE_ENTRY("timeseries_value_list_t *timeseries_value_list = <%p>", timeseries_value_list);
1075 
1076  mcl_list_reset(timeseries_value_list->values);
1077 
1078  // Add size of timeseries value(s).
1079  for (index = 0; index < list_count; ++index)
1080  {
1081  mcl_list_node_t *node;
1082  mcl_list_next(timeseries_value_list->values, &node);
1083 
1085  }
1086 
1087  // Add delimiter (',') size.
1088  size += (list_count - 1) * DELIMITER_SIZE;
1089 
1090  MCL_VERBOSE_LEAVE("retVal = <%lu>", size);
1091  return size;
1092 }
1093 
1095 {
1097 
1098  MCL_VERBOSE_ENTRY("timeseries_value_t *timeseries_value = <%p>", timeseries_value);
1099 
1100  // Add size of timeseries value fields.
1101  size += mcl_string_util_strlen(timeseries_value->data_point_id);
1102  size += mcl_string_util_strlen(timeseries_value->quality_code);
1103  size += mcl_string_util_strlen(timeseries_value->value);
1104 
1105  MCL_VERBOSE_LEAVE("retVal = <%lu>", size);
1106  return size;
1107 }
1108 
1110 {
1111  // Event will be sent in a json array.
1113  char *temp_json = MCL_NULL;
1114 
1115  MCL_VERBOSE_ENTRY("event_t *event = <%p>", event);
1116 
1117  // Add size of event fields.
1118  size += mcl_string_util_strlen(event->payload->id);
1119  size += mcl_string_util_strlen(event->payload->type);
1120  size += mcl_string_util_strlen(event->payload->version);
1121 
1122  // For event version 1.0, severity is a single digit number.
1123  // For event version 2.0, severity is a double digit number.
1124  if (MCL_EVENT_VERSION_1_0 == event->item_base.version)
1125  {
1126  ++size;
1127  }
1128  else if (MCL_EVENT_VERSION_2_0 == event->item_base.version)
1129  {
1130  size += 2;
1131  }
1132 
1133  // Add correlation id size.
1134  if (MCL_NULL != event->payload->correlation_id)
1135  {
1138  }
1139 
1140  // Add description size.
1141  if (MCL_NULL != event->payload->description)
1142  {
1144  size += mcl_string_util_strlen(event->payload->description);
1145  }
1146 
1147  // Details json for event can be null, but it will be added as empty json anyway.
1148  if (MCL_NULL != event->payload->details)
1149  {
1150  (void) mcl_json_util_to_string(event->payload->details, &temp_json);
1151  }
1152 
1153  if (MCL_NULL != temp_json)
1154  {
1155  size += mcl_string_util_strlen(temp_json);
1156  MCL_FREE(temp_json);
1157  }
1158  else
1159  {
1160  size += DOUBLE_BRACE_SIZE;
1161  }
1162 
1163  MCL_VERBOSE_LEAVE("retVal = <%lu>", size);
1164  return size;
1165 }
1166 
1168 {
1170  mcl_size_t list_count = data_source_configuration->payload->data_sources->count;
1171  mcl_size_t index;
1172 
1173  MCL_VERBOSE_ENTRY("data_source_configuration_payload_t *data_source_configuration = <%p>", data_source_configuration);
1174 
1175  size += mcl_string_util_strlen(data_source_configuration->payload->configuration_id);
1176 
1177  mcl_list_reset(data_source_configuration->payload->data_sources);
1178 
1179  // Add size of data source(s).
1180  for (index = 0; index < list_count; ++index)
1181  {
1182  mcl_list_node_t *node;
1183  mcl_list_next(data_source_configuration->payload->data_sources, &node);
1184 
1186  }
1187 
1188  // Add delimiter (',') size.
1189  size += (list_count - 1) * DELIMITER_SIZE;
1190 
1191  MCL_VERBOSE_LEAVE("retVal = <%lu>", size);
1192  return size;
1193 }
1194 
1196 {
1198  mcl_size_t list_count = data_source->data_points->count;
1199  mcl_size_t index;
1200  char *temp_json = MCL_NULL;
1201 
1202  MCL_VERBOSE_ENTRY("data_source_t *data_source = <%p>", data_source);
1203 
1204  // Add size of data source fields.
1205  size += mcl_string_util_strlen(data_source->name);
1206  size += mcl_string_util_strlen(data_source->description);
1207 
1208  mcl_list_reset(data_source->data_points);
1209 
1210  // Add size of data point(s).
1211  for (index = 0; index < list_count; ++index)
1212  {
1213  mcl_list_node_t *node;
1214  mcl_list_next(data_source->data_points, &node);
1215 
1217  }
1218 
1219  // Add delimiter (',') size.
1220  size += (list_count - 1) * DELIMITER_SIZE;
1221 
1222  // Data source may have a custom data json.
1223  if (MCL_NULL != data_source->custom_data)
1224  {
1226  (void) mcl_json_util_to_string(data_source->custom_data, &temp_json);
1227 
1228  // If temp_json is NULL when data_source->custom_data is not NULL, calculated size will be less than actual size.
1229  if (MCL_NULL != temp_json)
1230  {
1231  size += mcl_string_util_strlen(temp_json);
1232  MCL_FREE(temp_json);
1233  }
1234  else
1235  {
1236  size += DOUBLE_BRACE_SIZE;
1237  }
1238  }
1239 
1240  MCL_VERBOSE_LEAVE("retVal = <%lu>", size);
1241  return size;
1242 }
1243 
1245 {
1247  char *temp_json = MCL_NULL;
1248 
1249  MCL_VERBOSE_ENTRY("data_point_t *data_point = <%p>", data_point);
1250 
1251  // Add size of data point fields.
1252  size += mcl_string_util_strlen(data_point->id);
1253  size += mcl_string_util_strlen(data_point->name);
1254  size += mcl_string_util_strlen(data_point->description);
1255  size += mcl_string_util_strlen(data_point->type);
1256  size += mcl_string_util_strlen(data_point->unit);
1257 
1258  // Data point may have a custom data json.
1259  if (MCL_NULL != data_point->custom_data)
1260  {
1262  (void) mcl_json_util_to_string(data_point->custom_data, &temp_json);
1263 
1264  // If temp_json is NULL when data_point->custom_data is not NULL, calculated size will be less than actual size.
1265  if (MCL_NULL != temp_json)
1266  {
1267  size += mcl_string_util_strlen(temp_json);
1268  MCL_FREE(temp_json);
1269  }
1270  else
1271  {
1272  size += DOUBLE_BRACE_SIZE;
1273  }
1274  }
1275 
1276  MCL_VERBOSE_LEAVE("retVal = <%lu>", size);
1277  return size;
1278 }
1279 
1281 {
1283 
1284  MCL_VERBOSE_ENTRY("mcl_item_t *item = <%p>", item);
1285 
1286  switch (item->type)
1287  {
1290  size += mcl_string_util_strlen(((timeseries_t *) item)->payload->configuration_id);
1292  break;
1293 
1294  case MCL_ITEM_TYPE_EVENT:
1297  break;
1298 
1299  case MCL_ITEM_TYPE_FILE:
1301  size += mcl_string_util_strlen(((file_t *) item)->payload->remote_name);
1302 
1303  if (MCL_NULL != ((file_t *) item)->payload->type)
1304  {
1306  size += mcl_string_util_strlen(((file_t *)item)->payload->type);
1307  }
1308 
1310  break;
1311 
1313  size += _custom_data_meta_size((custom_data_t *) item);
1314  break;
1315 
1319  break;
1320 
1321  default:
1322  break;
1323  }
1324 
1325  MCL_VERBOSE_LEAVE("retVal = <%lu>", size);
1326  return size;
1327 }
1328 
1330 {
1332 
1333  MCL_VERBOSE_ENTRY("custom_data_t *custom_data = <%p>", custom_data);
1334 
1335  size += mcl_string_util_strlen(custom_data->payload->type);
1336  size += mcl_string_util_strlen(custom_data->payload->version);
1337 
1338  if (MCL_NULL != custom_data->payload->details)
1339  {
1340  char *temp_json = MCL_NULL;
1342 
1343  (void) mcl_json_util_to_string(custom_data->payload->details, &temp_json);
1344 
1345  // If temp_json is NULL, calculated size will be less than actual size.
1346  if (MCL_NULL != temp_json)
1347  {
1348  size += mcl_string_util_strlen(temp_json);
1349  MCL_FREE(temp_json);
1350  }
1351  else
1352  {
1353  size += DOUBLE_BRACE_SIZE;
1354  }
1355  }
1356 
1357  MCL_VERBOSE_LEAVE("retVal = <%lu>", size);
1358  return size;
1359 }
1360 
1362 {
1363  mcl_error_t code;
1364  mcl_json_t *details_json = MCL_NULL;
1365 
1366  MCL_DEBUG_ENTRY("timeseries_t *timeseries = <%p>, mcl_json_t *payload = <%p>", timeseries, payload);
1367 
1369 
1370  // Add configuration id.
1371  if (MCL_OK == code)
1372  {
1374  }
1375 
1376  MCL_DEBUG_LEAVE("retVal = <%d>", code);
1377  return code;
1378 }
1379 
1381 {
1382  mcl_error_t code;
1383  mcl_json_t *details_json = MCL_NULL;
1384 
1385  MCL_DEBUG_ENTRY("file_t *file = <%p>, mcl_json_t *payload = <%p>", file, payload);
1386 
1388 
1389  // Add file name.
1390  if (MCL_OK == code)
1391  {
1393  }
1394 
1395  // Add creation date.
1396  if (MCL_OK == code)
1397  {
1399  }
1400 
1401  // Add file type.
1402  if ((MCL_OK == code) && (MCL_NULL != file->payload->type))
1403  {
1405  }
1406 
1407  MCL_DEBUG_LEAVE("retVal = <%d>", code);
1408  return code;
1409 }
1410 
1412  mcl_list_item_destroy_callback destroy_callback, mcl_list_t *list)
1413 {
1414  mcl_error_t code;
1415  mcl_size_t index;
1416  mcl_size_t array_size;
1417 
1418  MCL_DEBUG_ENTRY("mcl_json_t *json_array = <%p>, json_parser_callback callback = <%p>, mcl_list_item_destroy_callback destroy_callback = <%p>, "\
1419  "mcl_list_t *list = <%p>", json_array, parser_callback, destroy_callback, list);
1420 
1421  // Get array size.
1422  code = mcl_json_util_get_array_size(json_array, &array_size);
1423 
1424  for (index = 0; (MCL_OK == code) && (index < array_size); ++index)
1425  {
1426  mcl_json_t *item;
1427  void *a_struct = MCL_NULL;
1428 
1429  // Get item from array.
1430  code = mcl_json_util_get_array_item(json_array, (int) index, &item);
1431 
1432  // Parse json into a struct via parser_callback.
1433  if (MCL_OK == code)
1434  {
1435  code = parser_callback(item, &a_struct);
1436  }
1437 
1438  // Add parsed struct to the list.
1439  if (MCL_OK == code)
1440  {
1441  code = mcl_list_add(list, a_struct);
1442  }
1443 
1444  if (MCL_OK != code)
1445  {
1446  destroy_callback(a_struct);
1447  }
1448  }
1449 
1450  MCL_DEBUG_LEAVE("retVal = <%d>", code);
1451  return code;
1452 }
1453 
1455 {
1456  mcl_error_t code;
1457 
1458  MCL_DEBUG_ENTRY("mcl_json_t *json = <%p>, data_point_t **data_point = <%p>", json, data_point);
1459 
1460  code = mcl_data_point_initialize(data_point);
1461 
1462  // Parse id.
1463  if (MCL_OK == code)
1464  {
1465  code = _parse_and_get_string_value(json, payload_field_names[PAYLOAD_FIELD_ID], &((*data_point)->id));
1466  }
1467 
1468  // Parse name.
1469  if (MCL_OK == code)
1470  {
1472  }
1473 
1474  // Parse type.
1475  if (MCL_OK == code)
1476  {
1478  }
1479 
1480  // Parse unit.
1481  if (MCL_OK == code)
1482  {
1484  }
1485 
1486  // Parse description if exists.
1487  if (MCL_OK == code)
1488  {
1489  code = _parse_and_get_string_value(json, payload_field_names[PAYLOAD_FIELD_DESCRIPTION], &((*data_point)->description));
1490 
1491  if (MCL_JSON_NON_EXISTING_CHILD == code)
1492  {
1493  code = MCL_OK;
1494  }
1495  }
1496 
1497  // Duplicate custom data json if exists.
1498  if (MCL_OK == code)
1499  {
1500  mcl_json_t *custom_data_json = MCL_NULL;
1501 
1503 
1504  if (MCL_JSON_NON_EXISTING_CHILD == code)
1505  {
1506  code = MCL_OK;
1507  }
1508  else
1509  {
1510  code = mcl_json_util_duplicate(custom_data_json, &((*data_point)->custom_data));
1511  }
1512  }
1513 
1514  if (MCL_OK != code)
1515  {
1516  mcl_data_point_destroy(data_point);
1517  }
1518 
1519  MCL_DEBUG_LEAVE("retVal = <%d>", code);
1520  return code;
1521 }
1522 
1524 {
1525  mcl_error_t code;
1526 
1527  MCL_DEBUG_ENTRY("mcl_json_t *json = <%p>, data_source_t **data_source = <%p>", json, data_source);
1528 
1529  code = mcl_data_source_initialize(data_source);
1530 
1531  // Parse name.
1532  if (MCL_OK == code)
1533  {
1535  }
1536 
1537  // Parse description if exists.
1538  if (MCL_OK == code)
1539  {
1540  code = _parse_and_get_string_value(json, payload_field_names[PAYLOAD_FIELD_DESCRIPTION], &((*data_source)->description));
1541 
1542  if (MCL_JSON_NON_EXISTING_CHILD == code)
1543  {
1544  code = MCL_OK;
1545  }
1546  }
1547 
1548  // Duplicate custom data json if exists.
1549  if (MCL_OK == code)
1550  {
1551  mcl_json_t *custom_data_json = MCL_NULL;
1552 
1554 
1555  if (MCL_JSON_NON_EXISTING_CHILD == code)
1556  {
1557  code = MCL_OK;
1558  }
1559  else
1560  {
1561  code = mcl_json_util_duplicate(custom_data_json, &((*data_source)->custom_data));
1562  }
1563  }
1564 
1565  // Parse data points.
1566  if (MCL_OK == code)
1567  {
1568  mcl_json_t *data_point_array = MCL_NULL;
1569 
1571 
1572  if (MCL_OK == code)
1573  {
1575  (mcl_list_item_destroy_callback) mcl_data_point_destroy, (*data_source)->data_points);
1576  }
1577  }
1578 
1579  if (MCL_OK != code)
1580  {
1581  mcl_data_source_destroy(data_source);
1582  }
1583 
1584  MCL_DEBUG_LEAVE("retVal = <%d>", code);
1585  return code;
1586 }
1587 
1589 {
1590  mcl_error_t code;
1591 
1592  MCL_DEBUG_ENTRY("mcl_json_t *json = <%p>, data_source_configuration_t **data_source_configuration = <%p>", json, data_source_configuration);
1593 
1595 
1596  // Parse configuration id.
1597  if (MCL_OK == code)
1598  {
1600  &((*data_source_configuration)->payload->configuration_id));
1601  }
1602 
1603  // Parse data sources.
1604  if (MCL_OK == code)
1605  {
1606  mcl_json_t *data_point_array = MCL_NULL;
1607 
1609 
1610  if (MCL_OK == code)
1611  {
1613  (mcl_list_item_destroy_callback) mcl_data_source_destroy, (*data_source_configuration)->payload->data_sources);
1614  }
1615  }
1616 
1617  if (MCL_OK != code)
1618  {
1619  mcl_data_source_configuration_destroy(data_source_configuration);
1620  }
1621 
1622  MCL_DEBUG_LEAVE("retVal = <%d>", code);
1623  return code;
1624 }
1625 
1626 static mcl_error_t _parse_and_get_string_value(mcl_json_t *json, const char *field_name, char **string)
1627 {
1628  mcl_error_t code;
1629  mcl_json_t *object;
1630 
1631  MCL_DEBUG_ENTRY("mcl_json_t *json = <%p>, const char *field_name = <%p>, char **string = <%p>", json, field_name, string);
1632 
1633  code = mcl_json_util_get_object_item(json, field_name, &object);
1634 
1635  if (MCL_OK == code)
1636  {
1637  code = mcl_json_util_get_string(object, string);
1638  }
1639 
1640  MCL_DEBUG_LEAVE("retVal = <%d>", code);
1641  return code;
1642 }
mcl_int32_t severity
Severity level.
Definition: event.h:26
Value of payload field details.
Definition: json.c:146
char * correlation_id
Parent event id.
Definition: event.h:24
End of meta field names enumeration.
Definition: json.c:103
#define ITEM_EVENT_PAYLOAD_CORRELATION_ID_SIZE
Definition: json.c:49
Custom event id of payload field.
Definition: json.c:132
mcl_list_t * values
List of timeseries values.
Data source configuration module header file.
MCL_CORE_EXPORT mcl_error_t mcl_json_util_start_object(mcl_json_t *root, const char *object_name, mcl_json_t **json_object)
char * data_point_id
Data point id of the timeseries value.
size_t mcl_size_t
mcl_size_t json_get_item_size(void *item)
Definition: json.c:429
custom_data_payload_t * payload
Payload of custom data.
Definition: custom_data.h:34
Item type custom data.
Definition: item.h:27
Item type data source configuration.
Definition: item.h:28
Meta of meta field payload.
Definition: json.c:90
static mcl_error_t _add_item_meta_payload_file_details(file_t *file, mcl_json_t *payload)
Definition: json.c:1380
mcl_error_t json_from_item_meta(void *item, char **json_string)
Definition: json.c:326
MCL_OK
End of meta field values enumeration.
Definition: json.c:117
MCL_CORE_EXPORT mcl_error_t mcl_json_util_initialize(E_MCL_JSON_TYPE json_type, mcl_json_t **root)
char * id
Agent-unique identifier of the data point.
Definition: data_point.h:19
Source type of payload field.
Definition: json.c:134
static mcl_error_t _add_event_to_payload_array(event_t *event, mcl_json_t *event_payload_array)
Definition: json.c:606
mcl_json_t * details
Event/alarm details.
Definition: event.h:30
static mcl_error_t _add_item_meta_payload_details(mcl_item_t *item, mcl_json_t *payload)
Definition: json.c:558
Type of meta field.
Definition: json.c:88
static mcl_error_t _add_item_meta_payload_timeseries_details(timeseries_t *timeseries, mcl_json_t *payload)
Definition: json.c:1361
Payload field values.
Definition: json.c:127
Configuration id of meta field payload details.
Definition: json.c:95
const char * mcl_file_versions[MCL_FILE_VERSION_END]
Definition: file.c:15
mcl_error_t(* json_converter_callback)(void *any_struct, mcl_json_t **json)
Definition: json.c:236
char * version
Version of the event/alarm type.
Definition: event.h:29
void mcl_json_t
static mcl_error_t _json_from_timeseries_value(timeseries_value_t *timeseries_value, mcl_json_t **json)
Definition: json.c:966
mcl_error_t(* json_parser_callback)(mcl_json_t *json, void **any_struct)
Definition: json.c:239
Source id of payload field.
Definition: json.c:135
char * description
Event description.
Definition: event.h:27
file_payload_t * payload
Payload of file.
Definition: file.h:34
Total items of meta field details.
Definition: json.c:100
static mcl_size_t _item_payload_size_for_data_source_configuration(data_source_configuration_t *data_source_configuration)
Definition: json.c:1167
Meta field payload.
Definition: json.c:91
Data source configuration version 1.0.
MCL_JSON_OBJECT
char timestamp[MCL_TIMESTAMP_LENGTH]
Time of values in yyyy-MM-ddTHH:mm:ss.SSSZ format.
mcl_int32_t mcl_error_t
Type of payload field data sources data points.
Definition: json.c:157
char * version
Version of custom data.
Definition: custom_data.h:20
Description of payload field details.
Definition: json.c:150
Error code of payload field details.
Definition: json.c:144
mcl_json_t * details
Details of custom data.
Definition: custom_data.h:25
MCL_JSON_ARRAY
E_META_FIELD_VALUES
Definition: json.c:111
mcl_list_t * data_points
List of data points in the data source.
Definition: data_source.h:22
#define MCL_DEBUG_ENTRY(...)
char * description
Description of the data source.
Definition: data_source.h:21
Name of payload field details.
Definition: json.c:148
#define ITEM_EVENT_META_PAYLOAD_BASE_SIZE
Definition: json.c:42
void(* mcl_list_item_destroy_callback)(void **item)
MCL_CORE_EXPORT mcl_error_t mcl_json_util_parse(const char *json_string, mcl_size_t buffer_size, mcl_json_t **root)
File module header file.
#define ITEM_VERSION
Definition: json.c:21
MCL_CORE_EXPORT mcl_error_t mcl_json_util_start_array(mcl_json_t *root, const char *array_name, mcl_json_t **json_array)
mcl_json_t * custom_data
Custom parameters for data source.
Definition: data_source.h:23
Timestamp of payload field.
Definition: json.c:126
MCL_CORE_EXPORT mcl_error_t mcl_json_util_add_string(mcl_json_t *root, const char *object_name, const char *object_value)
static mcl_error_t _json_from_timeseries_value_list(timeseries_value_list_t *timeseries_value_list, mcl_json_t **json)
Definition: json.c:1002
static mcl_error_t _fill_array_using_list(mcl_json_t *json_array, mcl_list_t *list, json_converter_callback callback)
Definition: json.c:797
Data source configuration module interface header file.
Description of payload field.
Definition: json.c:137
MCL_CORE_EXPORT mcl_size_t mcl_string_util_strlen(const char *buffer)
MCL_CORE_EXPORT mcl_error_t mcl_list_next(mcl_list_t *list, mcl_list_node_t **node)
static mcl_size_t _item_payload_size_for_data_point(data_point_t *data_point)
Definition: json.c:1244
MCL_CORE_EXPORT void mcl_json_util_destroy(mcl_json_t **root)
mcl_list_t * value_lists
List of timeseries value lists.
Definition: timeseries.h:21
char * name
Name of the data point.
Definition: data_point.h:20
Event version 2.0.
Definition: mcl_event.h:42
event_payload_t * payload
Payload of event.
Definition: event.h:39
Meta field payload details.
Definition: json.c:94
MCL_CONNECTIVITY_EXPORT mcl_error_t mcl_data_point_initialize(mcl_data_point_t **data_point)
Definition: data_point.c:14
Item type timeseries.
Definition: item.h:24
#define ITEM_DATA_SOURCE_CONFIGURATION_META_PAYLOAD_BASE_SIZE
Definition: json.c:68
static mcl_size_t _custom_data_meta_size(custom_data_t *custom_data)
Definition: json.c:1329
#define MCL_NULL
Timeseries module header file.
End of payload field names enumeration.
Definition: json.c:159
const char * mcl_data_source_configuration_versions[MCL_DATA_SOURCE_CONFIGURATION_END]
timeseries_payload_t * payload
Payload of timeseries.
Definition: timeseries.h:30
Event module interface header file.
#define ITEM_FILE_META_PAYLOAD_BASE_SIZE
Definition: json.c:55
char * description
Description of the data point.
Definition: data_point.h:21
MCL_CONNECTIVITY_EXPORT void mcl_data_source_destroy(mcl_data_source_t **data_source)
Definition: data_source.c:147
Json module header file.
MCL_CONNECTIVITY_EXPORT void mcl_data_point_destroy(mcl_data_point_t **data_point)
Definition: data_point.c:108
static mcl_size_t _item_payload_size_for_event(event_t *event)
Definition: json.c:1109
#define MCL_VERBOSE_LEAVE(...)
static mcl_error_t _json_from_data_source(data_source_t *data_source, mcl_json_t **json)
Definition: json.c:903
Type of payload field.
Definition: json.c:139
Definition: file.h:31
char * value
Value of the timeseries value.
Value of payload field values.
Definition: json.c:129
char * quality_code
Quality code of the timeseries value.
#define ITEM_DATA_SOURCE_CONFIGURATION_PAYLOAD_BASE_SIZE
Definition: json.c:71
static mcl_error_t _add_item_meta_payload(mcl_item_t *item, mcl_json_t *root)
Definition: json.c:488
static mcl_error_t _parse_and_get_string_value(mcl_json_t *json, const char *field_name, char **string)
Definition: json.c:1626
static mcl_error_t _json_from_timeseries_payload(timeseries_t *timeseries, char **json_string)
Definition: json.c:768
static mcl_error_t _json_from_data_point(data_point_t *data_point, mcl_json_t **json)
Definition: json.c:837
MCL_CORE_EXPORT mcl_error_t mcl_list_add(mcl_list_t *list, void *data)
Message of payload field details.
Definition: json.c:143
#define ITEM_EVENT_PAYLOAD_DESCRIPTION_SIZE
Definition: json.c:52
#define DELIMITER_SIZE
Definition: json.c:24
#define MCL_FREE(p)
Custom data of payload field.
Definition: json.c:141
Creation date of meta field details.
Definition: json.c:99
MCL_CORE_EXPORT mcl_error_t mcl_json_util_get_object_item(mcl_json_t *json_parent, const char *child_name, mcl_json_t **json_child)
mcl_error_t json_parse_item(const char *json_string, mcl_size_t string_length, void **item)
Definition: json.c:467
Time series type of meta field payload.
Definition: json.c:113
static mcl_error_t _fill_list_using_json_array(mcl_json_t *json_array, json_parser_callback parser_callback, mcl_list_item_destroy_callback destroy_callback, mcl_list_t *list)
Definition: json.c:1411
Quality code of payload field values.
Definition: json.c:130
data_source_configuration_payload_t * payload
Unit of payload field data sources data points.
Definition: json.c:158
static mcl_size_t _item_payload_size_for_timeseries_value(timeseries_value_t *timeseries_value)
Definition: json.c:1094
Payload field data sources data points.
Definition: json.c:154
char * type
Type of the event.
Definition: event.h:28
E_META_FIELD_NAMES
Definition: json.c:86
char * unit
Measurement unit of the data point.
Definition: data_point.h:23
static mcl_error_t _add_item_meta_details(mcl_item_t *item, mcl_json_t *root)
Definition: json.c:695
#define ITEM_DATA_POINT_BASE_SIZE
Definition: json.c:77
char * name
Name of the data source.
Definition: data_source.h:20
#define ITEM_META_BASE_SIZE
Definition: json.c:29
#define ITEM_TYPE
Definition: json.c:20
static const char * payload_field_names[PAYLOAD_FIELD_NAMES_END]
Definition: json.c:198
MCL_CONNECTIVITY_EXPORT mcl_error_t mcl_data_source_initialize(mcl_data_source_t **data_source)
Definition: data_source.c:14
char * type
Type of the data point.
Definition: data_point.h:22
Payload field data sources.
Definition: json.c:152
#define ITEM_FILE_META_PAYLOAD_FILE_TYPE_SIZE
Definition: json.c:59
Details of payload field details.
Definition: json.c:145
MCL_CORE_EXPORT void mcl_list_reset(mcl_list_t *list)
mcl_json_t * custom_data
Custom parameters for the data point.
Definition: data_point.h:24
char * type
Type of file.
Definition: file.h:23
MCL_CORE_EXPORT mcl_error_t mcl_json_util_add_item_to_array(mcl_json_t *root, mcl_json_t *object)
mcl_item_t item_base
Item base of event.
Definition: event.h:38
char * configuration_id
Configuration ID of timeseries.
Definition: timeseries.h:20
Item type event.
Definition: item.h:25
Download link of payload field details.
Definition: json.c:147
#define ITEM_EVENT_PAYLOAD_BASE_SIZE
Definition: json.c:45
E_MCL_ITEM_TYPE type
Item type.
Definition: item.h:38
static mcl_error_t _json_from_event_payload(event_t *event, char **json_string)
Definition: json.c:399
MCL_CONNECTIVITY_EXPORT mcl_error_t mcl_data_source_configuration_initialize(E_MCL_DATA_SOURCE_CONFIGURATION_VERSION version, mcl_data_source_configuration_t **data_source_configuration)
Details of payload field.
Definition: json.c:142
MCL_CORE_EXPORT mcl_error_t mcl_json_util_duplicate(const mcl_json_t *source_json, mcl_json_t **duplicated_json)
Event module header file.
char * remote_name
Remote name of file.
Definition: file.h:22
Custom data module header file.
Version of payload field.
Definition: json.c:140
Timestamp of meta field payload details.
Definition: json.c:101
Business event type of meta field payload.
Definition: json.c:114
#define ITEM_CUSTOM_DATA_META_PAYLOAD_DETAILS_SIZE
Definition: json.c:65
const char * mcl_timeseries_versions[MCL_TIMESERIES_VERSION_END]
Definition: timeseries.c:14
static mcl_size_t _item_payload_size_for_timeseries(timeseries_t *timeseries)
Definition: json.c:1041
static mcl_size_t _item_payload_size_for_data_source(data_source_t *data_source)
Definition: json.c:1195
#define ITEM_TIMESERIES_VALUE_LIST_BASE_SIZE
Definition: json.c:39
static mcl_error_t _parse_data_source_configuration(mcl_json_t *json, data_source_configuration_t **data_source_configuration)
Definition: json.c:1588
Payload field id.
Definition: json.c:131
char * id
Unique identifier of the event.
Definition: event.h:23
Name of payload field data sources data points.
Definition: json.c:156
Correlation id of payload field.
Definition: json.c:133
static mcl_size_t _item_meta_size(mcl_item_t *item)
Definition: json.c:1280
static mcl_error_t _json_from_data_source_configuration_payload(data_source_configuration_t *data_source_configuration, char **json_string)
Definition: json.c:723
MCL_CORE_EXPORT mcl_error_t mcl_json_util_to_string(mcl_json_t *root, char **json_string)
MCL_CONNECTIVITY_EXPORT void mcl_data_source_configuration_destroy(mcl_data_source_configuration_t **data_source_configuration)
#define ITEM_TIMESERIES_META_PAYLOAD_BASE_SIZE
Definition: json.c:32
Item type file.
Definition: item.h:26
static const char * meta_field_values[META_FIELD_VALUES_END]
Definition: json.c:187
Severity of payload field.
Definition: json.c:136
static const char * meta_field_names[META_FIELD_NAMES_END]
Definition: json.c:165
mcl_size_t count
E_PAYLOAD_FIELD_NAMES
Definition: json.c:124
Version of payload field details.
Definition: json.c:149
mcl_list_t * data_sources
List of data sources definitions.
Data point id of payload field assets data sources data points.
Definition: json.c:155
Name of payload field data sources.
Definition: json.c:153
mcl_error_t json_from_item_payload(void *item, char **json_string)
Definition: json.c:370
Data point id of payload field values.
Definition: json.c:128
Status of payload field.
Definition: json.c:138
Definition: event.h:36
MCL_CORE_EXPORT mcl_error_t mcl_json_util_get_array_item(mcl_json_t *array, int index, mcl_json_t **item)
#define ITEM_TIMESERIES_VALUE_BASE_SIZE
Definition: json.c:36
static mcl_size_t _item_payload_size_for_timeseries_value_list(timeseries_value_list_t *timeseries_value_list)
Definition: json.c:1068
#define MCL_DEBUG_LEAVE(...)
char * type
Type of custom data.
Definition: custom_data.h:23
const char * mcl_event_versions[MCL_EVENT_VERSION_END]
Definition: event.c:17
MCL_CORE_EXPORT mcl_error_t mcl_json_util_add_object(mcl_json_t *root, const char *object_name, mcl_json_t *object)
MCL_CORE_EXPORT mcl_error_t mcl_json_util_add_uint(mcl_json_t *root, const char *object_name, const mcl_size_t number)
Meta field details.
Definition: json.c:96
#define MCL_VERBOSE_ENTRY(...)
#define ITEM_CUSTOM_DATA_META_PAYLOAD_BASE_SIZE
Definition: json.c:62
MCL_FAIL
#define ITEM_DATA_SOURCE_BASE_SIZE
Definition: json.c:74
File type of meta field details.
Definition: json.c:98
File name of meta field details.
Definition: json.c:97
char timestamp[MCL_TIMESTAMP_LENGTH]
Creation time of the event in ISO format.
Definition: event.h:25
Type of meta field payload.
Definition: json.c:92
Data source configuration type of meta field payload.
Definition: json.c:116
Duration of meta field payload details.
Definition: json.c:102
MCL_CORE_EXPORT mcl_error_t mcl_json_util_get_array_size(mcl_json_t *array, mcl_size_t *size)
#define ITEM_DATA_SOURCE_CONFIGURATION_PAYLOAD_CUSTOM_DATA_SIZE
Definition: json.c:80
static mcl_error_t _parse_data_point(mcl_json_t *json, data_point_t **data_point)
Definition: json.c:1454
char * creation_date
Creation date of file.
Definition: file.h:20
MCL_JSON_NON_EXISTING_CHILD
Version of meta field.
Definition: json.c:89
#define MCL_NULL_CHAR
Version of meta field payload.
Definition: json.c:93
mcl_uint32_t version
Item version.
Definition: item.h:39
char * configuration_id
Unique identifier of the configuration.
Event version 1.0.
Definition: mcl_event.h:41
MCL_CORE_EXPORT mcl_error_t mcl_json_util_get_string(mcl_json_t *json, char **string_value)
#define DOUBLE_BRACE_SIZE
Definition: json.c:23
Configuration id of payload field.
Definition: json.c:151
static mcl_error_t _parse_data_source(mcl_json_t *json, data_source_t **data_source)
Definition: json.c:1523
File type of meta field payload.
Definition: json.c:115