Debian Codegraph @

tests/service-mocks/media-player-mpris-mock/player-update.cpp

raw
1 /*
2 * Copyright (C) 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Author: Xavi Garcia <[email protected]>
17 */
18 #include "MediaPlayerMprisMockInterface.h"
19
20 #include <memory>
21
22 QMap<QString, QString> getPropertiesMap()
23 {
24 QMap<QString, QString> retMap;
25
26 retMap["CANPLAY"] = "setCanPlay";
27 retMap["CANPAUSE"] = "setCanPause";
28 retMap["CANGONEXT"] = "setCanGoNext";
29 retMap["CANGOPREVIOUS"] = "setCanGoPrevious";
30
31 return retMap;
32 }
33
34 bool getBoolValue(QString const & str)
35 {
36 if (str == "TRUE")
37 {
38 return true;
39 }
40 return false;
41 }
42
43 QTextStream& qStdErr()
44 {
45 static QTextStream ts( stderr );
46 return ts;
47 }
48
49 int main(int argc, char **argv)
50 {
51 QCoreApplication app(argc, argv);
52
53 if (argc != 4)
54 {
55 qStdErr() << "usage: " << argv[0] << "TEST_PLAYER_NAME PropertyName true|false\n";
56 return 1;
57 }
58
59 QString state = QString(argv[3]).toUpper();
60 QString property = QString(argv[2]).toUpper();
61 QString playerName = QString(argv[1]);
62
63 auto propertiesMap = getPropertiesMap();
64
65 std::shared_ptr<MediaPlayerMprisMockInterface> iface(
66 new MediaPlayerMprisMockInterface("org.mpris.MediaPlayer2." + playerName,
67 "/org/mpris/MediaPlayer2",
68 QDBusConnection::sessionBus()));
69 if (!iface)
70 {
71 qWarning() << argv[0] << ": error creating interface";
72 return 1;
73 }
74
75 QMap<QString, QString>::iterator iter = propertiesMap.find(property);
76 if (iter == propertiesMap.end())
77 {
78 qWarning() << argv[0] << ": property " << property << " was not found.";
79 return 1;
80 }
81
82 QDBusReply<void> set_prop = iface->call(QLatin1String((*iter).toStdString().c_str()),
83 QVariant::fromValue(getBoolValue(state)));
84
85 if (!set_prop.isValid())
86 {
87 qWarning() << argv[0] << ": D-Bus error: " << set_prop.error().message();
88 return 1;
89 }
90
91 return 0;
92 }
93