Open Lighting Architecture  0.9.2
 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 namespace client {
46 
51 class OlaClientCore: public ola::proto::OlaClientService {
52  public:
53  explicit OlaClientCore(ola::io::ConnectedDescriptor *descriptor);
54  ~OlaClientCore();
55 
56  bool Setup();
57  bool Stop();
58 
60 
68  void SetDMXCallback(RepeatableDMXCallback *callback);
69 
74  void ReloadPlugins(SetCallback *callback);
75 
80  void FetchPluginList(PluginListCallback *callback);
81 
88  void FetchPluginDescription(ola_plugin_id plugin_id,
89  PluginDescriptionCallback *callback);
90 
97  void FetchPluginState(ola_plugin_id plugin_id,
98  PluginStateCallback *callback);
99 
106  void FetchDeviceInfo(ola_plugin_id plugin_filter,
107  DeviceInfoCallback *callback);
108 
114 
122  void FetchCandidatePorts(unsigned int universe_id,
123  CandidatePortsCallback *callback);
124 
131  void ConfigureDevice(unsigned int device_alias,
132  const std::string &msg,
133  ConfigureDeviceCallback *callback);
134 
142  void SetPortPriorityInherit(unsigned int device_alias,
143  unsigned int port,
144  PortDirection port_direction,
145  SetCallback *callback);
146 
155  void SetPortPriorityOverride(unsigned int device_alias,
156  unsigned int port,
157  PortDirection port_direction,
158  uint8_t value,
159  SetCallback *callback);
160 
165  void FetchUniverseList(UniverseListCallback *callback);
166 
172  void FetchUniverseInfo(unsigned int universe,
173  UniverseInfoCallback *callback);
174 
181  void SetUniverseName(unsigned int universe,
182  const std::string &name,
183  SetCallback *callback);
184 
191  void SetUniverseMergeMode(unsigned int universe,
192  OlaUniverse::merge_mode mode,
193  SetCallback *callback);
194 
204  void Patch(unsigned int device_alias,
205  unsigned int port,
206  PortDirection port_direction,
207  PatchAction action,
208  unsigned int universe,
209  SetCallback *callback);
210 
218  void RegisterUniverse(unsigned int universe,
219  RegisterAction register_action,
220  SetCallback *callback);
221 
228  void SendDMX(unsigned int universe,
229  const DmxBuffer &data,
230  const SendDMXArgs &args);
231 
237  void FetchDMX(unsigned int universe, DMXCallback *callback);
238 
245  void RunDiscovery(unsigned int universe,
246  DiscoveryType discovery_type,
247  DiscoveryCallback *callback);
248 
254  void SetSourceUID(const ola::rdm::UID &uid, SetCallback *callback);
255 
266  void RDMGet(unsigned int universe,
267  const ola::rdm::UID &uid,
268  uint16_t sub_device,
269  uint16_t pid,
270  const uint8_t *data,
271  unsigned int data_length,
272  const SendRDMArgs& args);
273 
284  void RDMSet(unsigned int universe,
285  const ola::rdm::UID &uid,
286  uint16_t sub_device,
287  uint16_t pid,
288  const uint8_t *data,
289  unsigned int data_length,
290  const SendRDMArgs& args);
291 
297  void SendTimeCode(const ola::timecode::TimeCode &timecode,
298  SetCallback *callback);
299 
303  void UpdateDmxData(ola::rpc::RpcController* controller,
304  const ola::proto::DmxData* request,
305  ola::proto::Ack* response,
306  CompletionCallback* done);
307 
308  private:
309  ola::io::ConnectedDescriptor *m_descriptor;
310  std::auto_ptr<RepeatableDMXCallback> m_dmx_callback;
311  std::auto_ptr<ola::rpc::RpcChannel> m_channel;
312  std::auto_ptr<ola::proto::OlaServerService_Stub> m_stub;
313  int m_connected;
314 
318  void HandlePluginList(ola::rpc::RpcController *controller_ptr,
319  ola::proto::PluginListReply *reply_ptr,
320  PluginListCallback *callback);
321 
325  void HandlePluginDescription(ola::rpc::RpcController *controller,
326  ola::proto::PluginDescriptionReply *reply,
327  PluginDescriptionCallback *callback);
328 
332  void HandlePluginState(ola::rpc::RpcController *controller,
333  ola::proto::PluginStateReply *reply,
334  PluginStateCallback *callback);
335 
339  void HandleDeviceInfo(ola::rpc::RpcController *controller,
340  ola::proto::DeviceInfoReply *reply,
341  DeviceInfoCallback *callback);
342 
346  void HandleDeviceConfig(ola::rpc::RpcController *controller,
347  ola::proto::DeviceConfigReply *reply,
348  ConfigureDeviceCallback *callback);
349 
353  void HandleAck(ola::rpc::RpcController *controller,
354  ola::proto::Ack *reply,
355  SetCallback *callback);
356 
360  void HandleGeneralAck(ola::rpc::RpcController *controller,
361  ola::proto::Ack *reply,
362  GeneralSetCallback *callback);
363 
367  void HandleUniverseList(ola::rpc::RpcController *controller,
368  ola::proto::UniverseInfoReply *reply,
369  UniverseListCallback *callback);
370 
374  void HandleUniverseInfo(ola::rpc::RpcController *controller,
375  ola::proto::UniverseInfoReply *reply,
376  UniverseInfoCallback *callback);
377 
381  void HandleGetDmx(ola::rpc::RpcController *controller,
382  ola::proto::DmxData *reply,
383  DMXCallback *callback);
384 
388  void HandleUIDList(ola::rpc::RpcController *controller_ptr,
389  ola::proto::UIDListReply *reply_ptr,
390  DiscoveryCallback *callback);
391 
395  void HandleRDM(ola::rpc::RpcController *controller,
396  ola::proto::RDMResponse *reply,
397  RDMCallback *callback);
398 
402  void GenericFetchCandidatePorts(unsigned int universe_id,
403  bool include_universe,
404  CandidatePortsCallback *callback);
405 
409  void SendRDMCommand(bool is_set,
410  unsigned int universe,
411  const ola::rdm::UID &uid,
412  uint16_t sub_device,
413  uint16_t pid,
414  const uint8_t *data,
415  unsigned int data_length,
416  const SendRDMArgs &args);
417 
421  ola::rdm::RDMResponse *BuildRDMResponse(
422  ola::proto::RDMResponse *reply,
423  ola::rdm::rdm_response_code *response_code);
424 
425  static const char NOT_CONNECTED_ERROR[];
426 
427  DISALLOW_COPY_AND_ASSIGN(OlaClientCore);
428 };
429 
430 } // namespace client
431 } // namespace ola
432 #endif // OLA_OLACLIENTCORE_H_