Open Lighting Architecture  0.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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_
void SetDMXCallback(RepeatableDMXCallback *callback)
Set the callback to be run when new DMX data arrives. The DMX callback will be run when new data arri...
Definition: OlaClientCore.cpp:120
The constants for DMX source priorities.
A 0 arg, single use callback that returns void.
Definition: Callback.h:157
Represents the RPC session between a client and server.
Definition: RpcSession.h:45
An RDM Command that represents responses (GET, SET or DISCOVER).
Definition: RDMCommand.h:456
PortDirection
The port direction.
Definition: ClientArgs.h:54
RegisterAction
The register action, used with OlaClient::RegisterUniverse()
Definition: ClientArgs.h:46
void SetPortPriorityOverride(unsigned int device_alias, unsigned int port, PortDirection port_direction, uint8_t value, SetCallback *callback)
Set the priority for a port to override mode.
Definition: OlaClientCore.cpp:302
DiscoveryType
The type of discovery to run with OlaClient::RunDiscovery().
Definition: ClientArgs.h:62
Types used as return values from the OLA Client.
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition: Descriptor.h:282
void RunDiscovery(unsigned int universe, DiscoveryType discovery_type, DiscoveryCallback *callback)
Trigger discovery for a universe.
Definition: OlaClientCore.cpp:516
void Patch(unsigned int device_alias, unsigned int port, PortDirection port_direction, PatchAction action, unsigned int universe, SetCallback *callback)
Patch or unpatch a port from a universe.
Definition: OlaClientCore.cpp:412
void ConfigureDevice(unsigned int device_alias, const std::string &msg, ConfigureDeviceCallback *callback)
Send a device config request.
Definition: OlaClientCore.cpp:231
void FetchUniverseList(UniverseListCallback *callback)
Request a list of universes.
Definition: OlaClientCore.cpp:329
void RDMGet(unsigned int universe, const ola::rdm::UID &uid, uint16_t sub_device, uint16_t pid, const uint8_t *data, unsigned int data_length, const SendRDMArgs &args)
Send an RDM Get Command.
Definition: OlaClientCore.cpp:567
Used to hold a single universe of DMX data.
Definition: DmxBuffer.h:49
A RDM unique identifier (UID).
PatchAction
The patch action, used with OlaClient::Patch()
Definition: ClientArgs.h:38
A set of UIDs.
void FetchCandidatePorts(CandidatePortsCallback *callback)
Definition: OlaClientCore.cpp:227
A class used to hold a single universe of DMX data.
Arguments passed to the SendDMX() method.
Definition: ClientArgs.h:71
void FetchDMX(unsigned int universe, DMXCallback *callback)
Fetch the latest DMX data for a universe.
Definition: OlaClientCore.cpp:496
The low level C++ API to olad. Clients shouldn't use this directly. Instead use ola::client::OlaClien...
Definition: OlaClientCore.h:56
void ReloadPlugins(SetCallback *callback)
Trigger a plugin reload.
Definition: OlaClientCore.cpp:124
Definition: TimeCode.h:33
void SetPortPriorityInherit(unsigned int device_alias, unsigned int port, PortDirection port_direction, SetCallback *callback)
Set the priority for a port to inherit mode.
Definition: OlaClientCore.cpp:277
Types used as arguments for the OLA Client.
void FetchPluginList(PluginListCallback *callback)
Fetch the list of plugins loaded.
Definition: OlaClientCore.cpp:141
void SendDMX(unsigned int universe, const DmxBuffer &data, const SendDMXArgs &args)
Send DMX data.
Definition: OlaClientCore.cpp:467
void SendTimeCode(const ola::timecode::TimeCode &timecode, SetCallback *callback)
Send TimeCode data.
Definition: OlaClientCore.cpp:589
void SetPluginState(ola_plugin_id plugin_id, bool state, SetCallback *callback)
Set the state of a plugin.
Definition: OlaClientCore.cpp:255
void SetSourceUID(const ola::rdm::UID &uid, SetCallback *callback)
Set the source UID for this client.
Definition: OlaClientCore.cpp:546
The base class for all 1 argument callbacks.
Definition: Callback.h:982
Arguments used with OlaClient::RDMGet() and OlaClient::RDMSet() methods.
Definition: ClientArgs.h:103
void RDMSet(unsigned int universe, const ola::rdm::UID &uid, uint16_t sub_device, uint16_t pid, const uint8_t *data, unsigned int data_length, const SendRDMArgs &args)
Send an RDM Set Command.
Definition: OlaClientCore.cpp:578
void FetchDeviceInfo(ola_plugin_id plugin_filter, DeviceInfoCallback *callback)
Request a list of the available devices.
Definition: OlaClientCore.cpp:201
Helper macros.
void FetchUniverseInfo(unsigned int universe, UniverseInfoCallback *callback)
Fetch the information for a given universe.
Definition: OlaClientCore.cpp:346
void SetUniverseName(unsigned int universe, const std::string &name, SetCallback *callback)
Set the name of a universe.
Definition: OlaClientCore.cpp:366
A 2 argument callback which can be called multiple times.
Definition: Callback.h:1895
A 1 argument callback which deletes itself after it's run.
Definition: Callback.h:1004
A 3 argument callback which deletes itself after it's run.
Definition: Callback.h:2850
Represents a RDM UID.
Definition: UID.h:57
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
void FetchPluginDescription(ola_plugin_id plugin_id, PluginDescriptionCallback *callback)
Fetch the description for a plugin.
Definition: OlaClientCore.cpp:158
void FetchPluginState(ola_plugin_id plugin_id, PluginStateCallback *callback)
Fetch the state of a plugin. This returns the state and the list of plugins this plugin conflicts wit...
Definition: OlaClientCore.cpp:180
void SetCloseHandler(ClosedCallback *callback)
Definition: OlaClientCore.cpp:111
void UpdateDmxData(ola::rpc::RpcController *controller, const ola::proto::DmxData *request, ola::proto::Ack *response, CompletionCallback *done)
This is called by the channel when new DMX data arrives.
Definition: OlaClientCore.cpp:622
A RpcController object is passed every time an RPC is invoked and is used to indicate the success or ...
Definition: RpcController.h:42
void RegisterUniverse(unsigned int universe, RegisterAction register_action, SetCallback *callback)
Register our interest in a universe. The callback set by SetDMXCallback() will be called when new DMX...
Definition: OlaClientCore.cpp:442
The various callbacks used with the OLA Client.
void SetUniverseMergeMode(unsigned int universe, OlaUniverse::merge_mode mode, SetCallback *callback)
Set the merge mode of a universe.
Definition: OlaClientCore.cpp:388
A 2 argument callback which deletes itself after it's run.
Definition: Callback.h:1907