Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
PidStore.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * PidStore.h
17 * Holds information about RDM PIDs.
18 * Copyright (C) 2011 Simon Newton
19 */
20
29#ifndef INCLUDE_OLA_RDM_PIDSTORE_H_
30#define INCLUDE_OLA_RDM_PIDSTORE_H_
31
32#include <stdint.h>
33#include <ola/messaging/Descriptor.h>
34#include <ola/base/Macro.h>
35#include <istream>
36#include <map>
37#include <memory>
38#include <string>
39#include <vector>
40
41namespace ola {
42namespace rdm {
43
44class PidStore;
45class PidDescriptor;
46
47// The following % before Device is to stop Doxygen interpreting it as a class
69 public:
70 typedef std::map<uint16_t, const PidStore*> ManufacturerMap;
71
78 RootPidStore(const PidStore *esta_store,
79 const ManufacturerMap &manufacturer_stores,
80 uint64_t version = 0)
81 : m_esta_store(esta_store),
82 m_manufacturer_store(manufacturer_stores),
83 m_version(version) {
84 }
85
87
93 uint64_t Version() const { return m_version; }
94
100 const PidStore *EstaStore() const {
101 return m_esta_store.get();
102 }
103
110 const PidStore *ManufacturerStore(uint16_t esta_id) const;
111
117 const PidDescriptor *GetDescriptor(const std::string &pid_name) const;
118
126 const PidDescriptor *GetDescriptor(const std::string &pid_name,
127 uint16_t manufacturer_id) const;
128
134 const PidDescriptor *GetDescriptor(uint16_t pid_value) const;
135
143 const PidDescriptor *GetDescriptor(uint16_t pid_value,
144 uint16_t manufacturer_id) const;
145
152 static const RootPidStore *LoadFromFile(const std::string &file,
153 bool validate = true);
154
162 static const RootPidStore *LoadFromDirectory(const std::string &directory,
163 bool validate = true);
164
169 static const std::string DataLocation();
170
171 private:
172 std::auto_ptr<const PidStore> m_esta_store;
173 ManufacturerMap m_manufacturer_store;
174 uint64_t m_version;
175
176 const PidDescriptor *InternalESTANameLookup(
177 const std::string &pid_name) const;
178
179 RootPidStore(const RootPidStore &) = delete;
180 const RootPidStore &operator=(const RootPidStore &) = delete;
181};
182
183
187class PidStore {
188 public:
197 explicit PidStore(const std::vector<const PidDescriptor*> &pids);
198
202 ~PidStore();
203
208 unsigned int PidCount() const { return m_pid_by_value.size(); }
209
217 void AllPids(std::vector<const PidDescriptor*> *pids) const;
218
224 const PidDescriptor *LookupPID(uint16_t pid_value) const;
225
231 const PidDescriptor *LookupPID(const std::string &pid_name) const;
232
233 private:
234 typedef std::map<uint16_t, const PidDescriptor*> PidMap;
235 typedef std::map<std::string, const PidDescriptor*> PidNameMap;
236 PidMap m_pid_by_value;
237 PidNameMap m_pid_by_name;
238
239 PidStore(const PidStore &) = delete;
240 const PidStore &operator=(const PidStore &) = delete;
241};
242
243
249 public:
250 // TODO(simon): use the enums from the Pids.proto instead of duplicating
251 // here.
252 typedef enum {
253 ROOT_DEVICE, // 0 only
254 ANY_SUB_DEVICE, // 0 - 512 or ALL_DEVICES
255 NON_BROADCAST_SUB_DEVICE, // 0 - 512
256 SPECIFIC_SUB_DEVICE, // 1- 512
257 } sub_device_validator;
258
259 PidDescriptor(const std::string &name,
260 uint16_t value,
261 const ola::messaging::Descriptor *get_request,
262 const ola::messaging::Descriptor *get_response,
263 const ola::messaging::Descriptor *set_request,
264 const ola::messaging::Descriptor *set_response,
265 sub_device_validator get_sub_device_range,
266 sub_device_validator set_sub_device_range)
267 : m_name(name),
268 m_pid_value(value),
269 m_get_request(get_request),
270 m_get_response(get_response),
271 m_set_request(set_request),
272 m_set_response(set_response),
273 m_get_subdevice_range(get_sub_device_range),
274 m_set_subdevice_range(set_sub_device_range) {
275 }
277
278 const std::string &Name() const { return m_name; }
279 uint16_t Value() const { return m_pid_value; }
280 const ola::messaging::Descriptor *GetRequest() const { return m_get_request; }
281 const ola::messaging::Descriptor *GetResponse() const {
282 return m_get_response;
283 }
284 const ola::messaging::Descriptor *SetRequest() const { return m_set_request; }
285 const ola::messaging::Descriptor *SetResponse() const {
286 return m_set_response;
287 }
288
289 bool IsGetValid(uint16_t sub_device) const;
290 bool IsSetValid(uint16_t sub_device) const;
291
292 private:
293 const std::string m_name;
294 uint16_t m_pid_value;
295 const ola::messaging::Descriptor *m_get_request;
296 const ola::messaging::Descriptor *m_get_response;
297 const ola::messaging::Descriptor *m_set_request;
298 const ola::messaging::Descriptor *m_set_response;
299 sub_device_validator m_get_subdevice_range;
300 sub_device_validator m_set_subdevice_range;
301
302 bool RequestValid(uint16_t sub_device,
303 const sub_device_validator &validator) const;
304
305 PidDescriptor(const PidDescriptor &) = delete;
306 const PidDescriptor &operator=(const PidDescriptor &) = delete;
307};
308} // namespace rdm
309} // namespace ola
310#endif // INCLUDE_OLA_RDM_PIDSTORE_H_
Helper macros.
Definition Descriptor.h:399
Definition PidStore.h:248
bool IsSetValid(uint16_t sub_device) const
Definition PidStore.cpp:206
bool IsGetValid(uint16_t sub_device) const
Definition PidStore.cpp:196
~PidDescriptor()
Definition PidStore.cpp:157
Holds the PidDescriptors for a single manufacturer.
Definition PidStore.h:187
const PidDescriptor * LookupPID(uint16_t pid_value) const
Lookup a PidDescriptor by PID.
Definition PidStore.cpp:169
unsigned int PidCount() const
The number of PidDescriptors in this store.
Definition PidStore.h:208
~PidStore()
Clean up.
Definition PidStore.cpp:139
PidStore(const std::vector< const PidDescriptor * > &pids)
Create a new PidStore with the given PidDescriptors.
Definition PidStore.cpp:131
void AllPids(std::vector< const PidDescriptor * > *pids) const
Return a list of all PidDescriptors.
Definition PidStore.cpp:144
The root of the RDM parameter descriptor store.
Definition PidStore.h:68
static const RootPidStore * LoadFromDirectory(const std::string &directory, bool validate=true)
Load a RootPidStore from a directory.
Definition PidStore.cpp:115
uint64_t Version() const
The version of the RDM parameter data.
Definition PidStore.h:93
static const std::string DataLocation()
Returns the location of the installed PID data.
Definition PidStore.cpp:126
static const RootPidStore * LoadFromFile(const std::string &file, bool validate=true)
Load a RootPidStore from a file.
Definition PidStore.cpp:109
RootPidStore(const PidStore *esta_store, const ManufacturerMap &manufacturer_stores, uint64_t version=0)
Create a new RootPidStore.
Definition PidStore.h:78
const PidDescriptor * GetDescriptor(const std::string &pid_name) const
Lookup a PLASA-defined parameter by name.
Definition PidStore.cpp:48
const PidStore * EstaStore() const
Return the PidStore for PLASA (ESTA) parameters.
Definition PidStore.h:100
const PidStore * ManufacturerStore(uint16_t esta_id) const
Return the PidStore for a manufacturer.
Definition PidStore.cpp:41
The namespace containing all OLA symbols.
Definition Credentials.cpp:44