#ifndef JSONCOMMANDER_H #define JSONCOMMANDER_H #include #include "FileManager.h" /** * @class JsonCommander * * A class to execute the json commands which were sent by a client. * It also uses the file manager for writing and reading files. */ class JsonCommander { public: /** * Action for the json response. * send - send the json answer * closeAndSend - send the json answer and close the socket * close - close the socket */ enum Action { close, send, closeAndSend }; /** * Response for commands * * If action is set to close json can be uninitialized. */ struct Response { Action action; Json::Value json; }; /** * Creates a JsonCommaner */ JsonCommander(FileManager &fileManager); /** * Deletes the JsonCommander */ ~JsonCommander(); /** * Executes commands */ Response execute(const Json::Value &message); /** * Does version check before login */ Response testVersion(const Json::Value &message); /** * Checks if login is valid */ Response checkLogin(const Json::Value &message); private: /** * protocol version of the client server protocol */ const std::string protocolVersion = "0.2"; /** * Map of all commands * * Used to find the command function fast */ std::map commandsMap; /** * file manager for reading and writing files */ FileManager &fileManager; /** * * Last chunk number which was sent. */ int getFileRemaining; /** * Last chunk number which was received. */ int putFileReceived; /** * Executes the status command */ Response executeStatus(const Json::Value &message); /** * Executes the close command */ Response executeClose(const Json::Value &message); /** * Executes the list command */ Response executeList(const Json::Value &message); /** * Executes the put command */ Response executePut(const Json::Value &message); /** * Executes the putdata command */ Response executePutdata(const Json::Value &message); /** * Executes the get command */ Response executeGet(const Json::Value &message); /** * Executes the getdata command */ Response executeGetdata(const Json::Value &message); }; #endif