MIRA
ManifestAgent.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 #ifndef _MIRA_MANIFESTAGENT_H_
48 #define _MIRA_MANIFESTAGENT_H_
49 
50 #include <vector>
51 
52 #include <platform/Platform.h>
54 #include <factory/VacantClass.h>
55 #include <utils/Path.h>
56 
57 #include <error/LoggingCore.h>
58 #include <utils/PathFinder.h>
59 #include <utils/Foreach.h>
60 #include <serialization/adapters/boost/shared_ptr.hpp>
61 
62 namespace mira {
63 
65 
71  boost::shared_ptr<VacantClass> mClass;
72  std::vector< std::string > mParents;
73 
74  bool operator ==( ManifestClassInfo const& other ) {
75  return other.mClass == mClass;
76  }
77 
78  template<typename Reflector>
79  void reflect(Reflector& r)
80  {
81  r.member( "Class", mClass, "" );
82  r.member( "Parents", mParents, "" );
83  }
84 };
85 
87 
97 public:
98 
100 
105  ManifestAgent( std::string const& libraryName );
106 
110  ManifestAgent( std::string const& libraryName,
111  std::vector< ClassProxy > const& classes );
112 
116  void setLibraryVersion( int major, int minor, int patch );
117 
123  void addClasses( std::vector< ClassProxy > const& classes );
124 
134  void loadFile( Path const& filePath );
135 
139  void saveToFile( Path const& filePath );
140 
145  void finalize();
146 
147  template<typename Reflector>
148  void reflect(Reflector& r)
149  {
150  r.member( "LibraryName", mLibraryName, "" );
151  r.member( "LibraryVersion", mVersion, "" );
152  r.member( "Classes", mClasses, "" );
153  }
154 
155 protected:
156  std::vector< ManifestClassInfo > mClasses;
157  std::string mLibraryName;
159 };
160 
161 
162 
163 #ifdef MIRA_WINDOWS
164 # define MIRA_LIB_FOLDER "bin"
165 #else
166 # define MIRA_LIB_FOLDER "lib"
167 #endif
168 
173 inline void loadManifests(const Path& pattern = MIRA_LIB_FOLDER"/*.manifest")
174 {
175  std::vector<Path> manifests = findProjectFiles(pattern);
176  ManifestAgent manifestAgent;
177  foreach(const auto& p, manifests)
178  {
179  try
180  {
181  manifestAgent.loadFile(p);
182  } catch(XIO& ex)
183  {
184  // catch IO exceptions only (e.g. file not found, etc)
185  // all other exceptions concerning loading manifests are critical !!!
186  MIRA_LOG(ERROR) << "Failed to load manifest '" << p << "': " << ex.message();
187  } catch(Exception& ex) {
188  MIRA_RETHROW(ex, "in file '" << p.string() << "'");
189  }
190  }
191  manifestAgent.finalize();
192 }
193 
195 
196 } // namespace
197 
198 #endif /* _MIRA_MANIFESTAGENT_H_ */
199 
Macro for iterating over all elements in a container.
Different functions for searching files or directories.
std::string mLibraryName
Definition: ManifestAgent.h:157
Definition: LibraryRegistry.h:58
$Interface for the hollow class, which loads the library associated with the class if necessary...
boost::shared_ptr< VacantClass > mClass
Definition: ManifestAgent.h:71
void loadFile(Path const &filePath)
Load a single manifest file and announce the contained classes to the class factory.
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
boost::filesystem::path Path
Typedef of a Path (shorter version for boost::filesystem::path)
Definition: Path.h:69
MIRA_BASE_EXPORT PathVector findProjectFiles(const Path &file, bool recursive=false)
Same as findFiles above, but using all of the paths contained in $MIRA_PATH variable.
#define MIRA_LOG(level)
Use this macro to log data.
Definition: LoggingCore.h:529
#define MIRA_RETHROW(ex, msg)
Macro for rethrowing an exception with file and line information and for adding additional informatio...
Definition: Exception.h:148
void reflect(Reflector &r)
Definition: ManifestAgent.h:148
LibraryVersion mVersion
Definition: ManifestAgent.h:158
std::vector< std::string > mParents
Definition: ManifestAgent.h:72
Registry for shared libraries.
Core class of the logging library.
Class for managing manifest files.
Definition: ManifestAgent.h:96
bool operator==(const ImgIteratorBase &a, const ImgIteratorBase &b)
Definition: ImgIterator.h:225
Base class for exceptions.
Definition: Exception.h:199
void loadManifests(const Path &pattern=MIRA_LIB_FOLDER"/*.manifest")
Loads all manifest files that match the given file pattern within all paths that are specified in the...
Definition: ManifestAgent.h:173
Simple class encapsulation parent and class information stored in a "real" class object.
Definition: ManifestAgent.h:70
void finalize()
Register the parent - child relationships of the previously loaded files.
Functions for modifying file system paths.
void reflect(Reflector &r)
Definition: ManifestAgent.h:79
#define MIRA_LIB_FOLDER
Definition: ManifestAgent.h:166
#define MIRA_BASE_EXPORT
This is required because on windows there is a macro defined called ERROR.
Definition: Platform.h:153
Definition: LoggingCore.h:75
std::vector< ManifestClassInfo > mClasses
Definition: ManifestAgent.h:156
ManifestAgent()
Definition: ManifestAgent.h:99
Platform dependent defines and macros.