Open Lighting Architecture  0.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
45 namespace ola {
46 
47 namespace rpc {
48 class RpcSession;
49 class RpcServer;
50 }
51 
52 #ifdef HAVE_LIBMICROHTTPD
53 typedef class OladHTTPServer OladHTTPServer_t;
54 #else
55 typedef int OladHTTPServer_t;
56 #endif // HAVE_LIBMICROHTTPD
57 
62  public:
66  struct Options {
67  bool http_enable;
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,
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 
133 
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 
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
209 
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 
230 };
231 } // namespace ola
232 #endif // OLAD_OLASERVER_H_
void NewConnection(ola::io::ConnectedDescriptor *descriptor)
Add a new ConnectedDescriptor to this Server.
Definition: OlaServer.cpp:342
Represents the RPC session between a client and server.
Definition: RpcSession.h:45
Used to receive notifications of RPC client session activity.
Definition: RpcSessionHandler.h:36
const PreferencesFactory * GetPreferencesFactory()
Get the preferences factory.
Definition: OlaServer.h:157
Definition: Preferences.h:343
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
A container for the exported variables.
Definition: ExportMap.h:324
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition: Descriptor.h:282
std::string http_data_dir
Port to run the HTTP server on.
Definition: OlaServer.h:72
Holds information about RDM PIDs.
void Terminate()
Exit from the Run() loop.
Definition: SelectServer.cpp:116
A RDM unique identifier (UID).
Export variables on the http server.
bool http_enable_quit
Restrict access to localhost only.
Definition: OlaServer.h:69
Constants used throughout OLA.
Options for the OlaServer.
Definition: OlaServer.h:66
static const int OLA_DEFAULT_PORT
The default port which olad listens on for incoming RPC connections.
Definition: Constants.h:68
void * timeout_id
A timeout handle which can later be used to cancel a timeout.
Definition: SchedulerInterface.h:34
const std::string InstanceName()
Get the instance name.
Definition: OlaServer.h:149
The main OlaServer class.
Definition: OlaServer.h:61
void ReloadPidStore()
Reload the pid store.
Definition: OlaServer.cpp:330
Definition: Interface.h:35
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
void ReloadPlugins()
Reload all plugins.
Definition: OlaServer.cpp:326
A single threaded I/O event management system.
Definition: SelectServer.h:63
An RPC server.
Definition: RpcServer.h:48
bool http_localhost_only
Run the HTTP server.
Definition: OlaServer.h:68
ola::network::GenericSocketAddress LocalRPCAddress() const
Return the socket address the RPC server is listening on.
Definition: OlaServer.cpp:349
Helper macros.
void StopServer()
Stop the OLA Server.
Definition: OlaServer.h:126
Represents a RDM UID.
Definition: UID.h:57
Definition: TCPSocket.h:73
void NewClient(ola::rpc::RpcSession *session)
Called by the RpcServer when a client connects.
Definition: OlaServer.cpp:357
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
The root of the RDM parameter descriptor store.
Definition: PidStore.h:68
~OlaServer()
Shutdown the server.
Definition: OlaServer.cpp:113
void ClientRemoved(ola::rpc::RpcSession *session)
Called by the RpcServer when a client disconnects.
Definition: OlaServer.cpp:364
bool Init()
Initialize the OlaServer.
Definition: OlaServer.cpp:156
unsigned int http_port
Enable /quit URL.
Definition: OlaServer.h:70
a Generic Socket Address
Definition: SocketAddress.h:165