Open Lighting Architecture  0.9.0
 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * PidStoreHelper.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 <istream>
29 #include <string>
30 #include <vector>
31 #include "common/rdm/DescriptorConsistencyChecker.h"
32 #include "common/rdm/Pids.pb.h"
33 
34 namespace ola {
35 namespace rdm {
36 
41  public:
42  PidStoreLoader() {}
43  ~PidStoreLoader() {}
44 
45  // Load information into this store
46  const RootPidStore *LoadFromFile(const std::string &file,
47  bool validate = true);
48 
49  // Load information into this store
50  const RootPidStore *LoadFromDirectory(const std::string &directory,
51  bool validate = true);
52 
53  // Load information into this store
54  const RootPidStore *LoadFromStream(std::istream *data,
55  bool validate = true);
56 
57  private:
59  PidStoreLoader& operator=(const PidStoreLoader&);
61 
62  const RootPidStore *BuildStore(const ola::rdm::pid::PidStore &store_pb,
63  bool validate);
64  template <typename pb_object>
65  bool GetPidList(std::vector<const PidDescriptor*> *pids,
66  const pb_object &store,
67  bool validate,
68  bool limit_pid_values);
69  PidDescriptor *PidToDescriptor(const ola::rdm::pid::Pid &pid,
70  bool validate);
71  const ola::messaging::Descriptor* FrameFormatToDescriptor(
72  const ola::rdm::pid::FrameFormat &format,
73  bool validate);
74  const ola::messaging::FieldDescriptor *FieldToFieldDescriptor(
75  const ola::rdm::pid::Field &field);
76 
77  template <typename descriptor_class>
78  const ola::messaging::FieldDescriptor *IntegerFieldToFieldDescriptor(
79  const ola::rdm::pid::Field &field);
80 
81  const ola::messaging::FieldDescriptor *StringFieldToFieldDescriptor(
82  const ola::rdm::pid::Field &field);
83  const ola::messaging::FieldDescriptor *GroupFieldToFieldDescriptor(
84  const ola::rdm::pid::Field &field);
85  PidDescriptor::sub_device_validator ConvertSubDeviceValidator(
86  const ola::rdm::pid::SubDeviceRange &sub_device_range);
87  void CleanStore();
88 };
89 } // namespace rdm
90 } // namespace ola
91 #endif // COMMON_RDM_PIDSTORELOADER_H_