Music Hub ..
A session-wide music playback service
Loading...
Searching...
No Matches
error.cpp
Go to the documentation of this file.
1/*
2 * Copyright © 2021-2022 UBports Foundation.
3 *
4 * Contact: Alberto Mardegan <mardy@users.sourceforge.net>
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version 3,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include "error_p.h"
20
21#include "dbus_constants.h"
22
23#include <QDBusMessage>
24#include <QDebug>
25
26namespace lomiri {
27namespace MediaHub {
28
29Error errorFromDBus(const QDBusMessage &msg)
30{
31 using E = Error::Code;
32
33 Error::Code code = E::NoError;
34
35 const QString dbusCode = msg.errorName();
36 if (dbusCode.startsWith(QStringLiteral(MPRIS_ERROR_PREFIX))) {
37 const size_t prefixLength = sizeof(MPRIS_ERROR_PREFIX) - 1;
38 const QStringRef name = dbusCode.midRef(prefixLength);
39 if (name == MPRIS_ERROR_CREATING_SESSION ||
41 /* The client perfectly knows what it was trying to do, so there's
42 * no point in sending that information back.
43 */
44 code = E::InternalError;
46 code = E::AccessDeniedError;
47 } else if (name == MPRIS_ERROR_OOP_STREAMING_NOT_SUPPORTED) {
48 code = E::OutOfProcessBufferStreamingNotSupported;
49 } else if (name == MPRIS_ERROR_URI_NOT_FOUND) {
50 code = E::ResourceError;
51 }
52 } else if (dbusCode.startsWith(QStringLiteral(FDO_ERROR_PREFIX))) {
53 const size_t prefixLength = sizeof(FDO_ERROR_PREFIX) - 1;
54 const QStringRef name = dbusCode.midRef(prefixLength);
55 if (name == FDO_ERROR_ACCESS_DENIED) {
56 code = E::AccessDeniedError;
57 } else if (name == FDO_ERROR_DISCONNECTED ||
60 code = E::ServiceMissingError;
61 }
62 }
63
64 if (code == E::NoError) {
65 qWarning() << "Unexpected error code" << dbusCode;
66 code = E::InternalError;
67 }
68
69 return Error(code, msg.errorMessage());
70}
71
72Error errorFromApiCode(quint16 apiCode)
73{
74 Error::Code code;
75 QString text;
76 switch (apiCode) {
78 code = Error::NoError;
79 break;
82 text = "A media resource couldn't be resolved.";
83 break;
85 code = Error::FormatError;
86 text = "The media format type is not playable "
87 "due to a missing codec.";
88 break;
91 text = "A network error occurred.";
92 break;
95 text = "Insufficient privileges to play that media.";
96 break;
99 text = "A valid playback service was not found, "
100 "playback cannot proceed.";
101 break;
102 default:
103 qWarning() << "Unknown error code" << apiCode;
105 text = "The backend emitted an unrecognized error code";
106 }
107
108 return Error(code, text);
109}
110
111} // namespace MediaHub
112} // namespace lomiri
#define FDO_ERROR_PREFIX
#define MPRIS_ERROR_URI_NOT_FOUND
#define MPRIS_ERROR_OOP_STREAMING_NOT_SUPPORTED
#define MPRIS_ERROR_INSUFFICIENT_APPARMOR_PERMISSIONS
#define MPRIS_ERROR_CREATING_SESSION
#define FDO_ERROR_ACCESS_DENIED
#define FDO_ERROR_DISCONNECTED
#define MPRIS_ERROR_DESTROYING_SESSION
#define FDO_ERROR_NAME_HAS_NO_OWNER
#define FDO_ERROR_SERVICE_UNKNOWN
#define MPRIS_ERROR_PREFIX
Error errorFromDBus(const QDBusMessage &msg)
Definition error.cpp:29
Error errorFromApiCode(quint16 apiCode)
Definition error.cpp:72