Open Lighting Architecture: include/ola/http/OlaHTTPServer.h Source File

| 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 */
38 class OlaHTTPServer {
39 public:
40 OlaHTTPServer(const HTTPServer::HTTPServerOptions &options,
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,
71 ola::NewCallback<OlaHTTPServer,
72 int,
73 const HTTPRequest*,
74 HTTPResponse*>(
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_
ExportMap.h
Export variables on the http server.
Macro.h
Helper macros.
ola::Clock
Used to get the current time.
Definition Clock.h:230
ola::ExportMap
A container for the exported variables.
Definition ExportMap.h:324
ola::TimeStamp
Definition Clock.h:179
ola::http::HTTPRequest
Definition HTTPServer.h:65
ola::http::HTTPResponse
Definition HTTPServer.h:110
ola::http::HTTPServer
The base HTTP Server.
Definition HTTPServer.h:157
ola::http::HTTPServer::RegisterHandler
bool RegisterHandler(const std::string &path, BaseHTTPCallback *handler)
Register a handler.
Definition HTTPServer.cpp:659
ola::http::OlaHTTPServer
Definition OlaHTTPServer.h:38
ola::http::OlaHTTPServer::OlaHTTPServer
OlaHTTPServer(const HTTPServer::HTTPServerOptions &options, ola::ExportMap *export_map)
Definition OlaHTTPServer.cpp:46
ola::http::OlaHTTPServer::Init
virtual bool Init()
Definition OlaHTTPServer.cpp:64
ola::http::OlaHTTPServer::RegisterFile
void RegisterFile(const std::string &file, const std::string &content_type)
Definition OlaHTTPServer.h:57
ola::NewCallback
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
ola::http
The embedded HTTP server.
Definition HTTPServer.cpp:47
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
ola::http::HTTPServer::HTTPServerOptions
Definition HTTPServer.h:162