phaser-server  0.0.7
response.h
Go to the documentation of this file.
1 #ifndef RESPONSE_H
2 #define RESPONSE_H
8 #include <JSON.h>
9 
16 { public:
18  enum class Response_t { R_ok, R_warning, R_error };
20  JsonResponse(Response_t type) : m_type(type) {}
21  std::string operator()(void);
22 
23  protected:
25  virtual void Create(JSONObject &) = 0;
26 
27  private:
28  const Response_t m_type;
29 };
30 
31 
36 class TextResponse : public JsonResponse
37 { public:
38  TextResponse(Response_t, const char * = 0, const char * = 0);
39 
40  private:
41  const char *m_text;
42  const char *m_label;
43 
44  protected:
45  virtual void Create(JSONObject &) override;
46 };
47 
48 
51 class Success : public TextResponse
52 { public:
53  Success(void);
54 };
55 
56 
60 class Warning : public TextResponse
61 { public:
62  Warning(const char *);
63 };
64 
65 
69 class Failure : public TextResponse
70 { public:
71  Failure(const char *);
72 };
73 
74 
82 { public:
83  CavityNameResponse(const std::vector<std::string> &names);
84 
85  protected:
86  virtual void Create(JSONObject &) override;
87 
88  private:
89  const std::vector<std::string> &m_names;
90 };
91 
92 #endif
Provide the names of the RF cavities.
Definition: response.h:82
virtual void Create(JSONObject &) override
Add the cavity names as a JSON array value tagged as "cavities".
Definition: response.cpp:96
CavityNameResponse(const std::vector< std::string > &names)
Construct an instance.
Definition: response.cpp:87
An "error" response with a text diagnostic.
Definition: response.h:70
Failure(const char *)
An error response with a diagnostic using the JSON tag "message".
Definition: response.cpp:77
Abstract base for all responses.
Definition: response.h:16
JsonResponse(Response_t type)
Construct with the outcome enumeration.
Definition: response.h:20
Response_t
Status of processed request.
Definition: response.h:18
virtual void Create(JSONObject &)=0
Create the JSON encoded response.
std::string operator()(void)
Get the JSON encoded response string.
Definition: response.cpp:13
An "ok" response.
Definition: response.h:52
Success(void)
A successful outcome with no additional message.
Definition: response.cpp:60
Response with an optional text message.
Definition: response.h:37
TextResponse(Response_t, const char *=0, const char *=0)
Construct an instance.
Definition: response.cpp:41
virtual void Create(JSONObject &) override
Add the optional text message if one was provided.
Definition: response.cpp:52
An "warning" response with a text diagnostic.
Definition: response.h:61
Warning(const char *)
A warning response with a diagnostic using the JSON tag "message".
Definition: response.cpp:68