service_discovery
ServicePattern.hpp
Go to the documentation of this file.
1 #ifndef _SERVICE_DISCOVERY_SERVICEPATTERN_CORE_H_
2 #define _SERVICE_DISCOVERY_SERVICEPATTERN_CORE_H_
3 
4 #include <string>
5 #include <vector>
6 #include <boost/regex.hpp>
7 #include <service_discovery/impl/avahi/ServiceConfiguration.hpp>
8 
9 namespace servicediscovery {
10 namespace avahi {
11 
21 struct SearchPattern
22 {
23  SearchPattern(const std::string& _name = ".*" , const std::string& _label = ".*", const std::string& _txt = ".*", const std::string _type = ".*")
24  : namePattern(_name)
25  , labelPattern(_label)
26  , txtPattern(_txt)
27  , typePattern(_type)
28  {}
29 
30  virtual ~SearchPattern() {}
31 
32  boost::regex namePattern;
33  boost::regex labelPattern;
34  boost::regex txtPattern;
35  boost::regex typePattern;
36 
41  virtual bool isMatching(const ServiceDescription& description) const;
42 };
43 
44 
45 namespace pattern {
46 
50  enum Flags {
51  BUSY = 1,
52  READY = 2,
53  SLAM = 4,
54  MANIPULATOR = 8,
55  REMOTE = 16
56  };
57 
61  std::string castFlags(Flags flags);
62 }
63 
68 struct ServicePattern
69 {
70  virtual ~ServicePattern() {}
78  virtual bool matchDescription(const ServiceDescription& service) const = 0;
79 };
80 
81 // ----------------------------------------------------------------------------
82 
98 struct PropertyPattern : public ServicePattern
99 {
100  PropertyPattern(const std::string& label = "*", const std::string& expression = ".*")
101  : label(label), expression(expression, boost::regex::extended) {}
102 
103  virtual ~PropertyPattern() {}
104 
105  bool matchDescription(const ServiceDescription& service) const;
106 
107  private:
108  std::string label;
109  boost::regex expression;
110 };
111 
115 namespace pattern {
116  std::string hasAuthority(int authority);
117 }
118 
119 // ----------------------------------------------------------------------------
120 
128 struct PositionPattern : public ServicePattern
129 {
130  PositionPattern(int x, int y, int z, double distance)
131  : x(x), y(y), z(z), distance(distance) {}
132 
133  virtual ~PositionPattern() {}
134 
135  bool matchDescription(const ServiceDescription& service) const;
136 
137  private:
138  int x, y, z;
139  double distance;
140 };
141 
142 // ----------------------------------------------------------------------------
143 
150 struct FlagPattern : public ServicePattern
151 {
152  FlagPattern(int flags) : flags(flags) {}
153 
154  virtual ~FlagPattern() {}
155 
156  bool matchDescription(const ServiceDescription& service) const;
157 
158  private:
159  int flags;
160 };
161 
162 // ----------------------------------------------------------------------------
163 
179 struct MultiPattern : public ServicePattern
180 {
181  MultiPattern() {}
182 
183  virtual ~MultiPattern() {}
184 
185  bool matchDescription(const ServiceDescription& service) const;
186 
187  MultiPattern& operator<<(const ServicePattern& pattern) {
188  patterns.push_back(&pattern);
189  return *this;
190  }
191 
192  private:
193  std::vector<const ServicePattern*> patterns;
194 };
195 
196 // ----------------------------------------------------------------------------
197 
201 struct AuthorityPattern : public ServicePattern
202 {
203  AuthorityPattern(int authority, bool atleast = true) : authority(authority), atleast(atleast) {}
204 
205  virtual ~AuthorityPattern() {}
206 
207  bool matchDescription(const ServiceDescription& service) const;
208 
209  private:
210  int authority;
211  bool atleast;
212 };
213 
214 } // end namespace avahi
215 } // end namespace servicediscovery
216 #endif // _SERVICE_DISCOVERY_SERVICEPATTERN_CORE_H_
std::string castFlags(pattern::Flags flags)
Definition: ServicePattern.cpp:58