store.c File Reference

This file implements MCL Store Interface. More...

#include "store.h"
#include "time_series.h"
#include "custom_data.h"
#include "stream_data.h"
#include "data_source_configuration.h"
#include "event_list.h"
#include "file.h"
#include "log_util.h"
#include "memory.h"
#include "definitions.h"
#include "mcl/mcl_store.h"
#include "time_util.h"
Include dependency graph for store.c:

Go to the source code of this file.

Data Structures

struct  item_meta_payload_local_t
 

Enumerations

enum  E_STORE_DATA_PRIORITY { PRIORITY_HIGH, PRIORITY_LOW }
 
enum  E_EVENT_VERSION { EVENT_VERSION_1_0 = 0, EVENT_VERSION_2_0, EVENT_VERSION_END }
 

Functions

void _store_list_destroy_callback (void **item)
 
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)
 
static E_MCL_ERROR_CODE _compare_item_meta_of_event (void *data, const item_meta_payload_local_t *item_meta_payload)
 
static mcl_bool_t _is_valid_version (const char *version)
 
static mcl_bool_t _is_positive_integer (const char *version, mcl_size_t start_index, mcl_size_t end_index)
 
E_MCL_ERROR_CODE mcl_store_initialize (mcl_bool_t streamable, mcl_store_t **store)
 
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)
 
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)
 
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)
 
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)
 
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)
 
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)
 
E_MCL_ERROR_CODE mcl_store_destroy (mcl_store_t **store)
 
void store_data_set_state (store_data_t *store_data, E_STORE_DATA_STATE state)
 
E_STORE_DATA_STATE store_data_get_state (store_data_t *store_data)
 
E_MCL_ERROR_CODE store_data_remove (list_t *store_list, list_node_t *store_data_node)
 
mcl_size_t store_get_data_count (store_t *store)
 

Variables

static const string_t _event_versions [EVENT_VERSION_END]
 
static mcl_int32_t _event_severity_values [EVENT_VERSION_END][MCL_EVENT_SEVERITY_END]
 

Detailed Description

This file implements MCL Store Interface.


Date
Jul 18, 2016

Definition in file store.c.

Enumeration Type Documentation

Enumerator
EVENT_VERSION_1_0 
EVENT_VERSION_2_0 
EVENT_VERSION_END 

Definition at line 39 of file store.c.

Enumerator
PRIORITY_HIGH 

Represents the high priority data to be sent to MindSphere.

PRIORITY_LOW 

Represents the low priority data to be sent to MindSphere.

Definition at line 27 of file store.c.

Function Documentation

static E_MCL_ERROR_CODE _compare_item_meta_of_event ( void *  data,
const item_meta_payload_local_t item_meta_payload 
)
static
static mcl_bool_t _is_positive_integer ( const char *  version,
mcl_size_t  start_index,
mcl_size_t  end_index 
)
static

Definition at line 515 of file store.c.

References DEBUG_ENTRY, DEBUG_LEAVE, MCL_FALSE, and MCL_TRUE.

Referenced by _is_valid_version().

Here is the caller graph for this function:

static mcl_bool_t _is_valid_version ( const char *  version)
static

Definition at line 491 of file store.c.

References _is_positive_integer(), DEBUG_ENTRY, DEBUG_LEAVE, string_util_find(), and string_util_strlen().

Referenced by mcl_store_new_data_source_configuration(), mcl_store_new_file(), mcl_store_new_stream_data(), and mcl_store_new_time_series().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE mcl_store_destroy ( mcl_store_t **  store)

This function destroys the mcl_store_t object and frees any memory allocated.

Parameters
[in]storePreinitialized mcl_store_t object to destroy.
Returns

Definition at line 312 of file store.c.

References _store_list_destroy_callback(), ASSERT_NOT_NULL, DEBUG_ENTRY, DEBUG_LEAVE, list_destroy_with_content(), MCL_DEBUG, MCL_FREE, MCL_NULL, and MCL_OK.

Referenced by mcl_store_initialize().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE mcl_store_initialize ( mcl_bool_t  streamable,
mcl_store_t **  store 
)

This function creates and initializes an object of type mcl_store_t.

Store is used to hold different types of data. These data will be processed later by mcl_communication module to perform exchange operation. A store can be initialized as streamable or non-streamable (streamable). During exchange operation, data of a Non-Streamable store will be sent to MindSphere using a normal HTTP message, while the data of a streamable store will be sent using chunked Transfer-Encoding.

Parameters
[in]streamableIndicates if the content of this store will be exchanged using chunked Transfer-Encoding or not.
[out]storeThe newly initialized store.
Returns

Definition at line 68 of file store.c.

