Open Lighting Architecture  0.9.0
 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * OlaClientCore.h
17  * The OLA Client Core class
18  * Copyright (C) 2005-2008 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 FetchPluginList(PluginListCallback *callback);
75 
82  void FetchPluginDescription(ola_plugin_id plugin_id,
83  PluginDescriptionCallback *callback);
84 
91  void FetchPluginState(ola_plugin_id plugin_id,
92  PluginStateCallback *callback);
93 
100  void FetchDeviceInfo(ola_plugin_id plugin_filter,
101  DeviceInfoCallback *callback);
102 
108 
116  void FetchCandidatePorts(unsigned int universe_id,
117  CandidatePortsCallback *callback);
118 
125  void ConfigureDevice(unsigned int device_alias,
126  const std::string &msg,
127  ConfigureDeviceCallback *callback);
128 
136  void SetPortPriorityInherit(unsigned int device_alias,
137  unsigned int port,
138  PortDirection port_direction,
139  SetCallback *callback);
140 
149  void SetPortPriorityOverride(unsigned int device_alias,
150  unsigned int port,
151  PortDirection port_direction,
152  uint8_t value,
153  SetCallback *callback);
154 
159  void FetchUniverseList(UniverseListCallback *callback);
160 
166  void FetchUniverseInfo(unsigned int universe,
167  UniverseInfoCallback *callback);
168 
175  void SetUniverseName(unsigned int universe,
176  const std::string &name,
177  SetCallback *callback);
178 
185  void SetUniverseMergeMode(unsigned int universe,
186  OlaUniverse::merge_mode mode,
187  SetCallback *callback);
188 
198  void Patch(unsigned int device_alias,
199  unsigned int port,
200  PortDirection port_direction,
201  PatchAction action,
202  unsigned int universe,
203  SetCallback *callback);
204 
212  void RegisterUniverse(unsigned int universe,
213  RegisterAction register_action,
214  SetCallback *callback);
215 
222  void SendDMX(unsigned int universe,
223  const DmxBuffer &data,
224  const SendDMXArgs &args);
225 
231  void FetchDMX(unsigned int universe, DMXCallback *callback);
232 
239  void RunDiscovery(unsigned int universe,
240  DiscoveryType discovery_type,
241  DiscoveryCallback *callback);
242 
248  void SetSourceUID(const ola::rdm::UID &uid, SetCallback *callback);
249 
260  void RDMGet(unsigned int universe,
261  const ola::rdm::UID &uid,
262  uint16_t sub_device,
263  uint16_t pid,
264  const uint8_t *data,
265  unsigned int data_length,
266  const SendRDMArgs& args);
267 
278  void RDMSet(unsigned int universe,
279  const ola::rdm::UID &uid,
280  uint16_t sub_device,
281  uint16_t pid,
282  const uint8_t *data,
283  unsigned int data_length,
284  const SendRDMArgs& args);
285 
291  void SendTimeCode(const ola::timecode::TimeCode &timecode,
292  SetCallback *callback);
293 
297  void UpdateDmxData(ola::rpc::RpcController* controller,
298  const ola::proto::DmxData* request,
299  ola::proto::Ack* response,
300  CompletionCallback* done);
301 
302  private:
303  ola::io::ConnectedDescriptor *m_descriptor;
304  std::auto_ptr<RepeatableDMXCallback> m_dmx_callback;
305  std::auto_ptr<ola::rpc::RpcChannel> m_channel;
306  std::auto_ptr<ola::proto::OlaServerService_Stub> m_stub;
307  int m_connected;
308 
312  void HandlePluginList(ola::rpc::RpcController *controller_ptr,
313  ola::proto::PluginListReply *reply_ptr,
314  PluginListCallback *callback);
315 
319  void HandlePluginDescription(ola::rpc::RpcController *controller,
320  ola::proto::PluginDescriptionReply *reply,
321  PluginDescriptionCallback *callback);
322 
326  void HandlePluginState(ola::rpc::RpcController *controller,
327  ola::proto::PluginStateReply *reply,
328  PluginStateCallback *callback);
329 
333  void HandleDeviceInfo(ola::rpc::RpcController *controller,
334  ola::proto::DeviceInfoReply *reply,
335  DeviceInfoCallback *callback);
336 
340  void HandleDeviceConfig(ola::rpc::RpcController *controller,
341  ola::proto::DeviceConfigReply *reply,
342  ConfigureDeviceCallback *callback);
343 
347  void HandleAck(ola::rpc::RpcController *controller,
348  ola::proto::Ack *reply,
349  SetCallback *callback);
350 
354  void HandleGeneralAck(ola::rpc::RpcController *controller,
355  ola::proto::Ack *reply,
356  GeneralSetCallback *callback);
357 
361  void HandleUniverseList(ola::rpc::RpcController *controller,
362  ola::proto::UniverseInfoReply *reply,
363  UniverseListCallback *callback);
364 
368  void HandleUniverseInfo(ola::rpc::RpcController *controller,
369  ola::proto::UniverseInfoReply *reply,
370  UniverseInfoCallback *callback);
371 
375  void HandleGetDmx(ola::rpc::RpcController *controller,
376  ola::proto::DmxData *reply,
377  DMXCallback *callback);
378 
382  void HandleUIDList(ola::rpc::RpcController *controller_ptr,
383  ola::proto::UIDListReply *reply_ptr,
384  DiscoveryCallback *callback);
385 
389  void HandleRDM(ola::rpc::RpcController *controller,
390  ola::proto::RDMResponse *reply,
391  RDMCallback *callback);
392 
396  void GenericFetchCandidatePorts(unsigned int universe_id,
397  bool include_universe,
398  CandidatePortsCallback *callback);
399 
403  void SendRDMCommand(bool is_set,
404  unsigned int universe,
405  const ola::rdm::UID &uid,
406  uint16_t sub_device,
407  uint16_t pid,
408  const uint8_t *data,
409  unsigned int data_length,
410  const SendRDMArgs &args);
411 
415  ola::rdm::RDMResponse *BuildRDMResponse(
416  ola::proto::RDMResponse *reply,
417  ola::rdm::rdm_response_code *response_code);
418 
419  static const char NOT_CONNECTED_ERROR[];
420 
421  DISALLOW_COPY_AND_ASSIGN(OlaClientCore);
422 };
423 
424 } // namespace client
425 } // namespace ola
426 #endif // OLA_OLACLIENTCORE_H_