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/Framework.h>
55 
56 namespace mira {
57 
59 
79 {
80 public:
81 
83 
85  mService(other.mService), mInterface(other.mInterface) {}
86 
88  explicit ServiceProperty(const std::string& interface) :
89  mInterface(interface) {}
90 
91  template <typename Reflector>
92  void reflect(Reflector& r) {
93  r.member("Service", mService, "The concrete service that is used", "");
94  r.member("Interface", mInterface, "The interface that is required");
95  }
96 
98  r.member("Service", mService, "The concrete service that is used", "");
99 
100  std::string interface;
101  r.member("Interface", interface, "The interface that is required",
103 
104  if (interface.empty()) {
105  if (mService.empty()) {
106  r.atomic(mService); // if there is neither Service nor Interface node,
107  // try to read service name directly from node's content
108  // (for backward compatibility)
109  if (!mService.empty()) {
110  MIRA_LOG(WARNING) << "Expected Service and (optional) Interface nodes for "
111  "ServiceProperty '" << *r.getNode() << "', "
112  "found string '" << mService <<
113  "' (assuming this for service name). "
114  "Please update your config xml (" <<
115  r.getNode().uri() << " , line " << r.getNode().line() << ").";
116  }
117  }
118  } else
119  mInterface = interface;
120 
121  // Interface node is only strictly required if mInterface was not initialized
122  // in constructor already
123  if (mInterface.empty())
124  MIRA_THROW(XMemberNotFound,
125  "ServiceProperty: Node 'Interface' is missing or empty");
126  }
127 
128  bool operator==(const ServiceProperty& other) const {
129  return mInterface == other.mInterface && mService == other.mService;
130  }
131 
132  bool operator!=(const ServiceProperty& other) const {
133  return !operator==(other);
134  }
135 
137  mService = other.mService;
138  mInterface = other.mInterface;
139  return *this;
140  }
141 
142  ServiceProperty& operator=(const std::string& s) {
143  mService = s;
144  return *this;
145  }
146 
148  const std::string& getService() const {
149  return mService;
150  }
151 
153  void setInterface(const std::string& interface) {
154  mInterface = interface;
155  }
156 
158  const std::string& getInterface() const {
159  return mInterface;
160  }
161 
162  operator std::string() const { return mService; }
163 
164  bool isEmpty() const {
165  return mService.empty();
166  }
167 
168  bool empty() const {
169  return mService.empty();
170  }
171 
172  bool isValid() const {
173  if (isEmpty())
174  return false;
175 
176  return MIRA_FW.getRPCManager().existsService(mService);
177  }
178 
179 private:
180 
181  std::string mService;
182  std::string mInterface;
183 };
184 
186 
187 } // namespace
188 
189 #endif
bool empty() const
Definition: ServiceProperty.h:168
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:97
ServiceProperty & operator=(const std::string &s)
Definition: ServiceProperty.h:142
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:78
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:883
#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
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:78
Marker for indicating parameters that should be ignored if they are missing in the config file...
bool isEmpty() const
Definition: ServiceProperty.h:164
void setInterface(const std::string &interface)
Sets the interface a service must implement.
Definition: ServiceProperty.h:153
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:128
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:88
const std::string & getInterface() const
Return the interface a service must implement.
Definition: ServiceProperty.h:158
Definition: LoggingCore.h:76
void atomic(T &member)
Definition: XMLSerializer.h:452
void reflect(Reflector &r)
Definition: ServiceProperty.h:92
XMLSerializer and XMLDeserializer.
bool isValid() const
Definition: ServiceProperty.h:172
ServiceProperty & operator=(const ServiceProperty &other)
Definition: ServiceProperty.h:136
bool operator!=(const ServiceProperty &other) const
Definition: ServiceProperty.h:132
The framework that holds all manager classes and provides startup and shutdown of all framework relat...
ServiceProperty()
Definition: ServiceProperty.h:82
const std::string & getService() const
Return the service that is associated with this property.
Definition: ServiceProperty.h:148
XMLDom::const_iterator getNode()
Definition: XMLSerializer.h:602
Deserializer for serializing objects from XML format.
Definition: XMLSerializer.h:314
ServiceProperty(const ServiceProperty &other)
Definition: ServiceProperty.h:84