On Thu, 2010-06-17 at 11:25 +0200, Javier Fernandez Garcia-Boente wrote: > Yeah, I already thought about using Localnet; not sure whether Manual > would fit better with the unit testing purposes. Anyway, ill try to > continue your work and using Localnet for the time being.
Despite the Localnet provider could fit too for unit testing purposes, i think the Manual one fits better from the conceptional point of view. The Localnet requires network resources, even though it reads the location data from a configuration file; this file should be associated to an access point. So, bearing this in mind, i think the Manual provider should be the one to use for unit testing. I attached a patch for implementing the Position interface on such provider. Another issue to think about is how to choose the provider; I've already suggested in a former email a provider selection algorithm. I think it would deserve a bug in the bugzilla :) If everybody agrees, i could fill a new bug and work on it, developing my preliminary patch in a better way, perhaps considering more advanced heuristic to choose he best location provider. Anyway, getting back to the WebKit Geolocation unit tests topic, i think we should provide a way of forcing one provider as the selected one, even though if several are available. When programming unit tests, not every functionality have to be enabled; even more, some of them could be dangerous or inefficient for the automatic testing framework. The usual way of programming unit tests by setting a dummy GPS coordinates before executing the test and retrieving such dummy coordinates as the result of the operation, so the Manual provider seems to be the more appropriated for this way of use the Geolocation API. Do you think this is the right way to proceed ? Implementing a way of selecting a fixed provider. Greetings, -- Javi
commit 2e57f17d55a60d9a4777057ff6b8509a41e7b86e Author: Javier Fernandez <[email protected]> Date: Fri Jun 18 16:31:01 2010 +0000 The Manual provider implements the Position interface. It implements a DBus method, SetPosition, for setting a dummy position. diff --git a/providers/manual/geoclue-manual.c b/providers/manual/geoclue-manual.c index 3640c4b..4190c14 100644 --- a/providers/manual/geoclue-manual.c +++ b/providers/manual/geoclue-manual.c @@ -60,6 +60,7 @@ #include <geoclue/gc-provider.h> #include <geoclue/gc-iface-address.h> +#include <geoclue/gc-iface-position.h> typedef struct { GcProvider parent; @@ -71,6 +72,11 @@ typedef struct { int timestamp; GHashTable *address; GeoclueAccuracy *accuracy; + + int acc; + double latitude; + double longitude; + double altitude; } GeoclueManual; typedef struct { @@ -81,12 +87,23 @@ typedef struct { #define GEOCLUE_MANUAL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GEOCLUE_TYPE_MANUAL, GeoclueManual)) static void geoclue_manual_address_init (GcIfaceAddressClass *iface); +static void geoclue_manual_position_init (GcIfacePositionClass *iface); G_DEFINE_TYPE_WITH_CODE (GeoclueManual, geoclue_manual, GC_TYPE_PROVIDER, + G_IMPLEMENT_INTERFACE (GC_TYPE_IFACE_POSITION, + geoclue_manual_position_init) G_IMPLEMENT_INTERFACE (GC_TYPE_IFACE_ADDRESS, geoclue_manual_address_init)) static gboolean +geoclue_manual_set_position (GeoclueManual *manual, + gint acc, + gdouble longitude, + gdouble latitude, + gdouble altitude, + GError **error); + +static gboolean geoclue_manual_set_address (GeoclueManual *manual, int valid_until, GHashTable *address, @@ -258,6 +275,22 @@ geoclue_manual_set_address_fields (GeoclueManual *manual, return TRUE; } +static gboolean +geoclue_manual_set_position (GeoclueManual *manual, + gint acc, + gdouble longitude, + gdouble latitude, + gdouble altitude, + GError **error) +{ + manual->acc = acc; + manual->longitude = longitude; + manual->latitude = latitude; + manual->altitude = altitude; + + return TRUE; +} + static void finalize (GObject *object) @@ -298,6 +331,50 @@ geoclue_manual_init (GeoclueManual *manual) manual->address = geoclue_address_details_new (); manual->accuracy = geoclue_accuracy_new (GEOCLUE_ACCURACY_LEVEL_NONE, 0, 0); + + manual->longitude = G_MAXDOUBLE; + manual->latitude = G_MAXDOUBLE; + manual->altitude = G_MAXDOUBLE; +} + +static gboolean +get_position (GcIfacePosition *iface, + GeocluePositionFields *fields, + int *timestamp, + double *latitude, + double *longitude, + double *altitude, + GeoclueAccuracy **accuracy, + GError **error) +{ + GeoclueManual *obj = (GEOCLUE_MANUAL (iface)); + + *fields = GEOCLUE_POSITION_FIELDS_NONE; + + /* Get previously stored coordinates.*/ + if (latitude && (obj->latitude < G_MAXDOUBLE)) { + *latitude = obj->latitude; + *fields |= GEOCLUE_POSITION_FIELDS_LATITUDE; + } + if (longitude && (obj->longitude < G_MAXDOUBLE)) { + *longitude = obj->longitude; + *fields |= GEOCLUE_POSITION_FIELDS_LONGITUDE; + } + if (altitude && (obj->altitude < G_MAXDOUBLE)) { + *altitude = obj->altitude; + *fields |= GEOCLUE_POSITION_FIELDS_ALTITUDE; + } + + time ((time_t *)timestamp); + + if (*fields == GEOCLUE_POSITION_FIELDS_NONE) { + *accuracy = geoclue_accuracy_new (GEOCLUE_ACCURACY_LEVEL_NONE, + 0, 0); + } else { + *accuracy = geoclue_accuracy_new (GEOCLUE_ACCURACY_LEVEL_LOCALITY, + obj->acc, 0); + } + return TRUE; } static gboolean @@ -329,6 +406,12 @@ geoclue_manual_address_init (GcIfaceAddressClass *iface) iface->get_address = get_address; } +static void +geoclue_manual_position_init (GcIfacePositionClass *iface) +{ + iface->get_position = get_position; +} + int main (int argc, char **argv) diff --git a/providers/manual/geoclue-manual.provider b/providers/manual/geoclue-manual.provider index c45a9da..c6e3e39 100644 --- a/providers/manual/geoclue-manual.provider +++ b/providers/manual/geoclue-manual.provider @@ -2,6 +2,6 @@ Name=Manual Service=org.freedesktop.Geoclue.Providers.Manual Path=/org/freedesktop/Geoclue/Providers/Manual -Interfaces=org.freedesktop.Geoclue.Address +Interfaces=org.freedesktop.Geoclue.Position;org.freedesktop.Geoclue.Address Provides=ProvidesUpdates -Accuracy=Street +Accuracy=Locality diff --git a/providers/manual/geoclue-manual.xml b/providers/manual/geoclue-manual.xml index 9569a46..5a0575e 100644 --- a/providers/manual/geoclue-manual.xml +++ b/providers/manual/geoclue-manual.xml @@ -16,5 +16,11 @@ <arg type="s" name="postalcode" direction="in"/> <arg type="s" name="street" direction="in"/> </method> + <method name="SetPosition"> + <arg type="i" name="acc" direction="in"/> + <arg type="d" name="longitude" direction="in"/> + <arg type="d" name="latitude" direction="in"/> + <arg type="d" name="altitude" direction="in"/> + </method> </interface> </node> diff --git a/src/master.c b/src/master.c index 030b4cf..da8f050 100644 --- a/src/master.c +++ b/src/master.c @@ -207,7 +207,10 @@ gc_master_get_providers (GcInterfaceFlags iface_type, can_update, allowed)) { p = g_list_prepend (p, provider); - } + } else { + g_debug ("master: provider %s does not met the requirements.", + gc_master_provider_get_name (provider)); + } } return p;
signature.asc
Description: This is a digitally signed message part
_______________________________________________ GeoClue mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/geoclue
