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 
51 #ifndef _MIRA_LIBRARYREGISTRY_H_
52 #define _MIRA_LIBRARYREGISTRY_H_
53 
54 namespace mira {
55 
57 
59 {
60  LibraryVersion() : mMajor(0), mMinor(0), mPatch(0) {}
61  LibraryVersion(int iMajor, int iMinor, int iPatch)
62  : mMajor(iMajor), mMinor(iMinor), mPatch(iPatch) {}
63 
64  template<typename Reflector>
65  void reflect(Reflector& r)
66  {
67  r.member( "Major", mMajor, "" );
68  r.member( "Minor", mMinor, "" );
69  r.member( "Patch", mPatch, "" );
70  }
71 
72  bool operator==(const LibraryVersion& other) const
73  {
74  return (mMajor == other.mMajor) &&
75  (mMinor == other.mMinor) &&
76  (mPatch == other.mPatch);
77  }
78 
79  bool operator!=(const LibraryVersion& other) const { return !operator==(other); }
80 
81  int mMajor;
82  int mMinor;
83  int mPatch;
84 };
85 
86 std::ostream& operator<<(std::ostream& s, const LibraryVersion& version);
87 
89 
91 {
92 
93  LibraryInfo() : mHasManifest(false), mIsLoaded(false) {}
94 
95  template<typename Reflector>
96  void reflect(Reflector& r)
97  {
98  r.member( "Version", mVersion, "" );
99  r.member( "HasManifest", mHasManifest, "" );
100  r.member( "IsLoaded", mIsLoaded, "" );
101  }
102 
105  bool mIsLoaded;
106 };
107 
109 
116 class MIRA_BASE_EXPORT LibraryRegistry : public LazySingleton<LibraryRegistry>
117 {
118 public:
119  typedef std::map<std::string, LibraryInfo > Register;
120 
121 public:
122 
129  static void registerManifest( const std::string& name,
130  const LibraryVersion& version );
131 
139  static void registerLibrary( const std::string& name,
140  const LibraryVersion& version) ;
141 
146  {
147  boost::mutex::scoped_lock lock(instance().mMutex);
148  return instance().mLibraries;
149  }
150 
151 private:
152  boost::mutex mMutex;
153  Register mLibraries;
154 };
155 
157 
158 } // namespace
159 
160 #endif /* _MIRA_LIBRARYREGISTRY_H_ */
Definition: LibraryRegistry.h:58
int mMajor
Definition: LibraryRegistry.h:81
int mMinor
Definition: LibraryRegistry.h:82
A registry for shared libraries.
Definition: LibraryRegistry.h:116
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Provided for convenience.
Definition: Singleton.h:564
std::ostream & operator<<(std::ostream &s, const LibraryVersion &version)
void reflect(Reflector &r)
Definition: LibraryRegistry.h:65
std::map< std::string, LibraryInfo > Register
Definition: LibraryRegistry.h:119
int mPatch
Definition: LibraryRegistry.h:83
A singleton class that can be freely configured using policies that control the creation, instantiation, lifetime and thread-safety.
LibraryVersion()
Definition: LibraryRegistry.h:60
bool operator==(const LibraryVersion &other) const
Definition: LibraryRegistry.h:72
bool mIsLoaded
Definition: LibraryRegistry.h:105
bool mHasManifest
Definition: LibraryRegistry.h:104
LibraryVersion(int iMajor, int iMinor, int iPatch)
Definition: LibraryRegistry.h:61
LibraryVersion mVersion
Definition: LibraryRegistry.h:103
LibraryInfo()
Definition: LibraryRegistry.h:93
void reflect(Reflector &r)
Definition: LibraryRegistry.h:96
Definition: LibraryRegistry.h:90
#define MIRA_BASE_EXPORT
This is required because on windows there is a macro defined called ERROR.
Definition: Platform.h:153
static Register getRegister()
Get access to library register.
Definition: LibraryRegistry.h:145
bool operator!=(const LibraryVersion &other) const
Definition: LibraryRegistry.h:79