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