public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] add btd_error_agent_not_available()
@ 2010-12-16 17:58 Gustavo F. Padovan
  2010-12-16 17:58 ` [PATCH 2/3] add btd_error_not_ready() Gustavo F. Padovan
  2010-12-16 19:45 ` [PATCH 1/3] add btd_error_agent_not_available() Johan Hedberg
  0 siblings, 2 replies; 4+ messages in thread
From: Gustavo F. Padovan @ 2010-12-16 17:58 UTC (permalink / raw)
  To: linux-bluetooth

---
 audio/gateway.c |    3 +--
 src/adapter.c   |    3 +--
 src/error.c     |    6 ++++++
 src/error.h     |    1 +
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/audio/gateway.c b/audio/gateway.c
index 655047d..43a4b02 100644
--- a/audio/gateway.c
+++ b/audio/gateway.c
@@ -369,8 +369,7 @@ static DBusMessage *ag_connect(DBusConnection *conn, DBusMessage *msg,
 	int err;
 
 	if (!gw->agent)
-		return g_dbus_create_error(msg, ERROR_INTERFACE
-				".Failed", "Agent not assigned");
+		return btd_error_agent_not_available(msg);
 
 	err = get_records(au_dev);
 	if (err < 0)
diff --git a/src/adapter.c b/src/adapter.c
index 2ff59a0..a36d2b1 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1412,8 +1412,7 @@ static DBusMessage *request_session(DBusConnection *conn,
 	int err;
 
 	if (!adapter->agent)
-		return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
-						"No agent registered");
+		return btd_error_agent_not_available(msg);
 
 	if (!adapter->mode_sessions)
 		adapter->global_mode = adapter->mode;
diff --git a/src/error.c b/src/error.c
index 1ee98c8..ebfc614 100644
--- a/src/error.c
+++ b/src/error.c
@@ -97,6 +97,12 @@ DBusMessage *btd_error_no_such_adapter(DBusMessage *msg)
 					"No such adapter");
 }
 
