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