Skip to content
Snippets Groups Projects
Commit 51ff041b authored by Guillaume Desmottes's avatar Guillaume Desmottes
Browse files

service: add TrpServiceNavigationGuidanceProgress


High level service API to publish progress information.

Signed-off-by: default avatarGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Reviewed-by: default avatarPhilip Withnall <philip.withnall@collabora.co.uk>
Differential Revision: https://phabricator.apertis.org/D4620
parent 3cf14fe0
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,8 @@ DBUS_XML_FILES = \
dbus_libtraprain_codegen_la_SOURCES = \
dbus/org.apertis.Navigation1.c \
dbus/org.apertis.Navigation1.h \
dbus/org.apertis.NavigationGuidance1.Progress.c \
dbus/org.apertis.NavigationGuidance1.Progress.h \
dbus/org.apertis.Traprain1.Mock.c \
dbus/org.apertis.Traprain1.Mock.h \
$(NULL)
......@@ -197,6 +199,7 @@ noinst_LTLIBRARIES += traprain-service/libtraprain-service-internal.la
traprain_serviceincludedir = $(includedir)/traprain-service-@TRP_API_VERSION@
traprain_service_headers = \
traprain-service/navigation-guidance-progress.h \
traprain-service/navigation.h \
$(NULL)
......@@ -210,6 +213,7 @@ nobase_traprain_serviceinclude_HEADERS = \
$(NULL)
traprain_service_sources = \
traprain-service/navigation-guidance-progress.c \
traprain-service/navigation.c \
traprain-service/route.c \
$(NULL)
......@@ -554,6 +558,7 @@ test_programs = \
tests/test-service-navigation \
tests/test-client-navigation \
tests/test-mock-service \
tests/test-guidance-progress \
$(NULL)
tests_test_service_navigation_SOURCES = \
......@@ -634,6 +639,30 @@ tests_test_mock_service_LDADD = \
$(top_builddir)/tests/libtraprain-test-helper.la \
$(NULL)
tests_test_guidance_progress_SOURCES = \
tests/test-guidance-progress.c \
$(NULL)
tests_test_guidance_progress_CPPFLAGS = \
-I$(top_srcdir) \
-I$(top_builddir) \
$(NULL)
tests_test_guidance_progress_CFLAGS = \
$(WARN_CFLAGS) \
$(TRAPRAIN_CFLAGS) \
$(NULL)
tests_test_guidance_progress_LDFLAGS = \
-no-undefined \
$(WARN_LDFLAGS) \
$(NULL)
tests_test_guidance_progress_LDADD = \
$(TRAPRAIN_LIBS) \
$(top_builddir)/traprain-service/libtraprain-service-internal.la \
$(NULL)
EXTRA_DIST += tests/services/org.apertis.Navigation1.service.in
DISTCLEANFILES += tests/services/org.apertis.Navigation1.service
......
/* vim:set et sw=2 cin cino=t0,f0,(0,{s,>2s,n-s,^-s,e2s: */
/*
* Copyright © 2016 Collabora Ltd.
*
* SPDX-License-Identifier: MPL-2.0
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <gio/gio.h>
#include <glib.h>
#include "traprain-service/navigation-guidance-progress.h"
#include "dbus/org.apertis.NavigationGuidance1.Progress.h"
#define PROGRESS_PATH "/org/apertis/NavigationGuidance1/Progress"
#define PROGRESS_BUS_NAME "org.apertis.NavigationGuidance1.Progress"
typedef struct
{
GTestDBus *dbus; /* owned */
GDBusConnection *conn; /* owned */
GMainLoop *loop; /* owned */
GError *error; /* owned */
gboolean init_result;
TrpServiceNavigationGuidanceProgress *service; /* owned */
TrpNavigationGuidance1Progress *proxy; /* owned */
} Test;
static void
setup (Test *test,
gconstpointer unused)
{
const gchar *addr;
test->dbus = g_test_dbus_new (G_TEST_DBUS_NONE);
g_test_dbus_up (test->dbus);
addr = g_test_dbus_get_bus_address (test->dbus);
g_assert (addr != NULL);
test->conn = g_dbus_connection_new_for_address_sync (addr,
G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
NULL, NULL, &test->error);
test->service = trp_service_navigation_guidance_progress_new (test->conn);
g_assert_true (TRP_SERVICE_IS_NAVIGATION_GUIDANCE_PROGRESS (test->service));
test->loop = g_main_loop_new (NULL, FALSE);
test->error = NULL;
}
static void
teardown (Test *test,
gconstpointer unused)
{
g_clear_pointer (&test->loop, g_main_loop_unref);
g_clear_pointer (&test->error, g_error_free);
g_clear_object (&test->service);
g_clear_object (&test->proxy);
g_test_dbus_down (test->dbus);
g_clear_object (&test->dbus);
g_clear_object (&test->conn);
}
static void
init_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
Test *test = user_data;
test->init_result = g_async_initable_init_finish (G_ASYNC_INITABLE (source), res, &test->error);
g_main_loop_quit (test->loop);
}
static void
init_service (Test *test)
{
g_async_initable_init_async (G_ASYNC_INITABLE (test->service), G_PRIORITY_DEFAULT, NULL, init_cb, test);
g_main_loop_run (test->loop);
g_assert_true (test->init_result);
g_assert_no_error (test->error);
}
static void
proxy_cb (GObject *source,
GAsyncResult *res,
gpointer user_data)
{
Test *test = user_data;
test->proxy = trp_navigation_guidance1_progress_proxy_new_finish (res, &test->error);
g_main_loop_quit (test->loop);
}
static void
create_proxy (Test *test)
{
g_clear_object (&test->proxy);
trp_navigation_guidance1_progress_proxy_new (test->conn, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
PROGRESS_BUS_NAME, PROGRESS_PATH, NULL, proxy_cb, test);
g_main_loop_run (test->loop);
}
/* Init a TrpServiceNavigationGuidanceProgress */
static void
test_service_init (Test *test,
gconstpointer unused)
{
g_autofree gchar *owner = NULL;
/* Service is not yet initialized, so not yet exposed on the bus */
create_proxy (test);
g_assert_no_error (test->error);
owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (test->proxy));
g_assert (owner == NULL);
init_service (test);
/* Check that the proxy is owned now that the service is initialized */
create_proxy (test);
g_assert_no_error (test->error);
owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (test->proxy));
g_assert (owner != NULL);
}
static void
invalidated_cb (TrpServiceNavigationGuidanceProgress *service,
const GError *error,
Test *test)
{
g_assert_true (TRP_SERVICE_IS_NAVIGATION_GUIDANCE_PROGRESS (service));
g_assert (error != NULL);
g_clear_error (&test->error);
test->error = g_error_copy (error);
g_main_loop_quit (test->loop);
}
/* Invalidate a TrpServiceNavigationGuidanceProgress */
static void
test_service_invalidated (Test *test,
gconstpointer unused)
{
init_service (test);
g_assert_no_error (test->error);
g_signal_connect (test->service, "invalidated", G_CALLBACK (invalidated_cb),
test);
g_dbus_connection_close (test->conn, NULL, NULL, NULL);
g_main_loop_run (test->loop);
g_assert_error (test->error, G_DBUS_ERROR, G_DBUS_ERROR_NAME_HAS_NO_OWNER);
}
static void
notify_cb (GObject *object,
GParamSpec *spec,
Test *test)
{
g_main_loop_quit (test->loop);
}
/* Test trp_service_navigation_set_start_time(_now) API */
static void
test_service_start_time (Test *test,
gconstpointer unused)
{
GDateTime *dt, *now;
init_service (test);
create_proxy (test);
g_assert_no_error (test->error);
/* 0 is the default start time */
g_assert_cmpuint (trp_navigation_guidance1_progress_get_start_time (test->proxy), ==, 0);
g_signal_connect (test->proxy, "notify::start-time", G_CALLBACK (notify_cb), test);
/* Set an arbitrary start time */
dt = g_date_time_new_from_unix_utc (123456789);
g_assert_true (trp_service_navigation_guidance_progress_set_start_time (test->service, dt, &test->error));
g_date_time_unref (dt);
g_assert_no_error (test->error);
g_main_loop_run (test->loop);
g_assert_cmpuint (trp_navigation_guidance1_progress_get_start_time (test->proxy), ==, 123456789);
/* Unset the start time */
g_assert_true (trp_service_navigation_guidance_progress_set_start_time (test->service, NULL, &test->error));
g_assert_no_error (test->error);
g_main_loop_run (test->loop);
g_assert_cmpuint (trp_navigation_guidance1_progress_get_start_time (test->proxy), ==, 0);
/* Set the start time to now */
g_assert_true (trp_service_navigation_guidance_progress_set_start_time_now (test->service, &test->error));
g_assert_no_error (test->error);
g_main_loop_run (test->loop);
dt = g_date_time_new_from_unix_utc (trp_navigation_guidance1_progress_get_start_time (test->proxy));
now = g_date_time_new_now_utc ();
/* assuming it didn't take more than one minute between the call to set_start_time_now() and this check */
g_assert_cmpint (g_date_time_difference (now, dt), <, G_TIME_SPAN_MINUTE);
g_date_time_unref (dt);
g_date_time_unref (now);
/* Create a new TrpServiceNavigationGuidanceProgress and set the start time BEFORE initializing it */
g_clear_object (&test->service);
g_clear_object (&test->proxy);
test->service = trp_service_navigation_guidance_progress_new (test->conn);
g_assert_true (TRP_SERVICE_IS_NAVIGATION_GUIDANCE_PROGRESS (test->service));
dt = g_date_time_new_from_unix_utc (987654321);
g_assert_true (trp_service_navigation_guidance_progress_set_start_time (test->service, dt, &test->error));
g_date_time_unref (dt);
init_service (test);
create_proxy (test);
g_assert_no_error (test->error);
g_assert_cmpuint (trp_navigation_guidance1_progress_get_start_time (test->proxy), ==, 987654321);
}
/* Test trp_service_navigation_guidance_progress_set_estimated_end_time API */
static void
test_service_estimated_end_time (Test *test,
gconstpointer unused)
{
GDateTime *dt;
init_service (test);
create_proxy (test);
g_assert_no_error (test->error);
/* 0 is the default estimated end time */
g_assert_cmpuint (trp_navigation_guidance1_progress_get_estimated_end_time (test->proxy), ==, 0);
g_signal_connect (test->proxy, "notify::estimated-end-time", G_CALLBACK (notify_cb), test);
/* Set an arbitrary estimated end time */
dt = g_date_time_new_from_unix_utc (123456789);
g_assert_true (trp_service_navigation_guidance_progress_set_estimated_end_time (test->service, dt, &test->error));
g_date_time_unref (dt);
g_assert_no_error (test->error);
g_main_loop_run (test->loop);
g_assert_cmpuint (trp_navigation_guidance1_progress_get_estimated_end_time (test->proxy), ==, 123456789);
/* Unset the start time */
g_assert_true (trp_service_navigation_guidance_progress_set_estimated_end_time (test->service, NULL, &test->error));
g_assert_no_error (test->error);
g_main_loop_run (test->loop);
g_assert_cmpuint (trp_navigation_guidance1_progress_get_estimated_end_time (test->proxy), ==, 0);
/* Create a new TrpServiceNavigationGuidanceProgress and set the end time BEFORE initializing it */
g_clear_object (&test->service);
g_clear_object (&test->proxy);
test->service = trp_service_navigation_guidance_progress_new (test->conn);
g_assert_true (TRP_SERVICE_IS_NAVIGATION_GUIDANCE_PROGRESS (test->service));
dt = g_date_time_new_from_unix_utc (987654321);
g_assert_true (trp_service_navigation_guidance_progress_set_estimated_end_time (test->service, dt, &test->error));
g_date_time_unref (dt);
init_service (test);
create_proxy (test);
g_assert_no_error (test->error);
g_assert_cmpuint (trp_navigation_guidance1_progress_get_estimated_end_time (test->proxy), ==, 987654321);
}
int
main (int argc,
char **argv)
{
g_test_init (&argc, &argv, NULL);
g_test_add ("/navigation-guidance-progress/service/init", Test, NULL,
setup, test_service_init, teardown);
g_test_add ("/navigation-guidance-progress/service/invalidated", Test, NULL,
setup, test_service_invalidated, teardown);
g_test_add ("/navigation-guidance-progress/service/start-time", Test, NULL,
setup, test_service_start_time, teardown);
g_test_add ("/navigation-guidance-progress/service/estimated-end-time", Test, NULL,
setup, test_service_estimated_end_time, teardown);
return g_test_run ();
}
/* vim:set et sw=2 cin cino=t0,f0,(0,{s,>2s,n-s,^-s,e2s: */
/*
* Copyright © 2016 Collabora Ltd.
*
* SPDX-License-Identifier: MPL-2.0
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "config.h"
#include "navigation-guidance-progress.h"
#include "dbus/org.apertis.NavigationGuidance1.Progress.h"
#define PROGRESS_PATH "/org/apertis/NavigationGuidance1/Progress"
#define PROGRESS_BUS_NAME "org.apertis.NavigationGuidance1.Progress"
/**
* SECTION: traprain-service/navigation-guidance-progress.h
* @title: TrpServiceNavigationGuidanceProgress
* @short_description: Publish progress information about the current journey
*
* #TrpServiceNavigationGuidanceProgress is used to publish progress information
* about the current journey in the navigation system.
*
* A navigation service should create one #TrpServiceNavigationGuidanceProgress
* during its whole lifetime and use it to publish progress information to
* external applications.
* The information about the journey routes are published using #TrpServiceNavigation.
*
* Note that nothing is published until g_async_initable_init_async()
* has been called.
*
* Since: UNRELEASED
*/
/**
* TrpServiceNavigationGuidanceProgress:
*
* Object used to publish progress information about the current journey to
* navigation UIs and third party applications.
*
* Since: UNRELEASED
*/
struct _TrpServiceNavigationGuidanceProgress
{
GObject parent;
TrpNavigationGuidance1Progress *service; /* owned */
GDBusConnection *conn; /* owned */
GCancellable *cancellable; /* owned */
GList *init_tasks; /* owned */
gboolean registered;
guint own_name_id; /* 0 if the server is not registered yet */
GError *invalidated_error; /* owned, NULL until the service is invalidated */
};
typedef enum {
PROP_CONNECTION = 1,
/*< private >*/
PROP_LAST = PROP_CONNECTION
} _TrpServiceNavigationGuidanceProgressProperty;
static GParamSpec *properties[PROP_LAST + 1];
enum
{
SIG_INVALIDATED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
static void
async_initable_iface_init (gpointer g_iface,
gpointer data);
G_DEFINE_TYPE_WITH_CODE (TrpServiceNavigationGuidanceProgress, trp_service_navigation_guidance_progress, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init));
static void
trp_service_navigation_guidance_progress_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
TrpServiceNavigationGuidanceProgress *self = TRP_SERVICE_NAVIGATION_GUIDANCE_PROGRESS (object);
switch ((_TrpServiceNavigationGuidanceProgressProperty) prop_id)
{
case PROP_CONNECTION:
g_value_set_object (value, self->conn);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
trp_service_navigation_guidance_progress_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
TrpServiceNavigationGuidanceProgress *self = TRP_SERVICE_NAVIGATION_GUIDANCE_PROGRESS (object);
switch ((_TrpServiceNavigationGuidanceProgressProperty) prop_id)
{
case PROP_CONNECTION:
g_assert (self->conn == NULL); /* construct only */
self->conn = g_value_dup_object (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
trp_service_navigation_dispose (GObject *object)
{
TrpServiceNavigationGuidanceProgress *self = (TrpServiceNavigationGuidanceProgress *) object;
g_cancellable_cancel (self->cancellable);
g_clear_object (&self->cancellable);
if (self->own_name_id != 0)
{
g_bus_unown_name (self->own_name_id);
self->own_name_id = 0;
}
if (self->registered)
{
g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (self->service));
self->registered = FALSE;
}
g_clear_object (&self->service);
g_clear_object (&self->conn);
/* Init tasks hold a reference on @self */
g_assert (self->init_tasks == NULL);
g_clear_error (&self->invalidated_error);
G_OBJECT_CLASS (trp_service_navigation_guidance_progress_parent_class)
->dispose (object);
}
static void
trp_service_navigation_guidance_progress_class_init (TrpServiceNavigationGuidanceProgressClass *klass)
{
GObjectClass *object_class = (GObjectClass *) klass;
object_class->get_property = trp_service_navigation_guidance_progress_get_property;
object_class->set_property = trp_service_navigation_guidance_progress_set_property;
object_class->dispose = trp_service_navigation_dispose;
/**
* TrpServiceNavigationGuidanceProgress:connection:
*
* The #GDBusConnection used by the service to publish progress information.
*
* Since: UNRELEASED
*/
properties[PROP_CONNECTION] = g_param_spec_object (
"connection", "Connection", "GDBusConnection", G_TYPE_DBUS_CONNECTION,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
/**
* TrpServiceNavigationGuidanceProgress::invalidated:
* @self: a #TrpServiceNavigationGuidanceProgress
* @error: error which caused @self to be invalidated
*
* Emitted when the backing object underlying this #TrpServiceNavigationGuidanceProgress
* disappears, or it is otherwise disconnected.
* The most common reason for this signal to be emitted is if the
* underlying D-Bus service name is lost.
*
* After this signal is emitted, all method calls to #TrpServiceNavigationGuidanceProgress methods will
* fail with the same error as the one reported in the signal (usually
* #G_DBUS_ERROR_NAME_HAS_NO_OWNER).
*
* Since: UNRELEASED
*/
signals[SIG_INVALIDATED] = g_signal_new ("invalidated", TRP_SERVICE_TYPE_NAVIGATION_GUIDANCE_PROGRESS,
G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL,
G_TYPE_NONE, 1, G_TYPE_ERROR);
g_object_class_install_properties (object_class, G_N_ELEMENTS (properties), properties);
}
static void
trp_service_navigation_guidance_progress_init (TrpServiceNavigationGuidanceProgress *self)
{
self->service = trp_navigation_guidance1_progress_skeleton_new ();
self->cancellable = g_cancellable_new ();
}
/**
* trp_service_navigation_guidance_progress_new:
* @connection: the #GDBusConnection to use to publish routes
*
* Create a new #TrpServiceNavigationGuidanceProgress. This service won't expose anything
* on D-Bus until g_async_initable_init_async() has been called.
*
* Returns: (transfer full): a new #TrpServiceNavigationGuidanceProgress
* Since: UNRELEASED
*/
TrpServiceNavigationGuidanceProgress *
trp_service_navigation_guidance_progress_new (GDBusConnection *connection)
{
g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL);
return g_object_new (TRP_SERVICE_TYPE_NAVIGATION_GUIDANCE_PROGRESS, "connection", connection, NULL);
}
static void
fail_init_tasks (TrpServiceNavigationGuidanceProgress *self,
GError *error)
{
GList *l;
for (l = self->init_tasks; l != NULL; l = g_list_next (l))
{
GTask *task = l->data;
g_task_return_error (task, g_error_copy (error));
}
g_list_free_full (self->init_tasks, g_object_unref);
self->init_tasks = NULL;
}
static void
complete_init_tasks (TrpServiceNavigationGuidanceProgress *self)
{
GList *l;
for (l = self->init_tasks; l != NULL; l = g_list_next (l))
{
GTask *task = l->data;
g_task_return_boolean (task, TRUE);
}
g_list_free_full (self->init_tasks, g_object_unref);
self->init_tasks = NULL;
}
static void
bus_name_acquired_cb (GDBusConnection *conn,
const gchar *name,
gpointer user_data)
{
TrpServiceNavigationGuidanceProgress *self = user_data;
GError *error = NULL;
if (!g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->service),
conn, PROGRESS_PATH, &error))
{
fail_init_tasks (self, error);
}
else
{
self->registered = TRUE;
complete_init_tasks (self);
}
}
static void
bus_name_lost_cb (GDBusConnection *conn,
const gchar *name,
gpointer user_data)
{
TrpServiceNavigationGuidanceProgress *self = user_data;
g_clear_error (&self->invalidated_error);
self->invalidated_error = g_error_new (G_DBUS_ERROR, G_DBUS_ERROR_NAME_HAS_NO_OWNER, "Lost bus name '%s'", name);
fail_init_tasks (self, self->invalidated_error);
g_signal_emit (self, signals[SIG_INVALIDATED], 0, self->invalidated_error);
}
static void
trp_service_navigation_guidance_progress_init_async (GAsyncInitable *initable,
int io_priority,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
TrpServiceNavigationGuidanceProgress *self = TRP_SERVICE_NAVIGATION_GUIDANCE_PROGRESS (initable);
g_autoptr (GTask) task = NULL;
gboolean start_init;
g_return_if_fail (self->conn != NULL);
task = g_task_new (initable, cancellable, callback, user_data);
if (self->registered)
{
g_task_return_boolean (task, TRUE);
return;
}
start_init = (self->init_tasks == NULL);
self->init_tasks = g_list_append (self->init_tasks, g_object_ref (task));
if (start_init)
self->own_name_id = g_bus_own_name_on_connection (self->conn,
PROGRESS_BUS_NAME,
G_BUS_NAME_OWNER_FLAGS_NONE,
bus_name_acquired_cb,
bus_name_lost_cb, self,
NULL);
}
static gboolean
trp_service_navigation_guidance_progress_init_finish (GAsyncInitable *initable,
GAsyncResult *result,
GError **error)
{
g_return_val_if_fail (g_task_is_valid (result, initable), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
return g_task_propagate_boolean (G_TASK (result), error);
}
static void
async_initable_iface_init (gpointer g_iface,
gpointer data)
{
GAsyncInitableIface *iface = g_iface;
iface->init_async = trp_service_navigation_guidance_progress_init_async;
iface->init_finish = trp_service_navigation_guidance_progress_init_finish;
}
static gboolean
check_invalidated (TrpServiceNavigationGuidanceProgress *self,
GError **error)
{
if (self->invalidated_error == NULL)
return TRUE;
if (error != NULL)
*error = g_error_copy (self->invalidated_error);
return FALSE;
}
/**
* trp_service_navigation_guidance_progress_set_start_time:
* @self: a #TrpServiceNavigationGuidanceProgress
* @start_time: (nullable): a #GDateTime representing the new start time, or %NULL to unset the start time
* @error: return location for error or %NULL.
*
* Set the start time of the current journey to @start_time. To unset a previous start time
* and if there is currently no on going journey pass %NULL as @start_time.
*
* Returns: %TRUE if the operation succeeded, %FALSE otherwise.
*/
gboolean
trp_service_navigation_guidance_progress_set_start_time (TrpServiceNavigationGuidanceProgress *self,
GDateTime *start_time,
GError **error)
{
guint64 ts = 0;
g_return_val_if_fail (TRP_SERVICE_IS_NAVIGATION_GUIDANCE_PROGRESS (self), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (!check_invalidated (self, error))
return FALSE;
if (start_time != NULL)
ts = g_date_time_to_unix (start_time);
trp_navigation_guidance1_progress_set_start_time (self->service, ts);
return TRUE;
}
/**
* trp_service_navigation_guidance_progress_set_start_time_now:
* @self: a #TrpServiceNavigationGuidanceProgress
* @error: return location for error or %NULL.
*
* Set the start time of the current journey to the current time.
* See trp_service_navigation_guidance_progress_set_start_time() for details.
*
* Returns: %TRUE if the operation succeeded, %FALSE otherwise.
*/
gboolean
trp_service_navigation_guidance_progress_set_start_time_now (TrpServiceNavigationGuidanceProgress *self,
GError **error)
{
gboolean result;
g_autoptr (GDateTime) dt = NULL;
g_return_val_if_fail (TRP_SERVICE_IS_NAVIGATION_GUIDANCE_PROGRESS (self), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
dt = g_date_time_new_now_utc ();
result = trp_service_navigation_guidance_progress_set_start_time (self, dt, error);
return result;
}
/**
* trp_service_navigation_guidance_progress_set_estimated_end_time:
* @self: a #TrpServiceNavigationGuidanceProgress
* @end_time: (nullable): a #GDateTime representing the new estimated end time, or %NULL to unset it
* @error: return location for error or %NULL.
*
* Set the estimated time of the current journey to @end_time. To unset a previous end time
* pass %NULL as @end_time.
*
* Returns: %TRUE if the operation succeeded, %FALSE otherwise.
*/
gboolean
trp_service_navigation_guidance_progress_set_estimated_end_time (TrpServiceNavigationGuidanceProgress *self,
GDateTime *end_time,
GError **error)
{
guint64 ts = 0;
g_return_val_if_fail (TRP_SERVICE_IS_NAVIGATION_GUIDANCE_PROGRESS (self), FALSE);
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (!check_invalidated (self, error))
return FALSE;
if (end_time != NULL)
ts = g_date_time_to_unix (end_time);
trp_navigation_guidance1_progress_set_estimated_end_time (self->service, ts);
return TRUE;
}
/* vim:set et sw=2 cin cino=t0,f0,(0,{s,>2s,n-s,^-s,e2s: */
/*
* Copyright © 2016 Collabora Ltd.
*
* SPDX-License-Identifier: MPL-2.0
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef __TRAPRAIN_SERVICE_NAVIGATION_GUIDANCE_PROGRESS_H__
#define __TRAPRAIN_SERVICE_NAVIGATION_GUIDANCE_PROGRESS_H__
#include <gio/gio.h>
#include <glib-object.h>
G_BEGIN_DECLS
#define TRP_SERVICE_TYPE_NAVIGATION_GUIDANCE_PROGRESS (trp_service_navigation_guidance_progress_get_type ())
G_DECLARE_FINAL_TYPE (TrpServiceNavigationGuidanceProgress, trp_service_navigation_guidance_progress, TRP_SERVICE, NAVIGATION_GUIDANCE_PROGRESS, GObject)
TrpServiceNavigationGuidanceProgress *trp_service_navigation_guidance_progress_new (GDBusConnection *connection);
gboolean trp_service_navigation_guidance_progress_set_start_time (TrpServiceNavigationGuidanceProgress *self,
GDateTime *start_time,
GError **error);
gboolean trp_service_navigation_guidance_progress_set_start_time_now (TrpServiceNavigationGuidanceProgress *self,
GError **error);
gboolean trp_service_navigation_guidance_progress_set_estimated_end_time (TrpServiceNavigationGuidanceProgress *self,
GDateTime *end_time,
GError **error);
G_END_DECLS
#endif /* __TRAPRAIN_SERVICE_NAVIGATION_GUIDANCE_PROGRESS_H__ */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment