AWS IoT C++ SDK
|
Client Core State Class. More...
#include <ClientCoreState.hpp>
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 | |
ClientCoreState & | operator= (const ClientCoreState &) &=delete |
ClientCoreState & | operator= (ClientCoreState &&) &=delete |
![]() | |
virtual uint16_t | GetNextActionId ()=0 |
Get Action ID of the next Action. More... | |
ActionState (const ActionState &)=delete | |
ActionState (ActionState &&)=delete | |
ActionState & | operator= (const ActionState &) &=delete |
ActionState & | operator= (ActionState &&) &=delete |
Data Fields | |
ApplicationDisconnectCallbackPtr | disconnect_handler_ptr_ |
Pointer to the Application Disconnect Callback. | |
std::shared_ptr< DisconnectCallbackContextData > | p_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< ReconnectCallbackContextData > | p_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< ResubscribeCallbackContextData > | p_resubscribe_app_handler_data_ |
Data to be passed to the Application Handler. | |
std::shared_ptr< NetworkConnection > | p_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::CreateHandlerPtr > | action_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. | |
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
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
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
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
|
inline |
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.
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.
void awsiotsdk::ClientCoreState::DeleteExpiredAcks | ( | ) |
Deletes all Acks where the timeouts have expired. Responds with Code indicating request timeout
void awsiotsdk::ClientCoreState::DeletePendingAck | ( | uint16_t | action_id | ) |
action_id | - Action ID |
ResponseCode awsiotsdk::ClientCoreState::EnqueueOutboundAction | ( | ActionType | action_type, |
std::shared_ptr< ActionData > | action_data, | ||
uint16_t & | action_id_out | ||
) |
void awsiotsdk::ClientCoreState::ForwardReceivedAck | ( | uint16_t | action_id, |
ResponseCode | rc | ||
) |
action_id | - Action ID |
rc | - Response Code to pass to the Handler if found |
ResponseCode awsiotsdk::ClientCoreState::GetActionCreateHandler | ( | ActionType | action_type, |
Action::CreateHandlerPtr * | p_action_create_handler | ||
) |
|
inline |
This sync point is used to indicate SDK is still continuing execution. Set to false when exiting
|
inline |
|
inlinevirtual |
Implements awsiotsdk::ActionState.
Reimplemented in awsiotsdk::mqtt::ClientState.
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
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 |
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
thread_task_out_sync |
process_queued_actions_ ||
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
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 |
ResponseCode awsiotsdk::ClientCoreState::RegisterPendingAck | ( | uint16_t | action_id, |
ActionData::AsyncAckNotificationHandlerPtr | p_async_ack_handler | ||
) |
action_id | - Action ID |
p_async_ack_handler | - Handler to call on response |
|
inline |
size_t | max_queue_size |
|
inline |
process_queued_actions | value to set it to |
|
protected |
action_id | - ID of the Action that response was received for |
rc | - Received response |