Dispatch Challenge
Syncmultiplethreadssharingaresource
Classes | Typedefs | Functions | Variables
main.cpp File Reference
#include <iostream>
#include <map>
#include <string>
#include <functional>
#include <exception>
#include <vector>
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
Include dependency graph for main.cpp:

Go to the source code of this file.

Classes

class  Controller
 controller class of functions to "dispatch" from Command Dispatcher More...
 
class  CommandDispatcher
 

Typedefs

typedef std::function< bool(rapidjson::Value &)> CommandHandler
 

Functions

void debugPrinter (std::string id, std::string msg)
 DEBUG PRINTER function. More...
 
void exceptionPrinter (const char *excpt)
 EXCEPTION HANDLER function. More...
 
int main ()
 

Variables

bool g_done = false
 
bool TEST_ALL = true
 test all functionality before prompting user More...
 
bool VERBOSE = false
 turn on verbose messages More...
 
bool DEBUG = false
 turn on debug messages More...
 
auto fail_command
 
auto help_command
 
auto help_command_fail
 
auto exit_command
 
auto exit_command_fail
 
auto sum_command
 
auto sum_command_long
 
auto sum_command_floats
 
auto sum_command_fail_1
 
auto sum_command_fail_2
 
auto mean_command
 
auto mean_command_fraction
 
auto mean_command_long
 
auto query_payload_command
 

Typedef Documentation

◆ CommandHandler

typedef std::function<bool(rapidjson::Value &)> CommandHandler

Definition at line 546 of file main.cpp.

Function Documentation

◆ debugPrinter()

void debugPrinter ( std::string  id,
std::string  msg 
)

DEBUG PRINTER function.

Parameters
idan integer that defines thread number (0 for main)
msga string containing message to be printed

Prints to standard error

Warning
NOT thread-safe; must be called within a thread-safe scope

Definition at line 54 of file main.cpp.

◆ exceptionPrinter()

void exceptionPrinter ( const char *  excpt)

EXCEPTION HANDLER function.

Parameters
excpta const char* containing a message

Prints to standard out

Warning
NOT thread-safe; must be called within a thread-safe scope

Definition at line 70 of file main.cpp.

◆ main()

int main ( )
Note
exit_command commented out to allow fallthrough to user prompt. If uncommented, exit_command will successfully exit program prior to user prompt. Ok to uncomment if desired.
The "//

Definition at line 753 of file main.cpp.

Variable Documentation

◆ DEBUG

bool DEBUG = false

turn on debug messages

Definition at line 41 of file main.cpp.

◆ exit_command

auto exit_command
Initial value:
= R"(
{
"command":"exit",
"payload": {
"reason":"Exiting program on user request."
}
}
)"

Definition at line 109 of file main.cpp.

◆ exit_command_fail

auto exit_command_fail
Initial value:
= R"(
{
"command":"exit",
"payload": {
"booga":"gooba"
}
}
)"

Definition at line 118 of file main.cpp.

◆ fail_command

auto fail_command
Initial value:
= R"(
{
"command":"fail",
"payload": {
"Does not":"really matter what is in here."
}
}
)"

Definition at line 81 of file main.cpp.

◆ g_done

bool g_done = false

Definition at line 35 of file main.cpp.

◆ help_command

auto help_command
Initial value:
= R"(
{
"command":"help",
"payload": {
"usage":"Enter json command in 'command':'<command>','payload': { // json payload of arguments }"
}
}
)"

Definition at line 91 of file main.cpp.

◆ help_command_fail

auto help_command_fail
Initial value:
= R"(
{
"command":"help",
"payload": {
"reason":"Not usage."
}
}
)"

Definition at line 100 of file main.cpp.

◆ mean_command

auto mean_command
Initial value:
= R"(
{
"command": "mean_ints",
"payload": {
"addends": [1, 2, 3, 4, 5]
}
}
)"

Definition at line 173 of file main.cpp.

◆ mean_command_fraction

auto mean_command_fraction
Initial value:
= R"(
{
"command": "mean_ints",
"payload": {
"addends": [1, 2, 2]
}
}
)"

Definition at line 182 of file main.cpp.

◆ mean_command_long

auto mean_command_long
Initial value:
= R"(
{
"command": "mean_ints",
"payload": {
"addends": [1, 2, 3, 4, 5, 100, 999999999, -1, 0, -999]
}
}
)"

Definition at line 191 of file main.cpp.

◆ query_payload_command

auto query_payload_command
Initial value:
= R"(
{
"command": "query_payload",
"payload": {
"hello": "world",
"t": true ,
"f": false,
"n": null,
"i": 123,
"pi": 3.1416,
"a": [1, 2, 3, 4]
}
}
)"

Definition at line 200 of file main.cpp.

◆ sum_command

auto sum_command
Initial value:
= R"(
{
"command": "sum_ints",
"payload": {
"addends": [1, 2, 3]
}
}
)"

Definition at line 127 of file main.cpp.

◆ sum_command_fail_1

auto sum_command_fail_1
Initial value:
= R"(
{
"command": "sum_ints",
"payload": {
"addends": ["apples", "oranges", "turtles"]
}
}
)"

Definition at line 154 of file main.cpp.

◆ sum_command_fail_2

auto sum_command_fail_2
Initial value:
= R"(
{
"command": "sum_ints",
"payload": {
"well":"formed",
"json":"test"
}
}
)"

Definition at line 163 of file main.cpp.

◆ sum_command_floats

auto sum_command_floats
Initial value:
= R"(
{
"command": "sum_ints",
"payload": {
"addends": [1, 2, 3, 4.5, 5.0, 100.1, 999999999.1, -1.1, 0, -999.1]
}
}
)"

Definition at line 145 of file main.cpp.

◆ sum_command_long

auto sum_command_long
Initial value:
= R"(
{
"command": "sum_ints",
"payload": {
"addends": [1, 2, 3, 4, 5, 100, 999999999, -1, 0, -999]
}
}
)"

Definition at line 136 of file main.cpp.

◆ TEST_ALL

bool TEST_ALL = true

test all functionality before prompting user

Definition at line 39 of file main.cpp.

◆ VERBOSE

bool VERBOSE = false

turn on verbose messages

Definition at line 40 of file main.cpp.