Dispatch Challenge
Syncmultiplethreadssharingaresource
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CommandDispatcher Class Reference
Collaboration diagram for CommandDispatcher:
Collaboration graph
[legend]

Public Member Functions

 CommandDispatcher ()
 
virtual ~CommandDispatcher ()
 
bool addCommandHandler (std::string command, CommandHandler handler)
 adds a command and handler pair to the map More...
 
bool dispatchCommand (std::string command_json)
 initial receiver of command More...
 

Private Member Functions

 CommandDispatcher (const CommandDispatcher &)=delete
 
CommandDispatcheroperator= (const CommandDispatcher &)=delete
 

Private Attributes

std::string CUR_SCOPE = "class CommandDispatcher"
 
std::map< std::string, CommandHandlercommand_handlers_
 map of command handlers More...
 
std::map< std::string, CommandHandler >::iterator map_itr
 iterator for the map More...
 
rapidjson::Document doc
 

Detailed Description

Definition at line 548 of file main.cpp.

Constructor & Destructor Documentation

◆ CommandDispatcher() [1/2]

CommandDispatcher::CommandDispatcher ( )
inline

Definition at line 551 of file main.cpp.

◆ ~CommandDispatcher()

virtual CommandDispatcher::~CommandDispatcher ( )
inlinevirtual

Definition at line 560 of file main.cpp.

◆ CommandDispatcher() [2/2]

CommandDispatcher::CommandDispatcher ( const CommandDispatcher )
privatedelete

Member Function Documentation

◆ addCommandHandler()

bool CommandDispatcher::addCommandHandler ( std::string  command,
CommandHandler  handler 
)
inline

adds a command and handler pair to the map

Parameters
commanda string
handlera CommandHandler object containing a DOM value
Returns
true if addition successful, false if not

add command and handler pair to map

check if command already added to map

Definition at line 585 of file main.cpp.

◆ dispatchCommand()

bool CommandDispatcher::dispatchCommand ( std::string  command_json)
inline

initial receiver of command

Parameters
command_jsona raw string of JSON commands
Exceptions
exceptionif JSON malformed
exceptionif JSON contains no member "command"
exceptionif JSON contains no member "payload"
exceptionif no match for command found in map
Returns
true if command dispatched to handler
Todo:
change cout calls to shared print?
Todo:
maybe typcast instead?

Definition at line 623 of file main.cpp.

◆ operator=()

CommandDispatcher& CommandDispatcher::operator= ( const CommandDispatcher )
privatedelete

Member Data Documentation

◆ command_handlers_

std::map<std::string, CommandHandler> CommandDispatcher::command_handlers_
private

map of command handlers

Definition at line 730 of file main.cpp.

◆ CUR_SCOPE

std::string CommandDispatcher::CUR_SCOPE = "class CommandDispatcher"
private

Definition at line 728 of file main.cpp.

◆ doc

rapidjson::Document CommandDispatcher::doc
private

Definition at line 735 of file main.cpp.

◆ map_itr

std::map<std::string, CommandHandler>::iterator CommandDispatcher::map_itr
private
Initial value:
=
this->command_handlers_.begin()

iterator for the map

Definition at line 732 of file main.cpp.


The documentation for this class was generated from the following file: