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);
75 std::vector<std::string> packets;
86 OLA_WARN <<
"Received request for the wrong UID, "
87 <<
"expected " << target_uid <<
", got "
93 RDM_WAS_BROADCAST : RDM_TIMEOUT),
100 on_complete->Run(RDM_PLUGIN_DISCOVERY_NOT_SUPPORTED, NULL, packets);
107 OLA_WARN <<
"Received broadcast GET command";
108 on_complete->Run(RDM_WAS_BROADCAST, NULL, packets);
113 rdm_response_code response_code = RDM_COMPLETED_OK;
116 bool for_our_subdevice = request->
SubDevice() == sub_device ||
117 request->
SubDevice() == ALL_RDM_SUBDEVICES;
119 if (!for_our_subdevice) {
121 on_complete->Run(RDM_WAS_BROADCAST, NULL, packets);
123 response =
NackWithReason(request.get(), NR_SUB_DEVICE_OUT_OF_RANGE);
124 on_complete->Run(RDM_COMPLETED_OK, response, packets);
130 if (request->
SubDevice() == ALL_RDM_SUBDEVICES &&
133 response =
NackWithReason(request.get(), NR_SUB_DEVICE_OUT_OF_RANGE);
134 on_complete->Run(RDM_COMPLETED_OK, response, packets);
138 InternalParamHandler *handler =
STLFind(&m_handlers, request->
ParamId());
141 on_complete->Run(RDM_WAS_BROADCAST, NULL, packets);
144 on_complete->Run(RDM_COMPLETED_OK, response, packets);
152 response_code = RDM_WAS_BROADCAST;
154 if (handler->get_handler) {
155 response = (target->*(handler->get_handler))(request.get());
158 case PID_SUPPORTED_PARAMETERS:
159 response = HandleSupportedParams(request.get());
163 NR_UNSUPPORTED_COMMAND_CLASS);
168 if (handler->set_handler) {
169 response = (target->*(handler->set_handler))(request.get());
171 response =
NackWithReason(request.get(), NR_UNSUPPORTED_COMMAND_CLASS);
179 on_complete->Run(RDM_WAS_BROADCAST, NULL, packets);
181 on_complete->Run(response_code, response, packets);
185 template <
class Target>
191 std::vector<uint16_t> params;
192 params.reserve(m_handlers.size());
193 typename RDMHandlers::const_iterator iter = m_handlers.begin();
194 for (; iter != m_handlers.end(); ++iter) {
195 uint16_t pid = iter->first;
197 if (m_include_required_pids || (
198 pid != PID_SUPPORTED_PARAMETERS &&
199 pid != PID_PARAMETER_DESCRIPTION &&
200 pid != PID_DEVICE_INFO &&
201 pid != PID_SOFTWARE_VERSION_LABEL &&
202 pid != PID_DMX_START_ADDRESS &&
203 pid != PID_IDENTIFY_DEVICE)) {
204 params.push_back(iter->first);
207 sort(params.begin(), params.end());
209 std::vector<uint16_t>::iterator param_iter = params.begin();
210 for (; param_iter != params.end(); ++param_iter) {
211 *param_iter = ola::network::HostToNetwork(*param_iter);
216 reinterpret_cast<uint8_t*>(¶ms[0]),
217 params.size() *
sizeof(uint16_t));
221 #endif // INCLUDE_OLA_RDM_RESPONDEROPSPRIVATE_H_