References ASSERT_CODE_MESSAGE, ASSERT_NOT_NULL, ASSERT_STATEMENT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, list_initialize(), MCL_DEBUG, MCL_FAIL, MCL_FALSE, MCL_NEW, MCL_NULL, MCL_OK, MCL_OPERATION_IS_NOT_SUPPORTED, MCL_OUT_OF_MEMORY, and mcl_store_destroy().

Here is the call graph for this function:

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 
)

This function creates and initializes a new mcl_custom_data_t structure.

Parameters
[in]storeMCL store which will contain the new mcl_custom_data_t structure created.
[in]versionVersion of the custom_data.
[in]typeType of the custom_data.
[in]routingRouting information which is optional. NULL can be given to use the default parser.
[out]custom_dataCreated and initialized mcl_custom_data_t object.
Returns

Definition at line 230 of file store.c.

References _store_add_data(), ASSERT_CODE_MESSAGE, ASSERT_NOT_NULL, ASSERT_STATEMENT_CODE_MESSAGE, custom_data_destroy(), custom_data_initialize(), DEBUG_ENTRY, DEBUG_LEAVE, MCL_OK, PRIORITY_HIGH, and STORE_DATA_CUSTOM.

Here is the call graph for this function:

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 
)

This function creates and initializes a new mcl_data_source_configuration_t structure.

Parameters
[in]storeMCL store which will contain the new mcl_data_source_configuration_t structure created.
[in]versionVersion of the data_source_configuration. Format must be in the form of MAJOR.MINOR where major and minor are non-negative integers.
[out]data_source_configurationCreated and initialized mcl_data_source_configuration_t object.
Returns

Definition at line 286 of file store.c.

References _is_valid_version(), _store_add_data(), ASSERT_CODE_MESSAGE, ASSERT_NOT_NULL, ASSERT_STATEMENT_CODE_MESSAGE, data_source_configuration_destroy(), data_source_configuration_initialize(), DEBUG_ENTRY, DEBUG_LEAVE, MCL_INVALID_PARAMETER, MCL_OK, MCL_TRUE, PRIORITY_HIGH, and STORE_DATA_DATA_SOURCE_CONFIGURATION.

Here is the call graph for this function:

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 
)

This function creates and initializes a new mcl_event_t structure.

Parameters
[in]storeMCL store which will contain the new mcl_event_t structure created.
[in]versionVersion of event. Format must be in the form of MAJOR.MINOR where major and minor are non-negative integers.
[in]typeType of event.
[in]type_versionVersion of event type.
[in]severitySeverity level declared in E_MCL_EVENT_SEVERITY.
[in]timestampTimestamp of the event in YYYY-MM-DDThh:mm:ss.sssZ format. Ex:2016-04-26T08:06:25.317Z.
[out]eventCreated and initialized event data struct.
Returns

Definition at line 125 of file store.c.

References _compare_item_meta_of_event(), _event_severity_values, _store_add_data(), ASSERT_CODE_MESSAGE, ASSERT_NOT_NULL, ASSERT_STATEMENT_CODE_MESSAGE, string_t::buffer, store_data_t::data, DEBUG_ENTRY, DEBUG_LEAVE, event_destroy(), event_initialize(), event_list_add_event(), event_list_destroy(), event_list_initialize(), EVENT_VERSION_END, list_exist(), MCL_EVENT_SEVERITY_END, MCL_EVENT_SEVERITY_ERROR, MCL_FAIL, MCL_INVALID_PARAMETER, MCL_NULL, MCL_OK, MCL_TRUE, event_list_t::meta, META_FIELD_PAYLOAD_TYPE_BUSINESS_EVENT, meta_field_values, PRIORITY_HIGH, STORE_DATA_EVENT_LIST, string_compare_with_cstr(), time_util_validate_timestamp(), item_meta_payload_local_t::type, and item_meta_payload_local_t::version.

Here is the call graph for this function:

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 
)

This function creates and initializes a new mcl_file_t structure.

Parameters
[in]storeMCL store which will contain the new mcl_file_t structure created.
[in]versionVersion of file type. Format must be in the form of MAJOR.MINOR where major and minor are non-negative integers.
[in]file_pathPath of the file to be added to store.
[in]file_nameName of the file. This name will be assigned to the file that is being uploaded.
[in]file_typeType of the file.
[in]routingRouting information which is optional. NULL can be given to use the default parser.
[out]fileCreated and initialized file data struct.
Returns

Definition at line 196 of file store.c.

References _is_valid_version(), _store_add_data(), ASSERT_CODE_MESSAGE, ASSERT_NOT_NULL, ASSERT_STATEMENT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, file_destroy(), file_initialize(), MCL_ERROR, MCL_FAIL, MCL_INVALID_PARAMETER, MCL_OK, MCL_TRUE, PRIORITY_HIGH, and STORE_DATA_FILE.

Here is the call graph for this function:

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 
)

