MIRA
ServiceProperty.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_SERVICEPROPERTY_H_
48 #define _MIRA_SERVICEPROPERTY_H_
49 
53 
54 #include <fw/FrameworkExports.h>
55 #include <fw/Framework.h>
56 
57 namespace mira {
58 
60 
80 {
81 public:
82 
84 
86  mService(other.mService), mInterface(other.mInterface) {}
87 
89  explicit ServiceProperty(const std::string& interface) :
90  mInterface(interface) {}
91 
92  template <typename Reflector>
93  void reflect(Reflector& r) {
94  r.member("Service", mService, "The concrete service that is used", "");
95  r.member("Interface", mInterface, "The interface that is required");
96  }
97 
99  r.member("Service", mService, "The concrete service that is used", "");
100 
101  std::string interface;
102  r.member("Interface", interface, "The interface that is required",
104 
105  if (interface.empty()) {
106  if (mService.empty()) {
107  r.atomic(mService); // if there is neither Service nor Interface node,
108  // try to read service name directly from node's content
109  // (for backward compatibility)
110  if (!mService.empty()) {
111  MIRA_LOG(WARNING) << "Expected Service and (optional) Interface nodes for "
112  "ServiceProperty '" << *r.getNode() << "', "
113  "found string '" << mService <<
114  "' (assuming this for service name). "
115  "Please update your config xml (" <<
116  r.getNode().uri() << " , line " << r.getNode().line() << ").";
117  }
118  }
119  } else
120  mInterface = interface;
121 
122  // Interface node is only strictly required if mInterface was not initialized
123  // in constructor already
124  if (mInterface.empty())
125  MIRA_THROW(XMemberNotFound,
126  "ServiceProperty: Node 'Interface' is missing or empty");
127  }
128 
129  bool operator==(const ServiceProperty& other) const {
130  return mInterface == other.mInterface && mService == other.mService;
131  }
132 
133  bool operator!=(const ServiceProperty& other) const {
134  return !operator==(other);
135  }
136 
138  mService = other.mService;
139  mInterface = other.mInterface;
140  return *this;
141  }
142 
143  ServiceProperty& operator=(const std::string& s) {
144  mService = s;
145  return *this;
146  }
147 
149  const std::string& getService() const {
150  return mService;
151  }
152 
154  void setInterface(const std::string& interface) {
155  mInterface = interface;
156  }
157 
159  const std::string& getInterface() const {
160  return mInterface;
161  }
162 
163  operator std::string() const { return mService; }
164 
165  bool isEmpty() const {
166  return mService.empty();
167  }
168 
169  bool empty() const {
170  return mService.empty();
171  }
172 
173  bool isValid() const {
174  if (isEmpty())
175  return false;
176 
177  return MIRA_FW.getRPCManager().existsService(mService);
178  }
179 
180 private:
181 
182  std::string mService;
183  std::string mInterface;
184 };
185 
187 
188 } // namespace
189 
190 #endif
bool empty() const
Definition: ServiceProperty.h:169
This object can use object tracking internally, but the object tracking system&#39;s state remains unchan...
Definition: ReflectControlFlags.h:82
void reflect(XMLDeserializer &r)
Definition: ServiceProperty.h:98
ServiceProperty & operator=(const std::string &s)
Definition: ServiceProperty.h:143
std::string uri() const
Return the uri of the node.
Use this class instead of a string property whenever your module has a service as property...
Definition: ServiceProperty.h:79
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
void member(const char *name, T &member, const char *comment, ReflectCtrlFlags flags=REFLECT_CTRLFLAG_NONE)
Definition: RecursiveMemberReflector.h:862
#define MIRA_LOG(level)
Use this macro to log data.
Definition: LoggingCore.h:529
#define MIRA_FW
Macro for accessing the framework instance.
Definition: Framework.h:74
Framework export macro declaration.
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:82
Marker for indicating parameters that should be ignored if they are missing in the config file...
bool isEmpty() const
Definition: ServiceProperty.h:165
void setInterface(const std::string &interface)
Sets the interface a service must implement.
Definition: ServiceProperty.h:154
Marker for indicating parameters that should be ignored if they are missing in the config file...
Definition: IgnoreMissing.h:73
Contains the base interface of all Reflectors, Serializers, etc.
bool operator==(const ServiceProperty &other) const
Definition: ServiceProperty.h:129
uint32 line() const
Gets the underlying line number of the loaded document for this node.
ServiceProperty(const std::string &interface)
Constructor where the interface is specified that the service must implement.
Definition: ServiceProperty.h:89
const std::string & getInterface() const
Return the interface a service must implement.
Definition: ServiceProperty.h:159
Definition: LoggingCore.h:76
void atomic(T &member)
Definition: XMLSerializer.h:444
void reflect(Reflector &r)
Definition: ServiceProperty.h:93
XMLSerializer and XMLDeserializer.
bool isValid() const
Definition: ServiceProperty.h:173
ServiceProperty & operator=(const ServiceProperty &other)
Definition: ServiceProperty.h:137
bool operator!=(const ServiceProperty &other) const
Definition: ServiceProperty.h:133
The framework that holds all manager classes and provides startup and shutdown of all framework relat...
ServiceProperty()
Definition: ServiceProperty.h:83
const std::string & getService() const
Return the service that is associated with this property.
Definition: ServiceProperty.h:149
XMLDom::const_iterator getNode()
Definition: XMLSerializer.h:591
Deserializer for serializing objects from XML format.
Definition: XMLSerializer.h:313
ServiceProperty(const ServiceProperty &other)
Definition: ServiceProperty.h:85