Commit 2f163a94 authored by Jussi Kukkonen's avatar Jussi Kukkonen

Added basic civic location support

  * basic "civic_location" method added, also to the C-wrapper
  * hostip supports country, locality (=city)
  * gpsd returns "not supported", manual returns "not supported yet"

Coming Soon
  * civic_location_changed-signal
  * libconic support (like current_position)
  * some convenience methods
parent 67d396ae
......@@ -270,6 +270,26 @@ gboolean geoclue_position_moon_set(GeocluePosition *obj, const gdouble IN_latitu
return FALSE;
}
gboolean geoclue_position_civic_location (GeocluePosition* obj,
char** OUT_country,
char** OUT_region,
char** OUT_locality,
char** OUT_area,
char** OUT_postalcode,
char** OUT_street,
char** OUT_building,
char** OUT_floor,
char** OUT_room,
char** OUT_text,
GError** error)
{
g_set_error (error,
GEOCLUE_POSITION_ERROR,
GEOCLUE_POSITION_ERROR_NOTSUPPORTED,
"Backend does not implement this method.");
return FALSE;
}
gboolean geoclue_position_service_available(GeocluePosition *obj, gboolean* OUT_available, char** OUT_reason, GError** error)
{
......@@ -282,6 +302,7 @@ gboolean geoclue_position_service_available(GeocluePosition *obj, gboolean* OUT_
gboolean geoclue_position_shutdown(GeocluePosition *obj, GError** error)
{
g_debug("position_shutdown");
g_main_loop_quit (obj->loop);
return TRUE;
}
......@@ -340,6 +361,7 @@ int main(int argc, char **argv)
}
#ifdef HAVE_LIBGPSBT
g_debug("gpsbt_stop...");
gpsbt_stop (&bt_ctx);
#endif
......
......@@ -77,6 +77,19 @@ gboolean geoclue_position_sun_set(GeocluePosition *obj, const gdouble IN_latitud
gboolean geoclue_position_moon_rise(GeocluePosition *obj, const gdouble IN_latitude, const gdouble IN_longitude, const gint IN_year, const gint IN_month, const gint IN_day, gint* OUT_hours, gint* OUT_minutes, gint* OUT_seconds, GError **error );
gboolean geoclue_position_moon_set(GeocluePosition *obj, const gdouble IN_latitude, const gdouble IN_longitude, const gint IN_year, const gint IN_month, const gint IN_day, gint* OUT_hours, gint* OUT_minutes, gint* OUT_seconds, GError **error );
gboolean geoclue_position_civic_location (GeocluePosition* obj,
char** OUT_country,
char** OUT_region,
char** OUT_locality,
char** OUT_area,
char** OUT_postalcode,
char** OUT_street,
char** OUT_building,
char** OUT_floor,
char** OUT_room,
char** OUT_text,
GError** error);
gboolean geoclue_position_service_available(GeocluePosition *obj, gboolean* OUT_available, char** OUT_reason, GError** error);
gboolean geoclue_position_shutdown(GeocluePosition *obj, GError** error);
......
......@@ -50,7 +50,7 @@ static guint signals[LAST_SIGNAL];
/* Default handler */
void geoclue_position_current_position_changed(GeocluePosition* obj, gdouble lat, gdouble lon)
{
{
g_print("Current Position Changed\n");
}
......@@ -245,7 +245,7 @@ static gboolean query_position (gdouble* OUT_latitude, gdouble* OUT_longitude, G
*OUT_longitude = -999.99;
/* evaluate xpath expression */
xpathObj = xmlXPathEvalExpression ((xmlChar*)"//gml:coordinates", xpathCtx);
xpathObj = xmlXPathEvalExpression ((xmlChar*)"//gml:featureMember/hostip:Hostip//gml:coordinates", xpathCtx);
xmlXPathFreeContext(xpathCtx);
if (!xpathObj || xmlXPathNodeSetIsEmpty (xpathObj->nodesetval)) {
......@@ -258,8 +258,8 @@ static gboolean query_position (gdouble* OUT_latitude, gdouble* OUT_longitude, G
}
return FALSE;
}
sscanf ((char*)xmlXPathCastNodeSetToString (xpathObj->nodesetval),
sscanf ((char*)xmlXPathCastNodeSetToString (xpathObj->nodesetval),
"%lf,%lf", OUT_longitude , OUT_latitude);
xmlXPathFreeObject(xpathObj);
......@@ -466,6 +466,67 @@ gboolean geoclue_position_moon_set(GeocluePosition *obj, const gdouble IN_latitu
}
gboolean geoclue_position_civic_location (GeocluePosition* obj,
char** OUT_country,
char** OUT_region,
char** OUT_locality,
char** OUT_area,
char** OUT_postalcode,
char** OUT_street,
char** OUT_building,
char** OUT_floor,
char** OUT_room,
char** OUT_text,
GError** error)
{
*OUT_locality = NULL;
*OUT_country = NULL;
xmlXPathObjectPtr xpathObj = NULL;
xmlXPathContextPtr xpathCtx = get_hostip_xpath_context (error);
xpathObj = xmlXPathEvalExpression ((xmlChar*)"//gml:featureMember/hostip:Hostip/gml:name",
xpathCtx);
if (xpathObj) {
if (xpathObj->nodesetval && !xmlXPathNodeSetIsEmpty (xpathObj->nodesetval)) {
*OUT_locality = g_strdup ((char*)xmlXPathCastNodeSetToString (xpathObj->nodesetval));
/* this seems to be the only way to check for missing ("guessed") data... */
if (g_ascii_strcasecmp (*OUT_locality, "(Unknown city)") == 0) {
g_free (*OUT_locality);
*OUT_locality = NULL;
}
}
xmlXPathFreeObject(xpathObj);
}
xpathObj = xmlXPathEvalExpression ((xmlChar*)"//gml:featureMember/hostip:Hostip/hostip:countryName",
xpathCtx);
if (xpathObj) {
if (xpathObj->nodesetval && !xmlXPathNodeSetIsEmpty (xpathObj->nodesetval)) {
*OUT_country = g_strdup ((char*)xmlXPathCastNodeSetToString (xpathObj->nodesetval));
}
xmlXPathFreeObject(xpathObj);
}
xmlXPathFreeContext(xpathCtx);
if ((*OUT_locality == NULL) && (*OUT_country == NULL)) {
g_set_error (error,
GEOCLUE_POSITION_ERROR,
GEOCLUE_POSITION_ERROR_NODATA,
"%s does not have civic location data for this IP address.", HOSTIP_API);
if (xpathObj) {
xmlXPathFreeObject(xpathObj);
}
return FALSE;
}
g_debug ("civic_location done");
return TRUE;
}
/* TODO: Is this method sane? We have "GError**" in the call signatures:
This means calling current_position and checking return value
(and reading error->message on FALSE) gives the exact same
......
......@@ -90,6 +90,19 @@ gboolean geoclue_position_sun_set(GeocluePosition *obj, const gdouble IN_latitud
gboolean geoclue_position_moon_rise(GeocluePosition *obj, const gdouble IN_latitude, const gdouble IN_longitude, const gint IN_year, const gint IN_month, const gint IN_day, gint* OUT_hours, gint* OUT_minutes, gint* OUT_seconds, GError **error );
gboolean geoclue_position_moon_set(GeocluePosition *obj, const gdouble IN_latitude, const gdouble IN_longitude, const gint IN_year, const gint IN_month, const gint IN_day, gint* OUT_hours, gint* OUT_minutes, gint* OUT_seconds, GError **error );
gboolean geoclue_position_civic_location (GeocluePosition* obj,
char** OUT_country,
char** OUT_region,
char** OUT_locality,
char** OUT_area,
char** OUT_postalcode,
char** OUT_street,
char** OUT_building,
char** OUT_floor,
char** OUT_room,
char** OUT_text,
GError** error);
gboolean geoclue_position_service_available(GeocluePosition *obj, gboolean* OUT_available, char** OUT_reason, GError** error);
gboolean geoclue_position_shutdown(GeocluePosition *obj, GError** error);
......
bin_PROGRAMS = geoclue-position-server-manual
geoclue_position_server_manual_SOURCES = geoclue_position_server_manual.c \
geoclue_position_signal_marshal.c
geoclue_position_signal_marshal.c \
../geoclue_position_error.c
AM_CPPFLAGS = $(YAHOO_CFLAGS) -I$(top_srcdir)
AM_LDFLAGS = $(YAHOO_LIBS) ../../geoclue/libgeoclue.la
......
......@@ -17,20 +17,17 @@
* Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <string.h>
#include <dbus/dbus-glib-bindings.h>
#include <gtk/gtk.h>
#include <geoclue_position_server_manual.h>
#include "geoclue_position_server_manual.h"
#include "../geoclue_position_error.h"
#include <geoclue_position_server_glue.h>
#include <geoclue_position_signal_marshal.h>
//#include <geoclue/position.h>
#include <geoclue/map.h>
#include <geoclue/map_gtk_layout.h>
#include <dbus/dbus-glib-bindings.h>
#include <gtk/gtk.h>
#include <stdio.h>
#include <string.h>
#define PROGRAM_HEIGHT 640
#define PROGRAM_WIDTH 480
......@@ -198,13 +195,24 @@ gboolean geoclue_position_moon_set(GeocluePosition *obj, const gdouble IN_latitu
return FALSE;
}
gboolean geoclue_position_geocode(GeocluePosition *obj, const char * IN_street, const char * IN_city, const char * IN_state, const char * IN_zip, gdouble* OUT_latitude, gdouble* OUT_longitude, gint* OUT_return_code, GError **error )
{
return FALSE;
}
gboolean geoclue_position_geocode_free_text(GeocluePosition *obj, const char * IN_free_text, gdouble* OUT_latitude, gdouble* OUT_longitude, gint* OUT_return_code, GError **error )
gboolean geoclue_position_civic_location (GeocluePosition* obj,
char** OUT_country,
char** OUT_region,
char** OUT_locality,
char** OUT_area,
char** OUT_postalcode,
char** OUT_street,
char** OUT_building,
char** OUT_floor,
char** OUT_room,
char** OUT_text,
GError** error)
{
g_set_error (error,
GEOCLUE_POSITION_ERROR,
GEOCLUE_POSITION_ERROR_FAILED,
"Method not implemented yet.");
return FALSE;
}
......@@ -270,7 +278,7 @@ int main(int argc, char **argv)
if(geoclue_map_init())
{
g_print("Error initializing map backend\n");
g_print("Error Opening Geomap\n");
}
GeocluePosition* obj = NULL;
......
......@@ -72,8 +72,19 @@ gboolean geoclue_position_sun_rise(GeocluePosition *obj, const gdouble IN_latitu
gboolean geoclue_position_sun_set(GeocluePosition *obj, const gdouble IN_latitude, const gdouble IN_longitude, const gint IN_year, const gint IN_month, const gint IN_day, gint* OUT_hours, gint* OUT_minutes, gint* OUT_seconds, GError **error );
gboolean geoclue_position_moon_rise(GeocluePosition *obj, const gdouble IN_latitude, const gdouble IN_longitude, const gint IN_year, const gint IN_month, const gint IN_day, gint* OUT_hours, gint* OUT_minutes, gint* OUT_seconds, GError **error );
gboolean geoclue_position_moon_set(GeocluePosition *obj, const gdouble IN_latitude, const gdouble IN_longitude, const gint IN_year, const gint IN_month, const gint IN_day, gint* OUT_hours, gint* OUT_minutes, gint* OUT_seconds, GError **error );
gboolean geoclue_position_geocode(GeocluePosition *obj, const char * IN_street, const char * IN_city, const char * IN_state, const char * IN_zip, gdouble* OUT_latitude, gdouble* OUT_longitude, gint* OUT_return_code, GError **error );
gboolean geoclue_position_geocode_free_text(GeocluePosition *obj, const char * IN_free_text, gdouble* OUT_latitude, gdouble* OUT_longitude, gint* OUT_return_code, GError **error );
gboolean geoclue_position_civic_location (GeocluePosition* obj,
char** OUT_country,
char** OUT_region,
char** OUT_locality,
char** OUT_area,
char** OUT_postalcode,
char** OUT_street,
char** OUT_building,
char** OUT_floor,
char** OUT_room,
char** OUT_text,
GError** error);
gboolean geoclue_position_service_available(GeocluePosition *obj, gboolean* OUT_available, char** OUT_reason, GError** error);
gboolean geoclue_position_shutdown(GeocluePosition *obj, GError** error);
......
......@@ -40,7 +40,7 @@ int main (int argc, char** argv)
g_thread_init (NULL);
if (argv[1] != NULL) {
g_debug ("Testing specified backend: %s\n", argv[1]);
g_debug ("Testing specified backend: %s", argv[1]);
gchar* service = g_strdup_printf ("org.foinse_project.geoclue.position.%s", argv[1]);
gchar* path = g_strdup_printf ("/org/foinse_project/geoclue/position/%s", argv[1]);
......@@ -48,7 +48,7 @@ int main (int argc, char** argv)
init_ok = TRUE;
}
} else {
g_debug ("Testing default backend\n");
g_debug ("Testing default backend");
if (geoclue_position_init () == GEOCLUE_POSITION_SUCCESS){
init_ok = TRUE;
......@@ -60,13 +60,38 @@ int main (int argc, char** argv)
return 1;
}
g_debug ("Querying current position\n");
if (geoclue_position_current_position(&lat, &lon) != GEOCLUE_POSITION_SUCCESS) {
g_debug ("Querying current position");
if (geoclue_position_current_position (&lat, &lon) != GEOCLUE_POSITION_SUCCESS) {
g_debug ("current position query failed");
} else {
g_debug ("current position query ok");
printf ("You are at %f %f\n\n", lat, lon);
}
gchar* locality = NULL;
gchar* country = NULL;
g_debug ("Querying civic location");
if (geoclue_position_civic_location (&country, NULL, &locality, NULL,NULL, NULL, NULL, NULL,NULL, NULL) != GEOCLUE_POSITION_SUCCESS) {
g_debug ("civic location query failed");
} else {
g_debug ("civic location query ok");
if (locality && country) {
printf("You are in %s, %s\n\n", locality, country);
}else if (country){
/*TODO: This is never reached. Investigate why pointers are non-null
when there's no data? */
printf("You are in %s\n\n", country);
}
}
if (geoclue_position_close () != GEOCLUE_POSITION_SUCCESS){
g_debug ("position_close failed");
} else {
g_debug ("position_close ok");
}
return 0;
}
......@@ -19,6 +19,7 @@
#define DBUS_API_SUBJECT_TO_CHANGE
#include <glib.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <dbus/dbus.h>
......@@ -344,7 +345,39 @@ GEOCLUE_POSITION_RETURNCODE geoclue_position_satellites_data ( const gint IN_prn
}
GEOCLUE_POSITION_RETURNCODE geoclue_position_civic_location (char** OUT_country,
char** OUT_region,
char** OUT_locality,
char** OUT_area,
char** OUT_postalcode,
char** OUT_street,
char** OUT_building,
char** OUT_floor,
char** OUT_room,
char** OUT_text)
{
g_return_val_if_fail (geoclue_position_connection, GEOCLUE_POSITION_NOT_INITIALIZED);
g_return_val_if_fail (geoclue_position_proxy, GEOCLUE_POSITION_NOT_INITIALIZED);
GError* error = NULL;
org_foinse_project_geoclue_position_civic_location (geoclue_position_proxy,
OUT_country,
OUT_region,
OUT_locality,
OUT_area,
OUT_postalcode,
OUT_street,
OUT_building,
OUT_floor,
OUT_room,
OUT_text,
&error);
if( error != NULL )
{
g_printerr ("Error getting geoclue_position civic_location : %s\n", error->message);
g_error_free (error);
return GEOCLUE_POSITION_DBUS_ERROR;
}
return GEOCLUE_POSITION_SUCCESS;
}
......@@ -131,7 +131,19 @@ typedef enum _geoclue_position_fix
GEOCLUE_POSITION_RETURNCODE geoclue_position_satellites_in_view ( GArray** OUT_prn_numbers );
GEOCLUE_POSITION_RETURNCODE geoclue_position_satellites_data ( const gint IN_prn_number, gdouble* OUT_elevation, gdouble* OUT_azimuth, gdouble* OUT_signal_noise_ratio, gboolean* OUT_differential, gboolean* OUT_ephemeris );
/*
* NOTE: civic location part of the API is definitely not stable yet!
*/
GEOCLUE_POSITION_RETURNCODE geoclue_position_civic_location (char** OUT_country,
char** OUT_region,
char** OUT_locality,
char** OUT_area,
char** OUT_postalcode,
char** OUT_street,
char** OUT_building,
char** OUT_floor,
char** OUT_room,
char** OUT_text);
G_END_DECLS
......
......@@ -80,8 +80,20 @@
<arg type="b" name="ephemeris" direction="out" />
</method>
<method name="civic_location">
<arg type="s" name="country" direction="out" />
<arg type="s" name="region" direction="out" />
<arg type="s" name="locality" direction="out" />
<arg type="s" name="area" direction="out" />
<arg type="s" name="postalcode" direction="out" />
<arg type="s" name="street" direction="out" />
<arg type="s" name="building" direction="out" />
<arg type="s" name="floor" direction="out" />
<arg type="s" name="room" direction="out" />
<arg type="s" name="text" direction="out" />
</method>
<method name="service_available">
<arg type="b" name="available" direction="out" />
<arg type="s" name="reason" direction="out" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment