Open Lighting Architecture
 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 
42 using std::string;
43 
44 
45 /*
46  * Represents the state of a response and/or any error codes.
47  *
48  * RDM Handlers should first check for error being non-empty as this
49  * represents an underlying transport error. Then the resonse_code
50  * should be checked to catch invalid responses, timeouts etc. Finally, the
51  * value of response_type should be checked against the rdm_response_type
52  * codes.
53  */
55  public:
56  string error; // Non empty if the RPC failed
57  rdm_response_code response_code;
58  uint8_t response_type; // The RDM response type
59  uint8_t message_count; // Number of queued messages
60  uint16_t m_param;
61  bool set_command;
62  uint16_t pid_value;
63 
64  // helper methods
65  bool WasAcked() const {
66  return (error.empty() && response_code == RDM_COMPLETED_OK &&
67  response_type == RDM_ACK);
68  }
69 
70  bool WasNacked() const {
71  return (error.empty() && response_code == RDM_COMPLETED_OK &&
72  response_type == RDM_NACK_REASON);
73  }
74 
75  // Returns the NACK Reason code
76  uint16_t NackReason() const { return m_param; }
77 
78  // Returns the time (in ms) to wait before re-trying
79  unsigned int AckTimer() const { return 100 * m_param; }
80 };
81 
82 
83 /*
84  * This is the interface for an RDMAPI implementation
85  */
87  public:
88  virtual ~RDMAPIImplInterface() {}
89 
90  // args are the response type the param data
91  typedef ola::SingleUseCallback2<void,
92  const ResponseStatus&,
93  const string&> rdm_callback;
94 
95  // args are response type, pid & param data
96  typedef ola::SingleUseCallback3<void,
97  const ResponseStatus&,
98  uint16_t,
99  const string&> rdm_pid_callback;
100 
101  // get command
102  virtual bool RDMGet(rdm_callback *callback,
103  unsigned int universe,
104  const UID &uid,
105  uint16_t sub_device,
106  uint16_t pid,
107  const uint8_t *data = NULL,
108  unsigned int data_length = 0) = 0;
109 
110  // A version of Get that also returns the pid. This is used to deal with
111  // queued messages
112  virtual bool RDMGet(rdm_pid_callback *callback,
113  unsigned int universe,
114  const UID &uid,
115  uint16_t sub_device,
116  uint16_t pid,
117  const uint8_t *data = NULL,
118  unsigned int data_length = 0) = 0;
119 
120  // set command
121  virtual bool RDMSet(rdm_callback *callback,
122  unsigned int universe,
123  const UID &uid,
124  uint16_t sub_device,
125  uint16_t pid,
126  const uint8_t *data = NULL,
127  unsigned int data_length = 0) = 0;
128 };
129 } // namespace rdm
130 } // namespace ola
131 #endif // INCLUDE_OLA_RDM_RDMAPIIMPLINTERFACE_H_