Open Lighting Architecture  0.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
41 namespace ola {
42 namespace rdm {
43 
44 class PidStore;
45 class PidDescriptor;
46 
47 // The following % before Device is to stop Doxygen interpretting it as a class
68 class RootPidStore {
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 
86  ~RootPidStore();
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  DISALLOW_COPY_AND_ASSIGN(RootPidStore);
180 };
181 
182 
186 class PidStore {
187  public:
196  explicit PidStore(const std::vector<const PidDescriptor*> &pids);
197 
201  ~PidStore();
202 
207  unsigned int PidCount() const { return m_pid_by_value.size(); }
208 
216  void AllPids(std::vector<const PidDescriptor*> *pids) const;
217 
223  const PidDescriptor *LookupPID(uint16_t pid_value) const;
224 
230  const PidDescriptor *LookupPID(const std::string &pid_name) const;
231 
232  private:
233  typedef std::map<uint16_t, const PidDescriptor*> PidMap;
234  typedef std::map<std::string, const PidDescriptor*> PidNameMap;
235  PidMap m_pid_by_value;
236  PidNameMap m_pid_by_name;
237 
238  DISALLOW_COPY_AND_ASSIGN(PidStore);
239 };
240 
241 
247  public:
248  // TODO(simon): use the enums from the Pids.proto instead of duplicating
249  // here.
250  typedef enum {
251  ROOT_DEVICE, // 0 only
252  ANY_SUB_DEVICE, // 0 - 512 or ALL_DEVICES
253  NON_BROADCAST_SUB_DEVICE, // 0 - 512
254  SPECIFIC_SUB_DEVICE, // 1- 512
255  } sub_device_validator;
256 
257  PidDescriptor(const std::string &name,
258  uint16_t value,
259  const ola::messaging::Descriptor *get_request,
260  const ola::messaging::Descriptor *get_response,
261  const ola::messaging::Descriptor *set_request,
262  const ola::messaging::Descriptor *set_response,
263  sub_device_validator get_sub_device_range,
264  sub_device_validator set_sub_device_range)
265  : m_name(name),
266  m_pid_value(value),
267  m_get_request(get_request),
268  m_get_response(get_response),
269  m_set_request(set_request),
270  m_set_response(set_response),
271  m_get_subdevice_range(get_sub_device_range),
272  m_set_subdevice_range(set_sub_device_range) {
273  }
274  ~PidDescriptor();
275 
276  const std::string &Name() const { return m_name; }
277  uint16_t Value() const { return m_pid_value; }
278  const ola::messaging::Descriptor *GetRequest() const { return m_get_request; }
279  const ola::messaging::Descriptor *GetResponse() const {
280  return m_get_response;
281  }
282  const ola::messaging::Descriptor *SetRequest() const { return m_set_request; }
283  const ola::messaging::Descriptor *SetResponse() const {
284  return m_set_response;
285  }
286 
287  bool IsGetValid(uint16_t sub_device) const;
288  bool IsSetValid(uint16_t sub_device) const;
289 
290  private:
291  const std::string m_name;
292  uint16_t m_pid_value;
293  const ola::messaging::Descriptor *m_get_request;
294  const ola::messaging::Descriptor *m_get_response;
295  const ola::messaging::Descriptor *m_set_request;
296  const ola::messaging::Descriptor *m_set_response;
297  sub_device_validator m_get_subdevice_range;
298  sub_device_validator m_set_subdevice_range;
299 
300  bool RequestValid(uint16_t sub_device,
301  const sub_device_validator &validator) const;
302 
303  DISALLOW_COPY_AND_ASSIGN(PidDescriptor);
304 };
305 } // namespace rdm
306 } // namespace ola
307 #endif // INCLUDE_OLA_RDM_PIDSTORE_H_
Holds the PidDescriptors for a single manufacturer.
Definition: PidStore.h:186
~PidStore()
Clean up.
Definition: PidStore.cpp:139
const PidStore * ManufacturerStore(uint16_t esta_id) const
Return the PidStore for a manufacturer.
Definition: PidStore.cpp:41
static const RootPidStore * LoadFromFile(const std::string &file, bool validate=true)
Load a RootPidStore from a file.
Definition: PidStore.cpp:109
uint64_t Version() const
The version of the RDM parameter data.
Definition: PidStore.h:93
static const RootPidStore * LoadFromDirectory(const std::string &directory, bool validate=true)
Load a RootPidStore from a directory.
Definition: PidStore.cpp:115
const PidDescriptor * GetDescriptor(const std::string &pid_name) const
Lookup a PLASA-defined parameter by name.
Definition: PidStore.cpp:48
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
const PidStore * EstaStore() const
Return the PidStore for PLASA (ESTA) parameters.
Definition: PidStore.h:100
unsigned int PidCount() const
The number of PidDescriptors in this store.
Definition: PidStore.h:207
const PidDescriptor * LookupPID(uint16_t pid_value) const
Lookup a PidDescriptor by PID.
Definition: PidStore.cpp:169
Helper macros.
Definition: Descriptor.h:399
bool IsGetValid(uint16_t sub_device) const
Definition: PidStore.cpp:196
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
bool IsSetValid(uint16_t sub_device) const
Definition: PidStore.cpp:206
The root of the RDM parameter descriptor store.
Definition: PidStore.h:68
static const std::string DataLocation()
Returns the location of the installed PID data.
Definition: PidStore.cpp:126
~PidDescriptor()
Definition: PidStore.cpp:157
RootPidStore(const PidStore *esta_store, const ManufacturerMap &manufacturer_stores, uint64_t version=0)
Create a new RootPidStore.
Definition: PidStore.h:78
Definition: PidStore.h:246