linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/5] Add Debug property to Manager interface
@ 2010-06-05  7:25 Gustavo F. Padovan
  2010-06-05  7:25 ` [PATCH 2/5] Add SetProperty method and Debug read/write property Gustavo F. Padovan
  0 siblings, 1 reply; 5+ messages in thread
From: Gustavo F. Padovan @ 2010-06-05  7:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo

---
 src/log.c     |    5 +++++
 src/log.h     |    1 +
 src/manager.c |    4 ++++
 3 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/log.c b/src/log.c
index 1bc0a42..4043ee3 100644
--- a/src/log.c
+++ b/src/log.c
@@ -97,6 +97,11 @@ void __btd_toggle_debug()
 	debug_enabled = !debug_enabled;
 }
 
+int __btd_debug_enabled()
+{
+	return debug_enabled;
+}
+
 void __btd_log_init(const char *debug, int detach)
 {
 	int option = LOG_NDELAY | LOG_PID;
diff --git a/src/log.h b/src/log.h
index c9412c4..681e71d 100644
--- a/src/log.h
+++ b/src/log.h
@@ -30,6 +30,7 @@ void debug(const char *format, ...) __attribute__((format(printf, 1, 2)));
 void __btd_log_init(const char *debug, int detach);
 void __btd_log_cleanup(void);
 void __btd_toggle_debug();
+int __btd_debug_enabled();
 
 struct btd_debug_desc {
         const char *name;
diff --git a/src/manager.c b/src/manager.c
index cbbca1e..eab7e80 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -183,6 +183,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
 	DBusMessageIter dict;
 	GSList *list;
 	char **array;
+	gboolean debug_value;
 	int i;
 
 	reply = dbus_message_new_method_return(msg);
@@ -208,6 +209,9 @@ static DBusMessage *get_properties(DBusConnection *conn,
 	dict_append_array(&dict, "Adapters", DBUS_TYPE_OBJECT_PATH, &array, i);
 	g_free(array);
 
+	debug_value = __btd_debug_enabled();
+	dict_append_entry(&dict, "Debug", DBUS_TYPE_BOOLEAN, &debug_value);
+
 	dbus_message_iter_close_container(&iter, &dict);
 
 	return reply;
-- 
1.7.1


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

* [PATCH 2/5] Add SetProperty method and Debug read/write property
  2010-06-05  7:25 [PATCH 1/5] Add Debug property to Manager interface Gustavo F. Padovan
@ 2010-06-05  7:25 ` Gustavo F. Padovan
  2010-06-05  7:25   ` [PATCH 3/5] log: Add function to get/set debug_string Gustavo F. Padovan
  0 siblings, 1 reply; 5+ messages in thread
From: Gustavo F. Padovan @ 2010-06-05  7:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo

---
 src/manager.c |   52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/src/manager.c b/src/manager.c
index eab7e80..66e1511 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -80,6 +80,22 @@ static inline DBusMessage *no_such_adapter(DBusMessage *msg)
 			"No such adapter");
 }
 
+static DBusMessage *set_debug(DBusConnection *conn, DBusMessage *msg,
+				gboolean debug, void *data)
+{
+	gboolean old_debug = __btd_debug_enabled();
+
+	if (debug == old_debug)
+		return dbus_message_new_method_return(msg);
+
+	__btd_toggle_debug(debug);
+
+	emit_property_changed(connection, "/" , MANAGER_INTERFACE, "Debug",
+				DBUS_TYPE_BOOLEAN, &debug);
+
+	return dbus_message_new_method_return(msg);
+}
+
 static DBusMessage *default_adapter(DBusConnection *conn,
 					DBusMessage *msg, void *data)
 {
@@ -217,8 +233,44 @@ static DBusMessage *get_properties(DBusConnection *conn,
 	return reply;
 }
 
+static DBusMessage *set_property(DBusConnection *conn,
+					DBusMessage *msg, void *data)
+{
+	DBusMessageIter iter;
+	DBusMessageIter sub;
+	const char *property;
+
+	if (!dbus_message_iter_init(msg, &iter))
+		return invalid_args(msg);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+		return invalid_args(msg);
+
+	dbus_message_iter_get_basic(&iter, &property);
+	dbus_message_iter_next(&iter);
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
+		return invalid_args(msg);
+	dbus_message_iter_recurse(&iter, &sub);
+
+	if (g_str_equal("Debug", property)) {
+		gboolean debug;
+
+		if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_BOOLEAN)
+			return invalid_args(msg);
+
+		dbus_message_iter_get_basic(&sub, &debug);
+
+		return set_debug(conn, msg, debug, data);
+	}
+
+	return invalid_args(msg);
+}
+
 static GDBusMethodTable manager_methods[] = {
 	{ "GetProperties",	"",	"a{sv}",get_properties	},
+	{ "SetProperty",	"sv",	"",	set_property,
+						G_DBUS_METHOD_FLAG_ASYNC},
 	{ "DefaultAdapter",	"",	"o",	default_adapter	},
 	{ "FindAdapter",	"s",	"o",	find_adapter	},
 	{ "ListAdapters",	"",	"ao",	list_adapters,
-- 
1.7.1


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

* [PATCH 3/5] log: Add function to get/set debug_string
  2010-06-05  7:25 ` [PATCH 2/5] Add SetProperty method and Debug read/write property Gustavo F. Padovan
