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