Open Lighting Architecture
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HttpServerActions.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation; either version 2 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU Library General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  *
16  * HttpServerActions.h
17  * The list of actions the Ola Server performs.
18  * Copyright (C) 2005-2010 Simon Newton
19  */
20 
21 #ifndef OLAD_HTTPSERVERACTIONS_H_
22 #define OLAD_HTTPSERVERACTIONS_H_
23 
24 #include <stdint.h>
25 #include <string>
26 #include "ola/ActionQueue.h"
27 #include "ola/OlaCallbackClient.h"
28 
29 namespace ola {
30 
31 using std::string;
32 
33 
34 /*
35  * The base action
36  */
37 class BaseHttpAction: public Action {
38  public:
39  explicit BaseHttpAction(OlaCallbackClient *client):
40  Action(),
41  m_client(client),
42  m_failed(false),
43  m_on_done(NULL) {
44  }
45  virtual ~BaseHttpAction() {}
46 
47  bool Failed() const { return m_failed; }
48  void Perform(SingleUseCallback0<void> *on_done);
49  void CallbackComplete(const string &error);
50 
51  protected:
52  OlaCallbackClient *m_client;
53 
54  void RequestComplete(bool failure);
55  virtual bool DoAction() = 0;
56 
57  private:
58  bool m_failed;
59  SingleUseCallback0<void> *m_on_done;
60 
62  BaseHttpAction& operator=(const BaseHttpAction&);
63 };
64 
65 
66 /*
67  * An action that sets the name of a universe
68  */
70  public:
72  unsigned int universe,
73  const string &name,
74  bool is_fatal):
75  BaseHttpAction(client),
76  m_universe(universe),
77  m_name(name),
78  m_is_fatal(is_fatal) {
79  }
80 
81  bool IsFatal() const { return m_is_fatal; }
82 
83  protected:
84  bool DoAction();
85 
86  private:
87  unsigned int m_universe;
88  string m_name;
89  bool m_is_fatal;
90 
92  SetNameAction& operator=(const SetNameAction&);
93 };
94 
95 
96 /*
97  * An action that sets the merge mode of a universe
98  */
100  public:
102  unsigned int universe,
103  OlaUniverse::merge_mode mode):
104  BaseHttpAction(client),
105  m_universe(universe),
106  m_merge_mode(mode) {
107  }
108 
109  bool IsFatal() const { return false; }
110 
111  protected:
112  bool DoAction();
113 
114  private:
115  unsigned int m_universe;
116  OlaUniverse::merge_mode m_merge_mode;
117 
119  SetMergeModeAction& operator=(const SetMergeModeAction&);
120 };
121 
122 
123 /*
124  * An action that adds or removes a port from a universe.
125  */
127  public:
129  unsigned int device_alias,
130  unsigned int port,
131  PortDirection direction,
132  unsigned int universe,
133  PatchAction action):
134  BaseHttpAction(client),
135  m_device_alias(device_alias),
136  m_port(port),
137  m_direction(direction),
138  m_universe(universe),
139  m_action(action) {
140  }
141 
142  bool IsFatal() const { return false; }
143 
144  protected:
145  bool DoAction();
146 
147  private:
148  unsigned int m_device_alias;
149  unsigned int m_port;
150  PortDirection m_direction;
151  unsigned int m_universe;
152  PatchAction m_action;
153 
155  PatchPortAction& operator=(const PatchPortAction&);
156 };
157 
158 
159 /*
160  * An action that sets a port priority to inherit mode.
161  */
163  public:
165  unsigned int device_alias,
166  unsigned int port,
167  PortDirection direction):
168  BaseHttpAction(client),
169  m_device_alias(device_alias),
170  m_port(port),
171  m_direction(direction) {
172  }
173 
174  bool IsFatal() const { return false; }
175 
176  protected:
177  bool DoAction();
178 
179  private:
180  unsigned int m_device_alias;
181  unsigned int m_port;
182  PortDirection m_direction;
183 
186 };
187 
188 
189 /*
190  * An action that sets a port priority to override mode.
191  */
193  public:
195  unsigned int device_alias,
196  unsigned int port,
197  PortDirection direction,
198  uint8_t overide_value):
199  BaseHttpAction(client),
200  m_device_alias(device_alias),
201  m_port(port),
202  m_direction(direction),
203  m_override_value(overide_value) {
204  }
205 
206  bool IsFatal() const { return false; }
207 
208  protected:
209  bool DoAction();
210 
211  private:
212  unsigned int m_device_alias;
213  unsigned int m_port;
214  PortDirection m_direction;
215  uint8_t m_override_value;
216 
219 };
220 } // namespace ola
221 #endif // OLAD_HTTPSERVERACTIONS_H_