mapping.c
Go to the documentation of this file.
1 
10 #include "mapping.h"
11 #include "mcl_core/mcl_memory.h"
13 
15 {
16  mcl_error_t code = MCL_OK;
17 
18  MCL_DEBUG_ENTRY("mcl_mapping_t **mapping = <%p>", mapping);
19 
20  // Null check.
21  MCL_ASSERT_NOT_NULL(mapping, code);
22 
23  // Allocate memory for mapping.
24  if (MCL_NULL != MCL_NEW(*mapping))
25  {
26  // Set initial values.
27  (*mapping)->data_point_id = MCL_NULL;
28  (*mapping)->entity_id = MCL_NULL;
29  (*mapping)->property_set_name = MCL_NULL;
30  (*mapping)->property_name = MCL_NULL;
31  (*mapping)->keep_mapping = MCL_TRUE;
32  }
33  else
34  {
35  MCL_ERROR_STRING("Not enough memory to allocate new mapping.");
36  code = MCL_OUT_OF_MEMORY;
37  }
38 
40  MCL_DEBUG_LEAVE("retVal = <%d>", code);
41  return code;
42 }
43 
45 {
46  mcl_error_t code;
47 
48  MCL_DEBUG_ENTRY("mcl_mapping_t *mapping = <%p>, E_MCL_MAPPING_PARAMETER parameter = <%d>, const void *value = <%p>", mapping, parameter, value);
49 
50  // Null check.
51  MCL_ASSERT_NOT_NULL(mapping, code);
52  MCL_ASSERT_NOT_NULL(value, code);
53 
54  switch (parameter)
55  {
57  code = mcl_string_util_reset(value, &(mapping->data_point_id));
58  break;
59 
61  code = mcl_string_util_reset(value, &(mapping->entity_id));
62  break;
63 
65  code = mcl_string_util_reset(value, &(mapping->property_set_name));
66  break;
67 
69  code = mcl_string_util_reset(value, &(mapping->property_name));
70  break;
71 
73  mapping->keep_mapping = *((const mcl_bool_t *) value);
74  code = MCL_OK;
75  break;
76 
77  default:
78  code = MCL_INVALID_PARAMETER;
79  break;
80  }
81 
83  MCL_DEBUG_LEAVE("retVal = <%d>", code);
84  return code;
85 }
86 
88 {
89  mcl_error_t code = MCL_OK;
90 
91  MCL_DEBUG_ENTRY("mapping_t *mapping = <%p>", mapping);
92 
93  // Checks whether all mandatory parameters of a mapping are set or not.
94  if ((MCL_NULL == mapping->data_point_id) || (MCL_NULL == mapping->property_name) || (MCL_NULL == mapping->property_set_name))
95  {
96  code = MCL_INVALID_PARAMETER;
97  }
98 
99  MCL_DEBUG_LEAVE("retVal = <%d>", code);
100  return code;
101 }
102 
104 {
105  MCL_DEBUG_ENTRY("mcl_mapping_t **mapping = <%p>", mapping);
106 
107  // Destroys the mapping data structure.
108  if ((MCL_NULL != mapping) && (MCL_NULL != *mapping))
109  {
110  MCL_FREE((*mapping)->data_point_id);
111  MCL_FREE((*mapping)->entity_id);
112  MCL_FREE((*mapping)->property_set_name);
113  MCL_FREE((*mapping)->property_name);
114  MCL_FREE(*mapping);
115  }
116 
117  MCL_DEBUG_LEAVE("retVal = void");
118 }
Keep mapping (as mcl_bool_t *), true by default.
Definition: mcl_mapping.h:43
#define MCL_FUNCTION_LEAVE_LABEL
MCL_OK
Mapping module header file.
Entity ID (as char *), do not set if it is the agent itself.
Definition: mcl_mapping.h:40
struct mcl_mapping_t mcl_mapping_t
Definition: mcl_mapping.h:32
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(...)
E_MCL_MAPPING_PARAMETER
Definition: mcl_mapping.h:37
#define MCL_ERROR_STRING(string)
char * data_point_id
Mapping ID.
Definition: mapping.h:19
Property name (as char *), e.g. Voltage.
Definition: mcl_mapping.h:42
#define MCL_NEW(p)
#define MCL_NULL
Property set name (as char *), e.g. ElectricalProperties.
Definition: mcl_mapping.h:41
char * property_name
Property name.
Definition: mapping.h:22
mcl_error_t mapping_validate(mapping_t *mapping)
Definition: mapping.c:87
#define MCL_FREE(p)
#define MCL_ASSERT_NOT_NULL(argument, return_variable)
Data point mapping module interface header file.
void mcl_mapping_destroy(mcl_mapping_t **mapping)
Definition: mapping.c:103
mcl_uint8_t mcl_bool_t
Data point ID (as char *).
Definition: mcl_mapping.h:39
MCL_OUT_OF_MEMORY
mcl_error_t mcl_mapping_set_parameter(mcl_mapping_t *mapping, E_MCL_MAPPING_PARAMETER parameter, const void *value)
Definition: mapping.c:44
MCL_INVALID_PARAMETER
#define MCL_DEBUG_LEAVE(...)
#define MCL_TRUE
mcl_error_t mcl_mapping_initialize(mcl_mapping_t **mapping)
Definition: mapping.c:14
char * property_set_name
Property set name.
Definition: mapping.h:21