AWS IoT C++ SDK
Loading...
Searching...
No Matches
Data Structures | Public Types | Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
awsiotsdk::ClientCoreState Class Reference

Client Core State Class. More...

#include <ClientCoreState.hpp>

Inheritance diagram for awsiotsdk::ClientCoreState:
awsiotsdk::ActionState awsiotsdk::mqtt::ClientState

Data Structures

class  PendingAckData
 Pending Ack Data Class. More...
 

Public Types

typedef std::function< ResponseCode(util::String mqtt_client_id, std::shared_ptr< DisconnectCallbackContextData > p_app_handler_data)> ApplicationDisconnectCallbackPtr
 Define Handler for Disconnect Callbacks. More...
 
typedef std::function< ResponseCode(util::String mqtt_client_id, std::shared_ptr< ReconnectCallbackContextData > p_app_handler_data, ResponseCode reconnect_result)> ApplicationReconnectCallbackPtr
 Define Handler for Reconnect Callbacks. More...
 
typedef std::function< ResponseCode(util::String mqtt_client_id, std::shared_ptr< ResubscribeCallbackContextData > p_app_handler_data, ResponseCode resubscribe_result)> ApplicationResubscribeCallbackPtr
 Define Handler for Resubscribe Callbacks. More...
 

Public Member Functions

virtual uint16_t GetNextActionId ()
 Overload for Get next Action ID. More...
 
size_t GetMaxActionQueueSize ()
 Get current value of maximum action queue size. More...
 
void SetMaxActionQueueSize (size_t max_queue_size)
 Set max size for action queue. More...
 
std::shared_ptr< std::atomic_bool > GetCoreExecutionSyncPoint ()
 Get pointer to sync point used for execution status of the Core instance. More...
 
void SetProcessQueuedActions (bool process_queued_actions)
 Sets whether the Client is allowed to process queue actions. More...
 
bool CanProcessQueuedActions ()
 Get whether the Client can process queued actions. More...
 
void ProcessOutboundActionQueue (std::shared_ptr< std::atomic_bool > thread_task_out_sync)
 Process the outbound action queue. More...
 
ResponseCode PerformAction (ActionType action_type, std::shared_ptr< ActionData > action_data, std::chrono::milliseconds action_reponse_timeout)
 Perform Action in Blocking Mode. More...
 
ResponseCode RegisterAction (ActionType action_type, Action::CreateHandlerPtr p_action_create_handler, std::shared_ptr< ActionState > p_action_state)
 Register Action for execution by Client Core. More...
 
ResponseCode GetActionCreateHandler (ActionType action_type, Action::CreateHandlerPtr *p_action_create_handler)
 Get the Create Factory Method for the specified action type. More...
 
ResponseCode EnqueueOutboundAction (ActionType action_type, std::shared_ptr< ActionData > action_data, uint16_t &action_id_out)
 Enqueue Action for processing in Outbound Queue. More...
 
ResponseCode RegisterPendingAck (uint16_t action_id, ActionData::AsyncAckNotificationHandlerPtr p_async_ack_handler)
 Register Ack Handler for provided action id. More...
 
void DeletePendingAck (uint16_t action_id)
 Delete Ack Handler for specified Action ID. More...
 
void ForwardReceivedAck (uint16_t action_id, ResponseCode rc)
 Call registered Ack handler if it exists for specified Packet id. More...
 
void DeleteExpiredAcks ()
 Delete all expired Acks. More...
 
void ClearRegisteredActions ()
 Clears all registered Actions. More...
 
void ClearOutboundActionQueue ()
 Clears all pending outbound Actions. More...
 
 ClientCoreState ()
 Default Constructor.
 
virtual ~ClientCoreState ()
 Destructor.
 
 ClientCoreState (const ClientCoreState &)=delete
 
 ClientCoreState (ClientCoreState &&)=delete
 
ClientCoreStateoperator= (const ClientCoreState &) &=delete
 
ClientCoreStateoperator= (ClientCoreState &&) &=delete
 
- Public Member Functions inherited from awsiotsdk::ActionState
virtual uint16_t GetNextActionId ()=0
 Get Action ID of the next Action. More...
 
 ActionState (const ActionState &)=delete
 
 ActionState (ActionState &&)=delete
 
ActionStateoperator= (const ActionState &) &=delete
 
ActionStateoperator= (ActionState &&) &=delete
 

Data Fields

ApplicationDisconnectCallbackPtr disconnect_handler_ptr_
 Pointer to the Application Disconnect Callback.
 
std::shared_ptr< DisconnectCallbackContextDatap_disconnect_app_handler_data_
 Data to be passed to the Application Handler.
 
ApplicationReconnectCallbackPtr reconnect_handler_ptr_
 Pointer to the Application Reconnect Callback.
 
std::shared_ptr< ReconnectCallbackContextDatap_reconnect_app_handler_data_
 Data to be passed to the Application Handler.
 
