All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server)
@ 2011-09-26 19:13 Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 01/16] Phone Alert: add Phone Alert Service Anderson Lizardo
                   ` (16 more replies)
  0 siblings, 17 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

This RFC series contains our current work in progress for Phone Alert Status
GATT profile (server role). This profile was recently adopted and you can find
it on the Bluetooth SIG page:

https://www.bluetooth.org/Technical/Specifications/adopted.htm

We are sending these patches now for public review, and to discuss a few
implementation issues. A few notes about the implementation:

* Some events monitored by the profile require access to the session bus. Our
  approach was to introduce an Agent which listens on the session bus and sends
  events to BlueZ (which listens to system bus).

* The "Phone Agent" contains two D-Bus methods: SetSilentMode() and
  CancelSilentMode(). These methods map to the same functions found on the PAS
  profile. The implementation is platform specific, but on N9 (Harmattan) it
  asks the profile daemon to change to/from the "Silent" profile.

* The Alert Server exports three D-Bus methods: RegisterAgent(),
  NotifyRingerSetting(), NotifyAlertStatus(). These methods are called by the
  agent to notify platform specific events which cause either Ringer Setting or
  Alert Status (Ringer, Vibrator, Display) changes.

There are a number of know issues:

* The agent API is not stable yet. We are unsure if yet another agent is the
  best solution. Any ideas? (Remember: there is a requirement to read things
  from session bus).

* There is a call to NGF (N9 specific component) inside alert/server.c. This
  should be moved to the Maemo6/harmattan specific code inside BlueZ. Ideally,
  we should move anything platform-specific and shared between profiles (e.g.
  the "Stop Ringtone" call used by HFP which is now used by Phone Alert) to a
  common place in BlueZ.

Feedback is very welcome.

Regards,
--
Anderson Lizardo
Instituto Nokia de Tecnologia (INdT)
Manaus - Brazil


^ permalink raw reply	[flat|nested] 18+ messages in thread

* [PATCH RFC BlueZ 01/16] Phone Alert: add Phone Alert Service
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
@ 2011-09-26 19:13 ` Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 02/16] Phone Alert: add Ringer Control Point characteristic Anderson Lizardo
                   ` (15 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

---
 alert/server.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/alert/server.c b/alert/server.c
index d91b156..a4b301d 100644
--- a/alert/server.c
+++ b/alert/server.c
@@ -26,10 +26,29 @@
 #include <config.h>
 #endif
 
+#include <glib.h>
+#include <bluetooth/uuid.h>
+
+#include "att.h"
+#include "gattrib.h"
+#include "attrib-server.h"
+#include "gatt-service.h"
+#include "log.h"
 #include "server.h"
 
+#define PHONE_ALERT_STATUS_SVC_UUID		0x180E
+
+static void register_phone_alert_service(void)
+{
+	/* Phone Alert Status Service */
+	gatt_service_add(GATT_PRIM_SVC_UUID, PHONE_ALERT_STATUS_SVC_UUID,
+			GATT_OPT_INVALID);
+}
+
 int alert_server_init(void)
 {
+	register_phone_alert_service();
+
 	return 0;
 }
 
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC BlueZ 02/16] Phone Alert: add Ringer Control Point characteristic
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 01/16] Phone Alert: add Phone Alert Service Anderson Lizardo
@ 2011-09-26 19:13 ` Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 03/16] Phone Alert: add Ringer Setting characteristic Anderson Lizardo
                   ` (14 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

---
 alert/server.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/alert/server.c b/alert/server.c
index a4b301d..6d02adb 100644
--- a/alert/server.c
+++ b/alert/server.c
@@ -38,10 +38,24 @@
 
 #define PHONE_ALERT_STATUS_SVC_UUID		0x180E
 
+#define RINGER_CP_CHR_UUID		0x2A40
+
+static uint8_t control_point_write(struct attribute *a, gpointer user_data)
+{
+	DBG("a = %p", a);
+
+	return 0;
+}
+
 static void register_phone_alert_service(void)
 {
 	/* Phone Alert Status Service */
 	gatt_service_add(GATT_PRIM_SVC_UUID, PHONE_ALERT_STATUS_SVC_UUID,
+			/* Ringer Control Point characteristic */
+			GATT_OPT_CHR_UUID, RINGER_CP_CHR_UUID,
+			GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_WRITE,
+			GATT_OPT_CHR_VALUE_CB, ATTRIB_WRITE,
+			control_point_write,
 			GATT_OPT_INVALID);
 }
 
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC BlueZ 03/16] Phone Alert: add Ringer Setting characteristic
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 01/16] Phone Alert: add Phone Alert Service Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 02/16] Phone Alert: add Ringer Control Point characteristic Anderson Lizardo
@ 2011-09-26 19:13 ` Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 04/16] Phone Alert: implement org.bluez.PhoneAlert interface Anderson Lizardo
                   ` (13 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

---
 alert/server.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/alert/server.c b/alert/server.c
index 6d02adb..1135ca0 100644
--- a/alert/server.c
+++ b/alert/server.c
@@ -39,6 +39,7 @@
 #define PHONE_ALERT_STATUS_SVC_UUID		0x180E
 
 #define RINGER_CP_CHR_UUID		0x2A40
+#define RINGER_SETTING_CHR_UUID		0x2A41
 
 static uint8_t control_point_write(struct attribute *a, gpointer user_data)
 {
@@ -47,6 +48,13 @@ static uint8_t control_point_write(struct attribute *a, gpointer user_data)
 	return 0;
 }
 
+static uint8_t ringer_setting_read(struct attribute *a, gpointer user_data)
+{
+	DBG("a = %p", a);
+
+	return 0;
+}
+
 static void register_phone_alert_service(void)
 {
 	/* Phone Alert Status Service */
@@ -56,6 +64,12 @@ static void register_phone_alert_service(void)
 			GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_WRITE,
 			GATT_OPT_CHR_VALUE_CB, ATTRIB_WRITE,
 			control_point_write,
+			/* Ringer Setting characteristic */
+			GATT_OPT_CHR_UUID, RINGER_SETTING_CHR_UUID,
+			GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_READ |
+							ATT_CHAR_PROPER_NOTIFY,
+			GATT_OPT_CHR_VALUE_CB, ATTRIB_READ,
+			ringer_setting_read,
 			GATT_OPT_INVALID);
 }
 
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC BlueZ 04/16] Phone Alert: implement org.bluez.PhoneAlert interface
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
                   ` (2 preceding siblings ...)
  2011-09-26 19:13 ` [PATCH RFC BlueZ 03/16] Phone Alert: add Ringer Setting characteristic Anderson Lizardo
@ 2011-09-26 19:13 ` Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 05/16] Phone Alert: add agent operations to alert server Anderson Lizardo
                   ` (12 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

---
 alert/server.c |   75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 75 insertions(+), 0 deletions(-)

diff --git a/alert/server.c b/alert/server.c
index 1135ca0..66a5e42 100644
--- a/alert/server.c
+++ b/alert/server.c
@@ -27,9 +27,12 @@
 #endif
 
 #include <glib.h>
+#include <gdbus.h>
+#include <errno.h>
 #include <bluetooth/uuid.h>
 
 #include "att.h"
+#include "error.h"
 #include "gattrib.h"
 #include "attrib-server.h"
 #include "gatt-service.h"
@@ -41,6 +44,18 @@
 #define RINGER_CP_CHR_UUID		0x2A40
 #define RINGER_SETTING_CHR_UUID		0x2A41
 
+#define ALERT_INTERFACE "org.bluez.PhoneAlert"
+#define ALERT_PATH "/test/phonealert"
+
+struct agent {
+	char *name;
+	char *path;
+	guint listener_id;
+};
+
+static DBusConnection *connection = NULL;
+static struct agent agent;
+
 static uint8_t control_point_write(struct attribute *a, gpointer user_data)
 {
 	DBG("a = %p", a);
@@ -73,8 +88,66 @@ static void register_phone_alert_service(void)
 			GATT_OPT_INVALID);
 }
 
+static void agent_exited(DBusConnection *conn, void *user_data)
+{
+	DBG("Agent exiting ...");
+
+	g_free(agent.path);
+	g_free(agent.name);
+
+	agent.path = NULL;
+	agent.name = NULL;
+}
+
+static DBusMessage *register_agent(DBusConnection *conn, DBusMessage *msg,
+								void *data)
+{
+	const char *path, *name;
+
+	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+							DBUS_TYPE_INVALID))
+		return NULL;
+
+	if (agent.name != NULL)
+		return btd_error_already_exists(msg);
+
+	name = dbus_message_get_sender(msg);
+
+	DBG("Registering agent: path = %s, name = %s", path, name);
+
+	agent.path = strdup(path);
+	agent.name = strdup(name);
+
+	agent.listener_id = g_dbus_add_disconnect_watch(connection, name,
+							agent_exited, NULL,
+									NULL);
+
+	return dbus_message_new_method_return(msg);
+}
+
+static GDBusMethodTable alert_methods[] = {
+	{ "RegisterAgent",	"o",	"",	register_agent },
+	{ }
+};
+
 int alert_server_init(void)
 {
+	connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+	if (connection == NULL)
+		return -EIO;
+
+	if (!g_dbus_register_interface(connection, ALERT_PATH, ALERT_INTERFACE,
+				alert_methods, NULL, NULL,
+				NULL, NULL) == TRUE) {
+		error("D-Bus failed to register %s interface", ALERT_INTERFACE);
+		dbus_connection_unref(connection);
+		connection = NULL;
+
+		return -1;
+	}
+
+	DBG("Registered interface %s on path %s", ALERT_INTERFACE, ALERT_PATH);
+
 	register_phone_alert_service();
 
 	return 0;
@@ -82,4 +155,6 @@ int alert_server_init(void)
 
 void alert_server_exit(void)
 {
+	dbus_connection_unref(connection);
+	connection = NULL;
 }
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC BlueZ 05/16] Phone Alert: add agent operations to alert server
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
                   ` (3 preceding siblings ...)
  2011-09-26 19:13 ` [PATCH RFC BlueZ 04/16] Phone Alert: implement org.bluez.PhoneAlert interface Anderson Lizardo
@ 2011-09-26 19:13 ` Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 06/16] Phone Alert: add GetSilentMode() call in " Anderson Lizardo
                   ` (11 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

The operations "Set Silent Mode", "Cancel Silent Mode" and "Mute Once"
can be called via D-Bus. The agent will implement the communication with
the device.
---
 alert/server.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/alert/server.c b/alert/server.c
index 66a5e42..8926854 100644
--- a/alert/server.c
+++ b/alert/server.c
@@ -44,9 +44,16 @@
 #define RINGER_CP_CHR_UUID		0x2A40
 #define RINGER_SETTING_CHR_UUID		0x2A41
 
+#define AGENT_INTERFACE "org.bluez.PhoneAgent"
 #define ALERT_INTERFACE "org.bluez.PhoneAlert"
 #define ALERT_PATH "/test/phonealert"
 
+enum {
+	SET_SILENT_MODE = 1,
+	MUTE_ONCE,
+	CANCEL_SILENT_MODE,
+};
+
 struct agent {
 	char *name;
 	char *path;
@@ -56,10 +63,47 @@ struct agent {
 static DBusConnection *connection = NULL;
 static struct agent agent;
 
+static void agent_operation(const char *operation)
+{
+	DBusMessage *message;
+
+	if (!agent.name) {
+		error("Agent not registered");
+		return;
+	}
+
+	DBG("%s: agent %s, %s", operation, agent.name, agent.path);
+
+	message = dbus_message_new_method_call(agent.name, agent.path,
+						AGENT_INTERFACE, operation);
+
+	if (message == NULL) {
+		error("Couldn't allocate D-Bus message");
+		return;
+	}
+
+	if (!g_dbus_send_message(connection, message))
+		error("D-Bus error: agent_operation %s", operation);
+}
+
 static uint8_t control_point_write(struct attribute *a, gpointer user_data)
 {
 	DBG("a = %p", a);
 
+	switch (a->data[0]) {
+	case SET_SILENT_MODE:
+		agent_operation("SetSilentMode");
+		break;
+	case MUTE_ONCE:
+		agent_operation("MuteOnce");
+		break;
+	case CANCEL_SILENT_MODE:
+		agent_operation("CancelSilentMode");
+		break;
+	default:
+		DBG("Unknown mode");
+	}
+
 	return 0;
 }
 
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC BlueZ 06/16] Phone Alert: add GetSilentMode() call in alert server
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
                   ` (4 preceding siblings ...)
  2011-09-26 19:13 ` [PATCH RFC BlueZ 05/16] Phone Alert: add agent operations to alert server Anderson Lizardo
@ 2011-09-26 19:13 ` Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 07/16] Phone Alert: implement agent for N9 Anderson Lizardo
                   ` (10 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

The new method GetSilentMode() is used to initiate the current value of
Ringer Setting. This value will be used when reading operation is
required and to update attribute server.
---
 alert/server.c |   82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 81 insertions(+), 1 deletions(-)

diff --git a/alert/server.c b/alert/server.c
index 8926854..6b39bd4 100644
--- a/alert/server.c
+++ b/alert/server.c
@@ -54,6 +54,11 @@ enum {
 	CANCEL_SILENT_MODE,
 };
 
+enum {
+	RINGER_SILENT = 0,
+	RINGER_NORMAL = 1,
+};
+
 struct agent {
 	char *name;
 	char *path;
@@ -61,6 +66,7 @@ struct agent {
 };
 
 static DBusConnection *connection = NULL;
+static uint8_t ringer_setting = 0xff;
 static struct agent agent;
 
 static void agent_operation(const char *operation)
@@ -107,9 +113,83 @@ static uint8_t control_point_write(struct attribute *a, gpointer user_data)
 	return 0;
 }
 
+static void get_silent_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusError derr;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	const char *setting = NULL;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&derr);
+	if (dbus_set_error_from_message(&derr, reply)) {
+		error("D-Bus replied with error: %s, %s", derr.name,
+								derr.message);
+		dbus_error_free(&derr);
+		goto done;
+	}
+
+	dbus_message_iter_init(reply, &iter);
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) {
+		error("Unexpected signature for reply");
+		goto done;
+	}
+
+	dbus_message_iter_get_basic(&iter, &setting);
+
+	DBG("Ringer Setting: %s", setting);
+
+	if (g_str_equal(setting, "Silent"))
+		ringer_setting = RINGER_SILENT;
+	else
+		ringer_setting = RINGER_NORMAL;
+
+done:
+	dbus_message_unref(reply);
+	dbus_pending_call_unref(call);
+}
+
+static void get_silent_mode(DBusConnection *conn, void *user_data)
+{
+	DBusMessage *msg;
+	DBusPendingCall *call;
+
+	if (!agent.name) {
+		error("Agent not registered");
+		return;
+	}
+
+	DBG("Get Silent Mode: agent %s, %s", agent.name, agent.path);
+
+	msg = dbus_message_new_method_call(agent.name, agent.path,
+					AGENT_INTERFACE, "GetSilentMode");
+	if (msg == NULL) {
+		error("Unable to allocate new D-Bus message");
+		return;
+	}
+
+	if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
+		error("Failed to send D-Bus message");
+		return;
+	}
+
+	dbus_pending_call_set_notify(call, get_silent_reply, NULL, NULL);
+}
+
 static uint8_t ringer_setting_read(struct attribute *a, gpointer user_data)
 {
-	DBG("a = %p", a);
+	if (ringer_setting == 0xff) {
+		get_silent_mode(connection, NULL);
+		return ATT_ECODE_IO;
+	}
+
+	DBG("a = %p, setting = %s", a,
+			ringer_setting == RINGER_SILENT ? "Silent": "Normal");
+
+	if (a->data == NULL || a->data[0] != ringer_setting)
+		attrib_db_update(a->handle, NULL, &ringer_setting,
+						sizeof(ringer_setting), NULL);
 
 	return 0;
 }
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC BlueZ 07/16] Phone Alert: implement agent for N9
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
                   ` (5 preceding siblings ...)
  2011-09-26 19:13 ` [PATCH RFC BlueZ 06/16] Phone Alert: add GetSilentMode() call in " Anderson Lizardo
@ 2011-09-26 19:13 ` Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 08/16] Phone Alert: implement NotifyRingerSetting() method Anderson Lizardo
                   ` (9 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo

---
 test/phone-agent.py |  150 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 150 insertions(+), 0 deletions(-)
 create mode 100755 test/phone-agent.py

diff --git a/test/phone-agent.py b/test/phone-agent.py
new file mode 100755
index 0000000..2d9cf2d
--- /dev/null
+++ b/test/phone-agent.py
@@ -0,0 +1,150 @@
+#!/usr/bin/python
+import sys
+import dbus
+import dbus.service
+import dbus.mainloop.glib
+import gobject
+
+StateIncoming = 0
+StateEnded = 6
+
+on_call = False
+saved_ringer_setting = None
+ringer_setting = None
+silent_mode = False
+
+def set_ringer(value):
+    global ringer_setting
+    ringer_setting = value
+    profiled.set_value("", "ringing.alert.type", value, dbus_interface="com.nokia.profiled")
+
+def get_ringer():
+    return profiled.get_value("", "ringing.alert.type", dbus_interface="com.nokia.profiled")
+
+def silence_ringer():
+    print "silence_ringer()"
+    global saved_ringer_setting, ringer_setting
+    saved_ringer_setting = ringer_setting
+    set_ringer("Silent")
+
+def restore_ringer():
+    global saved_ringer_setting
+    if saved_ringer_setting:
+        print "Restoring ringer setting to \"%s\"" % saved_ringer_setting
+        set_ringer(saved_ringer_setting)
+        saved_ringer_setting = None
+
+def call_state_changed(*args, **kwargs):
+    global on_call
+
+    for item in args[0]:
+        if not isinstance(item, dbus.Dictionary):
+            continue
+        if item.get("state") is None:
+            continue
+        if item["state"] == StateIncoming:
+            on_call = True
+        elif item["state"] == StateEnded:
+            on_call = False
+            if not silent_mode:
+                restore_ringer()
+
+def profile_changed(*args, **kwargs):
+    global ringer_setting
+    print "profile_changed()"
+    for item in args[3]:
+        if item[0] != "ringing.alert.type":
+            continue
+        print "Ringer: %s" % item[1]
+        if item[1] != ringer_setting or silent_mode:
+            ringer_setting = item[1]
+            print "NotifyRingerSetting(%s)" % ringer_setting
+            phone.NotifyRingerSetting(ringer_setting)
+            if silent_mode:
+                # User has changed profile, update saved setting
+                saved_ringer_setting = ringer_setting
+
+class PhoneAgent(dbus.service.Object):
+    @dbus.service.method("org.bluez.PhoneAgent",
+            in_signature="", out_signature="")
+    def MuteOnce(self):
+        print "MuteOnce()"
+
+        global silent_mode
+        if silent_mode:
+            print "In Silent mode"
+            return
+
+        global on_call
+        if not on_call:
+            print "No active call"
+            return
+
+        global ringer_setting
+        if ringer_setting == "Silent":
+            print "Ringer already silent"
+            return
+
+        silence_ringer()
+
+    @dbus.service.method("org.bluez.PhoneAgent",
+            in_signature="", out_signature="")
+    def SetSilentMode(self):
+        print "SetSilentMode()"
+
+        global silent_mode
+        if silent_mode:
+            return
+
+        silence_ringer()
+        silent_mode = True
+
+    @dbus.service.method("org.bluez.PhoneAgent",
+            in_signature="", out_signature="")
+    def CancelSilentMode(self):
+        print "CancelSilentMode()"
+
+        global silent_mode
+        if not silent_mode:
+            return
+
+        silent_mode = False
+        restore_ringer()
+
+    @dbus.service.method("org.bluez.PhoneAgent",
+            in_signature="", out_signature="s")
+    def GetSilentMode(self):
+        print "GetSilentMode()"
+
+        global ringer_setting
+        return ringer_setting
+
+if __name__ == "__main__":
+    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+
+    system_bus = dbus.SystemBus()
+    session_bus = dbus.SessionBus()
+    agent_path = "/test/phoneagent"
+
+    # Monitor call incoming/ended events
+    contextkit = session_bus.get_object("com.nokia.CallUi.Context",
+            "/com/nokia/CallUi/ActiveCall")
+    contextkit.connect_to_signal("ValueChanged", call_state_changed,
+            dbus_interface="org.maemo.contextkit.Property")
+
+    profiled = session_bus.get_object("com.nokia.profiled",
+            "/com/nokia/profiled")
+    # Monitor profile changes
+    profiled.connect_to_signal("profile_changed", profile_changed,
+            dbus_interface="com.nokia.profiled")
+    ringer_setting = get_ringer()
+
+    phone = dbus.Interface(system_bus.get_object("org.bluez",
+            "/test/phonealert"), "org.bluez.PhoneAlert")
+
+    agent = PhoneAgent(system_bus, agent_path)
+    phone.RegisterAgent(agent_path)
+    print "destination:", system_bus.get_unique_name()
+
+    mainloop = gobject.MainLoop()
+    mainloop.run()
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC BlueZ 08/16] Phone Alert: implement NotifyRingerSetting() method
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
                   ` (6 preceding siblings ...)
  2011-09-26 19:13 ` [PATCH RFC BlueZ 07/16] Phone Alert: implement agent for N9 Anderson Lizardo
@ 2011-09-26 19:13 ` Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 09/16] Phone Alert: add Alert Status characteristic Anderson Lizardo
                   ` (8 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

Update Ringer Setting characteristic in alert server. This new value
will be notifiable if it was configured.
---
 alert/server.c |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)

diff --git a/alert/server.c b/alert/server.c
index 6b39bd4..d5b1e7b 100644
--- a/alert/server.c
+++ b/alert/server.c
@@ -67,6 +67,7 @@ struct agent {
 
 static DBusConnection *connection = NULL;
 static uint8_t ringer_setting = 0xff;
+static uint16_t handle_ringer_setting = 0x0000;
 static struct agent agent;
 
 static void agent_operation(const char *operation)
@@ -209,6 +210,7 @@ static void register_phone_alert_service(void)
 							ATT_CHAR_PROPER_NOTIFY,
 			GATT_OPT_CHR_VALUE_CB, ATTRIB_READ,
 			ringer_setting_read,
+			GATT_OPT_CHR_VALUE_GET_HANDLE, &handle_ringer_setting,
 			GATT_OPT_INVALID);
 }
 
@@ -249,8 +251,32 @@ static DBusMessage *register_agent(DBusConnection *conn, DBusMessage *msg,
 	return dbus_message_new_method_return(msg);
 }
 
+static DBusMessage *notify_ringer_setting(DBusConnection *conn,
+						DBusMessage *msg, void *data)
+{
+	const char *setting;
+
+	if (agent.name == NULL)
+		return NULL;
+
+	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &setting,
+							DBUS_TYPE_INVALID))
+		return NULL;
+
+	if (g_str_equal(setting, "Silent"))
+		ringer_setting = RINGER_SILENT;
+	else
+		ringer_setting = RINGER_NORMAL;
+
+	attrib_db_update(handle_ringer_setting, NULL, &ringer_setting,
+						sizeof(ringer_setting), NULL);
+
+	return dbus_message_new_method_return(msg);
+}
+
 static GDBusMethodTable alert_methods[] = {
-	{ "RegisterAgent",	"o",	"",	register_agent },
+	{ "RegisterAgent",	"o",	"",	register_agent		},
+	{ "NotifyRingerSetting","s",	"",	notify_ringer_setting	},
 	{ }
 };
 
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC BlueZ 09/16] Phone Alert: add Alert Status characteristic
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
                   ` (7 preceding siblings ...)
  2011-09-26 19:13 ` [PATCH RFC BlueZ 08/16] Phone Alert: implement NotifyRingerSetting() method Anderson Lizardo
@ 2011-09-26 19:13 ` Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 10/16] Phone Alert: add GetAlertStatus() call in alert server Anderson Lizardo
                   ` (7 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

---
 alert/server.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/alert/server.c b/alert/server.c
index d5b1e7b..2466f8b 100644
--- a/alert/server.c
+++ b/alert/server.c
@@ -41,6 +41,7 @@
 
 #define PHONE_ALERT_STATUS_SVC_UUID		0x180E
 
+#define ALERT_STATUS_CHR_UUID		0x2A3F
 #define RINGER_CP_CHR_UUID		0x2A40
 #define RINGER_SETTING_CHR_UUID		0x2A41
 
@@ -178,6 +179,13 @@ static void get_silent_mode(DBusConnection *conn, void *user_data)
 	dbus_pending_call_set_notify(call, get_silent_reply, NULL, NULL);
 }
 
+static uint8_t alert_status_read(struct attribute *a, gpointer user_data)
+{
+	DBG("a = %p", a);
+
+	return 0;
+}
+
 static uint8_t ringer_setting_read(struct attribute *a, gpointer user_data)
 {
 	if (ringer_setting == 0xff) {
@@ -199,6 +207,12 @@ static void register_phone_alert_service(void)
 {
 	/* Phone Alert Status Service */
 	gatt_service_add(GATT_PRIM_SVC_UUID, PHONE_ALERT_STATUS_SVC_UUID,
+			/* Alert Status characteristic */
+			GATT_OPT_CHR_UUID, ALERT_STATUS_CHR_UUID,
+			GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_READ |
+							ATT_CHAR_PROPER_NOTIFY,
+			GATT_OPT_CHR_VALUE_CB, ATTRIB_READ,
+			alert_status_read,
 			/* Ringer Control Point characteristic */
 			GATT_OPT_CHR_UUID, RINGER_CP_CHR_UUID,
 			GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_WRITE,
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC BlueZ 10/16] Phone Alert: add GetAlertStatus() call in alert server
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
                   ` (8 preceding siblings ...)
  2011-09-26 19:13 ` [PATCH RFC BlueZ 09/16] Phone Alert: add Alert Status characteristic Anderson Lizardo
@ 2011-09-26 19:13 ` Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 11/16] Phone Alert: add method for reading Alert Status Anderson Lizardo
                   ` (6 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

The new method GetAlertStatus() is used to initiate the current value of
Alert Status characteristic. This value will be used when reading
operation is required and to update attribute server.

NOTE: Only Ringer State field from Alert Status characteristic is
updated.
---
 alert/server.c |   81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 80 insertions(+), 1 deletions(-)

diff --git a/alert/server.c b/alert/server.c
index 2466f8b..cc2cd53 100644
--- a/alert/server.c
+++ b/alert/server.c
@@ -50,6 +50,12 @@
 #define ALERT_PATH "/test/phonealert"
 
 enum {
+	ALERT_RINGER_STATE = 1 << 0,
+	ALERT_VIBRATOR_STATE = 1 << 1,
+	ALERT_DISPLAY_STATE = 1 << 2,
+};
+
+enum {
 	SET_SILENT_MODE = 1,
 	MUTE_ONCE,
 	CANCEL_SILENT_MODE,
@@ -68,6 +74,7 @@ struct agent {
 
 static DBusConnection *connection = NULL;
 static uint8_t ringer_setting = 0xff;
+static uint8_t alert_status = 0xff;
 static uint16_t handle_ringer_setting = 0x0000;
 static struct agent agent;
 
@@ -115,6 +122,68 @@ static uint8_t control_point_write(struct attribute *a, gpointer user_data)
 	return 0;
 }
 
+static void get_alert_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusError derr;
+	DBusMessage *reply;
+	DBusMessageIter iter;
+	uint8_t state;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&derr);
+	if (dbus_set_error_from_message(&derr, reply)) {
+		error("D-Bus replied with error: %s, %s", derr.name,
+								derr.message);
+		dbus_error_free(&derr);
+		goto done;
+	}
+
+	dbus_message_iter_init(reply, &iter);
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BYTE) {
+		error("Unexpected signature for reply");
+		goto done;
+	}
+
+	dbus_message_iter_get_basic(&iter, &state);
+
+	DBG("Ringer State: %s",
+			state & ALERT_RINGER_STATE ? "Active": "Not Active");
+
+	alert_status = state;
+
+done:
+	dbus_message_unref(reply);
+	dbus_pending_call_unref(call);
+}
+
+static void get_alert_status(DBusConnection *conn, void *user_data)
+{
+	DBusMessage *msg;
+	DBusPendingCall *call;
+
+	if (!agent.name) {
+		error("Agent not registered");
+		return;
+	}
+
+	DBG("Get Alert Status: agent %s, %s", agent.name, agent.path);
+
+	msg = dbus_message_new_method_call(agent.name, agent.path,
+					AGENT_INTERFACE, "GetAlertStatus");
+	if (msg == NULL) {
+		error("Unable to allocate new D-Bus message");
+		return;
+	}
+
+	if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
+		error("Failed to send D-Bus message");
+		return;
+	}
+
+	dbus_pending_call_set_notify(call, get_alert_reply, NULL, NULL);
+}
+
 static void get_silent_reply(DBusPendingCall *call, void *user_data)
 {
 	DBusError derr;
@@ -181,7 +250,17 @@ static void get_silent_mode(DBusConnection *conn, void *user_data)
 
 static uint8_t alert_status_read(struct attribute *a, gpointer user_data)
 {
-	DBG("a = %p", a);
+	if (alert_status == 0xff) {
+		get_alert_status(connection, NULL);
+		return ATT_ECODE_IO;
+	}
+
+	DBG("a = %p, state = %s", a,
+		alert_status & ALERT_RINGER_STATE ? "Active": "Not Active");
+
+	if (a->data == NULL || a->data[0] != alert_status)
+		attrib_db_update(a->handle, NULL, &alert_status,
+						sizeof(alert_status), NULL);
 
 	return 0;
 }
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC BlueZ 11/16] Phone Alert: add method for reading Alert Status
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
                   ` (9 preceding siblings ...)
  2011-09-26 19:13 ` [PATCH RFC BlueZ 10/16] Phone Alert: add GetAlertStatus() call in alert server Anderson Lizardo
@ 2011-09-26 19:13 ` Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 12/16] Phone Alert: listen to Ringer State changes Anderson Lizardo
                   ` (5 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

---
 test/phone-agent.py |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/test/phone-agent.py b/test/phone-agent.py
index 2d9cf2d..927fdb1 100755
--- a/test/phone-agent.py
+++ b/test/phone-agent.py
@@ -8,10 +8,13 @@ import gobject
 StateIncoming = 0
 StateEnded = 6
 
+ALERT_RINGER_STATE = 1 << 0
+
 on_call = False
 saved_ringer_setting = None
 ringer_setting = None
 silent_mode = False
+alert_status = 0x00
 
 def set_ringer(value):
     global ringer_setting
@@ -21,6 +24,14 @@ def set_ringer(value):
 def get_ringer():
     return profiled.get_value("", "ringing.alert.type", dbus_interface="com.nokia.profiled")
 
+def set_alert_status():
+    global ringer_setting, alert_status, on_call
+
+    if on_call and ringer_setting != "Silent":
+        alert_status |= ALERT_RINGER_STATE
+    else:
+        alert_status &= ~ALERT_RINGER_STATE
+
 def silence_ringer():
     print "silence_ringer()"
     global saved_ringer_setting, ringer_setting
@@ -119,6 +130,15 @@ class PhoneAgent(dbus.service.Object):
         global ringer_setting
         return ringer_setting
 
+    @dbus.service.method("org.bluez.PhoneAgent",
+            in_signature="", out_signature="y")
+    def GetAlertStatus(self):
+        print "GetAlertStatus()"
+
+        global alert_status
+        return alert_status
+
+
 if __name__ == "__main__":
     dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 
@@ -139,6 +159,8 @@ if __name__ == "__main__":
             dbus_interface="com.nokia.profiled")
     ringer_setting = get_ringer()
 
+    set_alert_status()
+
     phone = dbus.Interface(system_bus.get_object("org.bluez",
             "/test/phonealert"), "org.bluez.PhoneAlert")
 
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC BlueZ 12/16] Phone Alert: listen to Ringer State changes
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
                   ` (10 preceding siblings ...)
  2011-09-26 19:13 ` [PATCH RFC BlueZ 11/16] Phone Alert: add method for reading Alert Status Anderson Lizardo
@ 2011-09-26 19:13 ` Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 13/16] Phone Alert: implement NotifyAlertStatus() method Anderson Lizardo
                   ` (4 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

Incoming and answered calls are monitored to update Ringer State field.
The bit field is set to 1 when on a incoming call and it is set to 0
when the call is answered.
---
 test/phone-agent.py |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/test/phone-agent.py b/test/phone-agent.py
index 927fdb1..b3b19a8 100755
--- a/test/phone-agent.py
+++ b/test/phone-agent.py
@@ -6,6 +6,7 @@ import dbus.mainloop.glib
 import gobject
 
 StateIncoming = 0
+StateActive = 3
 StateEnded = 6
 
 ALERT_RINGER_STATE = 1 << 0
@@ -55,8 +56,10 @@ def call_state_changed(*args, **kwargs):
             continue
         if item["state"] == StateIncoming:
             on_call = True
-        elif item["state"] == StateEnded:
+            set_alert_status()
+        elif item["state"] in [StateActive, StateEnded]:
             on_call = False
+            set_alert_status()
             if not silent_mode:
                 restore_ringer()
 
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC BlueZ 13/16] Phone Alert: implement NotifyAlertStatus() method
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
                   ` (11 preceding siblings ...)
  2011-09-26 19:13 ` [PATCH RFC BlueZ 12/16] Phone Alert: listen to Ringer State changes Anderson Lizardo
@ 2011-09-26 19:13 ` Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 14/16] Phone Alert: Mute once using new NGFD API Anderson Lizardo
                   ` (3 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

Update Alert Status characteristic in alert server. New value will be
notifiable if configured.
---
 alert/server.c      |   23 +++++++++++++++++++++++
 test/phone-agent.py |    5 +++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/alert/server.c b/alert/server.c
index cc2cd53..fb088a5 100644
--- a/alert/server.c
+++ b/alert/server.c
@@ -76,6 +76,7 @@ static DBusConnection *connection = NULL;
 static uint8_t ringer_setting = 0xff;
 static uint8_t alert_status = 0xff;
 static uint16_t handle_ringer_setting = 0x0000;
+static uint16_t handle_alert_status = 0x0000;
 static struct agent agent;
 
 static void agent_operation(const char *operation)
@@ -292,6 +293,7 @@ static void register_phone_alert_service(void)
 							ATT_CHAR_PROPER_NOTIFY,
 			GATT_OPT_CHR_VALUE_CB, ATTRIB_READ,
 			alert_status_read,
+			GATT_OPT_CHR_VALUE_GET_HANDLE, &handle_alert_status,
 			/* Ringer Control Point characteristic */
 			GATT_OPT_CHR_UUID, RINGER_CP_CHR_UUID,
 			GATT_OPT_CHR_PROPS, ATT_CHAR_PROPER_WRITE,
@@ -367,9 +369,30 @@ static DBusMessage *notify_ringer_setting(DBusConnection *conn,
 	return dbus_message_new_method_return(msg);
 }
 
+static DBusMessage *notify_alert_status(DBusConnection *conn,
+						DBusMessage *msg, void *data)
+{
+	uint8_t status;
+
+	if (agent.name == NULL)
+		return NULL;
+
+	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_BYTE, &status,
+							DBUS_TYPE_INVALID))
+		return NULL;
+
+	alert_status = status;
+
+	attrib_db_update(handle_alert_status, NULL, &alert_status,
+						sizeof(alert_status), NULL);
+
+	return dbus_message_new_method_return(msg);
+}
+
 static GDBusMethodTable alert_methods[] = {
 	{ "RegisterAgent",	"o",	"",	register_agent		},
 	{ "NotifyRingerSetting","s",	"",	notify_ringer_setting	},
+	{ "NotifyAlertStatus","y",	"",	notify_alert_status	},
 	{ }
 };
 
diff --git a/test/phone-agent.py b/test/phone-agent.py
index b3b19a8..04a742b 100755
--- a/test/phone-agent.py
+++ b/test/phone-agent.py
@@ -28,11 +28,16 @@ def get_ringer():
 def set_alert_status():
     global ringer_setting, alert_status, on_call
 
+    old_alert_status = alert_status
     if on_call and ringer_setting != "Silent":
         alert_status |= ALERT_RINGER_STATE
     else:
         alert_status &= ~ALERT_RINGER_STATE
 
+    if old_alert_status != alert_status:
+        print "NotifyAlertStatus(%02x)" % alert_status
+        phone.NotifyAlertStatus(dbus.Byte(alert_status))
+
 def silence_ringer():
     print "silence_ringer()"
     global saved_ringer_setting, ringer_setting
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC BlueZ 14/16] Phone Alert: Mute once using new NGFD API
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
                   ` (12 preceding siblings ...)
  2011-09-26 19:13 ` [PATCH RFC BlueZ 13/16] Phone Alert: implement NotifyAlertStatus() method Anderson Lizardo
@ 2011-09-26 19:13 ` Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 15/16] Phone Alert: Remove MuteOnce operation from phone-agent Anderson Lizardo
                   ` (2 subsequent siblings)
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Briglia

From: Anderson Briglia <anderson.briglia@openbossa.org>

NGFD API has changed and now we have a dbus method to mute the ringer.
---
 alert/server.c |   22 +++++++++++++++++++++-
 1 files changed, 21 insertions(+), 1 deletions(-)

diff --git a/alert/server.c b/alert/server.c
index fb088a5..77540a7 100644
--- a/alert/server.c
+++ b/alert/server.c
@@ -49,6 +49,11 @@
 #define ALERT_INTERFACE "org.bluez.PhoneAlert"
 #define ALERT_PATH "/test/phonealert"
 
+/* OHM plugin D-Bus definitions */
+#define OHM_BUS_NAME		"com.nokia.NonGraphicFeedback1"
+#define OHM_INTERFACE		"com.nokia.NonGraphicFeedback1"
+#define OHM_PATH		"/com/nokia/NonGraphicFeedback1"
+
 enum {
 	ALERT_RINGER_STATE = 1 << 0,
 	ALERT_VIBRATOR_STATE = 1 << 1,
@@ -102,6 +107,21 @@ static void agent_operation(const char *operation)
 		error("D-Bus error: agent_operation %s", operation);
 }
 
+static void stop_ringtone(void)
+{
+	DBusMessage *message;
+
+	message = dbus_message_new_method_call(OHM_BUS_NAME, OHM_PATH,
+					OHM_INTERFACE, "StopRingtone");
+	if (message == NULL) {
+		error("Couldn't allocate D-Bus message");
+		return;
+	}
+
+	if (!g_dbus_send_message(connection, message))
+		error("Failed to send D-Bus message");
+}
+
 static uint8_t control_point_write(struct attribute *a, gpointer user_data)
 {
 	DBG("a = %p", a);
@@ -111,7 +131,7 @@ static uint8_t control_point_write(struct attribute *a, gpointer user_data)
 		agent_operation("SetSilentMode");
 		break;
 	case MUTE_ONCE:
-		agent_operation("MuteOnce");
+		stop_ringtone();
 		break;
 	case CANCEL_SILENT_MODE:
 		agent_operation("CancelSilentMode");
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC BlueZ 15/16] Phone Alert: Remove MuteOnce operation from phone-agent
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
                   ` (13 preceding siblings ...)
  2011-09-26 19:13 ` [PATCH RFC BlueZ 14/16] Phone Alert: Mute once using new NGFD API Anderson Lizardo
@ 2011-09-26 19:13 ` Anderson Lizardo
  2011-09-26 19:13 ` [PATCH RFC BlueZ 16/16] Phone Alert: agent API changes Anderson Lizardo
  2011-09-26 20:12 ` [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Briglia

From: Anderson Briglia <anderson.briglia@openbossa.org>

---
 test/phone-agent.py |   22 ----------------------
 1 files changed, 0 insertions(+), 22 deletions(-)

diff --git a/test/phone-agent.py b/test/phone-agent.py
index 04a742b..372f832 100755
--- a/test/phone-agent.py
+++ b/test/phone-agent.py
@@ -86,28 +86,6 @@ def profile_changed(*args, **kwargs):
 class PhoneAgent(dbus.service.Object):
     @dbus.service.method("org.bluez.PhoneAgent",
             in_signature="", out_signature="")
-    def MuteOnce(self):
-        print "MuteOnce()"
-
-        global silent_mode
-        if silent_mode:
-            print "In Silent mode"
-            return
-
-        global on_call
-        if not on_call:
-            print "No active call"
-            return
-
-        global ringer_setting
-        if ringer_setting == "Silent":
-            print "Ringer already silent"
-            return
-
-        silence_ringer()
-
-    @dbus.service.method("org.bluez.PhoneAgent",
-            in_signature="", out_signature="")
     def SetSilentMode(self):
         print "SetSilentMode()"
 
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* [PATCH RFC BlueZ 16/16] Phone Alert: agent API changes
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
                   ` (14 preceding siblings ...)
  2011-09-26 19:13 ` [PATCH RFC BlueZ 15/16] Phone Alert: Remove MuteOnce operation from phone-agent Anderson Lizardo
@ 2011-09-26 19:13 ` Anderson Lizardo
  2011-09-26 20:12 ` [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 19:13 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Anderson Lizardo

* Remove GetSilentMode() and GetAlertStatus() functions
* Now initial Ringer Setting and Alert Status values are passed as
  arguments for RegisterAgent()
* Register Phone Alert Status Service only when agent is registered.
---
 alert/server.c      |  161 +++++++--------------------------------------------
 test/phone-agent.py |   19 +------
 2 files changed, 22 insertions(+), 158 deletions(-)

diff --git a/alert/server.c b/alert/server.c
index 77540a7..9fa0de6 100644
--- a/alert/server.c
+++ b/alert/server.c
@@ -83,6 +83,7 @@ static uint8_t alert_status = 0xff;
 static uint16_t handle_ringer_setting = 0x0000;
 static uint16_t handle_alert_status = 0x0000;
 static struct agent agent;
+static gboolean service_registered = FALSE;
 
 static void agent_operation(const char *operation)
 {
@@ -143,139 +144,8 @@ static uint8_t control_point_write(struct attribute *a, gpointer user_data)
 	return 0;
 }
 
-static void get_alert_reply(DBusPendingCall *call, void *user_data)
-{
-	DBusError derr;
-	DBusMessage *reply;
-	DBusMessageIter iter;
-	uint8_t state;
-
-	reply = dbus_pending_call_steal_reply(call);
-
-	dbus_error_init(&derr);
-	if (dbus_set_error_from_message(&derr, reply)) {
-		error("D-Bus replied with error: %s, %s", derr.name,
-								derr.message);
-		dbus_error_free(&derr);
-		goto done;
-	}
-
-	dbus_message_iter_init(reply, &iter);
-	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_BYTE) {
-		error("Unexpected signature for reply");
-		goto done;
-	}
-
-	dbus_message_iter_get_basic(&iter, &state);
-
-	DBG("Ringer State: %s",
-			state & ALERT_RINGER_STATE ? "Active": "Not Active");
-
-	alert_status = state;
-
-done:
-	dbus_message_unref(reply);
-	dbus_pending_call_unref(call);
-}
-
-static void get_alert_status(DBusConnection *conn, void *user_data)
-{
-	DBusMessage *msg;
-	DBusPendingCall *call;
-
-	if (!agent.name) {
-		error("Agent not registered");
-		return;
-	}
-
-	DBG("Get Alert Status: agent %s, %s", agent.name, agent.path);
-
-	msg = dbus_message_new_method_call(agent.name, agent.path,
-					AGENT_INTERFACE, "GetAlertStatus");
-	if (msg == NULL) {
-		error("Unable to allocate new D-Bus message");
-		return;
-	}
-
-	if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
-		error("Failed to send D-Bus message");
-		return;
-	}
-
-	dbus_pending_call_set_notify(call, get_alert_reply, NULL, NULL);
-}
-
-static void get_silent_reply(DBusPendingCall *call, void *user_data)
-{
-	DBusError derr;
-	DBusMessage *reply;
-	DBusMessageIter iter;
-	const char *setting = NULL;
-
-	reply = dbus_pending_call_steal_reply(call);
-
-	dbus_error_init(&derr);
-	if (dbus_set_error_from_message(&derr, reply)) {
-		error("D-Bus replied with error: %s, %s", derr.name,
-								derr.message);
-		dbus_error_free(&derr);
-		goto done;
-	}
-
-	dbus_message_iter_init(reply, &iter);
-	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) {
-		error("Unexpected signature for reply");
-		goto done;
-	}
-
-	dbus_message_iter_get_basic(&iter, &setting);
-
-	DBG("Ringer Setting: %s", setting);
-
-	if (g_str_equal(setting, "Silent"))
-		ringer_setting = RINGER_SILENT;
-	else
-		ringer_setting = RINGER_NORMAL;
-
-done:
-	dbus_message_unref(reply);
-	dbus_pending_call_unref(call);
-}
-
-static void get_silent_mode(DBusConnection *conn, void *user_data)
-{
-	DBusMessage *msg;
-	DBusPendingCall *call;
-
-	if (!agent.name) {
-		error("Agent not registered");
-		return;
-	}
-
-	DBG("Get Silent Mode: agent %s, %s", agent.name, agent.path);
-
-	msg = dbus_message_new_method_call(agent.name, agent.path,
-					AGENT_INTERFACE, "GetSilentMode");
-	if (msg == NULL) {
-		error("Unable to allocate new D-Bus message");
-		return;
-	}
-
-	if (!dbus_connection_send_with_reply(connection, msg, &call, -1)) {
-		error("Failed to send D-Bus message");
-		return;
-	}
-
-	dbus_pending_call_set_notify(call, get_silent_reply, NULL, NULL);
-}
-
 static uint8_t alert_status_read(struct attribute *a, gpointer user_data)
 {
-	if (alert_status == 0xff) {
-		get_alert_status(connection, NULL);
-		return ATT_ECODE_IO;
-	}
-
 	DBG("a = %p, state = %s", a,
 		alert_status & ALERT_RINGER_STATE ? "Active": "Not Active");
 
@@ -288,11 +158,6 @@ static uint8_t alert_status_read(struct attribute *a, gpointer user_data)
 
 static uint8_t ringer_setting_read(struct attribute *a, gpointer user_data)
 {
-	if (ringer_setting == 0xff) {
-		get_silent_mode(connection, NULL);
-		return ATT_ECODE_IO;
-	}
-
 	DBG("a = %p, setting = %s", a,
 			ringer_setting == RINGER_SILENT ? "Silent": "Normal");
 
@@ -343,15 +208,33 @@ static void agent_exited(DBusConnection *conn, void *user_data)
 static DBusMessage *register_agent(DBusConnection *conn, DBusMessage *msg,
 								void *data)
 {
-	const char *path, *name;
+	const char *path, *name, *setting;
 
 	if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path,
+						DBUS_TYPE_BYTE, &alert_status,
+						DBUS_TYPE_STRING, &setting,
 							DBUS_TYPE_INVALID))
 		return NULL;
 
 	if (agent.name != NULL)
 		return btd_error_already_exists(msg);
 
+	DBG("Ringer State (Alert Status): %s",
+		alert_status & ALERT_RINGER_STATE ? "Active": "Not Active");
+
+	DBG("Ringer Setting: %s", setting);
+	if (g_str_equal(setting, "Silent"))
+		ringer_setting = RINGER_SILENT;
+	else
+		ringer_setting = RINGER_NORMAL;
+
+	if (service_registered == FALSE) {
+		/* Register Phone Alert Status Service only when agent is
+		 * registered for the first time. */
+		register_phone_alert_service();
+		service_registered = TRUE;
+	}
+
 	name = dbus_message_get_sender(msg);
 
 	DBG("Registering agent: path = %s, name = %s", path, name);
@@ -410,7 +293,7 @@ static DBusMessage *notify_alert_status(DBusConnection *conn,
 }
 
 static GDBusMethodTable alert_methods[] = {
-	{ "RegisterAgent",	"o",	"",	register_agent		},
+	{ "RegisterAgent",	"oys",	"",	register_agent		},
 	{ "NotifyRingerSetting","s",	"",	notify_ringer_setting	},
 	{ "NotifyAlertStatus","y",	"",	notify_alert_status	},
 	{ }
@@ -434,8 +317,6 @@ int alert_server_init(void)
 
 	DBG("Registered interface %s on path %s", ALERT_INTERFACE, ALERT_PATH);
 
-	register_phone_alert_service();
-
 	return 0;
 }
 
diff --git a/test/phone-agent.py b/test/phone-agent.py
index 372f832..d2bd126 100755
--- a/test/phone-agent.py
+++ b/test/phone-agent.py
@@ -108,23 +108,6 @@ class PhoneAgent(dbus.service.Object):
         silent_mode = False
         restore_ringer()
 
-    @dbus.service.method("org.bluez.PhoneAgent",
-            in_signature="", out_signature="s")
-    def GetSilentMode(self):
-        print "GetSilentMode()"
-
-        global ringer_setting
-        return ringer_setting
-
-    @dbus.service.method("org.bluez.PhoneAgent",
-            in_signature="", out_signature="y")
-    def GetAlertStatus(self):
-        print "GetAlertStatus()"
-
-        global alert_status
-        return alert_status
-
-
 if __name__ == "__main__":
     dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
 
@@ -151,7 +134,7 @@ if __name__ == "__main__":
             "/test/phonealert"), "org.bluez.PhoneAlert")
 
     agent = PhoneAgent(system_bus, agent_path)
