Open Lighting Architecture  0.9.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OlaServerServiceImpl.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  * OlaServerServiceImpl.h
17  * Implemtation of the OlaService interface
18  * Copyright (C) 2005 - 2008 Simon Newton
19  */
20 
21 #include <memory>
22 #include <string>
23 #include <vector>
24 #include "common/protocol/Ola.pb.h"
25 #include "common/protocol/OlaService.pb.h"
26 #include "ola/Callback.h"
27 #include "ola/rdm/RDMCommand.h"
28 #include "ola/rdm/UID.h"
29 #include "olad/ClientBroker.h"
30 
31 #ifndef OLAD_OLASERVERSERVICEIMPL_H_
32 #define OLAD_OLASERVERSERVICEIMPL_H_
33 
34 namespace ola {
35 
36 
37 /*
38  * This class forms part of the core of the Server. It implements all the
39  * methods the clients can invoke on the server.o
40  *
41  * This class doesn't contain any client specific data, which means we only
42  * need to create one of them. Any client specific data is passed in
43  * per-method.
44  */
46  public:
48 
49  OlaServerServiceImpl(class UniverseStore *universe_store,
50  class DeviceManager *device_manager,
51  class PluginManager *plugin_manager,
52  class ExportMap *export_map,
53  class PortManager *port_manager,
54  class ClientBroker *broker,
55  const class TimeStamp *wake_up_time,
56  const ola::rdm::UID &uid,
57  ReloadPluginsCallback *reload_plugins_callback):
58  m_universe_store(universe_store),
59  m_device_manager(device_manager),
60  m_plugin_manager(plugin_manager),
61  m_export_map(export_map),
62  m_port_manager(port_manager),
63  m_broker(broker),
64  m_wake_up_time(wake_up_time),
65  m_reload_plugins_callback(reload_plugins_callback),
66  m_uid(uid) {}
68 
69  void GetDmx(ola::rpc::RpcController* controller,
70  const ola::proto::UniverseRequest* request,
71  ola::proto::DmxData* response,
73  void RegisterForDmx(ola::rpc::RpcController* controller,
74  const ola::proto::RegisterDmxRequest* request,
75  ola::proto::Ack* response,
77  class Client *client);
78  void UpdateDmxData(ola::rpc::RpcController* controller,
79  const ola::proto::DmxData* request,
80  ola::proto::Ack* response,
82  class Client *client);
83  void StreamDmxData(ola::rpc::RpcController* controller,
84  const ::ola::proto::DmxData* request,
85  ::ola::proto::STREAMING_NO_RESPONSE* response,
87  class Client *client);
88  void SetUniverseName(ola::rpc::RpcController* controller,
89  const ola::proto::UniverseNameRequest* request,
90  ola::proto::Ack* response,
92  void SetMergeMode(ola::rpc::RpcController* controller,
93  const ola::proto::MergeModeRequest* request,
94  ola::proto::Ack* response,
96  void PatchPort(ola::rpc::RpcController* controller,
97  const ola::proto::PatchPortRequest* request,
98  ola::proto::Ack* response,
100  void SetPortPriority(ola::rpc::RpcController* controller,
101  const ola::proto::PortPriorityRequest* request,
102  ola::proto::Ack* response,
104  void GetUniverseInfo(ola::rpc::RpcController* controller,
105  const ola::proto::OptionalUniverseRequest* request,
106  ola::proto::UniverseInfoReply* response,
108  void GetPlugins(ola::rpc::RpcController* controller,
109  const ola::proto::PluginListRequest* request,
110  ola::proto::PluginListReply* response,
112  void ReloadPlugins(ola::rpc::RpcController* controller,
113  const ::ola::proto::PluginReloadRequest* request,
114  ::ola::proto::Ack* response,
116  void GetPluginDescription(
117  ola::rpc::RpcController* controller,
118  const ola::proto::PluginDescriptionRequest* request,
119  ola::proto::PluginDescriptionReply* response,
121  void GetPluginState(
122  ola::rpc::RpcController* controller,
123  const ola::proto::PluginStateRequest* request,
124  ola::proto::PluginStateReply* response,
126  void GetDeviceInfo(ola::rpc::RpcController* controller,
127  const ola::proto::DeviceInfoRequest* request,
128  ola::proto::DeviceInfoReply* response,
130  void GetCandidatePorts(ola::rpc::RpcController* controller,
131  const ola::proto::OptionalUniverseRequest* request,
132  ola::proto::DeviceInfoReply* response,
134  void ConfigureDevice(ola::rpc::RpcController* controller,
135  const ola::proto::DeviceConfigRequest* request,
136  ola::proto::DeviceConfigReply* response,
138  void GetUIDs(ola::rpc::RpcController* controller,
139  const ola::proto::UniverseRequest* request,
140  ola::proto::UIDListReply* response,
142  void ForceDiscovery(ola::rpc::RpcController* controller,
143  const ola::proto::DiscoveryRequest* request,
144  ola::proto::UIDListReply* response,
146  void RDMCommand(ola::rpc::RpcController* controller,
147  const ::ola::proto::RDMRequest* request,
148  ola::proto::RDMResponse* response,
150  const ola::rdm::UID *uid,
151  class Client *client);
152  void RDMDiscoveryCommand(ola::rpc::RpcController* controller,
153  const ::ola::proto::RDMDiscoveryRequest* request,
154  ola::proto::RDMResponse* response,
156  const ola::rdm::UID *uid,
157  class Client *client);
158  void SetSourceUID(ola::rpc::RpcController* controller,
159  const ::ola::proto::UID* request,
160  ola::proto::Ack* response,
162 
163  void SendTimeCode(ola::rpc::RpcController* controller,
164  const ::ola::proto::TimeCode* request,
165  ::ola::proto::Ack* response,
167 
168  private:
169  void HandleRDMResponse(ola::proto::RDMResponse* response,
171  bool include_raw_packets,
172  ola::rdm::rdm_response_code code,
173  const ola::rdm::RDMResponse *rdm_response,
174  const std::vector<std::string> &packets);
175  void RDMDiscoveryComplete(unsigned int universe,
177  ola::proto::UIDListReply *response,
178  const ola::rdm::UIDSet &uids);
179 
180  void MissingUniverseError(ola::rpc::RpcController* controller);
181  void MissingPluginError(ola::rpc::RpcController* controller);
182  void MissingDeviceError(ola::rpc::RpcController* controller);
183  void MissingPortError(ola::rpc::RpcController* controller);
184 
185  void AddPlugin(class AbstractPlugin *plugin,
186  ola::proto::PluginInfo *plugin_info) const;
187  void AddDevice(class AbstractDevice *device,
188  unsigned int alias,
189  ola::proto::DeviceInfoReply* response) const;
190 
191  template <class PortClass>
192  void PopulatePort(const PortClass &port,
193  ola::proto::PortInfo *port_info) const;
194 
195  void SetProtoUID(const ola::rdm::UID &uid, ola::proto::UID *pb_uid);
196 
197  UniverseStore *m_universe_store;
198  DeviceManager *m_device_manager;
199  class PluginManager *m_plugin_manager;
200  class ExportMap *m_export_map;
201  class PortManager *m_port_manager;
202  class ClientBroker *m_broker;
203  const class TimeStamp *m_wake_up_time;
204  std::auto_ptr<ReloadPluginsCallback> m_reload_plugins_callback;
205  ola::rdm::UID m_uid;
206 };
207 
208 
209 /*
210  * This implements the client specific portion of the OlaServerService.
211  * In other words, it implements the methods that the clients can invoke on the
212  * server and holds the client data so the requests can be performed. It pretty
213  * much passes everything through to the OlaServerServiceImpl.
214  */
215 class OlaClientService: public ola::proto::OlaServerService {
216  public:
217  OlaClientService(class Client *client,
218  OlaServerServiceImpl *impl):
219  m_client(client),
220  m_impl(impl),
221  m_uid(NULL) {
222  }
223  ~OlaClientService();
224 
225  void GetDmx(ola::rpc::RpcController* controller,
226  const ola::proto::UniverseRequest* request,
227  ola::proto::DmxData* response,
229  m_impl->GetDmx(controller, request, response, done);
230  }
231 
232  void RegisterForDmx(ola::rpc::RpcController* controller,
233  const ola::proto::RegisterDmxRequest* request,
234  ola::proto::Ack* response,
236  m_impl->RegisterForDmx(controller, request, response, done, m_client);
237  }
238 
239  void UpdateDmxData(ola::rpc::RpcController* controller,
240  const ola::proto::DmxData* request,
241  ola::proto::Ack* response,
243  m_impl->UpdateDmxData(controller, request, response, done, m_client);
244  }
245 
246  void StreamDmxData(ola::rpc::RpcController* controller,
247  const ::ola::proto::DmxData* request,
248  ::ola::proto::STREAMING_NO_RESPONSE* response,
250  m_impl->StreamDmxData(controller, request, response, done, m_client);
251  }
252 
253  void SetUniverseName(ola::rpc::RpcController* controller,
254  const ola::proto::UniverseNameRequest* request,
255  ola::proto::Ack* response,
257  m_impl->SetUniverseName(controller, request, response, done);
258  }
259 
260  void SetMergeMode(ola::rpc::RpcController* controller,
261  const ola::proto::MergeModeRequest* request,
262  ola::proto::Ack* response,
264  m_impl->SetMergeMode(controller, request, response, done);
265  }
266 
267  void PatchPort(ola::rpc::RpcController* controller,
268  const ola::proto::PatchPortRequest* request,
269  ola::proto::Ack* response,
271  m_impl->PatchPort(controller, request, response, done);
272  }
273 
274  void SetPortPriority(ola::rpc::RpcController* controller,
275  const ola::proto::PortPriorityRequest* request,
276  ola::proto::Ack* response,
278  m_impl->SetPortPriority(controller, request, response, done);
279  }
280 
281  void GetUniverseInfo(ola::rpc::RpcController* controller,
282  const ola::proto::OptionalUniverseRequest* request,
283  ola::proto::UniverseInfoReply* response,
285  m_impl->GetUniverseInfo(controller, request, response, done);
286  }
287 
288  void GetPlugins(ola::rpc::RpcController* controller,
289  const ola::proto::PluginListRequest* request,
290  ola::proto::PluginListReply* response,
292  m_impl->GetPlugins(controller, request, response, done);
293  }
294 
295  void ReloadPlugins(ola::rpc::RpcController* controller,
296  const ::ola::proto::PluginReloadRequest* request,
297  ::ola::proto::Ack* response,
299  m_impl->ReloadPlugins(controller, request, response, done);
300  }
301 
302  void GetPluginDescription(
303  ola::rpc::RpcController* controller,
304  const ola::proto::PluginDescriptionRequest* request,
305  ola::proto::PluginDescriptionReply* response,
307  m_impl->GetPluginDescription(controller, request, response, done);
308  }
309 
310  void GetPluginState(
311  ola::rpc::RpcController* controller,
312  const ola::proto::PluginStateRequest* request,
313  ola::proto::PluginStateReply* response,
315  m_impl->GetPluginState(controller, request, response, done);
316  }
317 
318  void GetDeviceInfo(ola::rpc::RpcController* controller,
319  const ola::proto::DeviceInfoRequest* request,
320  ola::proto::DeviceInfoReply* response,
322  m_impl->GetDeviceInfo(controller, request, response, done);
323  }
324 
325  void GetCandidatePorts(ola::rpc::RpcController* controller,
326  const ola::proto::OptionalUniverseRequest* request,
327  ola::proto::DeviceInfoReply* response,
329  m_impl->GetCandidatePorts(controller, request, response, done);
330  }
331 
332  void ConfigureDevice(ola::rpc::RpcController* controller,
333  const ola::proto::DeviceConfigRequest* request,
334  ola::proto::DeviceConfigReply* response,
336  m_impl->ConfigureDevice(controller, request, response, done);
337  }
338 
339  void GetUIDs(ola::rpc::RpcController* controller,
340  const ola::proto::UniverseRequest* request,
341  ola::proto::UIDListReply* response,
343  m_impl->GetUIDs(controller, request, response, done);
344  }
345 
346  void ForceDiscovery(ola::rpc::RpcController* controller,
347  const ola::proto::DiscoveryRequest* request,
348  ola::proto::UIDListReply* response,
350  m_impl->ForceDiscovery(controller, request, response, done);
351  }
352 
353  void RDMCommand(ola::rpc::RpcController* controller,
354  const ::ola::proto::RDMRequest* request,
355  ola::proto::RDMResponse* response,
357  m_impl->RDMCommand(controller, request, response, done, m_uid, m_client);
358  }
359 
360  void RDMDiscoveryCommand(ola::rpc::RpcController* controller,
361  const ::ola::proto::RDMDiscoveryRequest* request,
362  ola::proto::RDMResponse* response,
364  m_impl->RDMDiscoveryCommand(controller, request, response, done, m_uid,
365  m_client);
366  }
367 
368  void SetSourceUID(ola::rpc::RpcController* controller,
369  const ::ola::proto::UID* request,
370  ola::proto::Ack* response,
372 
373  void SendTimeCode(ola::rpc::RpcController* controller,
374  const ::ola::proto::TimeCode* request,
375  ::ola::proto::Ack* response,
377  m_impl->SendTimeCode(controller, request, response, done);
378  }
379 
380  Client *GetClient() const { return m_client; }
381 
382  private:
383  class Client *m_client;
384  OlaServerServiceImpl *m_impl;
385  ola::rdm::UID *m_uid;
386 };
387 
388 
393  public:
394  OlaClientService *New(Client *client, OlaServerServiceImpl *impl);
395 };
396 } // namespace ola
397 #endif // OLAD_OLASERVERSERVICEIMPL_H_