ApplicationResubscribeCallbackPtr resubscribe_handler_ptr_
 Pointer to the Application Resubscribe Callback.
 
std::shared_ptr< ResubscribeCallbackContextDatap_resubscribe_app_handler_data_
 Data to be passed to the Application Handler.
 
std::shared_ptr< NetworkConnectionp_network_connection_
 Network connection instance to use for this instance of the Client This is shared between Actions, public to avoid multiple shared pointer operations while passing as argument by ClientCore.
 

Protected Member Functions

void SyncActionHandler (uint16_t action_id, ResponseCode rc)
 Internal Action Handler for Sync Action responses. More...
 

Protected Attributes

std::atomic< uint16_t > next_action_id_
 Atomic, ID of the next Action that will be enqueued.
 
std::atomic_int cur_core_threads_
 Atomic, Count of currently running core threads.
 
std::atomic_int max_hardware_threads_
 Atomic, Count of the maximum allowed hardware threads.
 
std::atomic_size_t max_queue_size_
 Atomic, Current configured max queue size.
 
std::chrono::seconds ack_timeout_
 Timeout for pending Acks, older Acks are deleted with a failed response.
 
std::mutex register_action_lock_
 Mutex for Register Action Request flow.
 
std::mutex ack_map_lock_
 Mutex for Ack Map operations.
 
std::mutex sync_action_request_lock_
 Mutex for Sync Action Request flow.
 
std::mutex sync_action_response_lock_
 Mutex for Sync Action Response flow.
 
std::condition_variable sync_action_response_wait_
 Condition variable used to wake up calling thread on Sync Action response.
 
ResponseCode sync_action_response_
 Variable to store received Sync Action response.
 
std::atomic_bool process_queued_actions_
 Atomic, indicates whether currently queued Actions should be processed or not.
 
std::shared_ptr< std::atomic_bool > continue_execution_
 Atomic, Used to synchronize running threads, false value causes running threads to stop.
 
util::Map< ActionType, std::unique_ptr< Action > > action_map_
 Map containing currently initialized Action Instances.
 
util::Map< uint16_t, std::unique_ptr< PendingAckData > > pending_ack_map_
 Map containing currently pending Acks.
 
util::Map< ActionType, Action::CreateHandlerPtraction_create_handler_map_
 Map containing currently registered Action Types and corrosponding Factories.
 
util::Queue< std::pair< ActionType, std::shared_ptr< ActionData > > > outbound_action_queue_
 Queue of outbound actions.
 

Detailed Description

Defining a class for the Core Client State. This class is responsible for maintaing the state information for the core client It can also be extended to provide state information to Actions. It contains the action queue, an action registry and also keeps track of the Common Action State as well as the Network connection

Member Typedef Documentation

◆ ApplicationDisconnectCallbackPtr

typedef std::function<ResponseCode(util::String mqtt_client_id, std::shared_ptr<DisconnectCallbackContextData> p_app_handler_data)> awsiotsdk::ClientCoreState::ApplicationDisconnectCallbackPtr

This handler is used to provide notification to the application when a disconnect occurs NOTE: This handler should be NON-BLOCKING

◆ ApplicationReconnectCallbackPtr

typedef std::function<ResponseCode(util::String mqtt_client_id, std::shared_ptr<ReconnectCallbackContextData> p_app_handler_data, ResponseCode reconnect_result)> awsiotsdk::ClientCoreState::ApplicationReconnectCallbackPtr

This handler is used to provide notification to the application when a reconnect occurs NOTE: This handler should be NON-BLOCKING

◆ ApplicationResubscribeCallbackPtr

typedef std::function<ResponseCode(util::String mqtt_client_id, std::shared_ptr<ResubscribeCallbackContextData> p_app_handler_data, ResponseCode resubscribe_result)> awsiotsdk::ClientCoreState::ApplicationResubscribeCallbackPtr

This handler is used to provide notification to the application when a resubscribe occurs. NOTE: This handler should be NON-BLOCKING

Member Function Documentation

◆ CanProcessQueuedActions()

bool awsiotsdk::ClientCoreState::CanProcessQueuedActions ( )
inline
Returns
boolean value indicating status

◆ ClearOutboundActionQueue()

void awsiotsdk::ClientCoreState::ClearOutboundActionQueue ( )

Utility method to remove all pending outbound actions registered by the client. Also helps in breaking out of cyclic reference introduced when EnqueueOutboundAction is called.

◆ ClearRegisteredActions()

void awsiotsdk::ClientCoreState::ClearRegisteredActions ( )

Utility method to remove all registered actions by the client. Also helps in breaking out of cyclic reference introduced when RegisterAction is called.

◆ DeleteExpiredAcks()

void awsiotsdk::ClientCoreState::DeleteExpiredAcks ( )

Deletes all Acks where the timeouts have expired. Responds with Code indicating request timeout

◆ DeletePendingAck()

