MIRA
LibraryRegistry.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) by
3  * MetraLabs GmbH (MLAB), GERMANY
4  * and
5  * Neuroinformatics and Cognitive Robotics Labs (NICR) at TU Ilmenau, GERMANY
6  * All rights reserved.
7  *
8  * Contact: info@mira-project.org
9  *
10  * Commercial Usage:
11  * Licensees holding valid commercial licenses may use this file in
12  * accordance with the commercial license agreement provided with the
13  * software or, alternatively, in accordance with the terms contained in
14  * a written agreement between you and MLAB or NICR.
15  *
16  * GNU General Public License Usage:
17  * Alternatively, this file may be used under the terms of the GNU
18  * General Public License version 3.0 as published by the Free Software
19  * Foundation and appearing in the file LICENSE.GPL3 included in the
20  * packaging of this file. Please review the following information to
21  * ensure the GNU General Public License version 3.0 requirements will be
22  * met: http://www.gnu.org/copyleft/gpl.html.
23  * Alternatively you may (at your option) use any later version of the GNU
24  * General Public License if such license has been publicly approved by
25  * MLAB and NICR (or its successors, if any).
26  *
27  * IN NO EVENT SHALL "MLAB" OR "NICR" BE LIABLE TO ANY PARTY FOR DIRECT,
28  * INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
29  * THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF "MLAB" OR
30  * "NICR" HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * "MLAB" AND "NICR" SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
33  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
34  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
35  * ON AN "AS IS" BASIS, AND "MLAB" AND "NICR" HAVE NO OBLIGATION TO
36  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS.
37  */
38 
47 #include <map>
48 
49 #include <utils/Singleton.h>
50 
52 #include <utils/MakeString.h>
53 
54 #ifndef _MIRA_LIBRARYREGISTRY_H_
55 #define _MIRA_LIBRARYREGISTRY_H_
56 
57 namespace mira {
58 
60 
62 {
63  LibraryVersion() : mMajor(0), mMinor(0), mPatch(0) {}
64  LibraryVersion(uint32 iMajor, uint32 iMinor, uint32 iPatch)
65  : mMajor(iMajor), mMinor(iMinor), mPatch(iPatch) {}
66 
67  template<typename Reflector>
68  void reflect(Reflector& r)
69  {
70  r.member( "Major", mMajor, "" );
71  r.member( "Minor", mMinor, "" );
72  r.member( "Patch", mPatch, "" );
73  }
74 
75  bool operator==(const LibraryVersion& other) const
76  {
77  return (mMajor == other.mMajor) &&
78  (mMinor == other.mMinor) &&
79  (mPatch == other.mPatch);
80  }
81 
82  bool operator!=(const LibraryVersion& other) const { return !operator==(other); }
83 
84  bool empty() { return (mMajor + mMinor + mPatch) == 0; }
85 
89 };
90 
91 std::ostream& operator<<(std::ostream& s, const LibraryVersion& version);
92 
94 
96 {
97  enum ErrorType {
98  NoError = 0,
103  };
104 
105  template<typename Reflector>
106  void reflect(Reflector& r)
107  {
108  auto version = r.version(2, this);
109  r.member("Version", mVersion, "Library version",
111  r.member("HasManifest", mHasManifest, "Found a manifest for this lib",
113  r.member("IsLoaded", mIsLoaded, "Lib was loaded",
115  if (version >= 2) {
116  r.member("LoadError", mLoadError, "Type of load error (or NoError)");
117  r.roproperty("LoadError", mLoadError, "Type of load error (or NoError)",
119  "1=Manifest loaded twice;"
120  "2=Manifest version conflict;"
121  "3=Library loaded twice;"
122  "4=Library version conflict"));
123  r.member("ConflictingVersion", mConflictingVersion,
124  "Version of manifest/library that was conflicting (if any)",
126  }
127  }
128 
129  void setLoadError(ErrorType error,
130  LibraryVersion conflictingVersion = LibraryVersion());
131 
132  std::string reportError() const;
133 
135 
136  bool mHasManifest = false;
137  bool mIsLoaded = false;
138 
141 };
142 
144 
151 class LibraryRegistry : public LazySingleton<LibraryRegistry>
152 {
153 public:
154  typedef std::map<std::string, LibraryInfo > Register;
155 
156 public:
157 
164  static void registerManifest( const std::string& name,
165  const LibraryVersion& version );
166 
174  static void registerLibrary( const std::string& name,
175  const LibraryVersion& version) ;
176 
181  {
182  boost::mutex::scoped_lock lock(instance().mMutex);
183  return instance().mLibraries;
184  }
185 
189  static bool hasLoadError();
190 
194  static std::string reportErrors();
195 
196 private:
197  boost::mutex mMutex;
198  Register mLibraries;
199 };
200 
202 
203 } // namespace
204 
205 #endif /* _MIRA_LIBRARYREGISTRY_H_ */
uint32 mPatch
Definition: LibraryRegistry.h:88
Definition: LibraryRegistry.h:61
Class for in place stream formatting.
Definition: LibraryRegistry.h:99
Definition: LibraryRegistry.h:98
static Type & instance()
Returns a reference to the singleton instance.
Definition: Singleton.h:508
A registry for shared libraries.
Definition: LibraryRegistry.h:151
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
LibraryVersion mConflictingVersion
Definition: LibraryRegistry.h:140
PropertyHint enumeration(const std::string &values)
Sets the attribute "enumeration".
Definition: PropertyHint.h:306
Provides property hints and attributes.
std::string reportError() const
uint32_t uint32
Definition: Types.h:64
Provided for convenience.
Definition: Singleton.h:528
uint32 mMajor
Definition: LibraryRegistry.h:86
ErrorType
Definition: LibraryRegistry.h:97
std::ostream & operator<<(std::ostream &s, const LibraryVersion &version)
void reflect(Reflector &r)
Definition: LibraryRegistry.h:68
Definition: LibraryRegistry.h:101
std::map< std::string, LibraryInfo > Register
Definition: LibraryRegistry.h:154
bool empty()
Definition: LibraryRegistry.h:84
A singleton class that can be freely configured using policies that control the creation, instantiation, lifetime and thread-safety.
LibraryVersion()
Definition: LibraryRegistry.h:63
uint32 mMinor
Definition: LibraryRegistry.h:87
static std::string reportErrors()
Get full list of load error descriptions as string.
bool operator==(const LibraryVersion &other) const
Definition: LibraryRegistry.h:75
bool mIsLoaded
Definition: LibraryRegistry.h:137
void setLoadError(ErrorType error, LibraryVersion conflictingVersion=LibraryVersion())
bool mHasManifest
Definition: LibraryRegistry.h:136
static void registerLibrary(const std::string &name, const LibraryVersion &version)
Register library is loaded.
LibraryVersion mVersion
Definition: LibraryRegistry.h:134
static bool hasLoadError()
Query whether any library/manifest had an error when loading.
void reflect(Reflector &r)
Definition: LibraryRegistry.h:106
Definition: LibraryRegistry.h:100
ErrorType mLoadError
Definition: LibraryRegistry.h:139
Definition: LibraryRegistry.h:95
LibraryVersion(uint32 iMajor, uint32 iMinor, uint32 iPatch)
Definition: LibraryRegistry.h:64
static void registerManifest(const std::string &name, const LibraryVersion &version)
Register library manifest.
Definition: LibraryRegistry.h:102
static Register getRegister()
Get access to library register.
Definition: LibraryRegistry.h:180
When this flag is used in calls to Reflector::member(), that member is also reflected as read-only pr...
Definition: ReflectControlFlags.h:103
bool operator!=(const LibraryVersion &other) const
Definition: LibraryRegistry.h:82