Open Lighting Architecture  Latest Git
OlaCallbackClient.h
Go to the documentation of this file.
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  * OlaCallbackClient.h
17  * The legacy callback client.
18  * Copyright (C) 2010 Simon Newton
19  */
20 
21 #ifndef OLA_OLACALLBACKCLIENT_H_
22 #define OLA_OLACALLBACKCLIENT_H_
23 
24 #include <ola/Callback.h>
25 #include <ola/DmxBuffer.h>
26 #include <ola/OlaDevice.h>
27 #include <ola/client/Result.h>
28 #include <ola/base/Macro.h>
29 #include <ola/network/Socket.h>
30 #include <ola/plugin_id.h>
32 #include <ola/rdm/RDMCommand.h>
33 #include <ola/rdm/UID.h>
34 #include <ola/rdm/UIDSet.h>
35 #include <ola/timecode/TimeCode.h>
36 
37 #include <memory>
38 #include <string>
39 #include <vector>
40 
47 namespace ola {
48 
49 namespace client {
50 class OlaClientCore;
51 }
52 
53 enum PatchAction {PATCH, UNPATCH};
56 
62  public:
63  struct PluginState {
64  std::string name;
65  bool enabled;
66  bool active;
67  std::string preferences_source;
68  std::vector<OlaPlugin> conflicting_plugins;
69  };
70 
73 
76 
77  typedef Callback4<void, unsigned int, uint8_t, const DmxBuffer&,
78  const std::string&> DMXCallbackWithPriority;
79 
80  explicit OlaCallbackClient(ola::io::ConnectedDescriptor *descriptor);
82 
83  bool Setup();
84  bool Stop();
85 
86  void SetCloseHandler(ola::SingleUseCallback0<void> *callback);
87 
88  // plugin methods
89  bool FetchPluginList(
90  SingleUseCallback2<void,
91  const std::vector<OlaPlugin>&,
92  const std::string&> *callback);
93 
94  bool FetchPluginDescription(
95  ola_plugin_id plugin_id,
96  SingleUseCallback2<void,
97  const std::string&,
98  const std::string&> *callback);
99 
100  bool FetchPluginState(ola_plugin_id plugin_id,
101  PluginStateCallback *callback);
102 
103  // device methods
104  bool FetchDeviceInfo(
105  ola_plugin_id filter,
106  SingleUseCallback2<void,
107  const std::vector<OlaDevice>&,
108  const std::string&> *callback);
109 
110  bool FetchCandidatePorts(
111  unsigned int universe_id,
112  SingleUseCallback2<void,
113  const std::vector<OlaDevice>&,
114  const std::string&> *callback);
115 
116  bool FetchCandidatePorts(
117  SingleUseCallback2<void,
118  const std::vector<OlaDevice>&,
119  const std::string&> *callback);
120 
121  bool ConfigureDevice(
122  unsigned int device_alias,
123  const std::string &msg,
124  SingleUseCallback2<void, const std::string&,
125  const std::string&> *callback);
126 
127  // port methods
128  bool SetPortPriorityInherit(
129  unsigned int device_alias,
130  unsigned int port,
131  PortDirection port_direction,
133  bool SetPortPriorityOverride(
134  unsigned int device_alias,
135  unsigned int port,
136  PortDirection port_direction,
137  uint8_t value,
139 
140  // universe methods
141  bool FetchUniverseList(
142  SingleUseCallback2<void,
143  const std::vector<OlaUniverse>&,
144  const std::string &> *callback);
145  bool FetchUniverseInfo(
146  unsigned int universe,
148  bool SetUniverseName(
149  unsigned int uni,
150  const std::string &name,
152  bool SetUniverseMergeMode(
153  unsigned int uni,
154  OlaUniverse::merge_mode mode,
156 
157  // patching
158  bool Patch(
159  unsigned int device_alias,
160  unsigned int port,
161  ola::PortDirection port_direction,
162  ola::PatchAction action,
163  unsigned int uni,
165 
166  // DMX methods
167  void SetDmxCallback(
168  Callback3<void,
169  unsigned int,
170  const DmxBuffer&, const std::string&> *callback);
171 
172  // Similar to above, but this also passes the source priority.
173  void SetDmxCallback(
174  Callback4<void,
175  unsigned int,
176  uint8_t,
177  const DmxBuffer&, const std::string&> *callback);
178 
179  bool RegisterUniverse(
180  unsigned int universe,
181  ola::RegisterAction register_action,
183  bool SendDmx(
184  unsigned int universe,
185  const DmxBuffer &data,
187  bool SendDmx(
188  unsigned int universe,
189  const DmxBuffer &data,
191  // A version of SendDmx that doesn't wait for confirmation
192  bool SendDmx(unsigned int universe, const DmxBuffer &data);
193 
194  bool FetchDmx(
195  unsigned int universe,
196  SingleUseCallback2<void, const DmxBuffer&,
197  const std::string&> *callback);
198 
199  // rdm methods
200  bool FetchUIDList(
201  unsigned int universe,
202  SingleUseCallback2<void,
203  const ola::rdm::UIDSet&,
204  const std::string&> *callback);
205  bool RunDiscovery(
206  unsigned int universe,
207  bool full,
209  const ola::rdm::UIDSet&,
210  const std::string&> *callback);
211  bool SetSourceUID(const ola::rdm::UID &uid,
213  const std::string&> *callback);
214 
215  bool RDMGet(ola::rdm::RDMAPIImplInterface::rdm_callback *callback,
216  unsigned int universe,
217  const ola::rdm::UID &uid,
218  uint16_t sub_device,
219  uint16_t pid,
220  const uint8_t *data,
221  unsigned int data_length);
223  unsigned int universe,
224  const ola::rdm::UID &uid,
225  uint16_t sub_device,
226  uint16_t pid,
227  const uint8_t *data,
228  unsigned int data_length);
229  bool RDMSet(ola::rdm::RDMAPIImplInterface::rdm_callback *callback,
230  unsigned int universe,
231  const ola::rdm::UID &uid,
232  uint16_t sub_device,
233  uint16_t pid,
234  const uint8_t *data,
235  unsigned int data_length);
237  unsigned int universe,
238  const ola::rdm::UID &uid,
239  uint16_t sub_device,
240  uint16_t pid,
241  const uint8_t *data,
242  unsigned int data_length);
243 
244  // timecode
245  bool SendTimeCode(ola::SingleUseCallback1<void,
246  const std::string&> *callback,
247  const ola::timecode::TimeCode &timecode);
248 
249  private:
250  std::auto_ptr<client::OlaClientCore> m_core;
251  std::auto_ptr<DMXCallback> m_dmx_callback;
252  std::auto_ptr<DMXCallbackWithPriority> m_priority_dmx_callback;
253 
254  void HandlePluginList(
255  SingleUseCallback2<void, const std::vector<OlaPlugin>&,
256  const std::string&> *callback,
257  const client::Result &result,
258  const std::vector<OlaPlugin> &plugins);
259 
260  void HandlePluginDescription(
261  SingleUseCallback2<void,
262  const std::string&,
263  const std::string&> *callback,
264  const client::Result &result,
265  const std::string &description);
266 
267  void HandlePluginState(
268  PluginStateCallback *callback,
269  const client::Result &result,
270  const client::PluginState &state);
271 
272  void HandleDeviceInfo(
273  SingleUseCallback2<void,
274  const std::vector<OlaDevice>&,
275  const std::string&> *callback,
276  const client::Result &result,
277  const std::vector<OlaDevice> &devices);
278 
279  void HandleConfigureDevice(
280  SingleUseCallback2<void,
281  const std::string&,
282  const std::string&> *callback,
283  const client::Result &result,
284  const std::string &reply);
285 
286  void HandleUniverseList(
287  SingleUseCallback2<void, const std::vector<OlaUniverse>&,
288  const std::string &> *callback,
289  const client::Result &result,
290  const std::vector<OlaUniverse> &universes);
291 
292  void HandleUniverseInfo(
294  const client::Result &result,
295  const OlaUniverse &universe);
296 
297  void HandleFetchDmx(
298  SingleUseCallback2<void,
299  const DmxBuffer&,
300  const std::string&> *callback,
301  const client::Result &result,
302  const client::DMXMetadata &metadata,
303  const DmxBuffer &data);
304 
305  void HandleDiscovery(
307  const ola::rdm::UIDSet&,
308  const std::string&> *callback,
309  const client::Result &result,
310  const ola::rdm::UIDSet &uids);
311 
312  void HandleSetCallback(
314  const client::Result &result);
315 
316  void HandleRepeatableSetCallback(
318  const client::Result &result);
319 
320  void HandleDMX(const client::DMXMetadata &metadata,
321  const DmxBuffer &data);
322 
323  void HandleRDMResponse(
325  const client::Result &result,
326  const client::RDMMetadata &metadata,
327  const ola::rdm::RDMResponse *response);
328 
329  void HandleRDMResponseWithPid(
331  const client::Result &result,
332  const client::RDMMetadata &metadata,
333  const ola::rdm::RDMResponse *response);
334 
335  void GetResponseStatusAndData(
336  const client::Result &result,
337  ola::rdm::rdm_response_code response_code,
338  const ola::rdm::RDMResponse *response,
339  rdm::ResponseStatus *response_status,
340  std::string *data);
341 
342  void GetParamFromReply(
343  const std::string &message_type,
344  const ola::rdm::RDMResponse *response,
345  ola::rdm::ResponseStatus *new_status);
346 
348 };
349 } // namespace ola
350 #endif // OLA_OLACALLBACKCLIENT_H_
Represents a set of RDM UIDs.
Definition: UIDSet.h:48
Definition: ClientArgs.h:56
A 0 arg, single use callback that returns void.
Definition: Callback.h:157
RDMStatusCode
RDM Status Codes.
Definition: RDMResponseCodes.h:45
SingleUseCallback3< void, const Result &, const DMXMetadata &, const DmxBuffer & > DMXCallback
Called once when OlaClient::FetchDMX() completes.
Definition: CallbackTypes.h:134
An RDM Command that represents responses (GET, SET or DISCOVER).
Definition: RDMCommand.h:457
PortDirection
The port direction.
Definition: ClientArgs.h:54
Metadata that accompanies RDM Responses.
Definition: ClientTypes.h:332
RegisterAction
The register action, used with OlaClient::RegisterUniverse()
Definition: ClientArgs.h:46
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Creates dummy copy constructor and assignment operator declarations.
Definition: Macro.h:44
A BidirectionalFileDescriptor that also generates notifications when closed.
Definition: Descriptor.h:282
SingleUseCallback2< void, const Result &, const PluginState & > PluginStateCallback
Invoked when OlaClient::FetchPluginState() completes.
Definition: CallbackTypes.h:63
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
The Result object passed to OLA client callbacks.
A 4 argument callback which can be called multiple times.
Definition: Callback.h:3821
The legacy callback client.
Definition: OlaCallbackClient.h:61
A set of UIDs.
The interface for an RDM API Implementation.
A class used to hold a single universe of DMX data.
Definition: ClientArgs.h:47
Definition: TimeCode.h:33
The state of a plugin. This information can be used to detect conflicts between plugins.
Definition: ClientTypes.h:93
A 3 argument callback which can be called multiple times.
Definition: Callback.h:2838
Indicates the result of a OLA API call.
Definition: Result.h:52
Represents the state of a response and/or any error codes.
Definition: RDMAPIImplInterface.h:51
Represents a universe.
Definition: ClientTypes.h:264
Definition: ClientArgs.h:39
Definition: ClientArgs.h:40
This is the interface for an RDMAPI implementation.
Definition: RDMAPIImplInterface.h:83
Helper macros.
Definition: ClientArgs.h:48
A 1 argument callback which deletes itself after it&#39;s run.
Definition: Callback.h:1004
A 3 argument callback which deletes itself after it&#39;s run.
Definition: Callback.h:2850
Represents a RDM UID.
Definition: UID.h:57
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
Definition: OlaCallbackClient.h:63
Metadata that accompanies DMX packets.
Definition: ClientTypes.h:311
Definition: ClientArgs.h:55
A 1 argument callback which can be called multiple times.
Definition: Callback.h:992
A 2 argument callback which deletes itself after it&#39;s run.
Definition: Callback.h:1907
Classes that represent RDM commands.