This function creates and initializes a new streamable mcl_stream_data_t structure.

With this data type, user can specify a callback and context to fill the payload of the custom data. The callback will be called while performing the send operation.

Warning
The store must be initialized as 'streamable' to be able to add this type of item.
Parameters
[in]storeMCL store which will contain the new mcl_stream_data_t structure created.
[in]versionVersion of the stream_data. Format must be in the form of MAJOR.MINOR where major and minor are non-negative integers.
[in]typeType of the stream_data.
[in]routingRouting information which is optional. NULL can be given to use the default parser.
[in]stream_data_read_callbackStream data read callback function.
[in]user_contextUser context used to sent to the callback function.
[out]stream_dataCreated and initialized stream_data data struct.
Returns

Definition at line 255 of file store.c.

References _is_valid_version(), _store_add_data(), ASSERT_CODE_MESSAGE, ASSERT_NOT_NULL, ASSERT_STATEMENT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, MCL_INVALID_PARAMETER, MCL_OK, MCL_TRUE, PRIORITY_HIGH, STORE_DATA_STREAM, stream_data_destroy(), and stream_data_initialize().

Here is the call graph for this function:

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 
)

This function creates and initializes a new mcl_time_series_t structure.

Parameters
[in]storeMCL store which will contain the new mcl_time_series_t structure created.
[in]versionVersion of the time series data. Format must be in the form of MAJOR.MINOR where major and minor are non-negative integers.
[in]configuration_idConfiguration ID of the time series data.
[in]routingRouting information which is optional. NULL can be given to use the default parser.
[out]time_seriesCreated and initialized time series data struct.
Returns

Definition at line 98 of file store.c.

References _is_valid_version(), _store_add_data(), ASSERT_CODE_MESSAGE, ASSERT_NOT_NULL, ASSERT_STATEMENT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, MCL_INVALID_PARAMETER, MCL_OK, MCL_TRUE, PRIORITY_HIGH, STORE_DATA_TIME_SERIES, time_series_destroy(), and time_series_initialize().

Here is the call graph for this function:

E_STORE_DATA_STATE store_data_get_state ( store_data_t store_data)

This function is used to get the state of the data.

Parameters
[in]store_dataCurrent store data.
Returns
Returns the state of the data.

Definition at line 345 of file store.c.

References DEBUG_ENTRY, DEBUG_LEAVE, MCL_DEBUG, and store_data_t::state.

Referenced by _exchange_clear_sent_data_from_store(), _exchange_fill_http_request(), and _exchange_update_store_data_state().

Here is the caller graph for this function:

E_MCL_ERROR_CODE store_data_remove ( list_t store_list,
list_node_t store_data_node 
)

This function is used to remove a store data from the store.

Needs to know in which list ( high_priority_list or low_priority_list ) this data resides.

Parameters
[in]store_listThe list in the store holding the data.
[in]store_data_nodeList node of the data requested to be removed.
Returns

Definition at line 355 of file store.c.

References _store_list_destroy_callback(), DEBUG_ENTRY, DEBUG_LEAVE, and list_remove_with_content().

Referenced by _exchange_clear_sent_data_from_store().

Here is the call graph for this function:

Here is the caller graph for this function:

void store_data_set_state ( store_data_t store_data,
E_STORE_DATA_STATE  state 
)

This function is used to set the state of the store data.

Parameters
[in]store_dataCurrent store data.
[in]stateNew state of the data.

Definition at line 334 of file store.c.

References DEBUG_ENTRY, DEBUG_LEAVE, MCL_DEBUG, and store_data_t::state.

Referenced by _exchange_add_current_data_to_request(), _exchange_add_current_data_to_request_by_streaming(), _exchange_fill_http_request(), _exchange_prepare_data(), and _exchange_update_store_data_state().

Here is the caller graph for this function:

mcl_size_t store_get_data_count ( store_t store)

This function is used to get the count of items in store.

Parameters
[in]storeThe store handle.
Returns
Returns the number of store data items.

Definition at line 366 of file store.c.

References mcl_list_t::count, DEBUG_ENTRY, DEBUG_LEAVE, store_t::high_priority_list, and store_t::low_priority_list.

Referenced by http_processor_exchange(), and http_processor_stream().

Here is the caller graph for this function:

Variable Documentation

mcl_int32_t _event_severity_values[EVENT_VERSION_END][MCL_EVENT_SEVERITY_END]
static
Initial value:
=
{
{1, 2, 3},
{20, 30, 40}
}

Definition at line 52 of file store.c.

Referenced by mcl_store_new_event().

const string_t _event_versions[EVENT_VERSION_END]
static
Initial value:
=
{
}
Strings with this type will NOT allocate its buffer during initialization (buffer only points of the ...
Definition: string_type.h:37

Definition at line 46 of file store.c.