geofencingApi.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include <boost/function.hpp>
6 #include <boost/system/error_code.hpp>
7 #include <boost/shared_ptr.hpp>
8 #include <list>
9 
10 class GeofencingClient;
11 
12 //To avoid redefinition in client and app
13 #ifndef GEOFENCING_TYPES
14 #define GEOFENCING_TYPES
15 
21 namespace dpyGeofencing {
22 
26 struct Geofence
27 {
28  std::string name;
29  bool enabled;
30  bool active;
31  std::list<std::pair<double,double>> points;
32  double radius;
33 };
34 
39 {
40  SOG_ADDED = 0,
42 };
43 
48 {
51 };
52 
57 {
58  ENTER = 0,
59  EXIT = 1,
62  ENABLED = 4,
63  DISABLED = 5,
64 };
65 
70 {
73 };
74 
79 typedef boost::function<void(const bool &available)> service_availability_handler;
80 
87 typedef boost::function<void(boost::system::error_code error_code)> result_handler_function;
88 
96 typedef boost::function<void(boost::system::error_code error_code, std::map<int, Geofence> &geofencesMap)> geofences_list_handler_function;
97 
105 typedef boost::function<void(boost::system::error_code error_code, std::list<std::string> &sogsList)> sogs_list_handler_function;
106 
107 
119 typedef boost::function<void(boost::system::error_code error_code, GeofenceEvent event, std::string sogid, int id, Geofence geofence, double angle)> geofence_event_handler_function;
120 
121 
132 typedef boost::function<void(boost::system::error_code error_code, SogEvent event, std::string sogid, int id, Geofence geofence)> sog_event_handler_function;
133 
134 
143 typedef boost::function<void(boost::system::error_code error_code, SogListEvent event, std::string sogid)> soglist_event_handler_function;
144 
145 } //dpyGeofencing
146 
147 #endif
148 
154 {
155 public:
164  virtual void NewEvent(dpyGeofencing::GeofenceEvent type, std::string sogid, int id, dpyGeofencing::Geofence geofence, double angle) = 0;
169  {
170  }
171 };
172 
173 
180 {
181 private:
182  boost::shared_ptr<GeofencingClient> mClient;
183 public:
184  explicit Geofencing(std::string ip = "127.0.0.1");
185  ~Geofencing();
186 
187  bool isAlive();
188  void monitorServiceAvailability_S(dpyGeofencing::service_availability_handler handler);
189  void monitorServiceAvailability_U();
190  void asyncAddPolygon(dpyGeofencing::result_handler_function handler, std::string sogid, int id, std::string name, bool enabled, std::vector<std::pair<double, double>> positionList);
191  void asyncAddCircle(dpyGeofencing::result_handler_function handler, std::string sogid, int id, std::string name, bool enabled, std::pair<double, double> position, int radius);
192  void asyncAddBufferedLine(dpyGeofencing::result_handler_function handler, std::string sogid, int id, std::string name, bool enabled, std::vector<std::pair<double, double>> positionList, int radius);
193  void asyncDeleteGeofence(dpyGeofencing::result_handler_function handler, std::string sogid, int id);
194  void asyncEnableGeofence(dpyGeofencing::result_handler_function handler, std::string sogid, int id);
195  void asyncDisableGeofence(dpyGeofencing::result_handler_function handler, std::string sogid, int id);
196  void asyncFeedPosition(dpyGeofencing::result_handler_function handler, std::pair<double, double> position);
197  boost::system::error_code feedPosition(std::pair<double, double> position);
198  void asyncDisableFeedPosition(dpyGeofencing::result_handler_function handler);
199  boost::system::error_code disableFeedPosition();
200 
201  void asyncGetSOGs(dpyGeofencing::sogs_list_handler_function handler);
202  void asyncGetGeofences(dpyGeofencing::geofences_list_handler_function handler, std::string sogid);
203 
204  //Observer
205  boost::system::error_code subscribePeriodicPosition(IgeofencingObserver *observer);
206  boost::system::error_code unsubscribePeriodicPosition(IgeofencingObserver *observer);
207 
208  void sogListEvents_S(dpyGeofencing::soglist_event_handler_function handler);
209  void sogListEvents_U();
210  void sogEvents_S(dpyGeofencing::sog_event_handler_function handler);
211  void sogEvents_U();
212  void geofenceEvents_S(dpyGeofencing::geofence_event_handler_function handler);
213  void geofenceEvents_U();
214 };
bool active
indicates if the geofence is active. It means the current position is inside the geofence.
Definition: geofencingApi.h:30
A geofence is removed from the set.
Definition: geofencingApi.h:50
Custom position feed disabled.
Definition: geofencingApi.h:71
ENTER.
Definition: geofencingApi.h:58
EXIT.
Definition: geofencingApi.h:59
boost::function< void(boost::system::error_code error_code, SogListEvent event, std::string sogid)> soglist_event_handler_function
Handler for command function callback.
Definition: geofencingApi.h:143
DISABLED.
Definition: geofencingApi.h:63
boost::function< void(const bool &available)> service_availability_handler
Prototype of the handler function used to monitor service availability.
Definition: geofencingApi.h:79
std::string name
name of the geofence
Definition: geofencingApi.h:28
boost::function< void(boost::system::error_code error_code, SogEvent event, std::string sogid, int id, Geofence geofence)> sog_event_handler_function
Handler for command function callback.
Definition: geofencingApi.h:132
ENABLED.
Definition: geofencingApi.h:62
SogEvent
Definition: geofencingApi.h:47
Deepsy Geofencing namespace that includes the different enums, structs or method signatures that shou...
boost::function< void(boost::system::error_code error_code, std::list< std::string > &sogsList)> sogs_list_handler_function
Handler for get "sets of geofences" request.
Definition: geofencingApi.h:105
boost::function< void(boost::system::error_code error_code, GeofenceEvent event, std::string sogid, int id, Geofence geofence, double angle)> geofence_event_handler_function
Handler for command function callback.
Definition: geofencingApi.h:119
ENTER_ENABLED.
Definition: geofencingApi.h:60
boost::function< void(boost::system::error_code error_code)> result_handler_function
Handler for command function callback.
Definition: geofencingApi.h:87
virtual ~IgeofencingObserver()
Destructor.
Definition: geofencingApi.h:168
FeedStatus
Definition: geofencingApi.h:69
Interacts with geofencing server.
Definition: geofencingClient.h:13
Definition: geofencingApi.h:26
Allows to interact with geofencing server.
Definition: geofencingApi.h:179
A set of geofences is removed.
Definition: geofencingApi.h:41
Geofencing Observer base class.
Definition: geofencingApi.h:153
GeofenceEvent
Definition: geofencingApi.h:56
EXIT_DISABLED.
Definition: geofencingApi.h:61
std::list< std::pair< double, double > > points
list of points that defines the geofence
Definition: geofencingApi.h:31
double radius
radius of the geofence (0 if polygon, >0 if buffered line or circle)
Definition: geofencingApi.h:32
boost::function< void(boost::system::error_code error_code, std::map< int, Geofence > &geofencesMap)> geofences_list_handler_function
Handler for get geofences requests.
Definition: geofencingApi.h:96
A set of geofences is added.
Definition: geofencingApi.h:40
bool enabled
indicates if the geofence is enabled or disabled. If disabled the geofence is not considered when sea...
Definition: geofencingApi.h:29
Custom position feed enabled.
Definition: geofencingApi.h:72
A geofence is added to the set.
Definition: geofencingApi.h:49
SogListEvent
Definition: geofencingApi.h:38