29 #ifndef INCLUDE_OLA_RDM_RESPONDEROPSPRIVATE_H_
30 #define INCLUDE_OLA_RDM_RESPONDEROPSPRIVATE_H_
33 #include <ola/network/NetworkUtils.h>
36 #include <ola/rdm/RDMResponseCodes.h>
48 template <
class Target>
50 bool include_required_pids)
51 : m_include_required_pids(include_required_pids) {
53 struct InternalParamHandler placeholder = {NULL, NULL};
54 STLReplace(&m_handlers, PID_SUPPORTED_PARAMETERS, placeholder);
58 struct InternalParamHandler pid_handler = {
67 template <
class Target>
69 const UID &target_uid,
74 std::auto_ptr<const RDMRequest> request(raw_request);
85 OLA_WARN <<
"Received request for the wrong UID, "
86 <<
"expected " << target_uid <<
", got "
106 OLA_WARN <<
"Received broadcast GET command";
112 RDMStatusCode status_code = RDM_COMPLETED_OK;
115 bool for_our_subdevice = request->
SubDevice() == sub_device ||
116 request->
SubDevice() == ALL_RDM_SUBDEVICES;
118 if (!for_our_subdevice) {
124 on_complete->Run(&reply);
130 if (request->
SubDevice() == ALL_RDM_SUBDEVICES &&
135 on_complete->Run(&reply);
139 InternalParamHandler *handler =
STLFind(&m_handlers, request->
ParamId());
146 on_complete->Run(&reply);
154 status_code = RDM_WAS_BROADCAST;
156 if (handler->get_handler) {
157 response = (target->*(handler->get_handler))(request.get());
160 case PID_SUPPORTED_PARAMETERS:
161 response = HandleSupportedParams(request.get());
165 NR_UNSUPPORTED_COMMAND_CLASS);
170 if (handler->set_handler) {
171 response = (target->*(handler->set_handler))(request.get());
173 response =
NackWithReason(request.get(), NR_UNSUPPORTED_COMMAND_CLASS);
183 RDMReply reply(status_code, response);
184 on_complete->Run(&reply);
188 template <
class Target>
194 std::vector<uint16_t> params;
195 params.reserve(m_handlers.size());
196 typename RDMHandlers::const_iterator iter = m_handlers.begin();
197 for (; iter != m_handlers.end(); ++iter) {
198 uint16_t pid = iter->first;
200 if (m_include_required_pids || (
201 pid != PID_SUPPORTED_PARAMETERS &&
202 pid != PID_PARAMETER_DESCRIPTION &&
203 pid != PID_DEVICE_INFO &&
204 pid != PID_SOFTWARE_VERSION_LABEL &&
205 pid != PID_DMX_START_ADDRESS &&
206 pid != PID_IDENTIFY_DEVICE)) {
207 params.push_back(iter->first);
210 sort(params.begin(), params.end());
212 std::vector<uint16_t>::iterator param_iter = params.begin();
213 for (; param_iter != params.end(); ++param_iter) {
219 reinterpret_cast<uint8_t*>(¶ms[0]),
220 params.size() *
sizeof(uint16_t));
224 #endif // INCLUDE_OLA_RDM_RESPONDEROPSPRIVATE_H_
Definitions and Interfaces to implement an RDMController that sends a single message at a time...
uint16_t HostToNetwork(uint16_t value)
16-bit unsigned host to network conversion.
Definition: NetworkUtils.cpp:155
An RDM Command that represents responses (GET, SET or DISCOVER).
Definition: RDMCommand.h:456
RDMResponse * GetResponseFromData(const RDMRequest *request, const uint8_t *data, unsigned int length, rdm_response_type type, uint8_t outstanding_messages)
Generate an ACK Response with some data.
Definition: RDMCommand.cpp:584
bool DirectedToUID(const UID &uid) const
Check if this UID matches against another.
Definition: UID.h:175
RDM Commands that represent requests (GET, SET or DISCOVER).
Definition: RDMCommand.h:233
RDMHandler set_handler
Definition: ResponderOps.h:79
Definition: RDMCommand.h:69
RDMResponse * NackWithReason(const RDMRequest *request, rdm_nack_reason reason_enum, uint8_t outstanding_messages)
Generate a NACK response with a reason code.
Definition: RDMCommand.cpp:572
#define OLA_WARN
Definition: Logging.h:73
bool IsBroadcast() const
Check if this UID is a broadcast or vendorcast UID.
Definition: UID.h:150
the structure that defines the behaviour for a specific PID.o
Definition: ResponderOps.h:76
A class which dispatches RDM requests to registered PID handlers.
Definition: ResponderOps.h:60
unsigned int ParamDataSize() const
Returns the Size of the Parameter Data of the RDMCommand.
Definition: RDMCommand.h:140
uint16_t pid
Definition: ResponderOps.h:77
const UID & DestinationUID() const
Returns the Destination UID of the RDMCommand.
Definition: RDMCommand.h:119
ResponderOps(const ParamHandler param_handlers[], bool include_required_pids=false)
Construct a new ResponderOps object.
Definition: ResponderOpsPrivate.h:49
void HandleRDMRequest(Target *target, const UID &target_uid, uint16_t sub_device, const RDMRequest *request, RDMCallback *on_complete)
Handle a RDMRequest.
Definition: ResponderOpsPrivate.h:68
RDMHandler get_handler
Definition: ResponderOps.h:78
The base class for all 1 argument callbacks.
Definition: Callback.h:982
Definition: RDMCommand.h:71
Helper functions for STL classes.
Holds the final state of an RDM request.
Definition: RDMReply.h:43
uint16_t ParamId() const
Returns the Parameter ID of the RDMCommand.
Definition: RDMCommand.h:137
uint16_t SubDevice() const
Returns the SubDevice of the RDMCommand.
Definition: RDMCommand.h:131
RDMCommandClass CommandClass() const
The CommmandClass of this message.
Definition: RDMCommand.h:293
void RunRDMCallback(RDMCallback *callback, RDMStatusCode status_code)
A helper message to run a RDMCallback with the given status code.
Definition: RDMControllerInterface.h:59
Represents a RDM UID.
Definition: UID.h:57
bool STLReplace(T1 *container, const typename T1::key_type &key, const typename T1::mapped_type &value)
Replace a value in a pair associative container, inserting the key, value if it doesn't already exist...
Definition: STLUtils.h:258
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
T1::mapped_type * STLFind(T1 *container, const typename T1::key_type &key)
Lookup a value by key in a associative container.
Definition: STLUtils.h:193
Header file for OLA Logging.
Definition: RDMCommand.h:67
Classes that represent RDM commands.