stream_data.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 stream_data.c
9 * @date Jul 27, 2016
10 * @brief Stream data module implementation file.
11 *
12 ************************************************************************/
13 
14 #include "mcl/mcl_common.h"
15 #include "mcl/mcl_custom_data.h"
16 #include "stream_data.h"
17 #include "log_util.h"
18 #include "memory.h"
19 #include "definitions.h"
20 
21 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,
22  void *user_context, stream_data_t **stream_data)
23 {
24  DEBUG_ENTRY("const char *version = <%s>, const char *type = <%s>, const char *routing = <%p>, mcl_stream_data_read_callback_t stream_data_read_callback = <%p>, void *user_context = <%p>, stream_data_t **stream_data = <%p>",
25  version, type, routing, stream_data_read_callback, user_context, stream_data)
26 
27  E_MCL_ERROR_CODE result;
28 
29  MCL_NEW(*stream_data);
30  ASSERT_CODE_MESSAGE(MCL_NULL != *stream_data, MCL_OUT_OF_MEMORY, "Memory can not be allocated for stream data.");
31 
32  (*stream_data)->user_context = user_context;
33  (*stream_data)->read_callback = stream_data_read_callback;
34 
35  result = custom_data_initialize(version, type, routing, &((*stream_data)->base));
36 
37  ASSERT_STATEMENT_CODE_MESSAGE(MCL_OK == result, stream_data_destroy(stream_data), result, "Base custom data meta initialization failed !");
38 
39  DEBUG_LEAVE("retVal = <%d>", result);
40  return result;
41 }
42 
44 {
45  DEBUG_ENTRY("mcl_stream_data_t *stream_data = <%p>, const mcl_json_t *details = <%p>", stream_data, details)
46 
47  E_MCL_ERROR_CODE result;
48 
49  ASSERT_NOT_NULL(stream_data);
50 
51  result = mcl_custom_data_set_meta_details(stream_data->base, details);
52 
53  DEBUG_LEAVE("retVal = <%d>", result);
54  return result;
55 }
56 
58 {
59  DEBUG_ENTRY("stream_data_t **stream_data = <%p>", stream_data)
60 
61  custom_data_destroy(&((*stream_data)->base));
62 
63  MCL_FREE(*stream_data);
64 
65  DEBUG_LEAVE("retVal = void");
66 }
struct mcl_json_t mcl_json_t
This struct is used for json handling.
E_MCL_ERROR_CODE mcl_stream_data_set_meta_details(mcl_stream_data_t *stream_data, const mcl_json_t *details)
Adds a custom details object to stream_data.
Definition: stream_data.c:43
MCL_EXPORT E_MCL_ERROR_CODE mcl_custom_data_set_meta_details(mcl_custom_data_t *custom_data, const mcl_json_t *details)
Adds a custom details object to custom_data.
Definition: custom_data.c:42
Memory module header file.
#define DEBUG_LEAVE(...)
Definition: log_util.h:81
#define DEBUG_ENTRY(...)
Definition: log_util.h:80
Common module interface header file.
#define MCL_NEW(p)
Definition: memory.h:121
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.
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
#define ASSERT_NOT_NULL(argument)
Definition: definitions.h:129
Log utility module header file.
E_MCL_ERROR_CODE
MCL Error code definitions. Every function returning an error code uses this enum values...
Definition: mcl_common.h:137
#define MCL_FREE(p)
Definition: memory.h:125
#define ASSERT_STATEMENT_CODE_MESSAGE(condition, statement, return_code,...)
Definition: definitions.h:121
Custom data module interface header file.
Stream data module header file.
#define ASSERT_CODE_MESSAGE(condition, return_code,...)
Definition: definitions.h:105
Definitions module header file.
void stream_data_destroy(stream_data_t **stream_data)
Destroys stream_data.
Definition: stream_data.c:57
struct mcl_stream_data_t mcl_stream_data_t
This struct is used for building the stream data type.
This struct is used for building the complete message of stream data.
Definition: stream_data.h:26
Success.
Definition: mcl_common.h:140
void custom_data_destroy(custom_data_t **custom_data)
Destroys custom_data.
Definition: custom_data.c:72
Memory allocation fail.
Definition: mcl_common.h:143
#define MCL_NULL
Definition: definitions.h:24
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