@ 2010-06-05  7:25   ` Gustavo F. Padovan
  2010-06-05  7:25     ` [PATCH 4/5] Add DebugString Property to Manager Gustavo F. Padovan
  0 siblings, 1 reply; 5+ messages in thread
From: Gustavo F. Padovan @ 2010-06-05  7:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo

---
 src/log.c |   56 +++++++++++++++++++++++++++++++++++++++++---------------
 src/log.h |    2 ++
 2 files changed, 43 insertions(+), 15 deletions(-)

diff --git a/src/log.c b/src/log.c
index 4043ee3..f0f2465 100644
--- a/src/log.c
+++ b/src/log.c
@@ -72,6 +72,7 @@ extern struct btd_debug_desc __stop___debug[];
 static gchar **enabled = NULL;
 
 int debug_enabled = FALSE;
+static char *debug_string = NULL;
 
 static gboolean is_enabled(struct btd_debug_desc *desc)
 {
@@ -92,6 +93,44 @@ static gboolean is_enabled(struct btd_debug_desc *desc)
         return 0;
 }
 
+static void debug_on()
+{
+	struct btd_debug_desc *desc;
+	const char *name = NULL, *file = NULL;
+
+	enabled = g_strsplit_set(debug_string, ":, ", 0);
+
+	for (desc = __start___debug; desc < __stop___debug; desc++) {
+		if (file != NULL || name != NULL) {
+			if (g_strcmp0(desc->file, file) == 0) {
+				if (desc->name == NULL)
+					desc->name = name;
+			} else
+				file = NULL;
+		}
+
+		if (is_enabled(desc))
+			desc->flags |= BTD_DEBUG_FLAG_PRINT;
+		else
+			desc->flags &= ~BTD_DEBUG_FLAG_PRINT;
+	}
+}
+
+char *__btd_get_debug_string()
+{
+	return debug_string;
+}
+
+char *__btd_set_debug_string(char *str)
+{
+	g_free(debug_string);
+	debug_string = g_strdup(str);
+
+	debug_on();
+
+	return debug_string;
+}
+
 void __btd_toggle_debug()
 {
 	debug_enabled = !debug_enabled;
@@ -105,8 +144,6 @@ int __btd_debug_enabled()
 void __btd_log_init(const char *debug, int detach)
 {
 	int option = LOG_NDELAY | LOG_PID;
-	struct btd_debug_desc *desc;
-	const char *name = NULL, *file = NULL;
 
 	if (debug != NULL) {
 		debug_enabled = TRUE;
@@ -115,20 +152,9 @@ void __btd_log_init(const char *debug, int detach)
 		debug_enabled = FALSE;
 	}
 
-	enabled = g_strsplit_set(debug, ":, ", 0);
-
-	for (desc = __start___debug; desc < __stop___debug; desc++) {
-		if (file != NULL || name != NULL) {
-			if (g_strcmp0(desc->file, file) == 0) {
-				if (desc->name == NULL)
-					desc->name = name;
-			} else
-				file = NULL;
-		}
+	debug_string = (char *)debug;
 
-		if (is_enabled(desc))
-			desc->flags |= BTD_DEBUG_FLAG_PRINT;
-	}
+	debug_on();
 
 	if (!detach)
 		option |= LOG_PERROR;
diff --git a/src/log.h b/src/log.h
index 681e71d..392c716 100644
--- a/src/log.h
+++ b/src/log.h
@@ -29,6 +29,8 @@ void debug(const char *format, ...) __attribute__((format(printf, 1, 2)));
 
 void __btd_log_init(const char *debug, int detach);
 void __btd_log_cleanup(void);
+char *__btd_get_debug_string();
+char *__btd_set_debug_string(char *str);
 void __btd_toggle_debug();
 int __btd_debug_enabled();
 
-- 
1.7.1


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

* [PATCH 4/5] Add DebugString Property to Manager
  2010-06-05  7:25   ` [PATCH 3/5] log: Add function to get/set debug_string Gustavo F. Padovan
@ 2010-06-05  7:25     ` Gustavo F. Padovan
  2010-06-05  7:25       ` [PATCH 5/5] Document the new Debug and DebugString property Gustavo F. Padovan
  0 siblings, 1 reply; 5+ messages in thread
From: Gustavo F. Padovan @ 2010-06-05  7:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo

---
 src/manager.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/src/manager.c b/src/manager.c
index 66e1511..220a8fe 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -96,6 +96,31 @@ static DBusMessage *set_debug(DBusConnection *conn, DBusMessage *msg,
 	return dbus_message_new_method_return(msg);
 }
 
+static DBusMessage *set_debug_string(DBusConnection *conn, DBusMessage *msg,
+					const char *debug_string, void *data)
+{
+	char *old_string;
+
+	if (!g_utf8_validate(debug_string, -1, NULL)) {
+		error("DebugString change failed: supplied string "
+							"isn't valid UTF-8");
+		return invalid_args(msg);
+	}
+
+	old_string = __btd_get_debug_string();
+
+	if (strcmp((char *)debug_string, old_string) == 0)
+		return dbus_message_new_method_return(msg);
+
+	if (!__btd_set_debug_string((char *)debug_string))
+		return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
+							strerror(ENOMEM));
+	emit_property_changed(connection, "/", MANAGER_INTERFACE,
+				"DebugString", DBUS_TYPE_STRING, &debug_string);
+
+	return dbus_message_new_method_return(msg);
+}
+
 static DBusMessage *default_adapter(DBusConnection *conn,
 					DBusMessage *msg, void *data)
 {
@@ -200,6 +225,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
 	GSList *list;
 	char **array;
 	gboolean debug_value;
+	char *debug_string;
 	int i;
 
 	reply = dbus_message_new_method_return(msg);
@@ -228,6 +254,10 @@ static DBusMessage *get_properties(DBusConnection *conn,
 	debug_value = __btd_debug_enabled();
 	dict_append_entry(&dict, "Debug", DBUS_TYPE_BOOLEAN, &debug_value);
 
+	debug_string = __btd_get_debug_string();
+	dict_append_entry(&dict, "DebugString", DBUS_TYPE_STRING,
+							&debug_string);
+
 	dbus_message_iter_close_container(&iter, &dict);
 
 	return reply;
@@ -262,6 +292,14 @@ static DBusMessage *set_property(DBusConnection *conn,
 		dbus_message_iter_get_basic(&sub, &debug);
 
 		return set_debug(conn, msg, debug, data);
+	} else if (g_str_equal("DebugString", property)) {
+		const char *string;
+
+		if (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_STRING)
+			return invalid_args(msg);
+		dbus_message_iter_get_basic(&sub, &string);
+
+		return set_debug_string(conn, msg, string, data);
 	}
 
 	return invalid_args(msg);
-- 
1.7.1


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

* [PATCH 5/5] Document the new Debug and DebugString property
  2010-06-05  7:25     ` [PATCH 4/5] Add DebugString Property to Manager Gustavo F. Padovan
@ 2010-06-05  7:25       ` Gustavo F. Padovan
  0 siblings, 0 replies; 5+ messages in thread
From: Gustavo F. Padovan @ 2010-06-05  7:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: gustavo

---
 doc/manager-api.txt |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/doc/manager-api.txt b/doc/manager-api.txt
index d2c1caf..07d4fde 100644
--- a/doc/manager-api.txt
+++ b/doc/manager-api.txt
@@ -22,6 +22,15 @@ Methods		dict GetProperties()
 			Possible Errors: org.bluez.Error.DoesNotExist
 					 org.bluez.Error.InvalidArguments
 
+		void SetProperty(string name, variant value)
+
+			Changes the value of the specified property. Only
+			properties that are listed a read-write are changeable.
+			On success this will emit a PropertyChanged signal.
+
+			Possible Errors: org.bluez.Error.DoesNotExist
+					 org.bluez.Error.InvalidArguments
+
 		object DefaultAdapter()
 
 			Returns object path for the default adapter.
@@ -72,3 +81,13 @@ Signals		PropertyChanged(string name, variant value)
 Properties	array{object} Adapters [readonly]
 
 			List of adapter object paths.
+
+		boolean Debug [readwrite]
+
+			Switch dynamic debug on or off.
+
+		string DebugString [readwrite]
+
+			Change the dynamic debug match string. Use it to
+			restrict debug to specific files. The default value is
+			"*" to debug all files.
-- 
1.7.1


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

end of thread, other threads:[~2010-06-05  7:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-05  7:25 [PATCH 1/5] Add Debug property to Manager interface Gustavo F. Padovan
2010-06-05  7:25 ` [PATCH 2/5] Add SetProperty method and Debug read/write property Gustavo F. Padovan
2010-06-05  7:25   ` [PATCH 3/5] log: Add function to get/set debug_string Gustavo F. Padovan
2010-06-05  7:25     ` [PATCH 4/5] Add DebugString Property to Manager Gustavo F. Padovan
2010-06-05  7:25       ` [PATCH 5/5] Document the new Debug and DebugString property Gustavo F. Padovan

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).