/usr/include/ola/rdm/ResponderOpsPrivate.h is in libola-dev 0.9.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | /*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* ResponderOpsPrivate.h
* A private helper functions for building RDM responders.
* Copyright (C) 2013 Simon Newton
*/
/**
* @addtogroup rdm_resp
* @{
* @file ResponderOpsPrivate.h
* @brief Private helper functions for building RDM responders.
* @}
*/
#ifndef INCLUDE_OLA_RDM_RESPONDEROPSPRIVATE_H_
#define INCLUDE_OLA_RDM_RESPONDEROPSPRIVATE_H_
#include <ola/Logging.h>
#include <ola/network/NetworkUtils.h>
#include <ola/rdm/RDMCommand.h>
#include <ola/rdm/RDMControllerInterface.h>
#include <ola/rdm/RDMResponseCodes.h>
#include <ola/stl/STLUtils.h>
#include <algorithm>
#include <map>
#include <memory>
#include <string>
#include <vector>
namespace ola {
namespace rdm {
template <class Target>
ResponderOps<Target>::ResponderOps(const ParamHandler param_handlers[],
bool include_required_pids)
: m_include_required_pids(include_required_pids) {
// We install placeholders for any pids which are handled internally.
struct InternalParamHandler placeholder = {NULL, NULL};
STLReplace(&m_handlers, PID_SUPPORTED_PARAMETERS, placeholder);
const ParamHandler *handler = param_handlers;
while (handler->pid && (handler->get_handler || handler->set_handler)) {
struct InternalParamHandler pid_handler = {
handler->get_handler,
handler->set_handler
};
STLReplace(&m_handlers, handler->pid, pid_handler);
handler++;
}
}
template <class Target>
void ResponderOps<Target>::HandleRDMRequest(Target *target,
const UID &target_uid,
uint16_t sub_device,
const RDMRequest *raw_request,
RDMCallback *on_complete) {
// Take ownership of the request object, so the targets don't have to.
std::auto_ptr<const RDMRequest> request(raw_request);
if (!on_complete) {
OLA_WARN << "Null callback passed!";
return;
}
// If this isn't directed to our UID (unicast, vendorcast or broadcast), we
// return early.
if (!request->DestinationUID().DirectedToUID(target_uid)) {
if (!request->DestinationUID().IsBroadcast()) {
OLA_WARN << "Received request for the wrong UID, "
<< "expected " << target_uid << ", got "
<< request->DestinationUID();
}
RunRDMCallback(
on_complete,
request->DestinationUID().IsBroadcast() ? RDM_WAS_BROADCAST :
RDM_TIMEOUT);
return;
}
// Right now we don't support discovery.
if (request->CommandClass() == RDMCommand::DISCOVER_COMMAND) {
RunRDMCallback(on_complete, RDM_PLUGIN_DISCOVERY_NOT_SUPPORTED);
return;
}
// broadcast GETs are noops.
if (request->CommandClass() == RDMCommand::GET_COMMAND &&
request->DestinationUID().IsBroadcast()) {
OLA_WARN << "Received broadcast GET command";
RunRDMCallback(on_complete, RDM_WAS_BROADCAST);
return;
}
RDMResponse *response = NULL;
RDMStatusCode status_code = RDM_COMPLETED_OK;
// Right now we don't support sub devices
bool for_our_subdevice = request->SubDevice() == sub_device ||
request->SubDevice() == ALL_RDM_SUBDEVICES;
if (!for_our_subdevice) {
if (request->DestinationUID().IsBroadcast()) {
RunRDMCallback(on_complete, RDM_WAS_BROADCAST);
} else {
RDMReply reply(RDM_COMPLETED_OK,
NackWithReason(request.get(), NR_SUB_DEVICE_OUT_OF_RANGE));
on_complete->Run(&reply);
}
return;
}
// gets to ALL_RDM_SUBDEVICES are a special case
if (request->SubDevice() == ALL_RDM_SUBDEVICES &&
request->CommandClass() == RDMCommand::GET_COMMAND) {
// The broadcast get case was handled above.
RDMReply reply(RDM_COMPLETED_OK,
NackWithReason(request.get(), NR_SUB_DEVICE_OUT_OF_RANGE));
on_complete->Run(&reply);
return;
}
InternalParamHandler *handler = STLFind(&m_handlers, request->ParamId());
if (!handler) {
if (request->DestinationUID().IsBroadcast()) {
RunRDMCallback(on_complete, RDM_WAS_BROADCAST);
} else {
RDMReply reply(RDM_COMPLETED_OK,
NackWithReason(request.get(), NR_UNKNOWN_PID));
on_complete->Run(&reply);
}
return;
}
if (request->CommandClass() == RDMCommand::GET_COMMAND) {
if (request->DestinationUID().IsBroadcast()) {
// this should have been handled above, but be safe.
status_code = RDM_WAS_BROADCAST;
} else {
if (handler->get_handler) {
response = (target->*(handler->get_handler))(request.get());
} else {
switch (request->ParamId()) {
case PID_SUPPORTED_PARAMETERS:
response = HandleSupportedParams(request.get());
break;
default:
response = NackWithReason(request.get(),
NR_UNSUPPORTED_COMMAND_CLASS);
}
}
}
} else if (request->CommandClass() == RDMCommand::SET_COMMAND) {
if (handler->set_handler) {
response = (target->*(handler->set_handler))(request.get());
} else {
response = NackWithReason(request.get(), NR_UNSUPPORTED_COMMAND_CLASS);
}
}
if (request->DestinationUID().IsBroadcast()) {
if (response) {
delete response;
}
RunRDMCallback(on_complete, RDM_WAS_BROADCAST);
} else {
RDMReply reply(status_code, response);
on_complete->Run(&reply);
}
}
template <class Target>
RDMResponse *ResponderOps<Target>::HandleSupportedParams(
const RDMRequest *request) {
if (request->ParamDataSize())
return NackWithReason(request, NR_FORMAT_ERROR);
std::vector<uint16_t> params;
params.reserve(m_handlers.size());
typename RDMHandlers::const_iterator iter = m_handlers.begin();
for (; iter != m_handlers.end(); ++iter) {
uint16_t pid = iter->first;
// some pids never appear in supported_parameters.
if (m_include_required_pids || (
pid != PID_SUPPORTED_PARAMETERS &&
pid != PID_PARAMETER_DESCRIPTION &&
pid != PID_DEVICE_INFO &&
pid != PID_SOFTWARE_VERSION_LABEL &&
pid != PID_DMX_START_ADDRESS &&
pid != PID_IDENTIFY_DEVICE)) {
params.push_back(iter->first);
}
}
sort(params.begin(), params.end());
std::vector<uint16_t>::iterator param_iter = params.begin();
for (; param_iter != params.end(); ++param_iter) {
*param_iter = ola::network::HostToNetwork(*param_iter);
}
return GetResponseFromData(
request,
reinterpret_cast<uint8_t*>(¶ms[0]),
params.size() * sizeof(uint16_t));
}
} // namespace rdm
} // namespace ola
#endif // INCLUDE_OLA_RDM_RESPONDEROPSPRIVATE_H_
|