void awsiotsdk::ClientCoreState::DeletePendingAck ( uint16_t  action_id)
Parameters
action_id- Action ID

◆ EnqueueOutboundAction()

ResponseCode awsiotsdk::ClientCoreState::EnqueueOutboundAction ( ActionType  action_type,
std::shared_ptr< ActionData action_data,
uint16_t &  action_id_out 
)
Parameters
action_type- Type of the Action
action_data- Data to be passed to perform Action
action_id_out[out]- Action ID that was assigned to this action by the Client
Returns
ResponseCode indicating result of the API call

◆ ForwardReceivedAck()

void awsiotsdk::ClientCoreState::ForwardReceivedAck ( uint16_t  action_id,
ResponseCode  rc 
)
Parameters
action_id- Action ID
rc- Response Code to pass to the Handler if found

◆ GetActionCreateHandler()

ResponseCode awsiotsdk::ClientCoreState::GetActionCreateHandler ( ActionType  action_type,
Action::CreateHandlerPtr p_action_create_handler 
)
Parameters
action_type- Type of the Action for which the handler is required
p_action_create_handler[out]- Create factory method for this Action
Returns
ResponseCode indicating result of the API call

◆ GetCoreExecutionSyncPoint()

std::shared_ptr< std::atomic_bool > awsiotsdk::ClientCoreState::GetCoreExecutionSyncPoint ( )
inline

This sync point is used to indicate SDK is still continuing execution. Set to false when exiting

Returns
std::shared_ptr<std::atomic_bool> pointer to the sync point

◆ GetMaxActionQueueSize()

size_t awsiotsdk::ClientCoreState::GetMaxActionQueueSize ( )
inline
Returns
size_t max_queue_size_

◆ GetNextActionId()

virtual uint16_t awsiotsdk::ClientCoreState::GetNextActionId ( )
inlinevirtual
Returns
uint16_t Action ID

Implements awsiotsdk::ActionState.

Reimplemented in awsiotsdk::mqtt::ClientState.

◆ PerformAction()

ResponseCode awsiotsdk::ClientCoreState::PerformAction ( ActionType  action_type,
std::shared_ptr< ActionData action_data,
std::chrono::milliseconds  action_reponse_timeout 
)

This API will perform the Action in Blocking mode. The timeout for the action to give a valid response is provided as an argument. This API stops processing of all outbound actions until Response is received for the requested Action Type

Parameters
action_type- Type of the Action to be executed. Must be registered
action_data- Action Data to be passed as argument to the Action instance
action_reponse_timeout- Timeout for this API call
Returns
ResponseCode indicating result of the API call

◆ ProcessOutboundActionQueue()

void awsiotsdk::ClientCoreState::ProcessOutboundActionQueue ( std::shared_ptr< std::atomic_bool >  thread_task_out_sync)

This function processes the actions queued up in the Outbound action queue. The function accepts a Sync point that can be used to control execution in a separate thread. If the value is set to false for the sync point, the function will perform one action from the queue. This puts the running thread to sleep if there are no queued up actions. DO NOT call from main thread unless you have a separate thread to queue up actions

Parameters
thread_task_out_sync

process_queued_actions_ ||

◆ RegisterAction()

ResponseCode awsiotsdk::ClientCoreState::RegisterAction ( ActionType  action_type,
Action::CreateHandlerPtr  p_action_create_handler,
std::shared_ptr< ActionState p_action_state 
)

This function allows Actions to be registered to be executed at a later stage by Client Core. Actions must be registered before PerformAction can be called using the Action Type. This also applies to Creating Action runners which allow running Actions in dedicated Thread Tasks. Only one Action can be registered to each Action Type. If a second call is made with the same Action Type, the previous registration will be overwritten

Parameters
action_type- Type of the Action that will be created using the provided handler
p_action_create_handler- Factory method pointer which returns an Action instance
p_action_state- Shared_ptr to use as argument for Action create
Returns
ResponseCode indicating result of the API call

◆ RegisterPendingAck()

ResponseCode awsiotsdk::ClientCoreState::RegisterPendingAck ( uint16_t  action_id,
ActionData::AsyncAckNotificationHandlerPtr  p_async_ack_handler 
)
Parameters
action_id- Action ID
p_async_ack_handler- Handler to call on response
Returns
ResponseCode indicating result of the API call

◆ SetMaxActionQueueSize()

void awsiotsdk::ClientCoreState::SetMaxActionQueueSize ( size_t  max_queue_size)
inline
Parameters
size_tmax_queue_size

◆ SetProcessQueuedActions()

void awsiotsdk::ClientCoreState::SetProcessQueuedActions ( bool  process_queued_actions)
inline
Parameters
process_queued_actionsvalue to set it to

◆ SyncActionHandler()

void awsiotsdk::ClientCoreState::SyncActionHandler ( uint16_t  action_id,
ResponseCode  rc 
)
protected
Parameters
action_id- ID of the Action that response was received for
rc- Received response