core.c File Reference

Core module implementation file. More...

#include "mcl_core/mcl_core.h"
#include "core.h"
#include "definitions.h"
#include "mcl_core/mcl_memory.h"
#include "string_util.h"
Include dependency graph for core.c:

Go to the source code of this file.

Macros

#define USER_AGENT_HEADER_FORMAT   "MCL/" MCL_VERSION_STRING " (%s)"
 

Functions

mcl_error_t mcl_core_initialize (mcl_core_configuration_t *configuration, mcl_core_t **core)
 
mcl_error_t mcl_core_onboard (mcl_core_t *core)
 
mcl_error_t mcl_core_rotate_key (mcl_core_t *core)
 
mcl_error_t mcl_core_update_credentials (mcl_core_t *core)
 
mcl_error_t mcl_core_get_access_token (mcl_core_t *core)
 
mcl_bool_t mcl_core_is_onboarded (mcl_core_t *core)
 
mcl_error_t mcl_core_get_last_access_token (mcl_core_t *core, char **token)
 
mcl_error_t mcl_core_get_last_token_time (mcl_core_t *core, char **token_time)
 
mcl_http_client_tmcl_core_get_http_client (mcl_core_t *core)
 
const char * mcl_core_get_host_name (mcl_core_t *core)
 
const char * mcl_core_get_client_id (mcl_core_t *core)
 
mcl_error_t mcl_core_destroy (mcl_core_t **core)
 

Detailed Description

Core module implementation file.

Definition in file core.c.

Macro Definition Documentation

#define USER_AGENT_HEADER_FORMAT   "MCL/" MCL_VERSION_STRING " (%s)"

Definition at line 15 of file core.c.

Function Documentation

mcl_error_t mcl_core_destroy ( mcl_core_t **  core)

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

Parameters
[in]corePreinitialized mcl_core_t object to destroy.
Returns

Definition at line 358 of file core.c.

References core_processor_destroy(), MCL_DEBUG, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FREE, MCL_NULL, and MCL_OK.

Referenced by mcl_core_initialize().

Here is the call graph for this function:

Here is the caller graph for this function:

mcl_error_t mcl_core_get_access_token ( mcl_core_t core)

This function is used to get access token from MindSphere. The access token contains the necessary authentication credentials for further exchange requests. The agent can use this function to get a new access token when MCL_UNAUTHORIZED is returned. The agent can use mcl_core_rotate_key function to renew its secret key if mcl_core_get_access_token function returns MCL_BAD_REQUEST.

Parameters
[in]coremcl_core_t object which is initialized and onboarded to MindSphere.
Returns

Definition at line 188 of file core.c.

References core_processor_get_access_token(), MCL_ASSERT_NOT_NULL, mcl_core_is_onboarded(), MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR, MCL_FUNCTION_LEAVE_LABEL, MCL_INFO, MCL_NOT_ONBOARDED, MCL_OK, and MCL_TRUE.

Here is the call graph for this function:

const char* mcl_core_get_client_id ( mcl_core_t core)

This function returns the client id.

User should not free/manipulate the client id buffer.

Parameters
[in]corePreinitialized mcl_core_t object.
Returns
  • Pointer to client id in case of success.
  • NULL if core is either NULL or is not initialized.

Definition at line 342 of file core.c.

References mcl_core_is_onboarded(), MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_NULL, and MCL_TRUE.

Here is the call graph for this function:

const char* mcl_core_get_host_name ( mcl_core_t core)

This function returns the host name.

Parameters
[in]corePreinitialized mcl_core_t object.
Returns
  • Pointer to host name in case of success.
  • NULL if core is either NULL or is not initialized.

Definition at line 326 of file core.c.

References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, and MCL_NULL.

mcl_http_client_t* mcl_core_get_http_client ( mcl_core_t core)

This function returns the http client.

Parameters
[in]corePreinitialized mcl_core_t object.
Returns

Definition at line 310 of file core.c.

References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, and MCL_NULL.

mcl_error_t mcl_core_get_last_access_token ( mcl_core_t core,
char **  token 
)

This function returns a copy of last received access token.

Parameters
[in]corePreinitialized mcl_core_t object.
[out]tokenThe lastly received access token.
Returns

Definition at line 235 of file core.c.

References MCL_ASSERT_NOT_NULL, MCL_CALLOC, mcl_core_is_onboarded(), MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FUNCTION_LEAVE_LABEL, MCL_NO_ACCESS_TOKEN_EXISTS, MCL_NOT_ONBOARDED, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, MCL_TRUE, string_util_memcpy(), and string_util_strlen().

