Commit 09eca2a7 authored by Jussi Kukkonen's avatar Jussi Kukkonen

New web service handling code for the backends

GeoclueWebService class
  a) notifies about connection changes
  b) makes web service interaction easier
See backend/common/geoclue_web_service.h for more info
parent 8c1d8dff
geoclue_web_service_CFLAGS = $(DBUS_CFLAGS) $(HTTPXML_CFLAGS) $(GOBJECT_CFLAGS) $(CONIC_CFLAGS) -I$(top_srcdir)
all: geoclue_web_service.o
geoclue_web_service.o: geoclue_web_service.c
$(CC) $(geoclue_web_service_CFLAGS) -c geoclue_web_service.c
This diff is collapsed.
/* Geoclue - A DBus api and wrapper for geography information
* Copyright (C) 2007 Jussi Kukkonen
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2 as published by the Free Software Foundation;
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*/
/* A GeoclueWebService is meant to be used in webservice based geoclue
* provider implementations. It has two tasks:
* a) simplify interaction with webservices
* a) notify about connectivity changes
* The only thing these two have in common is that they're usually
* needed in the same place.
*
*** CONSTRUCTION
*
* GeoclueWebservice takes the webservice base url as a construction
* parameter (you can also set it using normal gobject property set).
* Example:
* obj = g_object_new (GEOCLUE_TYPE_WEB_SERVICE,
* "base_url", "http://plazes.com/suggestions.xml",
* NULL);
*
*** CONNECTION-EVENT
*
* There's a "connection-event" signal for getting notified about
* connection events:
* g_signal_connect (GEOCLUE_WEB_SERVICE (obj),
* "connection-event",
* (GCallback)callback_func,
* NULL);
* This only works if the platform supports this: use
* "using-connection-events" property to check. Currently only Maemo
* (libconic) support is included, but Gnome (NetworkManager) support
* should be doable.
*
*** QUERYING DATA
*
* A typical web service query is done like this:
* if (geoclue_web_service_query (GEOCLUE_WEB_SERVICE (obj),
* "mac_address", "00:11:95:20:df:11",
* NULL)) {
* if (geoclue_web_service_get_string (GEOCLUE_WEB_SERVICE (obj),
* &addr, "//plaze/address")) {
* g_debug ("address: %s", addr);
* }
* if (geoclue_web_service_get_double (GEOCLUE_WEB_SERVICE (obj),
* &lat, "//plaze/latitude")) {
* g_debug ("latitude: %f", lat);
* }
* }
*
* So, geoclue_web_service_query takes a NULL-terminated list of
* key-value pairs that will be appended to base_url. The value part
* will be escaped. The example case query url will be:
* "http://plazes.com/suggestions.xml?mac_address=00%3A11%3A95%3A20%3Adf%3A11"
*
* The actual response data is available (see "response"-property),
* but if the data is xml it's easier to use
* "geoclue_web_service_get_*" -methods to get specific data using
* simple xpath expressions.
*/
#ifndef GEOCLUE_WEB_SERVICE_H
#define GEOCLUE_WEB_SERVICE_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <glib-object.h>
#include <libxml/xpath.h>
#ifdef HAVE_LIBCONIC
#define DBUS_API_SUBJECT_TO_CHANGE 1
#include <dbus/dbus.h>
#include <conicconnection.h>
#include <conicconnectionevent.h>
#endif
G_BEGIN_DECLS
#define GEOCLUE_TYPE_WEB_SERVICE (geoclue_web_service_get_type ())
#define GEOCLUE_WEB_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEOCLUE_TYPE_WEB_SERVICE, GeoclueWebService))
#define GEOCLUE_WEB_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GEOCLUE_TYPE_WEB_SERVICE, GeoclueWebServiceClass))
#define GEOCLUE_IS_WEB_SERVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEOCLUE_TYPE_WEB_SERVICE))
#define GEOCLUE_IS_WEB_SERVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GEOCLUE_TYPE_WEB_SERVICE))
#define GEOCLUE_WEB_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GEOCLUE_TYPE_WEB_SERVICE, GeoclueWebServiceClass))
typedef struct _GeoclueWebService GeoclueWebService;
typedef struct _GeoclueWebServiceClass GeoclueWebServiceClass;
struct _GeoclueWebService {
GObject parent;
/* private */
gchar* base_url;
gchar *response;
gboolean using_connection_events;
xmlXPathContext *xpath_ctx;
#ifdef HAVE_LIBCONIC
ConIcConnection* net_connection;
DBusConnection* system_bus;
#endif
};
struct _GeoclueWebServiceClass {
GObjectClass parent;
guint connection_event_signal_id;
/* default handler for connection event */
void (*connection_event) (GeoclueWebService *self,
gboolean connected);
};
GType geoclue_web_service_get_type (void);
/* Public methods */
gboolean geoclue_web_service_query (GeoclueWebService *self, ...);
gboolean geoclue_web_service_get_string (GeoclueWebService *self, gchar **OUT_value, gchar *xpath);
gboolean geoclue_web_service_get_double (GeoclueWebService *self, gdouble *OUT_value, gchar *xpath);
G_END_DECLS
#endif /* GEOCLUE_WEB_SERVICE_H */
......@@ -63,6 +63,10 @@ PKG_CHECK_MODULES(DEPS, gconf-2.0 dbus-glib-1 gtk+-2.0 gthread-2.0)
AC_SUBST(DEPS_CFLAGS)
AC_SUBST(DEPS_LIBS)
PKG_CHECK_MODULES(GOBJECT, gobject-2.0)
AC_SUBST(GOBJECT_CFLAGS)
AC_SUBST(GOBJECT_LIBS)
DBUS_SERVICES_DIR=`pkg-config dbus-1 --variable=exec_prefix`/share/dbus-1/services
AC_SUBST(DBUS_SERVICES_DIR)
......@@ -104,7 +108,7 @@ fi #gpds
dnl check for libconic
PKG_CHECK_MODULES(CONIC, conic, [have_libconic=yes], [have_libconic=no])
PKG_CHECK_MODULES(CONIC, conic dbus-1, [have_libconic=yes], [have_libconic=no])
AC_SUBST(CONIC_CFLAGS)
AC_SUBST(CONIC_LIBS)
if test "x$have_libconic" = "xyes"; then
......@@ -139,12 +143,13 @@ AC_SUBST(YAHOO_LIBS)
dnl substitute subdirs into makefiles
BACKEND_SUBDIRS="${BACKEND_SUBDIRS} map_yahoo geocode_yahoo position_manual position_hostip position_plazes"
BACKEND_SUBDIRS="${BACKEND_SUBDIRS} common map_yahoo geocode_yahoo position_manual position_hostip position_plazes"
AC_OUTPUT(
backend/Makefile
backend/common/Makefile
backend/map_yahoo/Makefile
backend/geocode_yahoo/Makefile
backend/position_manual/Makefile
......
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