Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
OlaHTTPServer.h
1/*
2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2.1 of the License, or (at your option) any later version.
6 *
7 * This library 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 GNU
10 * Lesser General Public License for more details.
11 *
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * OlaHTTPServer.h
17 * A HTTP Server with export map integration.
18 * Copyright (C) 2012 Simon Newton
19 */
20
21
22#ifndef INCLUDE_OLA_HTTP_OLAHTTPSERVER_H_
23#define INCLUDE_OLA_HTTP_OLAHTTPSERVER_H_
24
25#include <ola/Clock.h>
26#include <ola/ExportMap.h>
27#include <ola/base/Macro.h>
28#include <ola/http/HTTPServer.h>
29#include <string>
30
31namespace ola {
32namespace http {
33
34/*
35 * A HTTP Server with ExportMap support. You can inherit from this class to
36 * implement specific handlers.
37 */
39 public:
41 ola::ExportMap *export_map);
42 virtual ~OlaHTTPServer() {}
43
44 virtual bool Init();
45 bool Start() { return m_server.Start(); }
46 void Stop() { return m_server.Stop(); }
47
48 protected:
49 Clock m_clock;
50 ola::ExportMap *m_export_map;
51 HTTPServer m_server;
52 TimeStamp m_start_time;
53
57 void RegisterFile(const std::string &file,
58 const std::string &content_type) {
59 m_server.RegisterFile("/" + file, file, content_type);
60 }
61
62 private:
63 static const char K_DATA_DIR_VAR[];
64 static const char K_UPTIME_VAR[];
65
66 inline void RegisterHandler(
67 const std::string &path,
68 int (OlaHTTPServer::*method)(const HTTPRequest*, HTTPResponse*)) {
69 m_server.RegisterHandler(
70 path,
72 int,
73 const HTTPRequest*,
75 this,
76 method));
77 }
78
79 int DisplayDebug(const HTTPRequest *request, HTTPResponse *response);
80 int DisplayHandlers(const HTTPRequest *request, HTTPResponse *response);
81
82 OlaHTTPServer(const OlaHTTPServer &) = delete;
83 const OlaHTTPServer &operator=(const OlaHTTPServer &) = delete;
84};
85} // namespace http
86} // namespace ola
87#endif // INCLUDE_OLA_HTTP_OLAHTTPSERVER_H_
Export variables on the http server.
Helper macros.
Used to get the current time.
Definition Clock.h:230
A container for the exported variables.
Definition ExportMap.h:324
Definition Clock.h:179
Definition HTTPServer.h:65
Definition HTTPServer.h:110
The base HTTP Server.
Definition HTTPServer.h:157
bool RegisterFile(const std::string &path, const std::string &content_type)
Register a static file. The root of the URL corresponds to the data dir.
Definition HTTPServer.cpp:676
bool RegisterHandler(const std::string &path, BaseHTTPCallback *handler)
Register a handler.
Definition HTTPServer.cpp:659
void Stop()
Stop the HTTP server.
Definition HTTPServer.cpp:535
Definition OlaHTTPServer.h:38
OlaHTTPServer(const HTTPServer::HTTPServerOptions &options, ola::ExportMap *export_map)
Definition OlaHTTPServer.cpp:46
virtual bool Init()
Definition OlaHTTPServer.cpp:64
void RegisterFile(const std::string &file, const std::string &content_type)
Definition OlaHTTPServer.h:57
virtual bool Start()
Start the thread and wait for the thread to be running.
Definition Thread.cpp:90
Callback0< ReturnType > * NewCallback(ReturnType(*callback)())
A helper function to create a new Callback with 0 create-time arguments and 0 execution time argument...
Definition Callback.h:211
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
Definition HTTPServer.h:162