Hi,
Could you please send your patches directly and not as attachment? I
have to copy the patch over to for the review. The simplest way is to
use 'git send-email' directly.
On Wed, Dec 23, 2020 at 03:19:30PM +0000, VAUTRIN Emmanuel (Canal Plus Prestataire)
wrote:
As our system depends on https requests, and for boot performance
purposes, we need to be informed when a time synchronization (via the
ntp) is performed.
In this aim, please find the attached patch, adding the TimeSynced
signal emitted when the system time has been synced.
From cf311e998c85b18703886b49bc98c06840612c22 Mon Sep 17 00:00:00
2001
From: Emmanuel VAUTRIN <Emmanuel.VAUTRIN(a)cpexterne.org>
Date: Wed, 23 Dec 2020 12:06:04 +0100
Subject: [PATCH] clock: Add TimeSynced signal emitted when the system time has
been synced.
Please add a commit message explaining what problem it solves.
---
doc/clock-api.txt | 4 ++++
include/dbus.h | 2 ++
src/clock.c | 2 ++
src/dbus.c | 30 ++++++++++++++++++++++++++++++
src/timeserver.c | 3 +++
5 files changed, 41 insertions(+)
diff --git a/doc/clock-api.txt b/doc/clock-api.txt
index 6818f5a8..2e368d0a 100644
--- a/doc/clock-api.txt
+++ b/doc/clock-api.txt
@@ -27,6 +27,10 @@ Signals PropertyChanged(string name, variant value) [experimental]
This signal indicates a changed value of the given
property.
+ TimeSynced(uint64 Time) [experimental]
+
+ This signal indicates that the current system time
+ has been synced.
I think it would make more sense to just emit a bool and send out the
Time event along side. In this case it would be the same event for auto
or manual mode. This would be more consistent in my opinion.
Also, TimeserverSynced would be also be better name for it in this case.
Properties uint64 Time [readonly or readwrite] [experimental]
diff --git a/include/dbus.h b/include/dbus.h
index bcab4189..3208adc5 100644
--- a/include/dbus.h
+++ b/include/dbus.h
@@ -85,6 +85,8 @@ dbus_bool_t connman_dbus_setting_changed_array(const char *owner,
const char *path, const char *key, int type,
connman_dbus_append_cb_t function,
void *user_data);
+dbus_bool_t connman_dbus_time_synced(const char *path,
+ const char *interface);
static inline void connman_dbus_dict_open(DBusMessageIter *iter,
DBusMessageIter *dict)
diff --git a/src/clock.c b/src/clock.c
index 0fde2c34..315e908e 100644
--- a/src/clock.c
+++ b/src/clock.c
@@ -381,6 +381,8 @@ static const GDBusMethodTable clock_methods[] = {
static const GDBusSignalTable clock_signals[] = {
{ GDBUS_SIGNAL("PropertyChanged",
GDBUS_ARGS({ "name", "s" }, { "value", "v"
})) },
+ { GDBUS_SIGNAL("TimeSynced",
+ GDBUS_ARGS({ "name", "s" }, { "value", "v"
})) },
{ },
};
diff --git a/src/dbus.c b/src/dbus.c
index d80a46ce..73d1bad6 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -23,6 +23,8 @@
#include <config.h>
#endif
+#include <sys/time.h>
+
#include <string.h>
#include <errno.h>
#include <gdbus.h>
@@ -382,6 +384,34 @@ dbus_bool_t connman_dbus_setting_changed_array(const char *owner,
return TRUE;
}
+dbus_bool_t connman_dbus_time_synced(const char *path, const char *interface)
+{
+ DBusMessage *signal;
+ DBusMessageIter iter;
+ struct timeval tv;
+ dbus_uint64_t val = 0;
+
+ if (!path)
+ return FALSE;
+
+ signal = dbus_message_new_signal(path, interface, "TimeSynced");
+ if (!signal)
+ return FALSE;
+
+ dbus_message_iter_init_append(signal, &iter);
+
+ if (gettimeofday(&tv, NULL) == 0) {
+ val = tv.tv_sec;
+ }
+
+ connman_dbus_property_append_basic(&iter, "Time",
+ DBUS_TYPE_UINT64, &val);
+
+ g_dbus_send_message(connection, signal);
+
+ return TRUE;
+}
+
dbus_bool_t __connman_dbus_append_objpath_dict_array(DBusMessage *msg,
connman_dbus_append_cb_t function, void *user_data)
{
diff --git a/src/timeserver.c b/src/timeserver.c
index decca153..ebd1fab3 100644
--- a/src/timeserver.c
+++ b/src/timeserver.c
@@ -57,6 +57,9 @@ static void ntp_callback(bool success, void *user_data)
if (!success)
sync_next();
+ else
+ connman_dbus_time_synced(CONNMAN_MANAGER_PATH,
+ CONNMAN_CLOCK_INTERFACE);
You should also add it to get_properties.
Daniel