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, const std::string &ip)> gnss_source_ip_handler_function;
98 
106 typedef boost::function<void(boost::system::error_code error_code, std::map<int, Geofence> &geofencesMap)> geofences_list_handler_function;
107 
115 typedef boost::function<void(boost::system::error_code error_code, std::list<std::string> &sogsList)> sogs_list_handler_function;
116 
117 
129 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;
130 
131 
142 typedef boost::function<void(boost::system::error_code error_code, SogEvent event, std::string sogid, int id, Geofence geofence)> sog_event_handler_function;
143 
144 
153 typedef boost::function<void(boost::system::error_code error_code, SogListEvent event, std::string sogid)> soglist_event_handler_function;
154 
155 } //dpyGeofencing
156 
157 #endif
158 
164 {
165 public:
174  virtual void NewEvent(dpyGeofencing::GeofenceEvent type, std::string sogid, int id, dpyGeofencing::Geofence geofence, double angle) = 0;
179  {
180  }
181 };
182 
183 
190 {
191 private:
192  boost::shared_ptr<GeofencingClient> mClient;
193 public:
194  explicit Geofencing(std::string ip = "127.0.0.1");
195  ~Geofencing();
196 
197  bool isAlive();
198  void monitorServiceAvailability_S(dpyGeofencing::service_availability_handler handler);
199  void monitorServiceAvailability_U();
200  void asyncAddPolygon(dpyGeofencing::result_handler_function handler, std::string sogid, int id, std::string name, bool enabled, std::vector<std::pair<double, double>> positionList);
201  void asyncAddCircle(dpyGeofencing::result_handler_function handler, std::string sogid, int id, std::string name, bool enabled, std::pair<double, double> position, int radius);
202  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);
203  void asyncDeleteGeofence(dpyGeofencing::result_handler_function handler, std::string sogid, int id);
204  void asyncEnableGeofence(dpyGeofencing::result_handler_function handler, std::string sogid, int id);
205  void asyncDisableGeofence(dpyGeofencing::result_handler_function handler, std::string sogid, int id);
206  void asyncEnableSog(dpyGeofencing::result_handler_function handler, std::string sogid);
207  void asyncDisableSog(dpyGeofencing::result_handler_function handler, std::string sogid);
208  void asyncDeleteSog(dpyGeofencing::result_handler_function handler, std::string sogid);
209  void asyncFeedPosition(dpyGeofencing::result_handler_function handler, std::pair<double, double> position);
210  boost::system::error_code feedPosition(std::pair<double, double> position);
211  void asyncDisableFeedPosition(dpyGeofencing::result_handler_function handler);
212  boost::system::error_code disableFeedPosition();
213  void asyncSetGnssSourceIp(dpyGeofencing::result_handler_function handler, std::string ip);
214  boost::system::error_code setGnssSourceIp(std::string ip);
215  void asyncGetGnssSourceIp(dpyGeofencing::gnss_source_ip_handler_function handler);
216  boost::system::error_code getGnssSourceIp(std::string &ip);
217 
218  void asyncGetSOGs(dpyGeofencing::sogs_list_handler_function handler);
219  void asyncGetGeofences(dpyGeofencing::geofences_list_handler_function handler, std::string sogid);
220 
221  //Observer
222  boost::system::error_code subscribePeriodicPosition(IgeofencingObserver *observer);
223  boost::system::error_code unsubscribePeriodicPosition(IgeofencingObserver *observer);
224 
225  void sogListEvents_S(dpyGeofencing::soglist_event_handler_function handler);
226  void sogListEvents_U();
227  void sogEvents_S(dpyGeofencing::sog_event_handler_function handler);
228  void sogEvents_U();
229  void geofenceEvents_S(dpyGeofencing::geofence_event_handler_function handler);
230  void geofenceEvents_U();
231 };
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:153
@ ENABLED
ENABLED.
Definition: geofencingApi.h:63
@ ENTER_ENABLED
ENTER_ENABLED.
Definition: geofencingApi.h:61
Deepsy Geofencing namespace that includes the different enums, structs or method signatures that shou...
@ GEOFENCE_REMOVED
A geofence is removed from the set.
Definition: geofencingApi.h:51
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:106
Definition: geofencingApi.h:27
bool enabled
indicates if the geofence is enabled or disabled. If disabled the geofence is not considered when sea...
Definition: geofencingApi.h:30
@ SOG_REMOVED
A set of geofences is removed.
Definition: geofencingApi.h:42
Interacts with geofencing server.
Definition: geofencingClient.h:13
virtual void NewEvent(dpyGeofencing::GeofenceEvent type, std::string sogid, int id, dpyGeofencing::Geofence geofence, double angle)=0
NewEvent. This function will be called on new position received event.
double radius
radius of the geofence (0 if polygon, >0 if buffered line or circle)
Definition: geofencingApi.h:33
boost::function< void(const bool &available)> service_availability_handler
Prototype of the handler function used to monitor service availability.
Definition: geofencingApi.h:80
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:142
boost::function< void(boost::system::error_code error_code, const std::string &ip)> gnss_source_ip_handler_function
Handler for get GNSS source IP requests.
Definition: geofencingApi.h:97
SogEvent
Definition: geofencingApi.h:48
virtual ~IgeofencingObserver()
Destructor.
Definition: geofencingApi.h:178
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:115
FeedStatus
Definition: geofencingApi.h:70
boost::function< void(boost::system::error_code error_code)> result_handler_function
Handler for command function callback.
Definition: geofencingApi.h:88
@ SOG_ADDED
A set of geofences is added.
Definition: geofencingApi.h:41
std::list< std::pair< double, double > > points
list of points that defines the geofence
Definition: geofencingApi.h:32
@ FEED_ENABLED
Custom position feed enabled.
Definition: geofencingApi.h:73
bool active
indicates if the geofence is active. It means the current position is inside the geofence.
Definition: geofencingApi.h:31
@ DISABLED
DISABLED.
Definition: geofencingApi.h:64
@ FEED_DISABLED
Custom position feed disabled.
Definition: geofencingApi.h:72
@ EXIT_DISABLED
EXIT_DISABLED.
Definition: geofencingApi.h:62
@ EXIT
EXIT.
Definition: geofencingApi.h:60
GeofenceEvent
Definition: geofencingApi.h:57
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:129
@ GEOFENCE_ADDED
A geofence is added to the set.
Definition: geofencingApi.h:50
Geofencing Observer base class.
Definition: geofencingApi.h:163
Allows to interact with geofencing server.
Definition: geofencingApi.h:189
std::string name
name of the geofence
Definition: geofencingApi.h:29
SogListEvent
Definition: geofencingApi.h:39
@ ENTER
ENTER.
Definition: geofencingApi.h:59