Open Lighting Architecture  0.9.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OlaClientCore.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  * OlaClientCore.h
17  * The OLA Client Core class
18  * Copyright (C) 2005 Simon Newton
19  */
20 
21 #ifndef OLA_OLACLIENTCORE_H_
22 #define OLA_OLACLIENTCORE_H_
23 
24 #include <memory>
25 #include <string>
26 
27 #include "common/protocol/Ola.pb.h"
28 #include "common/protocol/OlaService.pb.h"
29 #include "common/rpc/RpcChannel.h"
30 #include "common/rpc/RpcController.h"
31 #include "ola/Callback.h"
32 #include "ola/DmxBuffer.h"
34 #include "ola/client/ClientArgs.h"
35 #include "ola/client/ClientTypes.h"
36 #include "ola/base/Macro.h"
38 #include "ola/io/Descriptor.h"
39 #include "ola/plugin_id.h"
40 #include "ola/rdm/UID.h"
41 #include "ola/rdm/UIDSet.h"
42 #include "ola/timecode/TimeCode.h"
43 
44 namespace ola {
45 
46 namespace rpc {
47 class RpcSession;
48 }
49 
50 namespace client {
51 
56 class OlaClientCore: public ola::proto::OlaClientService {
57  public:
59 
60  explicit OlaClientCore(ola::io::ConnectedDescriptor *descriptor);
61  ~OlaClientCore();
62 
63  bool Setup();
64  bool Stop();
65 
66  void SetCloseHandler(ClosedCallback *callback);
67 
75  void SetDMXCallback(RepeatableDMXCallback *callback);
76 
81  void ReloadPlugins(SetCallback *callback);
82 
87  void FetchPluginList(PluginListCallback *callback);
88 
95  void FetchPluginDescription(ola_plugin_id plugin_id,
96  PluginDescriptionCallback *callback);
97 
104  void FetchPluginState(ola_plugin_id plugin_id,
105  PluginStateCallback *callback);
106 
113  void FetchDeviceInfo(ola_plugin_id plugin_filter,
114  DeviceInfoCallback *callback);
115 
121 
129  void FetchCandidatePorts(unsigned int universe_id,
130  CandidatePortsCallback *callback);
131 
138  void ConfigureDevice(unsigned int device_alias,
139  const std::string &msg,
140  ConfigureDeviceCallback *callback);
141 
149  void SetPortPriorityInherit(unsigned int device_alias,
150  unsigned int port,
151  PortDirection port_direction,
152  SetCallback *callback);
153 
162  void SetPortPriorityOverride(unsigned int device_alias,
163  unsigned int port,
164  PortDirection port_direction,
165  uint8_t value,
166  SetCallback *callback);
167 
172  void FetchUniverseList(UniverseListCallback *callback);
173 
179  void FetchUniverseInfo(unsigned int universe,
180  UniverseInfoCallback *callback);
181 
188  void SetUniverseName(unsigned int universe,
189  const std::string &name,
190  SetCallback *callback);
191 
198  void SetUniverseMergeMode(unsigned int universe,
199  OlaUniverse::merge_mode mode,
200  SetCallback *callback);
201 
211  void Patch(unsigned int device_alias,
212  unsigned int port,
213  PortDirection port_direction,
214  PatchAction action,
215  unsigned int universe,
216  SetCallback *callback);
217 
225  void RegisterUniverse(unsigned int universe,
226  RegisterAction register_action,
227  SetCallback *callback);
228 
235  void SendDMX(unsigned int universe,
236  const DmxBuffer &data,
237  const SendDMXArgs &args);
238 
244  void FetchDMX(unsigned int universe, DMXCallback *callback);
245 
252  void RunDiscovery(unsigned int universe,
253  DiscoveryType discovery_type,
254  DiscoveryCallback *callback);
255 
261  void SetSourceUID(const ola::rdm::UID &uid, SetCallback *callback);
262 
273  void RDMGet(unsigned int universe,
274  const ola::rdm::UID &uid,
275  uint16_t sub_device,
276  uint16_t pid,
277  const uint8_t *data,
278  unsigned int data_length,
279  const SendRDMArgs& args);
280 
291  void RDMSet(unsigned int universe,
292  const ola::rdm::UID &uid,
293  uint16_t sub_device,
294  uint16_t pid,
295  const uint8_t *data,
296  unsigned int data_length,
297  const SendRDMArgs& args);
298 
304  void SendTimeCode(const ola::timecode::TimeCode &timecode,
305  SetCallback *callback);
306 
310  void UpdateDmxData(ola::rpc::RpcController* controller,
311  const ola::proto::DmxData* request,
312  ola::proto::Ack* response,
313  CompletionCallback* done);
314 
315  private:
316  ola::io::ConnectedDescriptor *m_descriptor;
317  std::auto_ptr<RepeatableDMXCallback> m_dmx_callback;
318  std::auto_ptr<ola::rpc::RpcChannel> m_channel;
319  std::auto_ptr<ola::proto::OlaServerService_Stub> m_stub;
320  int m_connected;
321 
322  void ChannelClosed(ClosedCallback *callback, ola::rpc::RpcSession *session);
323 
327  void HandlePluginList(ola::rpc::RpcController *controller_ptr,
328  ola::proto::PluginListReply *reply_ptr,
329  PluginListCallback *callback);
330 
334  void HandlePluginDescription(ola::rpc::RpcController *controller,
335  ola::proto::PluginDescriptionReply *reply,
336  PluginDescriptionCallback *callback);
337 
341  void HandlePluginState(ola::rpc::RpcController *controller,
342  ola::proto::PluginStateReply *reply,
343  PluginStateCallback *callback);
344 
348  void HandleDeviceInfo(ola::rpc::RpcController *controller,
349  ola::proto::DeviceInfoReply *reply,
350  DeviceInfoCallback *callback);
351 
355  void HandleDeviceConfig(ola::rpc::RpcController *controller,
356  ola::proto::DeviceConfigReply *reply,
357  ConfigureDeviceCallback *callback);
358 
362  void HandleAck(ola::rpc::RpcController *controller,
363  ola::proto::Ack *reply,
364  SetCallback *callback);
365 
369  void HandleGeneralAck(ola::rpc::RpcController *controller,
370  ola::proto::Ack *reply,
371  GeneralSetCallback *callback);
372 
376  void HandleUniverseList(ola::rpc::RpcController *controller,
377  ola::proto::UniverseInfoReply *reply,
378  UniverseListCallback *callback);
379 
383  void HandleUniverseInfo(ola::rpc::RpcController *controller,
384  ola::proto::UniverseInfoReply *reply,
385  UniverseInfoCallback *callback);
386 
390  void HandleGetDmx(ola::rpc::RpcController *controller,
391  ola::proto::DmxData *reply,
392  DMXCallback *callback);
393 
397  void HandleUIDList(ola::rpc::RpcController *controller_ptr,
398  ola::proto::UIDListReply *reply_ptr,
399  DiscoveryCallback *callback);
400 
404  void HandleRDM(ola::rpc::RpcController *controller,
405  ola::proto::RDMResponse *reply,
406  RDMCallback *callback);
407 
411  void GenericFetchCandidatePorts(unsigned int universe_id,
412  bool include_universe,
413  CandidatePortsCallback *callback);
414 
418  void SendRDMCommand(bool is_set,
419  unsigned int universe,
420  const ola::rdm::UID &uid,
421  uint16_t sub_device,
422  uint16_t pid,
423  const uint8_t *data,
424  unsigned int data_length,
425  const SendRDMArgs &args);
426 
430  ola::rdm::RDMResponse *BuildRDMResponse(
431  ola::proto::RDMResponse *reply,
432  ola::rdm::rdm_response_code *response_code);
433 
434  static const char NOT_CONNECTED_ERROR[];
435 
436  DISALLOW_COPY_AND_ASSIGN(OlaClientCore);
437 };
438 
439 } // namespace client
440 } // namespace ola
441 #endif // OLA_OLACLIENTCORE_H_