-    phone.RegisterAgent(agent_path)
+    phone.RegisterAgent(agent_path, dbus.Byte(alert_status), ringer_setting)
     print "destination:", system_bus.get_unique_name()
 
     mainloop = gobject.MainLoop()
-- 
1.7.0.4


^ permalink raw reply related	[flat|nested] 18+ messages in thread

* Re: [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server)
  2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
                   ` (15 preceding siblings ...)
  2011-09-26 19:13 ` [PATCH RFC BlueZ 16/16] Phone Alert: agent API changes Anderson Lizardo
@ 2011-09-26 20:12 ` Anderson Lizardo
  16 siblings, 0 replies; 18+ messages in thread
From: Anderson Lizardo @ 2011-09-26 20:12 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

On Mon, Sep 26, 2011 at 3:13 PM, Anderson Lizardo
<anderson.lizardo@openbossa.org> wrote:
> Hi,
>
> This RFC series contains our current work in progress for Phone Alert Status
> GATT profile (server role). This profile was recently adopted and you can find
> it on the Bluetooth SIG page:
>
> https://www.bluetooth.org/Technical/Specifications/adopted.htm

Forgot to mention: this series depends on another RFC I sent a while
ago named "GATT: high level API for service registration". Depending
on the feedback on that thread, I'll update this one accordingly. To
avoid polluting the list, we will only resend the series on major
changes. You can always follow development on my development tree:

git://gitorious.org/~lizardo/bluez/lizardo-bluez.git (branch "phone-alert")

Regards,
-- 
Anderson Lizardo
Instituto Nokia de Tecnologia - INdT
Manaus - Brazil

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2011-09-26 20:12 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-26 19:13 [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo
2011-09-26 19:13 ` [PATCH RFC BlueZ 01/16] Phone Alert: add Phone Alert Service Anderson Lizardo
2011-09-26 19:13 ` [PATCH RFC BlueZ 02/16] Phone Alert: add Ringer Control Point characteristic Anderson Lizardo
2011-09-26 19:13 ` [PATCH RFC BlueZ 03/16] Phone Alert: add Ringer Setting characteristic Anderson Lizardo
2011-09-26 19:13 ` [PATCH RFC BlueZ 04/16] Phone Alert: implement org.bluez.PhoneAlert interface Anderson Lizardo
2011-09-26 19:13 ` [PATCH RFC BlueZ 05/16] Phone Alert: add agent operations to alert server Anderson Lizardo
2011-09-26 19:13 ` [PATCH RFC BlueZ 06/16] Phone Alert: add GetSilentMode() call in " Anderson Lizardo
2011-09-26 19:13 ` [PATCH RFC BlueZ 07/16] Phone Alert: implement agent for N9 Anderson Lizardo
2011-09-26 19:13 ` [PATCH RFC BlueZ 08/16] Phone Alert: implement NotifyRingerSetting() method Anderson Lizardo
2011-09-26 19:13 ` [PATCH RFC BlueZ 09/16] Phone Alert: add Alert Status characteristic Anderson Lizardo
2011-09-26 19:13 ` [PATCH RFC BlueZ 10/16] Phone Alert: add GetAlertStatus() call in alert server Anderson Lizardo
2011-09-26 19:13 ` [PATCH RFC BlueZ 11/16] Phone Alert: add method for reading Alert Status Anderson Lizardo
2011-09-26 19:13 ` [PATCH RFC BlueZ 12/16] Phone Alert: listen to Ringer State changes Anderson Lizardo
2011-09-26 19:13 ` [PATCH RFC BlueZ 13/16] Phone Alert: implement NotifyAlertStatus() method Anderson Lizardo
2011-09-26 19:13 ` [PATCH RFC BlueZ 14/16] Phone Alert: Mute once using new NGFD API Anderson Lizardo
2011-09-26 19:13 ` [PATCH RFC BlueZ 15/16] Phone Alert: Remove MuteOnce operation from phone-agent Anderson Lizardo
2011-09-26 19:13 ` [PATCH RFC BlueZ 16/16] Phone Alert: agent API changes Anderson Lizardo
2011-09-26 20:12 ` [PATCH RFC BlueZ 00/16] Phone Alert Status GATT Profile (server) Anderson Lizardo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.