MIRA
ErrorService.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 
48 #ifndef _MIRA_ERRORSERVICE_H_
49 #define _MIRA_ERRORSERVICE_H_
50 
51 #include <serialization/adapters/std/vector>
52 
53 #include <fw/Framework.h>
54 
55 namespace mira {
56 
58 
60 class SQLiteDB;
61 
67 {
68 public:
70 
74  struct Error
75  {
76  std::string category;
77  std::string authority;
78  std::string trText;
79  std::string message;
80  uint32 count;
82 
83  template<typename Reflector>
84  void reflect(Reflector& r)
85  {
86  r.member("Category", category, "The error category.");
87  r.member("Authority", authority,
88  "The authority that reports the error.");
89  r.member("TrText", trText,
90  "The error text that is used for translation of errors.");
91  r.member("Message", message,
92  "The error message that will not be translated.");
93  r.member("Count", count,
94  "Number of error occurrences.");
95  r.member("TimeStamp", timestamp,
96  "Timestamp of last occurrence of the error.");
97  }
98 
99  Error() : count(0) {}
100  };
101 
103  typedef std::vector<Error> ErrorVector;
104 
106 
107  ErrorService(Authority& authority, const std::string& errorDBFilename);
108 
110  template<typename Reflector>
111  void reflect(Reflector& r)
112  {
113  r.interface("IError");
114  r.method("setError", &ErrorService::setError, this, "Set an error",
115  "category", "error category", "authority", "reporting authority",
116  "errorTxt", "error text (can be used for translation)",
117  "message", "error message (will not be translated)");
118  r.method("resetError", &ErrorService::resetError, this, "Reset an error",
119  "category", "error category", "authority", "reporting authority");
120  r.method("resetErrors", &ErrorService::resetErrors, this,
121  "Reset all errors for an authority",
122  "authority", "authority that reported the errors");
123  r.method("getErrorCount", &ErrorService::getErrorCount, this,
124  "Get number of errors for an authority",
125  "authority", "authority that reported the errors");
126  r.method("getErrors", &ErrorService::getErrors, this, "Get all errors");
127  r.method("getErrorText", &ErrorService::getErrorText, this,
128  "Translate an error text",
129  "error", "error text", "language", "language to translate to");
130  }
131 
140  void setError(const std::string& category, const std::string& authority,
141  const std::string& errorTxt, const std::string& message);
142 
148  void resetError(const std::string& category, const std::string& authority);
149 
154  void resetErrors(const std::string& authority);
155 
160  uint32 getErrorCount(const std::string& authority);
161 
165  ErrorVector getErrors();
166 
170  std::string getErrorText(const std::string& error, const std::string& language);
171 
172 protected:
173  void checkDB();
174  boost::mutex mMutex;
175 
177  std::string mErrorDBFilename;
178  boost::shared_ptr<SQLiteDB> mDB;
179 };
180 
182 
183 }
184 
185 #endif
std::string getErrorText(const std::string &error, const std::string &language)
Get a translation of an error text for the specified language.
void reflect(Reflector &r)
Definition: ErrorService.h:84
ErrorVector getErrors()
Get all errors from the database.
std::vector< Error > ErrorVector
A vector of errors.
Definition: ErrorService.h:103
Class that allows to store errors persistently in a SQLite database.
Definition: ErrorService.h:66
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Authority & mAuthority
Definition: ErrorService.h:176
Wrapper class for boost::posix_time::ptime for adding more functionality to it.
Definition: Time.h:416
std::string trText
Definition: ErrorService.h:78
boost::shared_ptr< SQLiteDB > mDB
Definition: ErrorService.h:178
void resetErrors(const std::string &authority)
Reset all errors for the given authority.
uint32 getErrorCount(const std::string &authority)
Get number of errors for the given authority.
std::string mErrorDBFilename
Definition: ErrorService.h:177
#define MIRA_FRAMEWORK_EXPORT
Definition: FrameworkExports.h:61
uint32 count
Definition: ErrorService.h:80
void resetError(const std::string &category, const std::string &authority)
Reset errors in a category for the given authority.
Authorities act as a facade to the framework.
Definition: Authority.h:94
void setError(const std::string &category, const std::string &authority, const std::string &errorTxt, const std::string &message)
Stores an error in a category for the given authority in the database.
std::string authority
Definition: ErrorService.h:77
void reflect(Reflector &r)
Reflect method for serialization.
Definition: ErrorService.h:111
boost::mutex mMutex
Definition: ErrorService.h:174
Error informations.
Definition: ErrorService.h:74
std::string message
Definition: ErrorService.h:79
std::string category
Definition: ErrorService.h:76
Error()
Definition: ErrorService.h:99
The framework that holds all manager classes and provides startup and shutdown of all framework relat...
Time timestamp
Definition: ErrorService.h:81