| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include <glib/gi18n.h> |
| 24 |
|
| 25 |
#include "gclue-service-location.h" |
| 26 |
|
| 27 |
static void |
| 28 |
gclue_service_location_initable_iface_init (GInitableIface *iface); |
| 29 |
|
| 30 |
struct _GClueServiceLocationPrivate |
| 31 |
{ |
| 32 |
GClueClientInfo *client_info; |
| 33 |
char *path; |
| 34 |
GDBusConnection *connection; |
| 35 |
}; |
| 36 |
|
| 37 |
G_DEFINE_TYPE_WITH_CODE (GClueServiceLocation, |
| 38 |
gclue_service_location, |
| 39 |
GCLUE_DBUS_TYPE_LOCATION_SKELETON, |
| 40 |
G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, |
| 41 |
gclue_service_location_initable_iface_init) |
| 42 |
G_ADD_PRIVATE (GClueServiceLocation)); |
| 43 |
|
| 44 |
enum |
| 45 |
{ |
| 46 |
PROP_0, |
| 47 |
PROP_CLIENT_INFO, |
| 48 |
PROP_PATH, |
| 49 |
PROP_CONNECTION, |
| 50 |
PROP_LOCATION, |
| 51 |
LAST_PROP |
| 52 |
}; |
| 53 |
|
| 54 |
static GParamSpec *gParamSpecs[LAST_PROP]; |
| 55 |
|
| 56 |
static void |
| 57 |
gclue_service_location_finalize (GObject *object) |
| 58 |
{ |
| 59 |
GClueServiceLocationPrivate *priv = GCLUE_SERVICE_LOCATION (object)->priv; |
| 60 |
|
| 61 |
g_clear_pointer (&priv->path, g_free); |
| 62 |
g_clear_object (&priv->connection); |
| 63 |
g_clear_object (&priv->client_info); |
| 64 |
|
| 65 |
|
| 66 |
G_OBJECT_CLASS (gclue_service_location_parent_class)->finalize (object); |
| 67 |
} |
| 68 |
|
| 69 |
static void |
| 70 |
gclue_service_location_get_property (GObject *object, |
| 71 |
guint prop_id, |
| 72 |
GValue *value, |
| 73 |
GParamSpec *pspec) |
| 74 |
{ |
| 75 |
GClueServiceLocation *self = GCLUE_SERVICE_LOCATION (object); |
| 76 |
|
| 77 |
switch (prop_id) { |
| 78 |
case PROP_CLIENT_INFO: |
| 79 |
g_value_set_object (value, self->priv->client_info); |
| 80 |
break; |
| 81 |
|
| 82 |
case PROP_PATH: |
| 83 |
g_value_set_string (value, self->priv->path); |
| 84 |
break; |
| 85 |
|
| 86 |
case PROP_CONNECTION: |
| 87 |
g_value_set_object (value, self->priv->connection); |
| 88 |
break; |
| 89 |
|
| 90 |
case PROP_LOCATION: |
| 91 |
{ |
| 92 |
GClueDBusLocation *location; |
| 93 |
GClueLocation *loc; |
| 94 |
GVariant *timestamp; |
| 95 |
guint64 sec, usec; |
| 96 |
|
| 97 |
location = GCLUE_DBUS_LOCATION (object); |
| 98 |
|
| 99 |
timestamp = gclue_dbus_location_get_timestamp (location); |
| 100 |
g_variant_get (timestamp, "(tt)", &sec, &usec); |
| 101 |
|
| 102 |
loc = gclue_location_new_full |
| 103 |
(gclue_dbus_location_get_latitude (location), |
| 104 |
gclue_dbus_location_get_longitude (location), |
| 105 |
gclue_dbus_location_get_accuracy (location), |
| 106 |
gclue_dbus_location_get_speed (location), |
| 107 |
gclue_dbus_location_get_heading (location), |
| 108 |
gclue_dbus_location_get_altitude (location), |
| 109 |
sec, |
| 110 |
gclue_dbus_location_get_description (location)); |
| 111 |
|
| 112 |
g_value_take_object (value, loc); |
| 113 |
break; |
| 114 |
} |
| 115 |
|
| 116 |
default: |
| 117 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
static void |
| 122 |
gclue_service_location_set_property (GObject *object, |
| 123 |
guint prop_id, |
| 124 |
const GValue *value, |
| 125 |
GParamSpec *pspec) |
| 126 |
{ |
| 127 |
GClueServiceLocation *self = GCLUE_SERVICE_LOCATION (object); |
| 128 |
|
| 129 |
switch (prop_id) { |
| 130 |
case PROP_CLIENT_INFO: |
| 131 |
self->priv->client_info = g_value_dup_object (value); |
| 132 |
break; |
| 133 |
|
| 134 |
case PROP_PATH: |
| 135 |
self->priv->path = g_value_dup_string (value); |
| 136 |
break; |
| 137 |
|
| 138 |
case PROP_CONNECTION: |
| 139 |
self->priv->connection = g_value_dup_object (value); |
| 140 |
break; |
| 141 |
|
| 142 |
case PROP_LOCATION: |
| 143 |
{ |
| 144 |
GClueDBusLocation *location; |
| 145 |
GClueLocation *loc; |
| 146 |
gdouble altitude; |
| 147 |
GVariant *timestamp; |
| 148 |
|
| 149 |
location = GCLUE_DBUS_LOCATION (object); |
| 150 |
loc = g_value_get_object (value); |
| 151 |
gclue_dbus_location_set_latitude |
| 152 |
(location, gclue_location_get_latitude (loc)); |
| 153 |
gclue_dbus_location_set_longitude |
| 154 |
(location, gclue_location_get_longitude (loc)); |
| 155 |
gclue_dbus_location_set_accuracy |
| 156 |
(location, gclue_location_get_accuracy (loc)); |
| 157 |
gclue_dbus_location_set_description |
| 158 |
(location, gclue_location_get_description (loc)); |
| 159 |
gclue_dbus_location_set_speed |
| 160 |
(location, gclue_location_get_speed (loc)); |
| 161 |
gclue_dbus_location_set_heading |
| 162 |
(location, gclue_location_get_heading (loc)); |
| 163 |
timestamp = g_variant_new |
| 164 |
("(tt)", |
| 165 |
(guint64) gclue_location_get_timestamp (loc), |
| 166 |
(guint64) 0); |
| 167 |
gclue_dbus_location_set_timestamp |
| 168 |
(location, timestamp); |
| 169 |
altitude = gclue_location_get_altitude (loc); |
| 170 |
if (altitude != GCLUE_LOCATION_ALTITUDE_UNKNOWN) |
| 171 |
gclue_dbus_location_set_altitude (location, altitude); |
| 172 |
break; |
| 173 |
} |
| 174 |
|
| 175 |
default: |
| 176 |
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
static void |
| 181 |
gclue_service_location_handle_method_call (GDBusConnection *connection, |
| 182 |
const gchar *sender, |
| 183 |
const gchar *object_path, |
| 184 |
const gchar *interface_name, |
| 185 |
const gchar *method_name, |
| 186 |
GVariant *parameters, |
| 187 |
GDBusMethodInvocation *invocation, |
| 188 |
gpointer user_data) |
| 189 |
{ |
| 190 |
GClueServiceLocationPrivate *priv = GCLUE_SERVICE_LOCATION (user_data)->priv; |
| 191 |
GDBusInterfaceSkeletonClass *skeleton_class; |
| 192 |
GDBusInterfaceVTable *skeleton_vtable; |
| 193 |
|
| 194 |
if (!gclue_client_info_check_bus_name (priv->client_info, sender)) { |
| 195 |
g_dbus_method_invocation_return_error_literal (invocation, |
| 196 |
G_DBUS_ERROR, |
| 197 |
G_DBUS_ERROR_ACCESS_DENIED, |
| 198 |
"Access denied"); |
| 199 |
return; |
| 200 |
} |
| 201 |
|
| 202 |
skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (gclue_service_location_parent_class); |
| 203 |
skeleton_vtable = skeleton_class->get_vtable (G_DBUS_INTERFACE_SKELETON (user_data)); |
| 204 |
skeleton_vtable->method_call (connection, |
| 205 |
sender, |
| 206 |
object_path, |
| 207 |
interface_name, |
| 208 |
method_name, |
| 209 |
parameters, |
| 210 |
invocation, |
| 211 |
user_data); |
| 212 |
} |
| 213 |
|
| 214 |
static GVariant * |
| 215 |
gclue_service_location_handle_get_property (GDBusConnection *connection, |
| 216 |
const gchar *sender, |
| 217 |
const gchar *object_path, |
| 218 |
const gchar *interface_name, |
| 219 |
const gchar *property_name, |
| 220 |
GError **error, |
| 221 |
gpointer user_data) |
| 222 |
{ |
| 223 |
GClueServiceLocationPrivate *priv = GCLUE_SERVICE_LOCATION (user_data)->priv; |
| 224 |
GDBusInterfaceSkeletonClass *skeleton_class; |
| 225 |
GDBusInterfaceVTable *skeleton_vtable; |
| 226 |
|
| 227 |
if (!gclue_client_info_check_bus_name (priv->client_info, sender)) { |
| 228 |
g_set_error (error, |
| 229 |
G_DBUS_ERROR, |
| 230 |
G_DBUS_ERROR_ACCESS_DENIED, |
| 231 |
"Access denied"); |
| 232 |
return NULL; |
| 233 |
} |
| 234 |
|
| 235 |
skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (gclue_service_location_parent_class); |
| 236 |
skeleton_vtable = skeleton_class->get_vtable (G_DBUS_INTERFACE_SKELETON (user_data)); |
| 237 |
return skeleton_vtable->get_property (connection, |
| 238 |
sender, |
| 239 |
object_path, |
| 240 |
interface_name, |
| 241 |
property_name, |
| 242 |
error, |
| 243 |
user_data); |
| 244 |
} |
| 245 |
|
| 246 |
static gboolean |
| 247 |
gclue_service_location_handle_set_property (GDBusConnection *connection, |
| 248 |
const gchar *sender, |
| 249 |
const gchar *object_path, |
| 250 |
const gchar *interface_name, |
| 251 |
const gchar *property_name, |
| 252 |
GVariant *variant, |
| 253 |
GError **error, |
| 254 |
gpointer user_data) |
| 255 |
{ |
| 256 |
GClueServiceLocationPrivate *priv = GCLUE_SERVICE_LOCATION (user_data)->priv; |
| 257 |
GDBusInterfaceSkeletonClass *skeleton_class; |
| 258 |
GDBusInterfaceVTable *skeleton_vtable; |
| 259 |
|
| 260 |
if (!gclue_client_info_check_bus_name (priv->client_info, sender)) { |
| 261 |
g_set_error (error, |
| 262 |
G_DBUS_ERROR, |
| 263 |
G_DBUS_ERROR_ACCESS_DENIED, |
| 264 |
"Access denied"); |
| 265 |
return FALSE; |
| 266 |
} |
| 267 |
|
| 268 |
skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (gclue_service_location_parent_class); |
| 269 |
skeleton_vtable = skeleton_class->get_vtable (G_DBUS_INTERFACE_SKELETON (user_data)); |
| 270 |
return skeleton_vtable->set_property (connection, |
| 271 |
sender, |
| 272 |
object_path, |
| 273 |
interface_name, |
| 274 |
property_name, |
| 275 |
variant, |
| 276 |
error, |
| 277 |
user_data); |
| 278 |
} |
| 279 |
|
| 280 |
static const GDBusInterfaceVTable gclue_service_location_vtable = |
| 281 |
{ |
| 282 |
gclue_service_location_handle_method_call, |
| 283 |
gclue_service_location_handle_get_property, |
| 284 |
gclue_service_location_handle_set_property, |
| 285 |
{NULL} |
| 286 |
}; |
| 287 |
|
| 288 |
static GDBusInterfaceVTable * |
| 289 |
gclue_service_location_get_vtable (GDBusInterfaceSkeleton *skeleton G_GNUC_UNUSED) |
| 290 |
{ |
| 291 |
return (GDBusInterfaceVTable *) &gclue_service_location_vtable; |
| 292 |
} |
| 293 |
|
| 294 |
static void |
| 295 |
gclue_service_location_class_init (GClueServiceLocationClass *klass) |
| 296 |
{ |
| 297 |
GObjectClass *object_class; |
| 298 |
GDBusInterfaceSkeletonClass *skeleton_class; |
| 299 |
|
| 300 |
object_class = G_OBJECT_CLASS (klass); |
| 301 |
object_class->finalize = gclue_service_location_finalize; |
| 302 |
object_class->get_property = gclue_service_location_get_property; |
| 303 |
object_class->set_property = gclue_service_location_set_property; |
| 304 |
|
| 305 |
skeleton_class = G_DBUS_INTERFACE_SKELETON_CLASS (klass); |
| 306 |
skeleton_class->get_vtable = gclue_service_location_get_vtable; |
| 307 |
|
| 308 |
gParamSpecs[PROP_CLIENT_INFO] = g_param_spec_object ("client-info", |
| 309 |
"ClientInfo", |
| 310 |
"Information on client", |
| 311 |
GCLUE_TYPE_CLIENT_INFO, |
| 312 |
G_PARAM_READWRITE | |
| 313 |
G_PARAM_CONSTRUCT_ONLY); |
| 314 |
g_object_class_install_property (object_class, |
| 315 |
PROP_CLIENT_INFO, |
| 316 |
gParamSpecs[PROP_CLIENT_INFO]); |
| 317 |
|
| 318 |
gParamSpecs[PROP_PATH] = g_param_spec_string ("path", |
| 319 |
"Path", |
| 320 |
"Path", |
| 321 |
NULL, |
| 322 |
G_PARAM_READWRITE | |
| 323 |
G_PARAM_CONSTRUCT_ONLY); |
| 324 |
g_object_class_install_property (object_class, |
| 325 |
PROP_PATH, |
| 326 |
gParamSpecs[PROP_PATH]); |
| 327 |
|
| 328 |
gParamSpecs[PROP_CONNECTION] = g_param_spec_object ("connection", |
| 329 |
"Connection", |
| 330 |
"DBus Connection", |
| 331 |
G_TYPE_DBUS_CONNECTION, |
| 332 |
G_PARAM_READWRITE | |
| 333 |
G_PARAM_CONSTRUCT_ONLY); |
| 334 |
g_object_class_install_property (object_class, |
| 335 |
PROP_CONNECTION, |
| 336 |
gParamSpecs[PROP_CONNECTION]); |
| 337 |
|
| 338 |
gParamSpecs[PROP_LOCATION] = g_param_spec_object ("location", |
| 339 |
"Location", |
| 340 |
"Location", |
| 341 |
GCLUE_TYPE_LOCATION, |
| 342 |
G_PARAM_READWRITE); |
| 343 |
g_object_class_install_property (object_class, |
| 344 |
PROP_LOCATION, |
| 345 |
gParamSpecs[PROP_LOCATION]); |
| 346 |
} |
| 347 |
|
| 348 |
static void |
| 349 |
gclue_service_location_init (GClueServiceLocation *location) |
| 350 |
{ |
| 351 |
location->priv = gclue_service_location_get_instance_private (location); |
| 352 |
gclue_dbus_location_set_altitude (GCLUE_DBUS_LOCATION (location), |
| 353 |
GCLUE_LOCATION_ALTITUDE_UNKNOWN); |
| 354 |
} |
| 355 |
|
| 356 |
static gboolean |
| 357 |
gclue_service_location_initable_init (GInitable *initable, |
| 358 |
GCancellable *cancellable, |
| 359 |
GError **error) |
| 360 |
{ |
| 361 |
return g_dbus_interface_skeleton_export |
| 362 |
(G_DBUS_INTERFACE_SKELETON (initable), |
| 363 |
GCLUE_SERVICE_LOCATION (initable)->priv->connection, |
| 364 |
GCLUE_SERVICE_LOCATION (initable)->priv->path, |
| 365 |
error); |
| 366 |
} |
| 367 |
|
| 368 |
static void |
| 369 |
gclue_service_location_initable_iface_init (GInitableIface *iface) |
| 370 |
{ |
| 371 |
iface->init = gclue_service_location_initable_init; |
| 372 |
} |
| 373 |
|
| 374 |
GClueServiceLocation * |
| 375 |
gclue_service_location_new (GClueClientInfo *info, |
| 376 |
const char *path, |
| 377 |
GDBusConnection *connection, |
| 378 |
GClueLocation *location, |
| 379 |
GError **error) |
| 380 |
{ |
| 381 |
return g_initable_new (GCLUE_TYPE_SERVICE_LOCATION, |
| 382 |
NULL, |
| 383 |
error, |
| 384 |
"client-info", info, |
| 385 |
"path", path, |
| 386 |
"connection", connection, |
| 387 |
"location", location, |
| 388 |
NULL); |
| 389 |
} |
| 390 |
|
| 391 |
const gchar * |
| 392 |
gclue_service_location_get_path (GClueServiceLocation *location) |
| 393 |
{ |
| 394 |
g_return_val_if_fail (GCLUE_IS_SERVICE_LOCATION(location), NULL); |
| 395 |
|
| 396 |
return location->priv->path; |
| 397 |
} |