| 1 |
#ifndef CSCOMMANDHANDLERBASE_H |
| 2 |
#define CSCOMMANDHANDLERBASE_H |
| 3 |
|
| 4 |
#include "file_logger.h" |
| 5 |
#include "JSON.h" |
| 6 |
#include <cl_command_event.h> |
| 7 |
#include <wx/event.h> |
| 8 |
#include <wx/sharedptr.h> |
| 9 |
#include <wx/string.h> |
| 10 |
|
| 11 |
class csManager; |
| 12 |
wxDECLARE_EVENT(wxEVT_COMMAND_PROCESSED, clCommandEvent); |
| 13 |
|
| 14 |
#define CHECK_STR_PARAM(str_option, sVal) \ |
| 15 |
if(!options.hasNamedObject(str_option)) { \ |
| 16 |
clERROR() << "Command is missing field:" << str_option; \ |
| 17 |
NotifyCompletion(); \ |
| 18 |
return; \ |
| 19 |
} \ |
| 20 |
sVal = options.namedObject(str_option).toString(); |
| 21 |
|
| 22 |
#define CHECK_INT_PARAM(str_option, iVal) \ |
| 23 |
if(!options.hasNamedObject(str_option)) { \ |
| 24 |
clERROR() << "Command is missing field:" << str_option; \ |
| 25 |
NotifyCompletion(); \ |
| 26 |
return; \ |
| 27 |
} \ |
| 28 |
iVal = options.namedObject(str_option).toInt(); |
| 29 |
|
| 30 |
#define CHECK_BOOL_PARAM(str_option, bVal) \ |
| 31 |
if(!options.hasNamedObject(str_option)) { \ |
| 32 |
clERROR() << "Command is missing field:" << str_option; \ |
| 33 |
NotifyCompletion(); \ |
| 34 |
return; \ |
| 35 |
} \ |
| 36 |
bVal = options.namedObject(str_option).toBool(); |
| 37 |
|
| 38 |
#define CHECK_ARRSTR_PARAM(str_option, arrVal) \ |
| 39 |
if(!options.hasNamedObject(str_option)) { \ |
| 40 |
clERROR() << "Command is missing field:" << str_option; \ |
| 41 |
NotifyCompletion(); \ |
| 42 |
return; \ |
| 43 |
} \ |
| 44 |
arrVal = options.namedObject(str_option).toArrayString(); |
| 45 |
|
| 46 |
#define CHECK_STR_PARAM_OPTIONAL(str_option, sVal) \ |
| 47 |
if(options.hasNamedObject(str_option)) { sVal = options.namedObject(str_option).toString(); } |
| 48 |
|
| 49 |
#define CHECK_INT_PARAM_OPTIONAL(str_option, iVal) \ |
| 50 |
if(options.hasNamedObject(str_option)) { iVal = options.namedObject(str_option).toInt(); } |
| 51 |
|
| 52 |
#define CHECK_BOOL_PARAM_OPTIONAL(str_option, bVal) \ |
| 53 |
if(options.hasNamedObject(str_option)) { bVal = options.namedObject(str_option).toBool(); } |
| 54 |
|
| 55 |
#define CHECK_ARRSTR_PARAM_OPTIONAL(str_option, arrVal) \ |
| 56 |
if(options.hasNamedObject(str_option)) { arrVal = options.namedObject(str_option).toArrayString(); } |
| 57 |
|
| 58 |
class csCommandHandlerBase |
| 59 |
{ |
| 60 |
protected: |
| 61 |
csManager* m_manager; |
| 62 |
bool m_notifyOnExit; |
| 63 |
|
| 64 |
public: |
| 65 |
typedef wxSharedPtr<csCommandHandlerBase> Ptr_t; |
| 66 |
|
| 67 |
protected: |
| 68 |
void NotifyCompletion(); |
| 69 |
void SetNotifyCompletion(bool b) { m_notifyOnExit = b; } |
| 70 |
|
| 71 |
public: |
| 72 |
/** |
| 73 |
* @brief process a request from the command line and print the result to the stdout |
| 74 |
* @param the handler options |
| 75 |
*/ |
| 76 |
virtual void DoProcessCommand(const JSONItem& options) = 0; |
| 77 |
|
| 78 |
public: |
| 79 |
csCommandHandlerBase(csManager* manager); |
| 80 |
virtual ~csCommandHandlerBase(); |
| 81 |
|
| 82 |
csManager* GetSink() { return m_manager; } |
| 83 |
|
| 84 |
/** |
| 85 |
* @brief process a request from the command line and print the result to the stdout |
| 86 |
* @param the handler options |
| 87 |
*/ |
| 88 |
void Process(const JSONItem& options); |
| 89 |
}; |
| 90 |
|
| 91 |
#endif // CSCOMMANDHANDLERBASE_H |