Commit ca15136c authored by Zeeshan Ali's avatar Zeeshan Ali

service: Standalone GClueLocation class

GClueLocation does not inherit from and therefore does not depend on
GeocodeLocation class anymore. This is in preparation for dropping the
internal geocode-glib copy in a following patch.
parent e00c54c1
......@@ -402,10 +402,8 @@ gclue_location_source_set_location (GClueLocationSource *source,
if (priv->scramble_location) {
gdouble latitude, distance, accuracy;
latitude = geocode_location_get_latitude
(GEOCODE_LOCATION (priv->location));
accuracy = geocode_location_get_accuracy
(GEOCODE_LOCATION (priv->location));
latitude = gclue_location_get_latitude (priv->location);
accuracy = gclue_location_get_accuracy (priv->location);
/* Randomization is needed to stop apps from calculationg the
* actual location.
......@@ -430,10 +428,9 @@ gclue_location_source_set_location (GClueLocationSource *source,
if (cur_location != NULL && priv->compute_movement) {
guint64 cur_timestamp, timestamp;
timestamp = geocode_location_get_timestamp
(GEOCODE_LOCATION (location));
cur_timestamp = geocode_location_get_timestamp
(GEOCODE_LOCATION (cur_location));
timestamp = gclue_location_get_timestamp (location);
cur_timestamp = gclue_location_get_timestamp
(cur_location);
if (timestamp != cur_timestamp)
gclue_location_set_speed_from_prev_location
......
This diff is collapsed.
......@@ -28,7 +28,6 @@
#include <glib-object.h>
#include <gio/gio.h>
#include "geocode-glib/geocode-location.h"
G_BEGIN_DECLS
......@@ -48,7 +47,7 @@ typedef struct _GClueLocationPrivate GClueLocationPrivate;
struct _GClueLocation
{
/* Parent instance structure */
GeocodeLocation parent_instance;
GObject parent_instance;
GClueLocationPrivate *priv;
};
......@@ -56,11 +55,60 @@ struct _GClueLocation
struct _GClueLocationClass
{
/* Parent class structure */
GeocodeLocationClass parent_class;
GObjectClass parent_class;
};
GType gclue_location_get_type (void);
/**
* GCLUE_LOCATION_ALTITUDE_UNKNOWN:
*
* Constant representing unknown altitude.
*/
#define GCLUE_LOCATION_ALTITUDE_UNKNOWN -G_MAXDOUBLE
/**
* GCLUE_LOCATION_ACCURACY_UNKNOWN:
*
* Constant representing unknown accuracy.
*/
#define GCLUE_LOCATION_ACCURACY_UNKNOWN -1
/**
* GCLUE_LOCATION_ACCURACY_STREET:
*
* Constant representing street-level accuracy.
*/
#define GCLUE_LOCATION_ACCURACY_STREET 1000 /* 1 km */
/**
* GCLUE_LOCATION_ACCURACY_CITY:
*
* Constant representing city-level accuracy.
*/
#define GCLUE_LOCATION_ACCURACY_CITY 15000 /* 15 km */
/**
* GCLUE_LOCATION_ACCURACY_REGION:
*
* Constant representing region-level accuracy.
*/
#define GCLUE_LOCATION_ACCURACY_REGION 50000 /* 50 km */
/**
* GCLUE_LOCATION_ACCURACY_COUNTRY:
*
* Constant representing country-level accuracy.
*/
#define GCLUE_LOCATION_ACCURACY_COUNTRY 300000 /* 300 km */
/**
* GCLUE_LOCATION_ACCURACY_CONTINENT:
*
* Constant representing continent-level accuracy.
*/
#define GCLUE_LOCATION_ACCURACY_CONTINENT 3000000 /* 3000 km */
/**
* GCLUE_LOCATION_HEADING_UNKNOWN:
*
......@@ -96,6 +144,22 @@ GClueLocation *gclue_location_create_from_gga
GClueLocation *gclue_location_duplicate
(GClueLocation *location);
void gclue_location_set_description
(GClueLocation *loc,
const char *description);
const char *gclue_location_get_description
(GClueLocation *loc);
gdouble gclue_location_get_latitude
(GClueLocation *loc);
gdouble gclue_location_get_longitude
(GClueLocation *loc);
gdouble gclue_location_get_altitude
(GClueLocation *loc);
gdouble gclue_location_get_accuracy
(GClueLocation *loc);
guint64 gclue_location_get_timestamp
(GClueLocation *loc);
void gclue_location_set_speed (GClueLocation *loc,
gdouble speed);
......@@ -115,5 +179,8 @@ void gclue_location_set_heading_from_prev_location
gdouble gclue_location_get_heading
(GClueLocation *loc);
double gclue_location_get_distance_from
(GClueLocation *loca,
GClueLocation *locb);
#endif /* GCLUE_LOCATION_H */
......@@ -83,26 +83,24 @@ set_location (GClueLocator *locator,
GClueLocation *location)
{
GClueLocation *cur_location;
GeocodeLocation *gloc, *cur_gloc;
cur_location = gclue_location_source_get_location
(GCLUE_LOCATION_SOURCE (locator));
gloc = GEOCODE_LOCATION (location);
cur_gloc = GEOCODE_LOCATION (cur_location);
g_debug ("New location available");
if (cur_location != NULL) {
if (geocode_location_get_timestamp (gloc) <
geocode_location_get_timestamp (cur_gloc)) {
if (gclue_location_get_timestamp (location) <
gclue_location_get_timestamp (cur_location)) {
g_debug ("New location older than current, ignoring.");
return;
}
if (geocode_location_get_distance_from (gloc, cur_gloc) * 1000 <
geocode_location_get_accuracy (gloc) &&
geocode_location_get_accuracy (gloc) >
geocode_location_get_accuracy (cur_gloc)) {
if (gclue_location_get_distance_from (location, cur_location)
* 1000 <
gclue_location_get_accuracy (location) &&
gclue_location_get_accuracy (location) >
gclue_location_get_accuracy (cur_location)) {
/* We only take the new location if either the previous one
* lies outside its accuracy circle or its more or as
* accurate as previous one.
......
......@@ -293,27 +293,27 @@ gclue_mozilla_create_submit_query (GClueLocation *location,
json_builder_begin_object (builder);
lat = geocode_location_get_latitude (GEOCODE_LOCATION (location));
lat = gclue_location_get_latitude (location);
json_builder_set_member_name (builder, "lat");
json_builder_add_double_value (builder, lat);
lon = geocode_location_get_longitude (GEOCODE_LOCATION (location));
lon = gclue_location_get_longitude (location);
json_builder_set_member_name (builder, "lon");
json_builder_add_double_value (builder, lon);
accuracy = geocode_location_get_accuracy (GEOCODE_LOCATION (location));
if (accuracy != GEOCODE_LOCATION_ACCURACY_UNKNOWN) {
accuracy = gclue_location_get_accuracy (location);
if (accuracy != GCLUE_LOCATION_ACCURACY_UNKNOWN) {
json_builder_set_member_name (builder, "accuracy");
json_builder_add_double_value (builder, accuracy);
}
altitude = geocode_location_get_altitude (GEOCODE_LOCATION (location));
if (altitude != GEOCODE_LOCATION_ALTITUDE_UNKNOWN) {
altitude = gclue_location_get_altitude (location);
if (altitude != GCLUE_LOCATION_ALTITUDE_UNKNOWN) {
json_builder_set_member_name (builder, "altitude");
json_builder_add_double_value (builder, altitude);
}
tv.tv_sec = geocode_location_get_timestamp (GEOCODE_LOCATION (location));
tv.tv_sec = gclue_location_get_timestamp (location);
tv.tv_usec = 0;
timestamp = g_time_val_to_iso8601 (&tv);
json_builder_set_member_name (builder, "time");
......
......@@ -134,8 +134,7 @@ distance_below_threshold (GClueServiceClient *client,
g_object_get (priv->location,
"location", &cur_location,
NULL);
distance = geocode_location_get_distance_from
(GEOCODE_LOCATION (cur_location), GEOCODE_LOCATION (location));
distance = gclue_location_get_distance_from (cur_location, location);
g_object_unref (cur_location);
threshold_km = priv->distance_threshold / 1000.0;
......@@ -165,9 +164,8 @@ time_below_threshold (GClueServiceClient *client,
"location", &cur_location,
NULL);
cur_ts = geocode_location_get_timestamp
(GEOCODE_LOCATION (cur_location));
ts = geocode_location_get_timestamp (GEOCODE_LOCATION (location));
cur_ts = gclue_location_get_timestamp (cur_location);
ts = gclue_location_get_timestamp (location);
diff_ts = ABS (ts - cur_ts);
g_object_unref (cur_location);
......
......@@ -144,32 +144,30 @@ gclue_service_location_set_property (GObject *object,
GClueDBusLocation *location;
GClueLocation *loc;
gdouble altitude;
GeocodeLocation *g_loc;
GVariant *timestamp;
location = GCLUE_DBUS_LOCATION (object);
loc = g_value_get_object (value);
g_loc = GEOCODE_LOCATION (loc);
gclue_dbus_location_set_latitude
(location, geocode_location_get_latitude (g_loc));
(location, gclue_location_get_latitude (loc));
gclue_dbus_location_set_longitude
(location, geocode_location_get_longitude (g_loc));
(location, gclue_location_get_longitude (loc));
gclue_dbus_location_set_accuracy
(location, geocode_location_get_accuracy (g_loc));
(location, gclue_location_get_accuracy (loc));
gclue_dbus_location_set_description
(location, geocode_location_get_description (g_loc));
(location, gclue_location_get_description (loc));
gclue_dbus_location_set_speed
(location, gclue_location_get_speed (loc));
gclue_dbus_location_set_heading
(location, gclue_location_get_heading (loc));
timestamp = g_variant_new
("(tt)",
(guint64) geocode_location_get_timestamp (g_loc),
(guint64) gclue_location_get_timestamp (loc),
(guint64) 0);
gclue_dbus_location_set_timestamp
(location, timestamp);
altitude = geocode_location_get_altitude (g_loc);
if (altitude != GEOCODE_LOCATION_ALTITUDE_UNKNOWN)
altitude = gclue_location_get_altitude (loc);
if (altitude != GCLUE_LOCATION_ALTITUDE_UNKNOWN)
gclue_dbus_location_set_altitude (location, altitude);
break;
}
......@@ -354,7 +352,7 @@ gclue_service_location_init (GClueServiceLocation *location)
GCLUE_TYPE_SERVICE_LOCATION,
GClueServiceLocationPrivate);
gclue_dbus_location_set_altitude (GCLUE_DBUS_LOCATION (location),
GEOCODE_LOCATION_ALTITUDE_UNKNOWN);
GCLUE_LOCATION_ALTITUDE_UNKNOWN);
}
static gboolean
......
......@@ -328,14 +328,13 @@ on_submit_source_location_notify (GObject *source_object,
location = gclue_location_source_get_location (source);
if (location == NULL ||
geocode_location_get_accuracy (GEOCODE_LOCATION (location)) >
gclue_location_get_accuracy (location) >
SUBMISSION_ACCURACY_THRESHOLD ||
geocode_location_get_timestamp (GEOCODE_LOCATION (location)) <
gclue_location_get_timestamp (location) <
web->priv->last_submitted + SUBMISSION_TIME_THRESHOLD)
return;
web->priv->last_submitted = geocode_location_get_timestamp
(GEOCODE_LOCATION (location));
web->priv->last_submitted = gclue_location_get_timestamp (location);
if (!get_internet_available ())
return;
......
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