Here is the call graph for this function:

mcl_error_t mcl_core_get_last_token_time ( mcl_core_t core,
char **  token_time 
)

This function returns the time when last received access token is generated, NULL if server time is not received.

Parameters
[in]corePreinitialized # mcl_core_t object.
[out]token_timeThe epoch time when last received access token is generated.
Returns

Definition at line 274 of file core.c.

References MCL_ASSERT_NOT_NULL, MCL_CALLOC, MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FUNCTION_LEAVE_LABEL, MCL_NO_SERVER_TIME, MCL_NULL, MCL_OK, MCL_OUT_OF_MEMORY, string_util_memcpy(), and string_util_strlen().

Here is the call graph for this function:

mcl_error_t mcl_core_initialize ( mcl_core_configuration_t configuration,
mcl_core_t **  core 
)

This function creates and initializes an object of type mcl_core_t according to the configuration parameters passed in as an argument. Memory is allocated for the core object and configuration parameters are copied to it.

Parameters
[in]configurationData structure holding the configuration parameters for the core object.
[out]coreCore handle which is going to be initialized.
Returns

Definition at line 17 of file core.c.

References core_configuration_log(), core_configuration_validate(), core_processor_initialize(), MCL_ASSERT_CODE_MESSAGE, MCL_ASSERT_NOT_NULL, MCL_ASSERT_STATEMENT_CODE_MESSAGE, mcl_core_destroy(), MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FUNCTION_LEAVE_LABEL, MCL_INFO, MCL_NEW, MCL_NULL, MCL_OK, and MCL_OUT_OF_MEMORY.

Here is the call graph for this function:

mcl_bool_t mcl_core_is_onboarded ( mcl_core_t core)

This function is used to determine if core handle is onboarded.

Parameters
[in]coreThe core handle on which the onboarding check will be performed.
Returns
MCL_TRUE if core is onboarded. Otherwise MCL_FALSE.

Definition at line 220 of file core.c.

References MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FALSE, MCL_NULL, and MCL_TRUE.

Referenced by mcl_core_get_access_token(), mcl_core_get_client_id(), mcl_core_get_last_access_token(), mcl_core_onboard(), mcl_core_rotate_key(), and mcl_core_update_credentials().

Here is the caller graph for this function:

mcl_error_t mcl_core_onboard ( mcl_core_t core)

This function registers the agent to MindSphere which is called Onboarding.

Parameters
[in]corePreinitialized mcl_core_t object.
Returns

Definition at line 54 of file core.c.

References core_processor_register(), MCL_ALREADY_ONBOARDED, MCL_ASSERT_NOT_NULL, MCL_ASSERT_OK, mcl_core_is_onboarded(), MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR, MCL_FALSE, MCL_FUNCTION_LEAVE_LABEL, MCL_INFO, MCL_NULL, and MCL_OK.

Here is the call graph for this function:

mcl_error_t mcl_core_rotate_key ( mcl_core_t core)

This function is used by the agent which is already onboarded to MindSphere to generate a new authentication key using the authentication key acquired earlier. Key rotation can be applied only when there is an authentication key available. Onboarding key is not necessary for key rotation.

Parameters
[in]coremcl_core_t object which is initialized and onboarded to MindSphere.
Returns

Definition at line 101 of file core.c.

References core_processor_register(), MCL_ASSERT_NOT_NULL, MCL_ASSERT_OK, mcl_core_is_onboarded(), MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_ERROR, MCL_FALSE, MCL_FUNCTION_LEAVE_LABEL, MCL_INFO, MCL_NOT_ONBOARDED, MCL_NULL, and MCL_OK.

Here is the call graph for this function:

mcl_error_t mcl_core_update_credentials ( mcl_core_t core)

This function is used by the agent which is already onboarded to update credentials mcl_core_t handle bears typically because the credentials are changed by another process and the mcl_core_t handle has to be synchronized.

Parameters
[in]coremcl_core_t object which is initialized and onboarded to MindSphere.
Returns

Definition at line 149 of file core.c.

References core_processor_update_credentials(), MCL_ASSERT_NOT_NULL, MCL_ASSERT_OK, mcl_core_is_onboarded(), MCL_DEBUG_ENTRY, MCL_DEBUG_LEAVE, MCL_FUNCTION_LEAVE_LABEL, MCL_NOT_ONBOARDED, MCL_NULL, and MCL_TRUE.

Here is the call graph for this function: