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>
50 template <
class Target>
52 bool include_required_pids)
53 : m_include_required_pids(include_required_pids) {
55 struct InternalParamHandler placeholder = {NULL, NULL};
56 STLReplace(&m_handlers, PID_SUPPORTED_PARAMETERS, placeholder);
60 struct InternalParamHandler pid_handler = {
69 template <
class Target>
71 const UID &target_uid,
76 auto_ptr<const RDMRequest> request(raw_request);
77 vector<string> packets;
86 if (!request->DestinationUID().DirectedToUID(target_uid)) {
87 if (!request->DestinationUID().IsBroadcast()) {
88 OLA_WARN <<
"Received request for the wrong UID, "
89 <<
"expected " << target_uid <<
", got "
90 << request->DestinationUID();
94 (request->DestinationUID().IsBroadcast() ?
95 RDM_WAS_BROADCAST : RDM_TIMEOUT),
102 on_complete->Run(RDM_PLUGIN_DISCOVERY_NOT_SUPPORTED, NULL, packets);
108 request->DestinationUID().IsBroadcast()) {
109 OLA_WARN <<
"Received broadcast GET command";
110 on_complete->Run(RDM_WAS_BROADCAST, NULL, packets);
115 rdm_response_code response_code = RDM_COMPLETED_OK;
118 bool for_our_subdevice = request->
SubDevice() == sub_device ||
119 request->SubDevice() == ALL_RDM_SUBDEVICES;
121 if (!for_our_subdevice) {
122 if (request->DestinationUID().IsBroadcast()) {
123 on_complete->Run(RDM_WAS_BROADCAST, NULL, packets);
125 response = NackWithReason(request.get(), NR_SUB_DEVICE_OUT_OF_RANGE);
126 on_complete->Run(RDM_COMPLETED_OK, response, packets);
132 if (request->SubDevice() == ALL_RDM_SUBDEVICES &&
135 response = NackWithReason(request.get(), NR_SUB_DEVICE_OUT_OF_RANGE);
136 on_complete->Run(RDM_COMPLETED_OK, response, packets);
140 InternalParamHandler *handler =
STLFind(&m_handlers, request->ParamId());
142 if (request->DestinationUID().IsBroadcast()) {
143 on_complete->Run(RDM_WAS_BROADCAST, NULL, packets);
145 response = NackWithReason(request.get(), NR_UNKNOWN_PID);
146 on_complete->Run(RDM_COMPLETED_OK, response, packets);
152 if (request->DestinationUID().IsBroadcast()) {
154 response_code = RDM_WAS_BROADCAST;
156 if (handler->get_handler) {
157 response = (target->*(handler->get_handler))(request.get());
159 switch (request->ParamId()) {
160 case PID_SUPPORTED_PARAMETERS:
161 response = HandleSupportedParams(request.get());
164 response = NackWithReason(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);
177 if (request->DestinationUID().IsBroadcast()) {
181 on_complete->Run(RDM_WAS_BROADCAST, NULL, packets);
183 on_complete->Run(response_code, response, packets);
187 template <
class Target>
191 return NackWithReason(request, NR_FORMAT_ERROR);
193 vector<uint16_t> params;
194 params.reserve(m_handlers.size());
195 typename RDMHandlers::const_iterator iter = m_handlers.begin();
196 for (; iter != m_handlers.end(); ++iter) {
197 uint16_t pid = iter->first;
199 if (m_include_required_pids || (
200 pid != PID_SUPPORTED_PARAMETERS &&
201 pid != PID_PARAMETER_DESCRIPTION &&
202 pid != PID_DEVICE_INFO &&
203 pid != PID_SOFTWARE_VERSION_LABEL &&
204 pid != PID_DMX_START_ADDRESS &&
205 pid != PID_IDENTIFY_DEVICE)) {
206 params.push_back(iter->first);
209 sort(params.begin(), params.end());
211 vector<uint16_t>::iterator param_iter = params.begin();
212 for (; param_iter != params.end(); ++param_iter) {
213 *param_iter = ola::network::HostToNetwork(*param_iter);
216 return GetResponseFromData(
218 reinterpret_cast<uint8_t*>(¶ms[0]),
219 params.size() *
sizeof(uint16_t));
223 #endif // INCLUDE_OLA_RDM_RESPONDEROPSPRIVATE_H_