Open Lighting Architecture  Latest Git
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PidStoreLoader.h
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  * PidStoreLoader.h
17  * This class does the heavy lifting for loading the PidStore from a protobuf.
18  * It's separate so that PidStore.h doesn't have to include the Pids.pb.h
19  * header.
20  * Copyright (C) 2011 Simon Newton
21  */
22 
23 #ifndef COMMON_RDM_PIDSTORELOADER_H_
24 #define COMMON_RDM_PIDSTORELOADER_H_
25 
26 #include <ola/messaging/Descriptor.h>
27 #include <ola/rdm/PidStore.h>
28 #include <map>
29 #include <istream>
30 #include <string>
31 #include <vector>
32 #include "common/rdm/DescriptorConsistencyChecker.h"
33 #include "common/rdm/Pids.pb.h"
34 
35 namespace ola {
36 namespace rdm {
37 
42  public:
43  PidStoreLoader() {}
44 
52  const RootPidStore *LoadFromFile(const std::string &file,
53  bool validate = true);
54 
64  const RootPidStore *LoadFromDirectory(const std::string &directory,
65  bool validate = true);
66 
74  const RootPidStore *LoadFromStream(std::istream *data,
75  bool validate = true);
76 
77  private:
78  typedef std::map<uint16_t, const PidDescriptor*> PidMap;
79  typedef std::map<uint16_t, PidMap*> ManufacturerMap;
80 
82 
83  bool ReadFile(const std::string &file_path,
84  ola::rdm::pid::PidStore *proto);
85 
86  const RootPidStore *BuildStore(
87  const ola::rdm::pid::PidStore &store_pb,
88  const ola::rdm::pid::PidStore &override_pb,
89  const ola::rdm::pid::PidStore &manufacturer_names_pb,
90  bool validate);
91 
92  inline const RootPidStore *BuildStore(
93  const ola::rdm::pid::PidStore &store_pb,
94  const ola::rdm::pid::PidStore &override_pb,
95  bool validate) {
96  ola::rdm::pid::PidStore manufacturer_names_pb;
97  return BuildStore(store_pb, override_pb, manufacturer_names_pb, validate);
98  }
99 
100  bool LoadFromProto(ManufacturerMap *pid_data,
101  const ola::rdm::pid::PidStore &proto,
102  bool validate);
103 
104  template <typename pb_object>
105  bool GetPidList(PidMap *pid_map,
106  const pb_object &store,
107  bool validate,
108  bool limit_pid_values);
109 
110  PidDescriptor *PidToDescriptor(const ola::rdm::pid::Pid &pid,
111  bool validate);
112  const ola::messaging::Descriptor* FrameFormatToDescriptor(
113  const ola::rdm::pid::FrameFormat &format,
114  bool validate);
115  const ola::messaging::FieldDescriptor *FieldToFieldDescriptor(
116  const ola::rdm::pid::Field &field);
117 
118  template <typename descriptor_class>
119  const ola::messaging::FieldDescriptor *IntegerFieldToFieldDescriptor(
120  const ola::rdm::pid::Field &field);
121 
122  const ola::messaging::FieldDescriptor *StringFieldToFieldDescriptor(
123  const ola::rdm::pid::Field &field);
124  const ola::messaging::FieldDescriptor *GroupFieldToFieldDescriptor(
125  const ola::rdm::pid::Field &field);
126  PidDescriptor::sub_device_validator ConvertSubDeviceValidator(
127  const ola::rdm::pid::SubDeviceRange &sub_device_range);
128 
129  void FreeManufacturerMap(ManufacturerMap *data);
130 
131  static const char OVERRIDE_FILE_NAME[];
132  static const char MANUFACTURER_NAMES_FILE_NAME[];
133  static const uint16_t ESTA_MANUFACTURER_ID;
134  static const uint16_t MANUFACTURER_PID_MIN;
135  static const uint16_t MANUFACTURER_PID_MAX;
136 
137  DISALLOW_COPY_AND_ASSIGN(PidStoreLoader);
138 };
139 } // namespace rdm
140 } // namespace ola
141 #endif // COMMON_RDM_PIDSTORELOADER_H_
const RootPidStore * LoadFromDirectory(const std::string &directory, bool validate=true)
Load PID information from a directory, including overrides.
Definition: PidStoreLoader.cpp:73
Definition: PidStoreLoader.h:41
Definition: Descriptor.h:66
Holds information about RDM PIDs.
const RootPidStore * LoadFromFile(const std::string &file, bool validate=true)
Load PID information from a file.
Definition: PidStoreLoader.cpp:59
const RootPidStore * LoadFromStream(std::istream *data, bool validate=true)
Load Pid information from a stream.
Definition: PidStoreLoader.cpp:142
Definition: DescriptorConsistencyChecker.h:43
Definition: Descriptor.h:403
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
The root of the RDM parameter descriptor store.
Definition: PidStore.h:68
Definition: PidStore.h:246