Open Lighting Architecture: olad/OladHTTPServer.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
OladHTTPServer.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 * OladHTTPServer.h
17 * Interface for the OLA HTTP class
18 * Copyright (C) 2005 Simon Newton
19 */
20
21#ifndef OLAD_OLADHTTPSERVER_H_
22#define OLAD_OLADHTTPSERVER_H_
23
24#include <time.h>
25#include <string>
26#include <vector>
27#include "ola/ExportMap.h"
28#include "ola/client/OlaClient.h"
29#include "ola/base/Macro.h"
30#include "ola/http/HTTPServer.h"
31#include "ola/http/OlaHTTPServer.h"
32#include "ola/network/Interface.h"
33#include "ola/rdm/PidStore.h"
34#include "olad/RDMHTTPModule.h"
35
36namespace ola {
37
38
39/*
40 * This is the main OLA HTTP Server
41 */
42 class OladHTTPServer: public ola::http::OlaHTTPServer {
43 public:
44 struct OladHTTPServerOptions: public
45 ola::http::HTTPServer::HTTPServerOptions {
46 public:
47 bool enable_quit;
48
49 OladHTTPServerOptions()
50 : ola::http::HTTPServer::HTTPServerOptions(),
51 enable_quit(true) {
52 }
53 };
54
55 OladHTTPServer(ExportMap *export_map,
56 const OladHTTPServerOptions &options,
57 ola::io::ConnectedDescriptor *client_socket,
58 class OlaServer *ola_server,
59 const ola::network::Interface &iface);
60 virtual ~OladHTTPServer();
61
62 bool Init();
63 void SetPidStore(const ola::rdm::RootPidStore *pid_store);
64
65 int JsonServerStats(const ola::http::HTTPRequest *request,
66 ola::http::HTTPResponse *response);
67 int JsonUniversePluginList(const ola::http::HTTPRequest *request,
68 ola::http::HTTPResponse *response);
69 int JsonPluginInfo(const ola::http::HTTPRequest *request,
70 ola::http::HTTPResponse *response);
71 int SetPluginState(const ola::http::HTTPRequest *request,
72 ola::http::HTTPResponse *response);
73 int JsonUniverseInfo(const ola::http::HTTPRequest *request,
74 ola::http::HTTPResponse *response);
75 int JsonAvailablePorts(const ola::http::HTTPRequest *request,
76 ola::http::HTTPResponse *response);
77 int CreateNewUniverse(const ola::http::HTTPRequest *request,
78 ola::http::HTTPResponse *response);
79 int ModifyUniverse(const ola::http::HTTPRequest *request,
80 ola::http::HTTPResponse *response);
81
82 int GetDmx(const ola::http::HTTPRequest *request,
83 ola::http::HTTPResponse *response);
84 int HandleSetDmx(const ola::http::HTTPRequest *request,
85 ola::http::HTTPResponse *response);
86 int DisplayQuit(const ola::http::HTTPRequest *request,
87 ola::http::HTTPResponse *response);
88 int ReloadPlugins(const ola::http::HTTPRequest *request,
89 ola::http::HTTPResponse *response);
90 int ReloadPidStore(const ola::http::HTTPRequest *request,
91 ola::http::HTTPResponse *response);
92
93 void HandlePluginList(ola::http::HTTPResponse *response,
94 const client::Result &result,
95 const std::vector<client::OlaPlugin> &plugins);
96
97 void HandleUniverseList(ola::http::HTTPResponse *response,
98 ola::web::JsonObject *json,
99 const client::Result &result,
100 const std::vector<client::OlaUniverse> &universes);
101
102 void HandlePartialPluginInfo(ola::http::HTTPResponse *response,
103 int plugin_id,
104 const client::Result &result,
105 const std::string &description);
106 void HandlePluginInfo(ola::http::HTTPResponse *response,
107 std::string description,
108 const client::Result &result,
109 const ola::client::PluginState &state);
110
111 void HandleUniverseInfo(ola::http::HTTPResponse *response,
112 const client::Result &result,
113 const client::OlaUniverse &universe);
114
115 void HandlePortsForUniverse(ola::http::HTTPResponse *response,
116 ola::web::JsonObject *json,
117 unsigned int universe_id,
118 const client::Result &result,
119 const std::vector<client::OlaDevice> &devices);
120
121 void HandleCandidatePorts(ola::http::HTTPResponse *response,
122 const client::Result &result,
123 const std::vector<client::OlaDevice> &devices);
124
125 void CreateUniverseComplete(ola::http::HTTPResponse *response,
126 unsigned int universe_id,
127 bool included_name,
128 class ActionQueue *action_queue);
129
130 void SendCreateUniverseResponse(ola::http::HTTPResponse *response,
131 unsigned int universe_id,
132 bool included_name,
133 class ActionQueue *action_queue);
134
135 void ModifyUniverseComplete(ola::http::HTTPResponse *response,
136 class ActionQueue *action_queue);
137 void SendModifyUniverseResponse(ola::http::HTTPResponse *response,
138 class ActionQueue *action_queue);
139
144 inline static int ServeHelpRedirect(ola::http::HTTPResponse *response) {
145 return ola::http::HTTPServer::ServeRedirect(response, HELP_REDIRECTION);
146 }
147
148 static int ServeUsage(ola::http::HTTPResponse *response,
149 const std::string &details);
150
151 static const char HELP_PARAMETER[];
152
153 private:
154 class ola::io::ConnectedDescriptor *m_client_socket;
155 ola::client::OlaClient m_client;
156 class OlaServer *m_ola_server;
157 bool m_enable_quit;
158 ola::network::Interface m_interface;
159 RDMHTTPModule m_rdm_module;
160 time_t m_start_time_t;
161
162 void HandleGetDmx(ola::http::HTTPResponse *response,
163 const client::Result &result,
164 const client::DMXMetadata &metadata,
165 const DmxBuffer &buffer);
166
167 void HandleBoolResponse(ola::http::HTTPResponse *response,
168 const client::Result &result);
169
170 void PortToJson(ola::web::JsonObject *object,
171 const client::OlaDevice &device,
172 const client::OlaPort &port,
173 bool is_output);
174
175 void AddPatchActions(ActionQueue *action_queue,
176 const std::string port_id_string,
177 unsigned int universe,
178 client::PatchAction port_action);
179
180 void AddPriorityActions(ActionQueue *action_queue,
181 const ola::http::HTTPRequest *request);
182
183 typedef struct {
184 unsigned int device_alias;
185 unsigned int port;
186 client::PortDirection direction;
187 std::string string_id;
188 } port_identifier;
189
190 void DecodePortIds(const std::string &port_ids,
191 std::vector<port_identifier> *ports);
192
193 void RegisterHandler(
194 const std::string &path,
195 int (OladHTTPServer::*method)(const ola::http::HTTPRequest*,
196 ola::http::HTTPResponse*));
197
198 static const char HELP_REDIRECTION[];
199 static const char K_BACKEND_DISCONNECTED_ERROR[];
200 static const unsigned int K_UNIVERSE_NAME_LIMIT = 100;
201 static const char K_PRIORITY_VALUE_SUFFIX[];
202 static const char K_PRIORITY_MODE_SUFFIX[];
203
204 OladHTTPServer(const OladHTTPServer &) = delete;
205 const OladHTTPServer &operator=(const OladHTTPServer &) = delete;
206};
207} // namespace ola
208#endif // OLAD_OLADHTTPSERVER_H_
ExportMap.h
Export variables on the http server.
Macro.h
Helper macros.
PidStore.h
Holds information about RDM PIDs.
ola::ActionQueue
Definition ActionQueue.h:54
ola::DmxBuffer
Used to hold a single universe of DMX data.
Definition DmxBuffer.h:49
ola::ExportMap
A container for the exported variables.
Definition ExportMap.h:324
ola::OlaServer
The main OlaServer class.
Definition OlaServer.h:61
ola::OladHTTPServer::JsonPluginInfo
int JsonPluginInfo(const ola::http::HTTPRequest *request, ola::http::HTTPResponse *response)
Print the plugin info as a JSON string.
Definition OladHTTPServer.cpp:332
ola::OladHTTPServer::SetPidStore
void SetPidStore(const ola::rdm::RootPidStore *pid_store)
Can be called while the HTTP server is running.
Definition OladHTTPServer.cpp:266
ola::OladHTTPServer::Init
bool Init()
Setup the OLA HTTP server.
Definition OladHTTPServer.cpp:245
ola::OladHTTPServer::ServeHelpRedirect
static int ServeHelpRedirect(ola::http::HTTPResponse *response)
Definition OladHTTPServer.h:144
ola::OladHTTPServer::OladHTTPServer
OladHTTPServer(ExportMap *export_map, const OladHTTPServerOptions &options, ola::io::ConnectedDescriptor *client_socket, class OlaServer *ola_server, const ola::network::Interface &iface)
Create a new OLA HTTP server.
Definition OladHTTPServer.cpp:77
ola::OladHTTPServer::HandleUniverseList
void HandleUniverseList(ola::http::HTTPResponse *response, ola::web::JsonObject *json, const client::Result &result, const std::vector< client::OlaUniverse > &universes)
Handle the universe list callback.
Definition OladHTTPServer.cpp:712
ola::OladHTTPServer::ServeUsage
static int ServeUsage(ola::http::HTTPResponse *response, const std::string &details)
Serve usage information.
Definition OladHTTPServer.cpp:1006
ola::OladHTTPServer::GetDmx
int GetDmx(const ola::http::HTTPRequest *request, ola::http::HTTPResponse *response)
Handle the get DMX command.
Definition OladHTTPServer.cpp:563
ola::OladHTTPServer::JsonAvailablePorts
int JsonAvailablePorts(const ola::http::HTTPRequest *request, ola::http::HTTPResponse *response)
Return a list of unbound ports.
Definition OladHTTPServer.cpp:385
ola::OladHTTPServer::SetPluginState
int SetPluginState(const ola::http::HTTPRequest *request, ola::http::HTTPResponse *response)
Set plugin state.
Definition OladHTTPServer.cpp:525
ola::OladHTTPServer::JsonUniversePluginList
int JsonUniversePluginList(const ola::http::HTTPRequest *request, ola::http::HTTPResponse *response)
Print the list of universes / plugins as a json string.
Definition OladHTTPServer.cpp:316
ola::OladHTTPServer::CreateNewUniverse
int CreateNewUniverse(const ola::http::HTTPRequest *request, ola::http::HTTPResponse *response)
Create a new universe by binding one or more ports.
Definition OladHTTPServer.cpp:420
ola::OladHTTPServer::JsonServerStats
int JsonServerStats(const ola::http::HTTPRequest *request, ola::http::HTTPResponse *response)
Print the server stats JSON.
Definition OladHTTPServer.cpp:277
ola::OladHTTPServer::HandleUniverseInfo
void HandleUniverseInfo(ola::http::HTTPResponse *response, const client::Result &result, const client::OlaUniverse &universe)
Handle the universe info.
Definition OladHTTPServer.cpp:808
ola::OladHTTPServer::JsonUniverseInfo
int JsonUniverseInfo(const ola::http::HTTPRequest *request, ola::http::HTTPResponse *response)
Return information about a universe.
Definition OladHTTPServer.cpp:358
ola::OladHTTPServer::HandlePluginList
void HandlePluginList(ola::http::HTTPResponse *response, const client::Result &result, const std::vector< client::OlaPlugin > &plugins)
Handle the plugin list callback.
Definition OladHTTPServer.cpp:675
ola::OladHTTPServer::HandleSetDmx
int HandleSetDmx(const ola::http::HTTPRequest *request, ola::http::HTTPResponse *response)
Handle the set DMX command.
Definition OladHTTPServer.cpp:587
ola::OladHTTPServer::HandlePartialPluginInfo
void HandlePartialPluginInfo(ola::http::HTTPResponse *response, int plugin_id, const client::Result &result, const std::string &description)
Handle the plugin description response.
Definition OladHTTPServer.cpp:745
ola::OladHTTPServer::ReloadPlugins
int ReloadPlugins(const ola::http::HTTPRequest *request, ola::http::HTTPResponse *response)
Reload all plugins.
Definition OladHTTPServer.cpp:643
ola::OladHTTPServer::HandleCandidatePorts
void HandleCandidatePorts(ola::http::HTTPResponse *response, const client::Result &result, const std::vector< client::OlaDevice > &devices)
Handle the list of candidate ports.
Definition OladHTTPServer.cpp:885
ola::OladHTTPServer::HandlePluginInfo
void HandlePluginInfo(ola::http::HTTPResponse *response, std::string description, const client::Result &result, const ola::client::PluginState &state)
Handle the plugin description response.
Definition OladHTTPServer.cpp:767
ola::OladHTTPServer::DisplayQuit
int DisplayQuit(const ola::http::HTTPRequest *request, ola::http::HTTPResponse *response)
Cause the server to shutdown.
Definition OladHTTPServer.cpp:619
ola::OladHTTPServer::ModifyUniverse
int ModifyUniverse(const ola::http::HTTPRequest *request, ola::http::HTTPResponse *response)
Modify an existing universe.
Definition OladHTTPServer.cpp:466
ola::OladHTTPServer::ReloadPidStore
int ReloadPidStore(const ola::http::HTTPRequest *request, ola::http::HTTPResponse *response)
Reload the PID Store.
Definition OladHTTPServer.cpp:657
ola::RDMHTTPModule
Definition RDMHTTPModule.h:45
ola::client::OlaClient
The callback based C++ client for OLA.
Definition OlaClient.h:45
ola::client::OlaDevice
Represents a device.
Definition ClientTypes.h:219
ola::client::OlaPort
The base class that represents a port.
Definition ClientTypes.h:119
ola::client::OlaUniverse
Represents a universe.
Definition ClientTypes.h:264
ola::client::Result
Indicates the result of a OLA API call.
Definition Result.h:52
ola::http::HTTPRequest
Definition HTTPServer.h:65
ola::http::HTTPResponse
Definition HTTPServer.h:110
ola::http::HTTPServer::ServeRedirect
static int ServeRedirect(HTTPResponse *response, const std::string &location)
Serve a redirect.
Definition HTTPServer.cpp:776
ola::http::OlaHTTPServer
Definition OlaHTTPServer.h:38
ola::io::ConnectedDescriptor
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition Descriptor.h:283
ola::network::Interface
Definition Interface.h:35
ola::rdm::RootPidStore
The root of the RDM parameter descriptor store.
Definition PidStore.h:68
ola::web::JsonObject
A JSON object. JSON Objects are key : value mappings, similar to dictionaries in Python.
Definition Json.h:899
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
ola::OladHTTPServer::OladHTTPServerOptions
Definition OladHTTPServer.h:45
ola::client::DMXMetadata
Metadata that accompanies DMX packets.
Definition ClientTypes.h:311
ola::client::PluginState
The state of a plugin. This information can be used to detect conflicts between plugins.
Definition ClientTypes.h:93
ola::http::HTTPServer::HTTPServerOptions
Definition HTTPServer.h:162