Open Lighting Architecture: olad/HttpServerActions.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 *
16 * HttpServerActions.h
17 * The list of actions the Ola Server performs.
18 * Copyright (C) 2005 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/client/OlaClient.h"
28#include "ola/base/Macro.h"
29
30namespace ola {
31
32/*
33 * The base action
34 */
35 class BaseHttpAction: public Action {
36 public:
37 explicit BaseHttpAction(client::OlaClient *client):
38 Action(),
39 m_client(client),
40 m_failed(false),
41 m_on_done(NULL) {
42 }
43 virtual ~BaseHttpAction() {}
44
45 bool Failed() const { return m_failed; }
46 void Perform(SingleUseCallback0<void> *on_done);
47 void CallbackComplete(const client::Result &result);
48
49 protected:
50 client::OlaClient *m_client;
51
52 void RequestComplete(bool failure);
53 virtual void DoAction() = 0;
54
55 private:
56 bool m_failed;
57 SingleUseCallback0<void> *m_on_done;
58
59 BaseHttpAction(const BaseHttpAction &) = delete;
60 const BaseHttpAction &operator=(const BaseHttpAction &) = delete;
61};
62
63
64/*
65 * An action that sets the name of a universe
66 */
67 class SetNameAction: public BaseHttpAction {
68 public:
69 SetNameAction(client::OlaClient *client,
70 unsigned int universe,
71 const std::string &name,
72 bool is_fatal):
73 BaseHttpAction(client),
74 m_universe(universe),
75 m_name(name),
76 m_is_fatal(is_fatal) {
77 }
78
79 bool IsFatal() const { return m_is_fatal; }
80
81 protected:
82 void DoAction();
83
84 private:
85 unsigned int m_universe;
86 std::string m_name;
87 bool m_is_fatal;
88
89 SetNameAction(const SetNameAction &) = delete;
90 const SetNameAction &operator=(const SetNameAction &) = delete;
91};
92
93
94/*
95 * An action that sets the merge mode of a universe
96 */
97 class SetMergeModeAction: public BaseHttpAction {
98 public:
99 SetMergeModeAction(client::OlaClient *client,
100 unsigned int universe,
101 client::OlaUniverse::merge_mode mode):
102 BaseHttpAction(client),
103 m_universe(universe),
104 m_merge_mode(mode) {
105 }
106
107 bool IsFatal() const { return false; }
108
109 protected:
110 void DoAction();
111
112 private:
113 unsigned int m_universe;
114 client::OlaUniverse::merge_mode m_merge_mode;
115
116 SetMergeModeAction(const SetMergeModeAction &) = delete;
117 const SetMergeModeAction &operator=(const SetMergeModeAction &) = delete;
118};
119
120
121/*
122 * An action that adds or removes a port from a universe.
123 */
124 class PatchPortAction: public BaseHttpAction {
125 public:
126 PatchPortAction(client::OlaClient *client,
127 unsigned int device_alias,
128 unsigned int port,
129 client::PortDirection direction,
130 unsigned int universe,
131 client::PatchAction action):
132 BaseHttpAction(client),
133 m_device_alias(device_alias),
134 m_port(port),
135 m_direction(direction),
136 m_universe(universe),
137 m_action(action) {
138 }
139
140 bool IsFatal() const { return false; }
141
142 protected:
143 void DoAction();
144
145 private:
146 unsigned int m_device_alias;
147 unsigned int m_port;
148 client::PortDirection m_direction;
149 unsigned int m_universe;
150 client::PatchAction m_action;
151
152 PatchPortAction(const PatchPortAction &) = delete;
153 const PatchPortAction &operator=(const PatchPortAction &) = delete;
154};
155
156
157/*
158 * An action that sets a port priority to inherit mode.
159 */
160 class PortPriorityInheritAction: public BaseHttpAction {
161 public:
162 PortPriorityInheritAction(client::OlaClient *client,
163 unsigned int device_alias,
164 unsigned int port,
165 client::PortDirection direction):
166 BaseHttpAction(client),
167 m_device_alias(device_alias),
168 m_port(port),
169 m_direction(direction) {
170 }
171
172 bool IsFatal() const { return false; }
173
174 protected:
175 void DoAction();
176
177 private:
178 unsigned int m_device_alias;
179 unsigned int m_port;
180 client::PortDirection m_direction;
181
182 PortPriorityInheritAction(const PortPriorityInheritAction &) = delete;
183 const PortPriorityInheritAction &operator=(const PortPriorityInheritAction &) = delete;
184};
185
186
187/*
188 * An action that sets a port priority to override mode.
189 */
190 class PortPriorityStaticAction: public BaseHttpAction {
191 public:
192 PortPriorityStaticAction(client::OlaClient *client,
193 unsigned int device_alias,
194 unsigned int port,
195 client::PortDirection direction,
196 uint8_t override_value):
197 BaseHttpAction(client),
198 m_device_alias(device_alias),
199 m_port(port),
200 m_direction(direction),
201 m_override_value(override_value) {
202 }
203
204 bool IsFatal() const { return false; }
205
206 protected:
207 void DoAction();
208
209 private:
210 unsigned int m_device_alias;
211 unsigned int m_port;
212 client::PortDirection m_direction;
213 uint8_t m_override_value;
214
215 PortPriorityStaticAction(const PortPriorityStaticAction &) = delete;
216 const PortPriorityStaticAction &operator=(const PortPriorityStaticAction &) = delete;
217};
218} // namespace ola
219#endif // OLAD_HTTPSERVERACTIONS_H_
Macro.h
Helper macros.
ola::SingleUseCallback0
A 0 argument callback which deletes itself after it's run.
Definition Callback.h:141
ola::client::OlaClient
The callback based C++ client for OLA.
Definition OlaClient.h:45
ola::client::Result
Indicates the result of a OLA API call.
Definition Result.h:52
ola::client
OLA C++ API.
ola::client::PatchAction
PatchAction
The patch action, used with OlaClient::Patch().
Definition ClientArgs.h:38
ola::client::PortDirection
PortDirection
The port direction.
Definition ClientArgs.h:54
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44