elocation: Add elocation libraray to EFL.

Elocation is meant as a convenience library to ease application developers
the usage of geo information in their apps. Adding a geo tag to a picture or
translating an address to a GPS position and show it on a map widget are just
some of the use cases.

In the beginning elocation will rely on the GeoClue1 DBus service. Supporting
the new GeoClue2 DBus service is planned and worked on. GeoClue offers
providers for various techniques to get hold off the current position. Ranging
from GeoIP over wifi and GSM cell location to GPS.

This has been developed a while ago and was living in my private dev space.
It is about time to move this into EFL and bring it forward.

The detection of the GeoClue service is being handled on runtime and no new
dependency is added due to this library.

@feature
This commit is contained in:
Stefan Schmidt 2014-10-28 11:22:55 +01:00
parent c2f130a2f7
commit a2d2cdaf9f
7 changed files with 2081 additions and 1 deletions

View File

@ -4374,6 +4374,42 @@ EFL_EVAL_PKGS([ELUA])
EFL_LIB_END_OPTIONAL([Elua])
#### End of Elua
#### Elocation
EFL_LIB_START([Elocation])
### Default values
### Additional options to configure
### Checks for programs
### Checks for libraries
EFL_PLATFORM_DEPEND([ELOCATION], [evil])
EFL_INTERNAL_DEPEND_PKG([ELOCATION], [eina])
EFL_INTERNAL_DEPEND_PKG([ELOCATION], [eo])
EFL_INTERNAL_DEPEND_PKG([ELOCATION], [ecore])
EFL_INTERNAL_DEPEND_PKG([ELOCATION], [eldbus])
EFL_ADD_LIBS([ELOCATION], [-lm])
### Checks for header files
### Checks for types
### Checks for structures
### Checks for compiler characteristics
### Checks for linker characteristics
### Checks for library functions
### Check availability
EFL_LIB_END([Elocation])
#### End of Elocation
### Add Wayland server library if test is enabled
if test "x${want_tests}" = "xyes" -a "x${want_wayland}" = "xyes"; then
EFL_DEPEND_PKG([ECORE_WAYLAND_SRV], [WAYLAND], [wayland-server >= 1.3.0])
@ -4496,6 +4532,7 @@ pc/edje-cxx.pc
pc/emotion.pc
pc/ethumb.pc
pc/ethumb_client.pc
pc/elocation.pc
dbus-services/org.enlightenment.Efreet.service
dbus-services/org.enlightenment.Ethumb.service
systemd-services/efreet.service

12
pc/elocation.pc.in Normal file
View File

@ -0,0 +1,12 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@
Name: elocation
Description: Enlightenment location library
@pkgconfig_requires_private@: @requirements_elocation@
Version: @VERSION@
Libs: -L${libdir} -lelocation
Libs.private: -lm
Cflags: -I${includedir}/elocation-@VMAJ@

View File

@ -78,8 +78,8 @@ include Makefile_Eolian_Cxx.am
include Makefile_Eet_Cxx.am
include Makefile_Eo_Cxx.am
include Makefile_Efl_Cxx.am
include Makefile_Elua.am
include Makefile_Elocation.am
.PHONY: benchmark examples

16
src/Makefile_Elocation.am Normal file
View File

@ -0,0 +1,16 @@
### Library
lib_LTLIBRARIES += lib/elocation/libelocation.la
installed_elocationsmainheadersdir = $(includedir)/elocation-@VMAJ@
dist_installed_elocationsmainheaders_DATA = \
lib/elocation/Elocation.h \
lib/elocation/elocation_private.h
lib_elocation_libelocation_la_SOURCES = \
lib/elocation/elocation.c
lib_elocation_libelocation_la_CPPFLAGS = -I$(top_builddir)/src/lib/efl @ELOCATION_CFLAGS@
lib_elocation_libelocation_la_LIBADD = @ELOCATION_LIBS@
lib_elocation_libelocation_la_DEPENDENCIES = @ELOCATION_INTERNAL_LIBS@
lib_elocation_libelocation_la_LDFLAGS = @EFL_LTLIBRARY_FLAGS@

View File

