Commit df764fee authored by Jussi Kukkonen's avatar Jussi Kukkonen

Finish Address support in MasterClient

Not much testing yet -- need a "simulator" provider
parent fca2cf72
......@@ -4,7 +4,7 @@
<interface name="org.freedesktop.Geoclue.MasterClient">
<method name="SetRequirements">
<arg name="accuracy" type="d" direction="in" />
<arg name="accuracy_level" type="i" direction="in" />
<arg name="time" type="i" direction="in" />
<arg name="require_updates" type="b" direction="in" />
<arg name="allowed_resources" type="i" direction="in" />
......
......@@ -58,6 +58,20 @@ position_changed (GcMasterProvider *provider,
accuracy);
}
static void
address_changed (GcMasterProvider *provider,
int timestamp,
GHashTable *details,
GeoclueAccuracy *accuracy,
GcMasterClient *client)
{
gc_iface_address_emit_address_changed
(GC_IFACE_ADDRESS (client),
timestamp,
details,
accuracy);
}
static gboolean
gc_iface_master_client_set_requirements (GcMasterClient *client,
GeoclueAccuracyLevel min_accuracy,
......@@ -66,7 +80,6 @@ gc_iface_master_client_set_requirements (GcMasterClient *client,
GeoclueResourceFlags allowed_resources,
GError **error)
{
/* get_providers here, choose which one to use */
GList *providers = NULL;
......@@ -75,31 +88,51 @@ gc_iface_master_client_set_requirements (GcMasterClient *client,
client->require_updates = require_updates;
client->allowed_resources = allowed_resources;
providers = gc_master_get_position_providers (min_accuracy,
require_updates,
allowed_resources,
NULL);
g_debug ("%d providers matching requirements found", g_list_length (providers));
/* position provider */
providers = gc_master_get_providers (GC_IFACE_POSITION,
min_accuracy,
require_updates,
allowed_resources,
NULL);
g_debug ("%d position providers matching requirements found", g_list_length (providers));
if (!providers) {
// TODO: should have a return value to indicate provider existence?
return TRUE;
} else {
/* TODO select which provider/interface to use out of the possible ones
* Now using the first one */
client->position_provider = providers->data;
g_signal_connect (G_OBJECT (client->position_provider),
"position-changed",
G_CALLBACK (position_changed),
client);
g_list_free (providers);
}
/* TODO select which provider/interface to use out of the possible ones
* Now using the first one */
client->position_provider = providers->data;
g_signal_connect (G_OBJECT (client->position_provider),
"position-changed",
G_CALLBACK (position_changed),
client);
/*
g_print ("Requirements set, provider '%s' chosen\n", client->position_provider->name);
*/
g_list_free (providers);
/* Address provider */
providers = gc_master_get_providers (GC_IFACE_ADDRESS,
min_accuracy,
require_updates,
allowed_resources,
NULL);
g_debug ("%d address providers matching requirements found", g_list_length (providers));
if (!providers) {
// TODO: should have a return value to indicate provider existence?
} else {
/* TODO select which provider/interface to use out of the possible ones
* Now using the first one */
client->address_provider = providers->data;
g_signal_connect (G_OBJECT (client->address_provider),
"position-changed",
G_CALLBACK (address_changed),
client);
g_list_free (providers);
}
return TRUE;
}
......@@ -156,10 +189,20 @@ get_address (GcIfaceAddress *iface,
GeoclueAccuracy **accuracy,
GError **error)
{
GcMasterClient *client = GC_MASTER_CLIENT (iface);
/* TODO: Implement */
if (client->address_provider == NULL) {
/* TODO: set error*/
g_warning ("get_position called, but no provider available");
return FALSE;
}
return FALSE;
return gc_master_provider_get_address
(client->address_provider,
timestamp,
address,
accuracy,
error);
}
static void
......
......@@ -28,6 +28,9 @@ typedef struct {
guint32 update_id;
GcMasterProvider *position_provider;
GcMasterProvider *address_provider;
} GcMasterClient;
typedef struct {
......
......@@ -761,7 +761,7 @@ gc_master_provider_get_address (GcMasterProvider *provider,
GcInterfaceFlags
static GcInterfaceFlags
gc_master_provider_get_supported_interfaces (GcMasterProvider *provider)
{
GcMasterProviderPrivate *priv = GET_PRIVATE (provider);
......@@ -781,11 +781,13 @@ gc_master_provider_get_supported_interfaces (GcMasterProvider *provider)
gboolean
gc_master_provider_is_good (GcMasterProvider *provider,
GcInterfaceFlags iface_type,
GeoclueAccuracyLevel min_accuracy,
GeoclueResourceFlags allowed_resources,
gboolean need_update)
gboolean need_update,
GeoclueResourceFlags allowed_resources)
{
GcMasterProviderPrivate *priv;
GcInterfaceFlags supported_ifaces;
GeoclueProvideFlags required_flags = GEOCLUE_PROVIDE_FLAGS_NONE;
priv = GET_PRIVATE (provider);
......@@ -794,11 +796,14 @@ gc_master_provider_is_good (GcMasterProvider *provider,
required_flags |= GEOCLUE_PROVIDE_FLAGS_UPDATES;
}
supported_ifaces = gc_master_provider_get_supported_interfaces (provider);
/* provider must provide all that is required and
* cannot require a resource that is not allowed */
/* TODO: really, we need to change some of those terms... */
return (((priv->provides & required_flags) == required_flags) &&
return (((supported_ifaces & iface_type) == iface_type) &&
((priv->provides & required_flags) == required_flags) &&
(priv->accuracy_level >= min_accuracy) &&
((priv->required_resources & (~allowed_resources)) == 0));
}
......
......@@ -11,7 +11,7 @@ G_BEGIN_DECLS
#define GC_MASTER_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GC_TYPE_MASTER_PROVIDER, GcMasterProvider))
#define GC_IS_MASTER_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GC_TYPE_MASTER_PROVIDER))
typedef enum _GcInterfaceFlags {
typedef enum {
GC_IFACE_NONE = 0,
GC_IFACE_GEOCLUE = 1 << 0,
GC_IFACE_POSITION = 1 << 1,
......@@ -44,17 +44,15 @@ GType gc_master_provider_get_type (void);
GcMasterProvider *gc_master_provider_new (const char *filename,
gboolean network_status_events);
GcInterfaceFlags gc_master_provider_get_supported_interfaces (GcMasterProvider *master_provider);
gboolean gc_master_provider_is_good (GcMasterProvider *provider,
GcInterfaceFlags iface_types,
GeoclueAccuracyLevel min_accuracy,
GeoclueResourceFlags allowed_resources,
gboolean need_update);
gboolean need_update,
GeoclueResourceFlags allowed_resources);
void gc_master_provider_network_status_changed (GcMasterProvider *provider,
GeoclueStatus status);
GeocluePositionFields gc_master_provider_get_position (GcMasterProvider *master_provider,
int *timestamp,
double *latitude,
......
......@@ -25,7 +25,7 @@
G_DEFINE_TYPE (GcMaster, gc_master, G_TYPE_OBJECT);
static GList *position_providers = NULL;
static GList *providers = NULL;
static gboolean gc_iface_master_create (GcMaster *master,
const char **object_path,
......@@ -103,11 +103,9 @@ gc_master_class_init (GcMasterClass *klass)
/* Load the provider details out of a keyfile */
static void
gc_master_add_new_provider (GcMaster *master,
const char *filename)
const char *filename)
{
GcMasterProvider *provider;
GcInterfaceFlags ifaces;
gboolean provider_used = FALSE;
provider = gc_master_provider_new (filename,
master->connectivity != NULL);
......@@ -116,19 +114,7 @@ gc_master_add_new_provider (GcMaster *master,
return;
}
ifaces = gc_master_provider_get_supported_interfaces (provider);
if (ifaces & GC_IFACE_POSITION) {
position_providers = g_list_prepend (position_providers,
provider);
provider_used = TRUE;
}
/*check for other provider types here*/
if (!provider_used) {
/* provider did not have any useful interfaces */
g_object_unref (provider);
}
providers = g_list_prepend (providers, provider);
}
/* Scan a directory for .provider files */
......@@ -190,12 +176,12 @@ network_status_changed (GeoclueConnectivity *connectivity,
GList *l;
GeoclueStatus gc_status;
if (position_providers == NULL) {
if (providers == NULL) {
return;
}
gc_status = ConnectivityStatusToProviderStatus[status];
for (l = position_providers; l; l = l->next) {
for (l = providers; l; l = l->next) {
GcMasterProvider *provider = l->data;
/* might be nicer to do this with a signal, but ... */
......@@ -233,24 +219,28 @@ gc_master_init (GcMaster *master)
GList *
gc_master_get_position_providers (GeoclueAccuracyLevel min_accuracy,
gboolean can_update,
GeoclueResourceFlags allowed,
GError **error)
gc_master_get_providers (GcInterfaceFlags iface_type,
GeoclueAccuracyLevel min_accuracy,
gboolean can_update,
GeoclueResourceFlags allowed,
GError **error)
{
GList *l, *p = NULL;
if (position_providers == NULL) {
if (providers == NULL) {
return NULL;
}
/* we should probably return in some order?
* accuracy? */
for (l = position_providers; l; l = l->next) {
for (l = providers; l; l = l->next) {
GcMasterProvider *provider = l->data;
if (gc_master_provider_is_good (provider, min_accuracy,
can_update, allowed)) {
if (gc_master_provider_is_good (provider,
iface_type,
min_accuracy,
can_update,
allowed)) {
p = g_list_prepend (p, provider);
}
}
......
......@@ -16,6 +16,7 @@
#include <geoclue/geoclue-common.h>
#include <geoclue/geoclue-accuracy.h>
#include "connectivity.h"
#include "master-provider.h"
#define GC_TYPE_MASTER (gc_master_get_type ())
#define GC_MASTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GC_TYPE_MASTER, GcMaster))
......@@ -33,10 +34,11 @@ typedef struct {
} GcMasterClass;
GType gc_master_get_type (void);
GList *gc_master_get_position_providers (GeoclueAccuracyLevel min_accuracy,
gboolean can_update,
GeoclueResourceFlags allowed,
GError **error);
GList *gc_master_get_providers (GcInterfaceFlags iface_type,
GeoclueAccuracyLevel min_accuracy,
gboolean can_update,
GeoclueResourceFlags allowed,
GError **error);
#endif
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