Open Lighting Architecture  0.9.6
 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 
148  void SetPluginState(ola_plugin_id plugin_id,
149  bool state,
150  SetCallback *callback);
151 
159  void SetPortPriorityInherit(unsigned int device_alias,
160  unsigned int port,
161  PortDirection port_direction,
162  SetCallback *callback);
163 
172  void SetPortPriorityOverride(unsigned int device_alias,
173  unsigned int port,
174  PortDirection port_direction,
175  uint8_t value,
176  SetCallback *callback);
177 
182  void FetchUniverseList(UniverseListCallback *callback);
183 
189  void FetchUniverseInfo(unsigned int universe,
190  UniverseInfoCallback *callback);
191 
198  void SetUniverseName(unsigned int universe,
199  const std::string &name,
200  SetCallback *callback);
201 
208  void SetUniverseMergeMode(unsigned int universe,
209  OlaUniverse::merge_mode mode,
210  SetCallback *callback);
211 
221  void Patch(unsigned int device_alias,
222  unsigned int port,
223  PortDirection port_direction,
224  PatchAction action,
225  unsigned int universe,
226  SetCallback *callback);
227 
235  void RegisterUniverse(unsigned int universe,
236  RegisterAction register_action,
237  SetCallback *callback);
238 
245  void SendDMX(unsigned int universe,
246  const DmxBuffer &data,
247  const SendDMXArgs &args);
248 
254  void FetchDMX(unsigned int universe, DMXCallback *callback);
255 
262  void RunDiscovery(unsigned int universe,
263  DiscoveryType discovery_type,
264  DiscoveryCallback *callback);
265 
271  void SetSourceUID(const ola::rdm::UID &uid, SetCallback *callback);
272 
283  void RDMGet(unsigned int universe,
284  const ola::rdm::UID &uid,
285  uint16_t sub_device,
286  uint16_t pid,
287  const uint8_t *data,
288  unsigned int data_length,
289  const SendRDMArgs& args);
290 
301  void RDMSet(unsigned int universe,
302  const ola::rdm::UID &uid,
303  uint16_t sub_device,
304  uint16_t pid,
305  const uint8_t *data,
306  unsigned int data_length,
307  const SendRDMArgs& args);
308 
314  void SendTimeCode(const ola::timecode::TimeCode &timecode,
315  SetCallback *callback);
316 
320  void UpdateDmxData(ola::rpc::RpcController* controller,
321  const ola::proto::DmxData* request,
322  ola::proto::Ack* response,
323  CompletionCallback* done);
324 
325  private:
326  ola::io::ConnectedDescriptor *m_descriptor;
327  std::auto_ptr<RepeatableDMXCallback> m_dmx_callback;
328  std::auto_ptr<ola::rpc::RpcChannel> m_channel;
329  std::auto_ptr<ola::proto::OlaServerService_Stub> m_stub;
330  int m_connected;
331 
332  void ChannelClosed(ClosedCallback *callback, ola::rpc::RpcSession *session);
333 
337  void HandlePluginList(ola::rpc::RpcController *controller_ptr,
338  ola::proto::PluginListReply *reply_ptr,
339  PluginListCallback *callback);
340 
344  void HandlePluginDescription(ola::rpc::RpcController *controller,
345  ola::proto::PluginDescriptionReply *reply,
346  PluginDescriptionCallback *callback);
347 
351  void HandlePluginState(ola::rpc::RpcController *controller,
352  ola::proto::PluginStateReply *reply,
353  PluginStateCallback *callback);
354 
358  void HandleDeviceInfo(ola::rpc::RpcController *controller,
359  ola::proto::DeviceInfoReply *reply,
360  DeviceInfoCallback *callback);
361 
365  void HandleDeviceConfig(ola::rpc::RpcController *controller,
366  ola::proto::DeviceConfigReply *reply,
367  ConfigureDeviceCallback *callback);
368 
372  void HandleAck(ola::rpc::RpcController *controller,
373  ola::proto::Ack *reply,
374  SetCallback *callback);
375 
379  void HandleGeneralAck(ola::rpc::RpcController *controller,
380  ola::proto::Ack *reply,
381  GeneralSetCallback *callback);
382 
386  void HandleUniverseList(ola::rpc::RpcController *controller,
387  ola::proto::UniverseInfoReply *reply,
388  UniverseListCallback *callback);
389 
393  void HandleUniverseInfo(ola::rpc::RpcController *controller,
394  ola::proto::UniverseInfoReply *reply,
395  UniverseInfoCallback *callback);
396 
400  void HandleGetDmx(ola::rpc::RpcController *controller,
401  ola::proto::DmxData *reply,
402  DMXCallback *callback);
403 
407  void HandleUIDList(ola::rpc::RpcController *controller_ptr,
408  ola::proto::UIDListReply *reply_ptr,
409  DiscoveryCallback *callback);
410 
414  void HandleRDM(ola::rpc::RpcController *controller,
415  ola::proto::RDMResponse *reply,
416  RDMCallback *callback);
417 
421  void GenericFetchCandidatePorts(unsigned int universe_id,
422  bool include_universe,
423  CandidatePortsCallback *callback);
424 
428  void SendRDMCommand(bool is_set,
429  unsigned int universe,
430  const ola::rdm::UID &uid,
431  uint16_t sub_device,
432  uint16_t pid,
433  const uint8_t *data,
434  unsigned int data_length,
435  const SendRDMArgs &args);
436 
440  ola::rdm::RDMResponse *BuildRDMResponse(
441  ola::proto::RDMResponse *reply,
442  ola::rdm::RDMStatusCode *status_code);
443 
444  static const char NOT_CONNECTED_ERROR[];
445 
446  DISALLOW_COPY_AND_ASSIGN(OlaClientCore);
447 };
448 
449 } // namespace client
450 } // namespace ola
451 #endif // OLA_OLACLIENTCORE_H_