From: Anderson Lizardo <anderson.lizardo@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: Sheldon Demario <sheldon.demario@openbossa.org>
Subject: [PATCH RFC BlueZ 3/5] Time Profile: Add "timed" time provider
Date: Fri, 2 Dec 2011 14:34:08 -0400 [thread overview]
Message-ID: <1322850850-18019-4-git-send-email-anderson.lizardo@openbossa.org> (raw)
In-Reply-To: <1322850850-18019-1-git-send-email-anderson.lizardo@openbossa.org>
From: Sheldon Demario <sheldon.demario@openbossa.org>
This provider adds support for timed, which is used on Harmattan for
managing time information.
---
Makefile.am | 2 +-
time/provider-timed.c | 141 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 142 insertions(+), 1 deletions(-)
create mode 100644 time/provider-timed.c
diff --git a/Makefile.am b/Makefile.am
index ac562b9..089d86f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -346,7 +346,7 @@ EXTRA_DIST += src/genbuiltin src/bluetooth.conf \
audio/audio.conf audio/telephony-dummy.c \
audio/telephony-maemo5.c audio/telephony-ofono.c \
audio/telephony-maemo6.c sap/sap-dummy.c sap/sap-u8500.c \
- time/provider-dummy.c \
+ time/provider-dummy.c time/provider-timed.c \
proximity/proximity.conf
if ALSA
diff --git a/time/provider-timed.c b/time/provider-timed.c
new file mode 100644
index 0000000..62774e1
--- /dev/null
+++ b/time/provider-timed.c
@@ -0,0 +1,141 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * Copyright (C) 2011 Nokia Corporation
+ * Copyright (C) 2011 Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib.h>
+#include <time.h>
+#include <errno.h>
+#include <bluetooth/uuid.h>
+#include <bluetooth/sdp.h>
+#include <dbus/dbus.h>
+#include <gdbus.h>
+
+#include "log.h"
+#include "server.h"
+#include "glib-helper.h"
+
+static guint watch = 0;
+static DBusConnection *connection = NULL;
+static gboolean source_online = FALSE;
+static uint8_t update_state = UPDATE_STATE_IDLE;
+static uint8_t update_result = UPDATE_RESULT_NOT_ATTEMPTED;
+
+uint8_t time_provider_control(int op)
+{
+ switch (op) {
+ case GET_REFERENCE_UPDATE:
+ /* Usually we should check for UPDATE_STATE_PENDING here, but
+ * on Harmattan reference time updates are passive (through
+ * cellular network). */
+
+ update_state = UPDATE_STATE_IDLE;
+ if (!source_online)
+ update_result = UPDATE_RESULT_NO_CONN;
+ else
+ update_result = UPDATE_RESULT_SUCCESSFUL;
+
+ break;
+ case CANCEL_REFERENCE_UPDATE:
+ update_state = UPDATE_STATE_IDLE;
+ update_result = UPDATE_RESULT_CANCELED;
+ break;
+ default:
+ DBG("Invalid control point value: 0x%02x", op);
+ }
+
+ return 0;
+}
+
+void time_provider_status(uint8_t *state, uint8_t *result)
+{
+ *state = update_state;
+ *result = update_result;
+}
+
+static gboolean settings_changed(DBusConnection *conn, DBusMessage *msg,
+ void *data)
+{
+ DBusMessageIter iter, res;
+
+ DBG("");
+
+ update_state = UPDATE_STATE_IDLE;
+
+ dbus_message_iter_init(msg, &iter);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRUCT) {
+ DBG("Unexpected signature");
+ update_result = UPDATE_RESULT_ERROR;
+
+ return TRUE;
+ }
+
+ dbus_message_iter_recurse(&iter, &res);
+ if (dbus_message_iter_get_arg_type(&res) != DBUS_TYPE_BOOLEAN) {
+ DBG("Unexpected signature");
+ update_result = UPDATE_RESULT_ERROR;
+
+ return TRUE;
+ }
+
+ dbus_message_iter_get_basic(&res, &source_online);
+ if (!source_online) {
+ DBG("No connection to reference time");
+ update_result = UPDATE_RESULT_NO_CONN;
+ } else
+ update_result = UPDATE_RESULT_SUCCESSFUL;
+
+ return TRUE;
+}
+
+int time_provider_init(void)
+{
+ connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+
+ watch = g_dbus_add_signal_watch(connection, "com.nokia.time",
+ "/com/nokia/time",
+ "com.nokia.time",
+ "settings_changed",
+ settings_changed,
+ NULL, NULL);
+
+ if (watch == 0) {
+ dbus_connection_unref(connection);
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+
+void time_provider_exit(void)
+{
+ g_dbus_remove_watch(connection, watch);
+ watch = 0;
+
+ dbus_connection_unref(connection);
+ connection = NULL;
+}
--
1.7.0.4
next prev parent reply other threads:[~2011-12-02 18:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-02 18:34 [PATCH RFC BlueZ 0/5] Time Profile (server) improvements Anderson Lizardo
2011-12-02 18:34 ` [PATCH RFC BlueZ 1/5] Time Profile: add Reference Time Update Service Anderson Lizardo
2011-12-02 18:34 ` [PATCH RFC BlueZ 2/5] Time Profile: implement generic "time provider" interface Anderson Lizardo
2011-12-02 18:34 ` Anderson Lizardo [this message]
2011-12-02 18:34 ` [PATCH RFC BlueZ 4/5] Add support for sending notifications for current time Anderson Lizardo
2011-12-02 18:34 ` [PATCH RFC BlueZ 5/5] Add testing API to dummy Time Server provider Anderson Lizardo
2012-02-01 22:48 ` [PATCH RFC BlueZ 0/5] Time Profile (server) improvements Arik Nemtsov
2012-02-01 23:12 ` Anderson Lizardo
2012-02-02 12:19 ` Arik Nemtsov
2012-02-02 13:07 ` Anderson Lizardo
2012-02-02 13:32 ` Arik Nemtsov
2012-02-02 14:06 ` Anderson Lizardo
2012-05-16 11:40 ` Arun K. Singh
2012-05-17 14:50 ` Anderson Lizardo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1322850850-18019-4-git-send-email-anderson.lizardo@openbossa.org \
--to=anderson.lizardo@openbossa.org \
--cc=linux-bluetooth@vger.kernel.org \
--cc=sheldon.demario@openbossa.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).