Commit c742058f authored by Jussi Kukkonen's avatar Jussi Kukkonen

refactor address hashtable usage + misc fixes

Add geoclue-address-details.[ch] with a couple of
convenience tunctions.

Stop destorying/creating GeoclueAccuracies when not needed

fix gc_master_provider_get_status() return type
parent fc824ae8
......@@ -22,6 +22,7 @@ libgeoclue_la_SOURCES = \
$(BUILT_SOURCES) \
geoclue-accuracy.c \
geoclue-address.c \
geoclue-address-details.c \
geoclue-common.c \
geoclue-error.c \
geoclue-geocode.c \
......@@ -57,6 +58,7 @@ geoclue_headers = \
gc-web-service.h \
geoclue-accuracy.h \
geoclue-address.h \
geoclue-address-details.h \
geoclue-common.h \
geoclue-error.h \
geoclue-geocode.h \
......
......@@ -90,31 +90,3 @@ gc_iface_address_emit_address_changed (GcIfaceAddress *gc,
g_signal_emit (gc, signals[ADDRESS_CHANGED], 0, timestamp,
address, accuracy);
}
GHashTable *
address_details_new ()
{
return g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free);
}
static void
copy_address_key_and_value (char *key, char *value, GHashTable *target)
{
g_hash_table_insert (target, g_strdup (key), g_strdup (value));
}
GHashTable *
address_details_copy (GHashTable *source)
{
GHashTable *target;
g_assert (source != NULL);
target = address_details_new ();
g_hash_table_foreach (source,
(GHFunc)copy_address_key_and_value,
target);
return target;
}
......@@ -48,12 +48,6 @@ void gc_iface_address_emit_address_changed (GcIfaceAddress *gc,
GHashTable *address,
GeoclueAccuracy *accuracy);
GHashTable *
address_details_new ();
GHashTable *
address_details_copy (GHashTable *source);
G_END_DECLS
#endif
......@@ -3,7 +3,7 @@
* geoclue-hostip.c - A hostip.info-based Address/Position provider
*
* Author: Jussi Kukkonen <jku@o-hand.com>
* Copyright 2007 by Garmin Ltd. or its subsidiaries
* Copyright 2007, 2008 by Garmin Ltd. or its subsidiaries
*/
#include <config.h>
......@@ -16,6 +16,7 @@
#include <geoclue/gc-iface-position.h>
#include <geoclue/gc-iface-address.h>
#include <geoclue/geoclue-address-details.h>
#include "geoclue-hostip.h"
......
......@@ -44,6 +44,7 @@
#include <geoclue/gc-provider.h>
#include <geoclue/gc-iface-address.h>
#include <geoclue/geoclue-address-details.h>
typedef struct {
GcProvider parent;
......@@ -300,10 +301,10 @@ get_address (GcIfaceAddress *gc,
*timestamp = manual->timestamp;
}
if (address) {
*address = manual->address;
*address = address_details_copy (manual->address);
}
if (accuracy) {
*accuracy = manual->accuracy;
*accuracy = geoclue_accuracy_copy (manual->accuracy);
}
return TRUE;
......
......@@ -31,6 +31,7 @@
#include <geoclue/geoclue-common.h>
#include <geoclue/geoclue-position.h>
#include <geoclue/geoclue-address.h>
#include <geoclue/geoclue-address-details.h>
#include <geoclue/geoclue-marshal.h>
typedef enum _GeoclueProvideFlags {
......@@ -119,6 +120,8 @@ gc_master_provider_set_position (GcMasterProvider *provider,
double altitude,
GeoclueAccuracy *accuracy)
{
GeoclueAccuracyLevel level;
double hor_acc, ver_acc;
GcMasterProviderPrivate *priv = GET_PRIVATE (provider);
gc_master_provider_handle_new_accuracy (provider, accuracy);
......@@ -129,8 +132,9 @@ gc_master_provider_set_position (GcMasterProvider *provider,
priv->position_cache.longitude = longitude;
priv->position_cache.altitude = altitude;
geoclue_accuracy_free (priv->position_cache.accuracy);
priv->position_cache.accuracy = geoclue_accuracy_copy (accuracy);
geoclue_accuracy_get_details (accuracy, &level, &hor_acc, &ver_acc);
geoclue_accuracy_set_details (priv->position_cache.accuracy,
level, hor_acc, ver_acc);
g_signal_emit (provider, signals[POSITION_CHANGED], 0,
fields, timestamp,
......@@ -138,54 +142,26 @@ gc_master_provider_set_position (GcMasterProvider *provider,
priv->position_cache.accuracy);
}
static void
free_address_key_and_value (char *key, char *value, gpointer userdata)
{
/* TODO: actually fix address frees...
* should probably use g_hash_table_destroy */
}
static void
copy_address_key_and_value (char *key, char *value, GHashTable *target)
{
g_hash_table_insert (target, key, value);
}
static void
free_address_details (GHashTable *details)
{
if (details) {
g_hash_table_foreach (details, (GHFunc)free_address_key_and_value, NULL);
g_hash_table_unref (details);
}
}
static GHashTable*
copy_address_details (GHashTable *details)
{
GHashTable *t = g_hash_table_new (g_str_hash, g_str_equal);
if (details) {
g_hash_table_foreach (details, (GHFunc)copy_address_key_and_value, t);
}
return t;
}
static void
gc_master_provider_set_address (GcMasterProvider *provider,
int timestamp,
GHashTable *details,
GeoclueAccuracy *accuracy)
{
GeoclueAccuracyLevel level;
double hor_acc, ver_acc;
GcMasterProviderPrivate *priv = GET_PRIVATE (provider);
gc_master_provider_handle_new_accuracy (provider, accuracy);
priv->address_cache.timestamp = timestamp;
g_hash_table_destroy (priv->address_cache.details);
priv->address_cache.details = address_details_copy (details);
free_address_details (priv->address_cache.details);
priv->address_cache.details = copy_address_details (details);
geoclue_accuracy_free (priv->address_cache.accuracy);
priv->address_cache.accuracy = geoclue_accuracy_copy (accuracy);
geoclue_accuracy_get_details (accuracy, &level, &hor_acc, &ver_acc);
geoclue_accuracy_set_details (priv->position_cache.accuracy,
level, hor_acc, ver_acc);
g_signal_emit (provider, signals[ADDRESS_CHANGED], 0,
priv->address_cache.timestamp,
......@@ -435,7 +411,7 @@ dispose (GObject *object)
priv->address = NULL;
}
if (priv->address_cache.details) {
free_address_details (priv->address_cache.details);
g_hash_table_destroy (priv->address_cache.details);
priv->address_cache.details = NULL;
}
......@@ -504,11 +480,13 @@ gc_master_provider_init (GcMasterProvider *provider)
priv->geoclue = NULL;
priv->position = NULL;
priv->position_cache.accuracy = NULL;
priv->position_cache.accuracy =
geoclue_accuracy_new (GEOCLUE_ACCURACY_LEVEL_NONE, 0 ,0);
priv->address = NULL;
priv->address_cache.accuracy = NULL;
priv->address_cache.details = NULL;
priv->address_cache.accuracy =
geoclue_accuracy_new (GEOCLUE_ACCURACY_LEVEL_NONE, 0 ,0);
priv->address_cache.details = address_details_new ();
}
......@@ -771,10 +749,6 @@ gc_master_provider_new (const char *filename,
priv->provides = GEOCLUE_PROVIDE_FLAGS_NONE;
}
/* TODO using the cache might not be smart for eg gps providers.
* ATM everything uses it though... */
priv->use_cache = TRUE;
if (connectivity &&
(priv->required_resources & GEOCLUE_RESOURCE_FLAGS_NETWORK)) {
......@@ -789,6 +763,10 @@ gc_master_provider_new (const char *filename,
priv->net_status = geoclue_connectivity_get_status (connectivity);
}
if (priv->provides & GEOCLUE_PROVIDE_FLAGS_UPDATES) {
priv->use_cache = TRUE;
}
if (gc_master_provider_initialize (provider, &error) == FALSE) {
g_warning ("Error starting %s: %s", priv->name,
error->message);
......@@ -863,7 +841,7 @@ gc_master_provider_get_address (GcMasterProvider *provider,
*timestamp = priv->address_cache.timestamp;
}
if (details != NULL) {
*details = copy_address_details (priv->address_cache.details);
*details = address_details_copy (priv->address_cache.details);
}
if (accuracy != NULL) {
*accuracy = geoclue_accuracy_copy (priv->address_cache.accuracy);
......@@ -927,7 +905,7 @@ gc_master_provider_is_good (GcMasterProvider *provider,
((priv->required_resources & (~allowed_resources)) == 0));
}
GeoclueNetworkStatus
GeoclueStatus
gc_master_provider_get_status (GcMasterProvider *provider)
{
GcMasterProviderPrivate *priv = GET_PRIVATE (provider);
......@@ -944,14 +922,6 @@ gc_master_provider_get_name (GcMasterProvider *provider)
return priv->name;
}
GeoclueAccuracyLevel
gc_master_provider_get_accuracy_level (GcMasterProvider *provider)
{
GcMasterProviderPrivate *priv = GET_PRIVATE (provider);
return priv->promised_accuracy;
}
/* GCompareFunc for sorting providers by accuracy and required resources */
gint
gc_master_provider_compare (GcMasterProvider *a,
......
......@@ -62,9 +62,8 @@ void gc_master_provider_network_status_changed (GcMasterProvider *provider,
GeoclueNetworkStatus status);
char* gc_master_provider_get_name (GcMasterProvider *provider);
GeoclueAccuracyLevel gc_master_provider_get_accuracy_level (GcMasterProvider *provider);
GeoclueNetworkStatus gc_master_provider_get_status (GcMasterProvider *provider);
GeoclueStatus gc_master_provider_get_status (GcMasterProvider *provider);
GeocluePositionFields gc_master_provider_get_position (GcMasterProvider *master_provider,
int *timestamp,
......
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