Open Lighting Architecture  0.9.6
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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(const ola::rdm::pid::PidStore &store_pb,
87  const ola::rdm::pid::PidStore &override_pb,
88  bool validate);
89 
90  bool LoadFromProto(ManufacturerMap *pid_data,
91  const ola::rdm::pid::PidStore &proto,
92  bool validate);
93 
94  template <typename pb_object>
95  bool GetPidList(PidMap *pid_map,
96  const pb_object &store,
97  bool validate,
98  bool limit_pid_values);
99 
100  PidDescriptor *PidToDescriptor(const ola::rdm::pid::Pid &pid,
101  bool validate);
102  const ola::messaging::Descriptor* FrameFormatToDescriptor(
103  const ola::rdm::pid::FrameFormat &format,
104  bool validate);
105  const ola::messaging::FieldDescriptor *FieldToFieldDescriptor(
106  const ola::rdm::pid::Field &field);
107 
108  template <typename descriptor_class>
109  const ola::messaging::FieldDescriptor *IntegerFieldToFieldDescriptor(
110  const ola::rdm::pid::Field &field);
111 
112  const ola::messaging::FieldDescriptor *StringFieldToFieldDescriptor(
113  const ola::rdm::pid::Field &field);
114  const ola::messaging::FieldDescriptor *GroupFieldToFieldDescriptor(
115  const ola::rdm::pid::Field &field);
116  PidDescriptor::sub_device_validator ConvertSubDeviceValidator(
117  const ola::rdm::pid::SubDeviceRange &sub_device_range);
118 
119  void FreeManufacturerMap(ManufacturerMap *data);
120 
121  static const char OVERRIDE_FILE_NAME[];
122  static const uint16_t ESTA_MANUFACTURER_ID;
123  static const uint16_t MANUFACTURER_PID_MIN;
124  static const uint16_t MANUFACTURER_PID_MAX;
125 
126  DISALLOW_COPY_AND_ASSIGN(PidStoreLoader);
127 };
128 } // namespace rdm
129 } // namespace ola
130 #endif // COMMON_RDM_PIDSTORELOADER_H_