Open Lighting Architecture  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RDMAPIImplInterface.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  * RDMAPIImplInterface.h
17  * The interface for an RDM API Implementation
18  * Copyright (C) 2010 Simon Newton
19  */
20 
29 #ifndef INCLUDE_OLA_RDM_RDMAPIIMPLINTERFACE_H_
30 #define INCLUDE_OLA_RDM_RDMAPIIMPLINTERFACE_H_
31 
32 #include <stdint.h>
33 #include <ola/rdm/UID.h>
34 #include <ola/Callback.h>
35 #include <ola/rdm/RDMEnums.h>
36 #include <ola/rdm/RDMResponseCodes.h>
37 #include <string>
38 
39 namespace ola {
40 namespace rdm {
41 
52  public:
53  std::string error; // Non empty if the RPC failed
54  RDMStatusCode response_code;
55  uint8_t response_type;
56  uint8_t message_count;
57  uint16_t m_param;
58  bool set_command;
59  uint16_t pid_value;
60 
61  // helper methods
62  bool WasAcked() const {
63  return (error.empty() && response_code == RDM_COMPLETED_OK &&
64  response_type == RDM_ACK);
65  }
66 
67  bool WasNacked() const {
68  return (error.empty() && response_code == RDM_COMPLETED_OK &&
69  response_type == RDM_NACK_REASON);
70  }
71 
72  // Returns the NACK Reason code
73  uint16_t NackReason() const { return m_param; }
74 
75  // Returns the time (in ms) to wait before re-trying
76  unsigned int AckTimer() const { return 100 * m_param; }
77 };
78 
79 
84  public:
85  virtual ~RDMAPIImplInterface() {}
86 
87  // args are the response type the param data
88  typedef ola::SingleUseCallback2<void,
89  const ResponseStatus&,
90  const std::string&> rdm_callback;
91 
92  // args are response type, pid & param data
93  typedef ola::SingleUseCallback3<void,
94  const ResponseStatus&,
95  uint16_t,
96  const std::string&> rdm_pid_callback;
97 
98  // get command
99  virtual bool RDMGet(rdm_callback *callback,
100  unsigned int universe,
101  const UID &uid,
102  uint16_t sub_device,
103  uint16_t pid,
104  const uint8_t *data = NULL,
105  unsigned int data_length = 0) = 0;
106 
107  // A version of Get that also returns the pid. This is used to deal with
108  // queued messages
109  virtual bool RDMGet(rdm_pid_callback *callback,
110  unsigned int universe,
111  const UID &uid,
112  uint16_t sub_device,
113  uint16_t pid,
114  const uint8_t *data = NULL,
115  unsigned int data_length = 0) = 0;
116 
117  // set command
118  virtual bool RDMSet(rdm_callback *callback,
119  unsigned int universe,
120  const UID &uid,
121  uint16_t sub_device,
122  uint16_t pid,
123  const uint8_t *data = NULL,
124  unsigned int data_length = 0) = 0;
125 };
126 } // namespace rdm
127 } // namespace ola
128 #endif // INCLUDE_OLA_RDM_RDMAPIIMPLINTERFACE_H_