@ -0,0 +1,418 @@
/**
* @brief Elocation Library
*
* @mainpage Elocation
* @version 0.0.0
* @author Stefan Schmidt <stefan@datenfreihafen.org>
* @date 2012
*
* @section intro Elocation Use Cases
*
* Elocation is meant as a convenience library to ease application developers
* the usage of geo information in their apps. Adding a geo tag to a picture or
* translating an address to a GPS position and show it on a map widget are just
* some of the use cases.
*
* In the beginning elocation will rely on the GeoClue DBus service. Its has
* providers for various techniques to get hold off the current position.
* Ranging from GeoIP over wifi and GSM cell location to GPS. As well as
* provider to translates between location in a textual form to coordinates
* (GeoCode).
*
* Elocation covers all of these interfaces but in the end it depends on your
* system and the installed GeoClue providers what can be used.
*
* Currently it offer the following functionality:
* @li Request current address in textual form
* @li Request current position in GPS format
* @li Translate a position into and address or an address in a position
*
* You can find the API documentation at @ref Location
*/
#ifndef _ELOCATION_H
#define _ELOCATION_H
#ifdef EAPI
# undef EAPI
#endif
#ifdef _WIN32
# ifdef EFL_ECORE_BUILD
# ifdef DLL_EXPORT
# define EAPI __declspec(dllexport)
# else
# define EAPI
# endif /* ! DLL_EXPORT */
# else
# define EAPI __declspec(dllimport)
# endif /* ! EFL_ECORE_BUILD */
#else
# ifdef __GNUC__
# if __GNUC__ >= 4
# define EAPI __attribute__ ((visibility("default")))
# else
# define EAPI
# endif
# else
# define EAPI
# endif
#endif /* ! _WIN32 */
#include <stdio.h>
#include <Ecore.h>
#include <Eldbus.h>
/**
* @file Elocation.h
*
* @defgroup Location Location
*/
/**
* @ingroup Location
* @brief Available location events that are emitted from the library
* @since 1.8
*
* Ecore events emitted by the library. Applications can register ecore event
* handlers to react on such events. After the initial query this can be used
* to keep track of changes and update your UI or data accordingly.
* @{
*/
EAPI extern int ELOCATION_EVENT_STATUS; /**< Status changed */
EAPI extern int ELOCATION_EVENT_POSITION; /**< Position changed */
EAPI extern int ELOCATION_EVENT_ADDRESS; /**< Address changed */
EAPI extern int ELOCATION_EVENT_VELOCITY; /**< Velocity changed */
EAPI extern int ELOCATION_EVENT_GEOCODE; /**< Reply for geocode translation arrived */
EAPI extern int ELOCATION_EVENT_REVERSEGEOCODE; /**< Reply for geocode translation arrived */
EAPI extern int ELOCATION_EVENT_NMEA; /**< NMEA update */
EAPI extern int ELOCATION_EVENT_SATELLITE; /**< Satellite info changed */
EAPI extern int ELOCATION_EVENT_POI; /**< POI reply */
EAPI extern int ELOCATION_EVENT_META_READY; /**< Meta provider is ready to be used */
/**@}*/
/**
* @ingroup Location
* @typedef Elocation_Accuracy_Level
* @since 1.8
*
* Different location accuracy levels from country level up to detailed,
* e.g. GPS, information.
* @{
*/
typedef enum {
ELOCATION_ACCURACY_LEVEL_NONE = 0,
ELOCATION_ACCURACY_LEVEL_COUNTRY,
ELOCATION_ACCURACY_LEVEL_REGION,
ELOCATION_ACCURACY_LEVEL_LOCALITY,
ELOCATION_ACCURACY_LEVEL_POSTALCODE,
ELOCATION_ACCURACY_LEVEL_STREET,
ELOCATION_ACCURACY_LEVEL_DETAILED,
} Elocation_Accuracy_Level;
/**@}*/
/**
* @ingroup Location
* @typedef Elocation_Resource_Flags
* @since 1.8
*
* Flags for available system resources to be used for locating. So far they
* cover physical resources like network connection, cellular network
* connection and GPS.
* @{
*/
typedef enum {
ELOCATION_RESOURCE_NONE = 0,
ELOCATION_RESOURCE_NETWORK = 1 << 0, /**< Internet connection is available */
ELOCATION_RESOURCE_CELL = 1 << 1, /**< Cell network information, e.g. GSM, is available */
ELOCATION_RESOURCE_GPS = 1 << 2, /**< GPS information is available */
ELOCATION_RESOURCE_ALL = (1 << 10) - 1 /**< All resources are available */
} Elocation_Resource_Flags;
/**@}*/
/**
* @ingroup Location
* @typedef Elocation_Accuracy
* @since 1.8
*
* Information about the accuracy of the reported location. For details about
* the level of accuracy see #Elocation_Accuracy_Level. It also covers
* horizontal and vertical accuracy. The values depend on the used provider
* and may very in quality.
*/
typedef struct _Elocation_Accuracy
{
Elocation_Accuracy_Level level;
double horizontal;
double vertical;
} Elocation_Accuracy;
/**
* @ingroup Location
* @typedef Elocation_Address
* @since 1.8
*
* Location information in textual form. Depending on the used provider this
* can cover only the country or a detailed address with postcode and street.
* The level of detail varies depending on the used provider.
* A timestamp is available to calculate the age of the address data.
*/
typedef struct _Elocation_Address
{
unsigned int timestamp; /**< Timestamp of data read out in seconds since epoch */
char *country;
char *countrycode;
char *locality;
char *postalcode;
char *region;
char *timezone;
Elocation_Accuracy *accur;
} Elocation_Address;
/**
* @ingroup Location
* @typedef Elocation_Position
* @since 1.8
*
* Location information based on the GPS grid. Latitude, longitude and altitude.
* A timestamp is available to calculate the age of the address data.
*/
typedef struct _Elocation_Postion
{
unsigned int timestamp; /**< Timestamp of data read out in seconds since epoch */
double latitude;
double longitude;
double altitude;
Elocation_Accuracy *accur;
} Elocation_Position;
/**
* @ingroup Location
* @typedef Elocation_Velocity
* @since 1.8
*
* Velocity information. So far this interface is only offered with GPS based
* providers. It offers information about speed, direction and climb.
* A timestamp is available to calculate the age of the address data.
*
* FIXME: check units and formats of this values coming in from GeoClue
*/
typedef struct _Elocation_Velocity
{
unsigned int timestamp; /**< Timestamp of data read out in seconds since epoch */
double speed;
double direction;
double climb;
} Elocation_Velocity;
/**
* @ingroup Location
* @typedef Elocation_Requirements
* @since 1.8
*
* Requirement settings for the location provider. Requirements can be a level
* of accuracy or allowed resources like network access or GPS. See
* #Elocation_Resource_Flags for all available resource flags.
*
* Based on this setting the best provider is chosen between the available
* providers of GeoClue.
*/
typedef struct _Elocation_Requirements
{
Elocation_Accuracy_Level accurancy_level;
int min_time; /**< Minimal time between updates. Not implemented upstream */
Eina_Bool require_update;
Elocation_Resource_Flags allowed_resources;
} Elocation_Requirements;
/**
* @brief Create a new address object to operate on.
* @return Address object.
*
* The returned address object is safe to be operated on. It can be used for
* all other elocation functions. Once finished with it it need to be destroyed
* with a call to #elocation_address_free.
*
* @ingroup Location
* @since 1.8
*/
EAPI Elocation_Address *elocation_address_new(void);
/**
* @brief Free an address object
* @param address Address object to be freed.
*
* Destroys an address object created with #elocation_address_new. Should be
* used during the cleanup of the application or whenever the address object is
* no longer needed.
*
* @ingroup Location
* @since 1.8
*/
EAPI void elocation_address_free(Elocation_Address *address);
/**
* @brief Create a new position object to operate on.
* @return Position object.
*
* The returned address object is safe to be operated on. It can be used for
* all other elocation functions. Once finished with it it need to be destroyed
* with a call to #elocation_address_free.
*
* @ingroup Location
* @since 1.8
*/
EAPI Elocation_Position *elocation_position_new(void);
/**
* @brief Free an position object
* @param position Position object to be freed.
*
* Destroys a position object created with #elocation_address_new. Should be
* used during the cleanup of the application or whenever the location object is
* no longer needed.
*
* @ingroup Location
* @since 1.8
*/
EAPI void elocation_position_free(Elocation_Position *position);
/**
* @brief Get the current address information.
* @param address Address struct to be filled with information.
* @return EINA_TRUE for success and EINA_FALSE for failure.
*
* Request the latest address. The requested to the underling components might
* be asynchronous so better check the timestamp if the data has changed. To get
* events when the address changes one can also subscribe to the
* #ELOCATION_EVENT_ADDRESS ecore event which will have the address object as
* event.
*
* @ingroup Location
* @since 1.8
*/
EAPI Eina_Bool elocation_address_get(Elocation_Address *address);
/**
* @brief Get the current position information.
* @param position Position struct to be filled with information.
* @return EINA_TRUE for success and EINA_FALSE for failure.
*
* Request the latest position. The requested to the underling components might
* be asynchronous so better check the timestamp if the data has changed. To get
* events when the position changes one can also subscribe to the
* #ELOCATION_EVENT_POSITION ecore event which will have the position object as
* event.
*
* @ingroup Location
* @since 1.8
*/
EAPI Eina_Bool elocation_position_get(Elocation_Position *position);
/**
* @brief Get the current status.
* @param status Status
* @return EINA_TRUE for success and EINA_FALSE for failure.
*
* @ingroup Location
* @since 1.8
*/
EAPI Eina_Bool elocation_status_get(int *status);
/**
* @brief Set the requirements.
* @param requirements Requirements
* @return EINA_TRUE for success and EINA_FALSE for failure.
*
* Set the requirements for selecting a provider.
*
* @ingroup Location
* @since 1.8
*/
EAPI Eina_Bool elocation_requirements_set(Elocation_Requirements *requirements);
/**
* @brief Convert position to address
* @param position_shadow Position input
* @param address_shadow Address output
* @return EINA_TRUE for success and EINA_FALSE for failure.
*
* Use a GeoCode provider to translate from a given GPS coordinate
* representation of a location to a representation in textual form.
*
* @ingroup Location
* @since 1.8
*/
EAPI Eina_Bool elocation_position_to_address(Elocation_Position *position_shadow, Elocation_Address *address_shadow);
/**
* @brief Convert address to position
* @param address_shadow Address input
* @param position_shadow Position output
* @return EINA_TRUE for success and EINA_FALSE for failure.
*
* Use a GeoCode provider to translate from a given textual form
* representation of a location to a representation as GPS coordinates.
*
* @ingroup Location
* @since 1.8
*/
EAPI Eina_Bool elocation_address_to_position(Elocation_Address *address_shadow, Elocation_Position *position_shadow);
/**
* @brief Convert free form address tring to position
* @param freeform_address Address string in free form
* @param position_shadow Position output
* @return EINA_TRUE for success and EINA_FALSE for failure.
*
* Similar GeoCode translation from textual form to GPS coordinates as
* #elocation_address_to_position but in this case the address is a simple
* string which hopefully contains enough information for the provider to
* understand and translate.
*
* Useful for an easy search interface in an application but also more error
* prone regarding correct results.
*
* @ingroup Location
* @since 1.8
*/
EAPI Eina_Bool elocation_freeform_address_to_position(const char *freeform_address, Elocation_Position *position_shadow);
/**
* @brief Request a landmark position
* @param position_shadow Position ouput
* @param address_shadow Address input
* @return EINA_TRUE for success and EINA_FALSE for failure.
*
* Request a landmark position also known as Point Of Interest (POI) from
* GeoClue.
*
* @ingroup Location
* @since 1.8
*/
EAPI Eina_Bool elocation_landmarks_get(Elocation_Position *position_shadow, Elocation_Address *address_shadow);
/**
* @brief Initialize the elocation subsystem.
* @return EINA_TRUE for success and EINA_FALSE for failure.
*
* This function must be called before using any of the Elocation functionality
* in your application to make sure it it setup correctly for usage.
*
* @ingroup Location
* @since 1.8
*/
EAPI Eina_Bool elocation_init(void);
/**
* @brief Cleanup and shutdown the elocation subsystem.
*
* This function must be called when the application is no longer using any of
* the Elocation functionality to allow the subsystem to shutdown cleanly.
*
* @ingroup Location
* @since 1.8
*/
EAPI void elocation_shutdown(void);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,181 @@
#ifndef _ELOCATION_PRIVATE_H
#define _ELOCATION_PRIVATE_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <Eina.h>
#include <Ecore.h>
#include <Eldbus.h>
#ifndef ELOCATION_COLOR_DEFAULT
#define ELOCATION_COLOR_DEFAULT EINA_COLOR_BLUE
#endif
extern int _elocation_log_dom;
#ifdef CRI
#undef CRI
#endif
#ifdef ERR
#undef ERR
#endif
#ifdef INF
#undef INF
#endif
#ifdef WARN
#undef WARN
#endif
#ifdef DBG
#undef DBG
#endif
#define CRI(...) EINA_LOG_DOM_CRIT(_elocation_log_dom, __VA_ARGS__)
#define DBG(...) EINA_LOG_DOM_DBG(_elocation_log_dom, __VA_ARGS__)
#define INF(...) EINA_LOG_DOM_INFO(_elocation_log_dom, __VA_ARGS__)
#define WARN(...) EINA_LOG_DOM_WARN(_elocation_log_dom, __VA_ARGS__)
#define ERR(...) EINA_LOG_DOM_ERR(_elocation_log_dom, __VA_ARGS__)
/* Provider bus names and object paths. Master is the generic one which should
* pick up the best one internally based on given requirements. It is also still
* possible to use providers directly */
#define GEOCLUE_DBUS_NAME "org.freedesktop.Geoclue.Master"
#define GEOCLUE_OBJECT_PATH "/org/freedesktop/Geoclue/Master"
#define GSMLOC_DBUS_NAME "org.freedesktop.Geoclue.Providers.Gsmloc"
#define GSMLOC_OBJECT_PATH "/org/freedesktop/Geoclue/Providers/Gsmloc"
#define HOSTIP_DBUS_NAME "org.freedesktop.Geoclue.Providers.Hostip"
#define HOSTIP_OBJECT_PATH "/org/freedesktop/Geoclue/Providers/Hostip"
#define SKYHOOK_DBUS_NAME "org.freedesktop.Geoclue.Providers.Skyhook"
#define SKYHOOK_OBJECT_PATH "/org/freedesktop/Geoclue/Providers/Skyhook"
#define UBUNTU_DBUS_NAME "org.freedesktop.Geoclue.Providers.UbuntuGeoIP"
#define UBUNTU_OBJECT_PATH "/org/freedesktop/Geoclue/Providers/UbuntuGeoIP"
#define GEONAMES_DBUS_NAME "org.freedesktop.Geoclue.Providers.Geonames"
#define GEONAMES_OBJECT_PATH "/org/freedesktop/Geoclue/Providers/Geonames"
#define PLAZES_DBUS_NAME "org.freedesktop.Geoclue.Providers.Plazes"
#define PLAZES_OBJECT_PATH "/org/freedesktop/Geoclue/Providers/Plazes"
#define YAHOO_DBUS_NAME "org.freedesktop.Geoclue.Providers.Yahoo"
#define YAHOO_OBJECT_PATH "/org/freedesktop/Geoclue/Providers/Yahoo"
/* Master interfaces to control geoclue */
#define GEOCLUE_MASTER_IFACE "org.freedesktop.Geoclue.Master"
#define GEOCLUE_MASTERCLIENT_IFACE "org.freedesktop.Geoclue.MasterClient"
/* Provider interfaces to access location data */
#define GEOCLUE_GEOCLUE_IFACE "org.freedesktop.Geoclue"
#define GEOCLUE_POSITION_IFACE "org.freedesktop.Geoclue.Position"
#define GEOCLUE_ADDRESS_IFACE "org.freedesktop.Geoclue.Address"
#define GEOCLUE_VELOCITY_IFACE "org.freedesktop.Geoclue.Velocity"
#define GEOCLUE_GEOCODE_IFACE "org.freedesktop.Geoclue.Geocode"
#define GEOCLUE_REVERSEGEOCODE_IFACE "org.freedesktop.Geoclue.ReverseGeocode"
/* More provider interfaces. These three are not in upstream geoclue but only
* in the Tizen version. Lets hope they get upstream at some point. Right now
* we will test at runtime if they are offered and ignore them if not */
#define GEOCLUE_NMEA_IFACE "org.freedesktop.Geoclue.Nmea"
#define GEOCLUE_SATELLITE_IFACE "org.freedesktop.Geoclue.Satellite"
#define GEOCLUE_POI_IFACE "org.freedesktop.Geoclue.Poi"
#define GEOCLUE_ADDRESS_KEY_AREA "area"
#define GEOCLUE_ADDRESS_KEY_COUNTRY "country"
#define GEOCLUE_ADDRESS_KEY_COUNTRYCODE "countrycode"
#define GEOCLUE_ADDRESS_KEY_LOCALITY "locality"
#define GEOCLUE_ADDRESS_KEY_POSTALCODE "postalcode"
#define GEOCLUE_ADDRESS_KEY_REGION "region"
#define GEOCLUE_ADDRESS_KEY_STREET "street"
extern int ELOCATION_EVENT_IN;
extern int ELOCATION_EVENT_OUT;
/* Some ENUMs that we mimic from GeoClue code as we only access it over the DBus
* interface and share no header file for such defines.
*/
/**
* @ingroup Location
* @typedef GeocluePositionFields
* @since 1.8
*
* Bitmask to indicate which of the supplied positions fields are valid.
*
* @{
*/
typedef enum {
GEOCLUE_POSITION_FIELDS_NONE = 0,
GEOCLUE_POSITION_FIELDS_LATITUDE = 1 << 0,
GEOCLUE_POSITION_FIELDS_LONGITUDE = 1 << 1,
GEOCLUE_POSITION_FIELDS_ALTITUDE = 1 << 2
} GeocluePositionFields;
/**@}*/
/**
* @ingroup Location
* @typedef GeoclueNetworkStatus
* @since 1.8
*
* Status of the network connectivity for GeoClue. Needed for all providers that
* access external data to determine the location. For example GeoIP or GeoCode
* providers.
*
* @{
*/
typedef enum {
GEOCLUE_CONNECTIVITY_UNKNOWN,
GEOCLUE_CONNECTIVITY_OFFLINE,
GEOCLUE_CONNECTIVITY_ACQUIRING,
GEOCLUE_CONNECTIVITY_ONLINE,
} GeoclueNetworkStatus;
/**@}*/
/**
* @ingroup Location
* @typedef GeoclueStatus
* @since 1.8
*
* Status of a GeoClue provider.
*
* @{
*/
typedef enum {
GEOCLUE_STATUS_ERROR,
GEOCLUE_STATUS_UNAVAILABLE,
GEOCLUE_STATUS_ACQUIRING,
GEOCLUE_STATUS_AVAILABLE
} GeoclueStatus;
/**@}*/
/**
* @ingroup Location
* @typedef GeoclueVelocityFields
* @since 1.8
*
* Bitmask to indicate which of the supplied velocity fields are valid.
*
* @{
*/
typedef enum {
GEOCLUE_VELOCITY_FIELDS_NONE = 0,
GEOCLUE_VELOCITY_FIELDS_SPEED = 1 << 0,
GEOCLUE_VELOCITY_FIELDS_DIRECTION = 1 << 1,
GEOCLUE_VELOCITY_FIELDS_CLIMB = 1 << 2
} GeoclueVelocityFields;
/**@}*/
/**
* @ingroup Location
* @typedef Elocation_Provider
* @since 1.8
*
* Data structure to hold information about a GeoClue provider.
*
*/
typedef struct _Elocation_Provider
{
char *name;
char *description;
char *service;
char *path;
GeoclueStatus status;
} Elocation_Provider;
#endif