Open Lighting Architecture: olad/OlaServer.h Source File

| Open Lighting Architecture 0.10.9

Loading...
Searching...
No Matches
OlaServer.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 * OlaServer.h
17 * Interface for the ola server class
18 * Copyright (C) 2005 Simon Newton
19 */
20
21#ifndef OLAD_OLASERVER_H_
22#define OLAD_OLASERVER_H_
23
24#if HAVE_CONFIG_H
25#include <config.h>
26#endif // HAVE_CONFIG_H
27
28#include <ola/Constants.h>
29#include <ola/ExportMap.h>
30#include <ola/base/Macro.h>
31#include <ola/io/SelectServer.h>
32#include <ola/network/InterfacePicker.h>
33#include <ola/network/Socket.h>
34#include <ola/network/TCPSocketFactory.h>
35#include <ola/plugin_id.h>
36#include <ola/rdm/PidStore.h>
37#include <ola/rdm/UID.h>
38#include <ola/rpc/RpcSessionHandler.h>
39
40#include <map>
41#include <memory>
42#include <string>
43#include <vector>
44
45namespace ola {
46
47namespace rpc {
48class RpcSession;
49class RpcServer;
50}
51
52#ifdef HAVE_LIBMICROHTTPD
53typedef class OladHTTPServer OladHTTPServer_t;
54#else
55typedef int OladHTTPServer_t;
56#endif // HAVE_LIBMICROHTTPD
57
61 class OlaServer : public ola::rpc::RpcSessionHandlerInterface {
62 public:
66 struct Options {
67 bool http_enable;
68 bool http_localhost_only;
69 bool http_enable_quit;
70 unsigned int http_port;
72 std::string http_data_dir;
73 std::string network_interface;
74 std::string pid_data_dir;
75 };
76
89 OlaServer(const std::vector<class PluginLoader*> &plugin_loaders,
90 class PreferencesFactory *preferences_factory,
91 ola::io::SelectServer *ss,
92 const Options &ola_options,
93 ola::network::TCPAcceptingSocket *socket = NULL,
94 ExportMap *export_map = NULL);
95
99 ~OlaServer();
100
105 bool Init();
106
112 void ReloadPlugins();
113
119 void ReloadPidStore();
120
126 void StopServer() { m_ss->Terminate(); }
127
132 void NewConnection(ola::io::ConnectedDescriptor *descriptor);
133
139 ola::network::GenericSocketAddress LocalRPCAddress() const;
140
141 // Called by the RpcServer when clients connect or disconnect.
142 void NewClient(ola::rpc::RpcSession *session);
143 void ClientRemoved(ola::rpc::RpcSession *session);
144
149 const std::string InstanceName() {
150 return m_instance_name;
151 }
152
157 const PreferencesFactory* GetPreferencesFactory() {
158 return m_preferences_factory;
159 }
160
161 static const unsigned int DEFAULT_HTTP_PORT = 9090;
162
163 static const unsigned int DEFAULT_RPC_PORT = OLA_DEFAULT_PORT;
164
165 private :
166 struct ClientEntry {
167 ola::io::ConnectedDescriptor *client_descriptor;
168 class OlaClientService *client_service;
169 };
170
171 typedef std::map<ola::io::DescriptorHandle, ClientEntry> ClientMap;
172
173 // These are all passed to the constructor.
174 const Options m_options;
175 std::vector<class PluginLoader*> m_plugin_loaders;
176 class PreferencesFactory *m_preferences_factory;
177 ola::io::SelectServer *m_ss;
178 ola::network::TCPAcceptingSocket *m_accepting_socket;
179 class ExportMap *m_export_map;
180
181 std::auto_ptr<class ExportMap> m_our_export_map;
182 ola::rdm::UID m_default_uid;
183
184 // These are all populated in Init.
185 std::auto_ptr<class DeviceManager> m_device_manager;
186 std::auto_ptr<class PluginManager> m_plugin_manager;
187 std::auto_ptr<class PluginAdaptor> m_plugin_adaptor;
188 std::auto_ptr<class UniverseStore> m_universe_store;
189 std::auto_ptr<class PortManager> m_port_manager;
190 std::auto_ptr<class OlaServerServiceImpl> m_service_impl;
191 std::auto_ptr<class ClientBroker> m_broker;
192 std::auto_ptr<class PortBroker> m_port_broker;
193 std::auto_ptr<const ola::rdm::RootPidStore> m_pid_store;
194 std::auto_ptr<class DiscoveryAgentInterface> m_discovery_agent;
195 std::auto_ptr<ola::rpc::RpcServer> m_rpc_server;
196 class Preferences *m_server_preferences;
197 class Preferences *m_universe_preferences;
198 std::string m_instance_name;
199
200 ola::thread::timeout_id m_housekeeping_timeout;
201 std::auto_ptr<OladHTTPServer_t> m_httpd;
202
203 bool RunHousekeeping();
204
205#ifdef HAVE_LIBMICROHTTPD
206 bool StartHttpServer(ola::rpc::RpcServer *server,
207 const ola::network::Interface &iface);
208#endif // HAVE_LIBMICROHTTPD
212 void StopPlugins();
213 bool InternalNewConnection(ola::rpc::RpcServer *server,
214 ola::io::ConnectedDescriptor *descriptor);
215 void ReloadPluginsInternal();
219 void UpdatePidStore(const ola::rdm::RootPidStore *pid_store);
220
221 static const char INSTANCE_NAME_KEY[];
222 static const char K_INSTANCE_NAME_VAR[];
223 static const char K_DISCOVERY_SERVICE_TYPE[];
224 static const char K_UID_VAR[];
225 static const char SERVER_PREFERENCES[];
226 static const char UNIVERSE_PREFERENCES[];
227 static const unsigned int K_HOUSEKEEPING_TIMEOUT_MS;
228
229 OlaServer(const OlaServer &) = delete;
230 const OlaServer &operator=(const OlaServer &) = delete;
231};
232} // namespace ola
233#endif // OLAD_OLASERVER_H_
Constants.h
Constants used throughout OLA.
ExportMap.h
Export variables on the http server.
Macro.h
Helper macros.
PidStore.h
Holds information about RDM PIDs.
UID.h
A RDM unique identifier (UID).
ola::ExportMap
A container for the exported variables.
Definition ExportMap.h:324
ola::OlaServer::ReloadPidStore
void ReloadPidStore()
Reload the pid store.
Definition OlaServer.cpp:330
ola::OlaServer::LocalRPCAddress
ola::network::GenericSocketAddress LocalRPCAddress() const
Return the socket address the RPC server is listening on.
Definition OlaServer.cpp:349
ola::OlaServer::ClientRemoved
void ClientRemoved(ola::rpc::RpcSession *session)
Called by the RpcServer when a client disconnects.
Definition OlaServer.cpp:364
ola::OlaServer::NewClient
void NewClient(ola::rpc::RpcSession *session)
Called by the RpcServer when a client connects.
Definition OlaServer.cpp:357
ola::OlaServer::StopServer
void StopServer()
Stop the OLA Server.
Definition OlaServer.h:126
ola::OlaServer::NewConnection
void NewConnection(ola::io::ConnectedDescriptor *descriptor)
Add a new ConnectedDescriptor to this Server.
Definition OlaServer.cpp:342
ola::OlaServer::InstanceName
const std::string InstanceName()
Get the instance name.
Definition OlaServer.h:149
ola::OlaServer::ReloadPlugins
void ReloadPlugins()
Reload all plugins.
Definition OlaServer.cpp:326
ola::OlaServer::~OlaServer
~OlaServer()
Shutdown the server.
Definition OlaServer.cpp:113
ola::OlaServer::Init
bool Init()
Initialize the OlaServer.
Definition OlaServer.cpp:156
ola::OlaServer::OlaServer
OlaServer(const std::vector< class PluginLoader * > &plugin_loaders, class PreferencesFactory *preferences_factory, ola::io::SelectServer *ss, const Options &ola_options, ola::network::TCPAcceptingSocket *socket=NULL, ExportMap *export_map=NULL)
Create a new instance of the OlaServer.
Definition OlaServer.cpp:91
ola::OlaServer::GetPreferencesFactory
const PreferencesFactory * GetPreferencesFactory()
Get the preferences factory.
Definition OlaServer.h:157
ola::OladHTTPServer
Definition OladHTTPServer.h:42
ola::PreferencesFactory
Definition Preferences.h:347
ola::io::ConnectedDescriptor
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition Descriptor.h:283
ola::io::SelectServer
A single threaded I/O event management system.
Definition SelectServer.h:63
ola::network::GenericSocketAddress
a Generic Socket Address
Definition SocketAddress.h:166
ola::network::Interface
Definition Interface.h:35
ola::network::TCPAcceptingSocket
Definition TCPSocket.h:74
ola::rdm::RootPidStore
The root of the RDM parameter descriptor store.
Definition PidStore.h:68
ola::rdm::UID
Represents a RDM UID.
Definition UID.h:57
ola::rpc::RpcServer
An RPC server.
Definition RpcServer.h:48
ola::rpc::RpcSessionHandlerInterface
Used to receive notifications of RPC client session activity.
Definition RpcSessionHandler.h:36
ola::rpc::RpcSession
Represents the RPC session between a client and server.
Definition RpcSession.h:45
ola::rpc
The RPC (Remote Procedure Call) system.
Definition RpcChannel.cpp:41
ola::thread::timeout_id
void * timeout_id
A timeout handle which can later be used to cancel a timeout.
Definition SchedulerInterface.h:34
ola
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
ola::OLA_DEFAULT_PORT
static const int OLA_DEFAULT_PORT
The default port which olad listens on for incoming RPC connections.
Definition Constants.h:68
ola::OlaServer::Options
Options for the OlaServer.
Definition OlaServer.h:66
ola::OlaServer::Options::http_localhost_only
bool http_localhost_only
Run the HTTP server.
Definition OlaServer.h:68
ola::OlaServer::Options::http_data_dir
std::string http_data_dir
Port to run the HTTP server on.
Definition OlaServer.h:72
ola::OlaServer::Options::http_enable_quit
bool http_enable_quit
Restrict access to localhost only.
Definition OlaServer.h:69
ola::OlaServer::Options::http_port
unsigned int http_port
Enable /quit URL.
Definition OlaServer.h:70