Skip to contentSkip to conversation

audio/player: Use proper errors instead of using .Failed

PATCH In review Luiz Augusto von Dentz 1 participant 3 messages Mar 13, 2014 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/2 audio/player: Use proper errors instead of using .Failed

From: Luiz Augusto von Dentz <[email protected]>

---
 profiles/audio/player.c | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)
profiles/audio/player.c +10 -19
index 2bd2d6e..c76352e 100644
@@ -778,19 +778,16 @@ static DBusMessage *media_folder_search(DBusConnection *conn, DBusMessage *msg,
 	dbus_message_iter_init(msg, &iter);
 
 	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
-		return btd_error_failed(msg, strerror(EINVAL));
+		return btd_error_invalid_args(msg);
 
 	dbus_message_iter_get_basic(&iter, &string);
 
-	if (!mp->searchable || folder != mp->folder)
-		return btd_error_failed(msg, strerror(ENOTSUP));
+	if (!mp->searchable || folder != mp->folder || !cb->cbs->search)
+		return btd_error_not_supported(msg);
 
 	if (folder->msg != NULL)
 		return btd_error_failed(msg, strerror(EINVAL));
 
-	if (cb->cbs->search == NULL)
-		return btd_error_failed(msg, strerror(ENOTSUP));
-
 	err = cb->cbs->search(mp, string, cb->user_data);
 	if (err < 0)
 		return btd_error_failed(msg, strerror(-err));
@@ -998,14 +995,14 @@ static DBusMessage *media_folder_change_folder(DBusConnection *conn,
 	if (!dbus_message_get_args(msg, NULL,
 					DBUS_TYPE_OBJECT_PATH, &path,
 					DBUS_TYPE_INVALID))
-		return btd_error_failed(msg, strerror(EINVAL));
+		return btd_error_invalid_args(msg);
 
 	if (folder->msg != NULL)
 		return btd_error_failed(msg, strerror(EBUSY));
 
 	folder = media_player_find_folder(mp, path);
 	if (folder == NULL)
-		return btd_error_failed(msg, strerror(EINVAL));
+		return btd_error_invalid_args(msg);
 
 	if (mp->scope == folder)
 		return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
@@ -1017,7 +1014,7 @@ static DBusMessage *media_folder_change_folder(DBusConnection *conn,
 	}
 
 	if (cb->cbs->change_folder == NULL)
-		return btd_error_failed(msg, strerror(ENOTSUP));
+		return btd_error_not_supported(msg);
 
 	err = cb->cbs->change_folder(mp, folder->item->name, folder->item->uid,
 								cb->user_data);
@@ -1473,11 +1470,8 @@ static DBusMessage *media_item_play(DBusConnection *conn, DBusMessage *msg,
 	struct player_callback *cb = mp->cb;
 	int err;
 
-	if (!item->playable)
-		return btd_error_failed(msg, strerror(ENOTSUP));
-
-	if (cb->cbs->play_item == NULL)
-		return btd_error_failed(msg, strerror(ENOTSUP));
+	if (!item->playable || !cb->cbs->play_item)
+		return btd_error_not_supported(msg);
 
 	err = cb->cbs->play_item(mp, item->path, item->uid, cb->user_data);
 	if (err < 0)
@@ -1494,11 +1488,8 @@ static DBusMessage *media_item_add_to_nowplaying(DBusConnection *conn,
 	struct player_callback *cb = mp->cb;
 	int err;
 
-	if (!item->playable)
-		return btd_error_failed(msg, strerror(ENOTSUP));
-
-	if (cb->cbs->play_item == NULL)
-		return btd_error_failed(msg, strerror(ENOTSUP));
+	if (!item->playable || !cb->cbs->play_item)
+		return btd_error_not_supported(msg);
 
 	err = cb->cbs->add_to_nowplaying(mp, item->path, item->uid,
 							cb->user_data);
Signature · 1 line
1.8.5.3
author maintainer
#1 lore raw

PATCH 2/2 doc/media-api: Include possible errors

From: Luiz Augusto von Dentz <[email protected]>

---
 doc/media-api.txt | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
doc/media-api.txt +38 -0
index 05f90e3..07ea991 100644
@@ -128,32 +128,53 @@ Methods		void Play()
 
 			Resume playback.
 
+			Possible Errors: org.bluez.Error.NotSupported
+					 org.bluez.Error.Failed
+
 		void Pause()
 
 			Pause playback.
 
+			Possible Errors: org.bluez.Error.NotSupported
+					 org.bluez.Error.Failed
+
 		void Stop()
 
 			Stop playback.
 
+			Possible Errors: org.bluez.Error.NotSupported
+					 org.bluez.Error.Failed
+
 		void Next()
 
 			Next item.
 
+			Possible Errors: org.bluez.Error.NotSupported
+					 org.bluez.Error.Failed
+
 		void Previous()
 
 			Previous item.
 
+			Possible Errors: org.bluez.Error.NotSupported
+					 org.bluez.Error.Failed
+
 		void FastForward()
 
 			Fast forward playback, this action is only stopped
 			when another method in this interface is called.
 
+			Possible Errors: org.bluez.Error.NotSupported
+					 org.bluez.Error.Failed
+
 		void Rewind()
 
 			Rewind playback, this action is only stopped
 			when another method in this interface is called.
 
+			Possible Errors: org.bluez.Error.NotSupported
+					 org.bluez.Error.Failed
+
 Properties	string Equalizer [readwrite]
 
 			Possible values: "off" or "on"
@@ -300,10 +321,17 @@ Methods		object Search(string value, dict filter)
 			To list the items found use the folder object returned
 			and pass to ChangeFolder.
 
+			Possible Errors: org.bluez.Error.NotSupported
+					 org.bluez.Error.Failed
+
 		array{objects, properties} ListItems(dict filter)
 
 			Return a list of items found
 
+			Possible Errors: org.bluez.Error.InvalidArguments
+					 org.bluez.Error.NotSupported
+					 org.bluez.Error.Failed
+
 		void ChangeFolder(object folder)
 
 			Change current folder.
@@ -313,6 +341,10 @@ Methods		object Search(string value, dict filter)
 			exception is NowPlaying folder which should be always
 			present while the player is active.
 
+			Possible Errors: org.bluez.Error.InvalidArguments
+					 org.bluez.Error.NotSupported
+					 org.bluez.Error.Failed
+
 Properties	uint32 NumberOfItems [readonly]
 
 			Number of items in the folder
@@ -368,10 +400,16 @@ Methods		void Play()
 
 			Play item
 
+			Possible Errors: org.bluez.Error.NotSupported
+					 org.bluez.Error.Failed
+
 		void AddtoNowPlaying()
 
 			Add item to now playing list
 
+			Possible Errors: org.bluez.Error.NotSupported
+					 org.bluez.Error.Failed
+
 Properties	object Player [readonly]
 
 			Player object path the item belongs to
Signature · 1 line
1.8.5.3
author maintainer
#2 lore raw
In reply to Luiz Augusto von Dentz

Hi,

Quoted 88 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 profiles/audio/player.c | 29 ++++++++++-------------------
 1 file changed, 10 insertions(+), 19 deletions(-)
profiles/audio/player.c +10 -20
index 2bd2d6e..c76352e 100644
@@ -778,19 +778,16 @@ static DBusMessage *media_folder_search(DBusConnection *conn, DBusMessage *msg,
        dbus_message_iter_init(msg, &iter);
 
        if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
-               return btd_error_failed(msg, strerror(EINVAL));
+               return btd_error_invalid_args(msg);
 
        dbus_message_iter_get_basic(&iter, &string);
 
-       if (!mp->searchable || folder != mp->folder)
-               return btd_error_failed(msg, strerror(ENOTSUP));
+       if (!mp->searchable || folder != mp->folder || !cb->cbs->search)
+               return btd_error_not_supported(msg);
 
        if (folder->msg != NULL)
                return btd_error_failed(msg, strerror(EINVAL));
 
-       if (cb->cbs->search == NULL)
-               return btd_error_failed(msg, strerror(ENOTSUP));
-
        err = cb->cbs->search(mp, string, cb->user_data);
        if (err < 0)
                return btd_error_failed(msg, strerror(-err));
@@ -998,14 +995,14 @@ static DBusMessage *media_folder_change_folder(DBusConnection *conn,
        if (!dbus_message_get_args(msg, NULL,
                                        DBUS_TYPE_OBJECT_PATH, &path,
                                        DBUS_TYPE_INVALID))
-               return btd_error_failed(msg, strerror(EINVAL));
+               return btd_error_invalid_args(msg);
 
        if (folder->msg != NULL)
                return btd_error_failed(msg, strerror(EBUSY));
 
        folder = media_player_find_folder(mp, path);
        if (folder == NULL)
-               return btd_error_failed(msg, strerror(EINVAL));
+               return btd_error_invalid_args(msg);
 
        if (mp->scope == folder)
                return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
@@ -1017,7 +1014,7 @@ static DBusMessage *media_folder_change_folder(DBusConnection *conn,
        }
 
        if (cb->cbs->change_folder == NULL)
-               return btd_error_failed(msg, strerror(ENOTSUP));
+               return btd_error_not_supported(msg);
 
        err = cb->cbs->change_folder(mp, folder->item->name, folder->item->uid,
                                                                cb->user_data);
@@ -1473,11 +1470,8 @@ static DBusMessage *media_item_play(DBusConnection *conn, DBusMessage *msg,
        struct player_callback *cb = mp->cb;
        int err;
 
-       if (!item->playable)
-               return btd_error_failed(msg, strerror(ENOTSUP));
-
-       if (cb->cbs->play_item == NULL)
-               return btd_error_failed(msg, strerror(ENOTSUP));
+       if (!item->playable || !cb->cbs->play_item)
+               return btd_error_not_supported(msg);
 
        err = cb->cbs->play_item(mp, item->path, item->uid, cb->user_data);
        if (err < 0)
@@ -1494,11 +1488,8 @@ static DBusMessage *media_item_add_to_nowplaying(DBusConnection *conn,
        struct player_callback *cb = mp->cb;
        int err;
 
-       if (!item->playable)
-               return btd_error_failed(msg, strerror(ENOTSUP));
-
-       if (cb->cbs->play_item == NULL)
-               return btd_error_failed(msg, strerror(ENOTSUP));
+       if (!item->playable || !cb->cbs->play_item)
+               return btd_error_not_supported(msg);
 
        err = cb->cbs->add_to_nowplaying(mp, item->path, item->uid,
                                                        cb->user_data);
--
Quoted 1 line

1.8.5.3

Pushed.

Signature · 1 line
Luiz Augusto von Dentz