+DBusMessage *btd_error_agent_not_available(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, ERROR_INTERFACE ".AgentNotAvailable",
+					"Agent Not Available");
+}
+
 DBusMessage *btd_error_failed(DBusMessage *msg, const char *str)
 {
 	return g_dbus_create_error(msg, ERROR_INTERFACE
diff --git a/src/error.h b/src/error.h
index f346c07..ffd4332 100644
--- a/src/error.h
+++ b/src/error.h
@@ -38,4 +38,5 @@ DBusMessage *btd_error_in_progress(DBusMessage *msg);
 DBusMessage *btd_error_does_not_exist(DBusMessage *msg);
 DBusMessage *btd_error_not_authorized(DBusMessage *msg);
 DBusMessage *btd_error_no_such_adapter(DBusMessage *msg);
+DBusMessage *btd_error_agent_not_available(DBusMessage *msg);
 DBusMessage *btd_error_failed(DBusMessage *msg, const char *str);
-- 
1.7.3.2


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

* [PATCH 2/3] add btd_error_not_ready()
  2010-12-16 17:58 [PATCH 1/3] add btd_error_agent_not_available() Gustavo F. Padovan
@ 2010-12-16 17:58 ` Gustavo F. Padovan
  2010-12-16 17:58   ` [PATCH 3/3] covert more dbus errors to btd_error_* Gustavo F. Padovan
  2010-12-16 19:45 ` [PATCH 1/3] add btd_error_agent_not_available() Johan Hedberg
  1 sibling, 1 reply; 4+ messages in thread
From: Gustavo F. Padovan @ 2010-12-16 17:58 UTC (permalink / raw)
  To: linux-bluetooth

---
 audio/headset.c |    3 +--
 src/adapter.c   |   16 +++++-----------
 src/error.c     |    6 ++++++
 src/error.h     |    1 +
 4 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/audio/headset.c b/audio/headset.c
index 01f91db..af75f8b 100644
--- a/audio/headset.c
+++ b/audio/headset.c
@@ -1696,8 +1696,7 @@ static DBusMessage *hs_connect(DBusConnection *conn, DBusMessage *msg,
 		return btd_error_already_connected(msg);
 
 	if (hs->hfp_handle && !ag.telephony_ready)
-		return g_dbus_create_error(msg, ERROR_INTERFACE ".NotReady",
-					"Telephony subsystem not ready");
+		return btd_error_not_ready(msg);
 
 	device->auto_connect = FALSE;
 
diff --git a/src/adapter.c b/src/adapter.c
index a36d2b1..cd53455 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -140,12 +140,6 @@ struct btd_adapter {
 static void adapter_set_pairable_timeout(struct btd_adapter *adapter,
 					guint interval);
 
-static inline DBusMessage *adapter_not_ready(DBusMessage *msg)
-{
-	return g_dbus_create_error(msg, ERROR_INTERFACE ".NotReady",
-			"Adapter is not ready");
-}
-
 static inline DBusMessage *not_in_progress(DBusMessage *msg, const char *str)
 {
 	return g_dbus_create_error(msg, ERROR_INTERFACE ".NotInProgress",
@@ -554,7 +548,7 @@ static DBusMessage *set_pairable(DBusConnection *conn, DBusMessage *msg,
 	int err;
 
 	if (adapter->scan_mode == SCAN_DISABLED)
-		return adapter_not_ready(msg);
+		return btd_error_not_ready(msg);
 
 	if (pairable == adapter->pairable)
 		goto done;
@@ -1166,7 +1160,7 @@ static DBusMessage *adapter_start_discovery(DBusConnection *conn,
 	int err;
 
 	if (!adapter->up)
-		return adapter_not_ready(msg);
+		return btd_error_not_ready(msg);
 
 	req = find_session(adapter->disc_sessions, sender);
 	if (req) {
@@ -1198,7 +1192,7 @@ static DBusMessage *adapter_stop_discovery(DBusConnection *conn,
 	const char *sender = dbus_message_get_sender(msg);
 
 	if (!adapter->up)
-		return adapter_not_ready(msg);
+		return btd_error_not_ready(msg);
 
 	req = find_session(adapter->disc_sessions, sender);
 	if (!req)
@@ -1575,7 +1569,7 @@ static DBusMessage *create_device(DBusConnection *conn,
 		return btd_error_invalid_args(msg);
 
 	if (!adapter->up)
-		return adapter_not_ready(msg);
+		return btd_error_not_ready(msg);
 
 	if (adapter_find_device(adapter, address))
 		return btd_error_already_exists(msg);
@@ -1652,7 +1646,7 @@ static DBusMessage *create_paired_device(DBusConnection *conn,
 		return btd_error_invalid_args(msg);
 
 	if (!adapter->up)
-		return adapter_not_ready(msg);
+		return btd_error_not_ready(msg);
 
 	sender = dbus_message_get_sender(msg);
 	if (adapter->agent &&
diff --git a/src/error.c b/src/error.c
index ebfc614..c2d9baa 100644
--- a/src/error.c
+++ b/src/error.c
@@ -103,6 +103,12 @@ DBusMessage *btd_error_agent_not_available(DBusMessage *msg)
 					"Agent Not Available");
 }
 
+DBusMessage *btd_error_not_ready(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, ERROR_INTERFACE ".NotReady",
+					"Resource Not Ready");
+}
+
 DBusMessage *btd_error_failed(DBusMessage *msg, const char *str)
 {
 	return g_dbus_create_error(msg, ERROR_INTERFACE
diff --git a/src/error.h b/src/error.h
index ffd4332..cdb8919 100644
--- a/src/error.h
+++ b/src/error.h
@@ -39,4 +39,5 @@ DBusMessage *btd_error_does_not_exist(DBusMessage *msg);
 DBusMessage *btd_error_not_authorized(DBusMessage *msg);
 DBusMessage *btd_error_no_such_adapter(DBusMessage *msg);
 DBusMessage *btd_error_agent_not_available(DBusMessage *msg);
+DBusMessage *btd_error_not_ready(DBusMessage *msg);
 DBusMessage *btd_error_failed(DBusMessage *msg, const char *str);
-- 
1.7.3.2


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

* [PATCH 3/3] covert more dbus errors to btd_error_*
  2010-12-16 17:58 ` [PATCH 2/3] add btd_error_not_ready() Gustavo F. Padovan
@ 2010-12-16 17:58   ` Gustavo F. Padovan
  0 siblings, 0 replies; 4+ messages in thread
From: Gustavo F. Padovan @ 2010-12-16 17:58 UTC (permalink / raw)
  To: linux-bluetooth

---
 audio/headset.c |   10 ++--------
 serial/port.c   |    8 +-------
 serial/proxy.c  |   12 ++----------
 src/adapter.c   |   10 ++--------
 4 files changed, 7 insertions(+), 33 deletions(-)

diff --git a/audio/headset.c b/audio/headset.c
index af75f8b..72bf5b6 100644
--- a/audio/headset.c
+++ b/audio/headset.c
@@ -1872,14 +1872,8 @@ static DBusMessage *hs_set_gain(DBusConnection *conn,
 		return btd_error_not_connected(msg);
 
 	err = headset_set_gain(device, gain, type);
-	if (err < 0) {
-		/* Ignore if nothing has changed */
-		if (err == -EALREADY)
-			return dbus_message_new_method_return(msg);
-		return g_dbus_create_error(msg, ERROR_INTERFACE
-						".InvalidArgument",
-						"Must be less than or equal to 15");
-	}
+	if (err < 0)
+		return btd_error_invalid_args(msg);
 
 	reply = dbus_message_new_method_return(msg);
 	if (!reply)
diff --git a/serial/port.c b/serial/port.c
index 33450b3..233e317 100644
--- a/serial/port.c
+++ b/serial/port.c
@@ -234,12 +234,6 @@ void port_release_all(void)
 	g_slist_free(devices);
 }
 
-static inline DBusMessage *failed(DBusMessage *msg, const char *description)
-{
-	return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
-							"%s", description);
-}
-
 static void open_notify(int fd, int err, struct serial_port *port)
 {
 	struct serial_device *device = port->device;
@@ -495,7 +489,7 @@ static DBusMessage *port_connect(DBusConnection *conn,
 	}
 
 	if (port->listener_id)
-		return failed(msg, "Port already in use");
+		return btd_error_failed(msg, "Port already in use");
 
 	port->listener_id = g_dbus_add_disconnect_watch(conn,
 						dbus_message_get_sender(msg),
diff --git a/serial/proxy.c b/serial/proxy.c
index 20aea7d..b1ee65e 100644
--- a/serial/proxy.c
+++ b/serial/proxy.c
@@ -131,12 +131,6 @@ static void proxy_free(struct serial_proxy *prx)
 	g_free(prx);
 }
 
-static inline DBusMessage *failed(DBusMessage *msg, const char *description)
-{
-	return g_dbus_create_error(msg, ERROR_INTERFACE ".Failed",
-							"%s", description);
-}
-
 static void add_lang_attr(sdp_record_t *r)
 {
 	sdp_lang_attr_t base_lang;
@@ -551,9 +545,7 @@ static DBusMessage *proxy_enable(DBusConnection *conn,
 	int err;
 
 	err = enable_proxy(prx);
-	if (err == -EALREADY)
-		return failed(msg, "Already enabled");
-	else if (err < 0)
+	if (err < 0)
 		return btd_error_failed(msg, strerror(-err));
 
 	return dbus_message_new_method_return(msg);
@@ -565,7 +557,7 @@ static DBusMessage *proxy_disable(DBusConnection *conn,
 	struct serial_proxy *prx = data;
 
 	if (!prx->io)
-		return failed(msg, "Not enabled");
+		return btd_error_failed(msg, "Not enabled");
 
 	/* Remove the watches and unregister the record */
 	disable_proxy(prx);
diff --git a/src/adapter.c b/src/adapter.c
index cd53455..5118306 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -140,12 +140,6 @@ struct btd_adapter {
 static void adapter_set_pairable_timeout(struct btd_adapter *adapter,
 					guint interval);
 
-static inline DBusMessage *not_in_progress(DBusMessage *msg, const char *str)
-{
-	return g_dbus_create_error(msg, ERROR_INTERFACE ".NotInProgress",
-								"%s", str);
-}
-
 static int found_device_cmp(const struct remote_dev_info *d1,
 			const struct remote_dev_info *d2)
 {
@@ -1226,7 +1220,7 @@ static DBusMessage *get_properties(DBusConnection *conn,
 	ba2str(&adapter->bdaddr, srcaddr);
 
 	if (check_address(srcaddr) < 0)
-		return adapter_not_ready(msg);
+		return btd_error_invalid_args(msg);
 
 	reply = dbus_message_new_method_return(msg);
 	if (!reply)
@@ -1505,7 +1499,7 @@ static DBusMessage *cancel_device_creation(DBusConnection *conn,
 
 	device = adapter_find_device(adapter, address);
 	if (!device || !device_is_creating(device, NULL))
-		return not_in_progress(msg, "Device creation not in progress");
+		return btd_error_does_not_exist(msg);
 
 	if (!device_is_creating(device, sender))
 		return btd_error_not_authorized(msg);
-- 
1.7.3.2


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

* Re: [PATCH 1/3] add btd_error_agent_not_available()
  2010-12-16 17:58 [PATCH 1/3] add btd_error_agent_not_available() Gustavo F. Padovan
  2010-12-16 17:58 ` [PATCH 2/3] add btd_error_not_ready() Gustavo F. Padovan
@ 2010-12-16 19:45 ` Johan Hedberg
  1 sibling, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2010-12-16 19:45 UTC (permalink / raw)
  To: Gustavo F. Padovan; +Cc: linux-bluetooth

Hi Gustavo,

On Thu, Dec 16, 2010, Gustavo F. Padovan wrote:
> ---
>  audio/gateway.c |    3 +--
>  src/adapter.c   |    3 +--
>  src/error.c     |    6 ++++++
>  src/error.h     |    1 +
>  4 files changed, 9 insertions(+), 4 deletions(-)

All three patches have been pushed upstream. Thanks.

In the future could you please start your summary lines with a capital
letter so we keep the commit history consistent. I went ahead and
changed them manually this time.

Johan

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

end of thread, other threads:[~2010-12-16 19:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-16 17:58 [PATCH 1/3] add btd_error_agent_not_available() Gustavo F. Padovan
2010-12-16 17:58 ` [PATCH 2/3] add btd_error_not_ready() Gustavo F. Padovan
2010-12-16 17:58   ` [PATCH 3/3] covert more dbus errors to btd_error_* Gustavo F. Padovan
2010-12-16 19:45 ` [PATCH 1/3] add btd_error_agent_not_available() Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox