Merge lp:~jamesh/mediascanner2/dbus-transport into lp:mediascanner2

Proposed by James Henstridge
Status: Merged
Merged at revision: 232
Proposed branch: lp:~jamesh/mediascanner2/dbus-transport
Merge into: lp:mediascanner2
Prerequisite: lp:~jamesh/mediascanner2/mediafile-constructor
Diff against target: 1336 lines (+1054/-10)
26 files modified
CMakeLists.txt (+2/-0)
debian/control (+4/-0)
debian/mediascanner2.0.install (+2/-0)
src/mediascanner/Album.cc (+3/-0)
src/mediascanner/Album.hh (+1/-1)
src/mediascanner/MediaFile.cc (+3/-0)
src/mediascanner/MediaFile.hh (+1/-1)
src/mediascanner/MediaStore.cc (+1/-1)
src/mediascanner/MediaStore.hh (+1/-1)
src/ms-dbus/CMakeLists.txt (+33/-0)
src/ms-dbus/com.canonical.MediaScanner2.service.in (+3/-0)
src/ms-dbus/dbus-codec.cc (+90/-0)
src/ms-dbus/dbus-codec.hh (+87/-0)
src/ms-dbus/dbus-interface.hh (+153/-0)
src/ms-dbus/main.cc (+38/-0)
src/ms-dbus/service-skeleton.cc (+232/-0)
src/ms-dbus/service-skeleton.hh (+51/-0)
src/ms-dbus/service-stub.cc (+103/-0)
src/ms-dbus/service-stub.hh (+61/-0)
src/ms-dbus/service.hh (+62/-0)
src/qml/Ubuntu/MediaScanner/CMakeLists.txt (+2/-1)
src/qml/Ubuntu/MediaScanner/MediaStoreWrapper.cc (+15/-1)
src/qml/Ubuntu/MediaScanner/MediaStoreWrapper.hh (+3/-2)
test/CMakeLists.txt (+6/-2)
test/test_dbus.cc (+67/-0)
test/test_qml.cc (+30/-0)
To merge this branch: bzr merge lp:~jamesh/mediascanner2/dbus-transport
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Jussi Pakkanen (community) Needs Fixing
Review via email: mp+220752@code.launchpad.net

Commit message

Add a D-Bus service exposing the MediaStore, and move the QML binding over to using it.

Description of the change

Add a D-Bus service exposing the MediaStore, and move the QML binding over to using it.

Eventually the libmediascanner MediaStore API should be going through this API, but I decided to move the QML binding over first before refactoring the core.

The impetus for this change is to allow for more fine grained control of access to the index from confined applications (which is also to come).

The no-argument MediaFile and Album constructors were necessary to work with libdbus-cpp's templates.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
252. By James Henstridge

Build-Depend on libdbus-1-dev.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
253. By James Henstridge

Build-Depend on libproperties-cpp-dev.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Jussi Pakkanen (jpakkane) wrote :

Looking good. All the dbus stuff is nicely isolated in its own thing away from the core. There are a few issues, though, but they are more fundamental than actual code problems.

> +set_target_properties(ms-dbus PROPERTIES COMPILE_FLAGS "-fPIC")

I assume this is because this library is used as part of the qml module? If yes, please add a comment above this line saying so.

> The no-argument MediaFile and Album constructors were necessary to work with
> libdbus-cpp's templates.

This is bad. It destroys the security we worked so hard to build into Mediafiles, namely that it is very hard to construct an invalid one. I would classify this as a bug in dbus-cpp, an RPC library should not place these sorts of requirements on the classes it handles. Could you file a bug on dbus-cpp about this with all the necessary information?

I'm also worried about the mixed technologies here. We are already dealing with quite a lot of Qt stuff and instead of using Qt's dbus system we use a different one. But since that ship has already sailed, let's go with this. We can always change it later thanks to the proper isolation of dbus from the core.

review: Needs Fixing
254. By James Henstridge

Add a comment explaining why the helper D-Bus library is linked with -fPIC.

Revision history for this message
James Henstridge (jamesh) wrote :

I've added a comment to the make file.

I've filed a bug report here:

https://bugs.launchpad.net/dbus-cpp/+bug/1322611

For reference, here is the class that required the default constructors:

http://bazaar.launchpad.net/~phablet-team/dbus-cpp/trunk/view/head:/include/core/dbus/result.h#L36

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
255. By James Henstridge

Remove some excess debug logging.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2014-03-28 03:43:17 +0000
+++ CMakeLists.txt 2014-05-24 09:41:18 +0000
@@ -15,6 +15,7 @@
15 sqlite315 sqlite3
16)16)
17pkg_check_modules(GST gstreamer-1.0 gstreamer-pbutils-1.0 REQUIRED)17pkg_check_modules(GST gstreamer-1.0 gstreamer-pbutils-1.0 REQUIRED)
18pkg_check_modules(DBUSCPP dbus-cpp REQUIRED)
18find_package(Threads REQUIRED)19find_package(Threads REQUIRED)
19find_package(Qt5Core REQUIRED)20find_package(Qt5Core REQUIRED)
2021
@@ -32,6 +33,7 @@
3233
33add_subdirectory(src/mediascanner)34add_subdirectory(src/mediascanner)
34add_subdirectory(src/daemon)35add_subdirectory(src/daemon)
36add_subdirectory(src/ms-dbus)
35add_subdirectory(src/qml/Ubuntu/MediaScanner)37add_subdirectory(src/qml/Ubuntu/MediaScanner)
36add_subdirectory(src/utils)38add_subdirectory(src/utils)
37add_subdirectory(test)39add_subdirectory(test)
3840
=== modified file 'debian/control'
--- debian/control 2014-03-28 03:43:17 +0000
+++ debian/control 2014-05-24 09:41:18 +0000
@@ -4,11 +4,15 @@
4Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com>4Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com>
5Standards-Version: 3.9.55Standards-Version: 3.9.5
6Build-Depends: cmake,6Build-Depends: cmake,
7 dbus,
7 debhelper (>= 9),8 debhelper (>= 9),
9 libdbus-1-dev,
10 libdbus-cpp-dev (>= 3.0.0),
8 libglib2.0-dev,11 libglib2.0-dev,
9 libgstreamer-plugins-base1.0-dev,12 libgstreamer-plugins-base1.0-dev,
10 libgstreamer1.0-dev,13 libgstreamer1.0-dev,
11 libgtest-dev,14 libgtest-dev,
15 libproperties-cpp-dev,
12 libsqlite3-dev,16 libsqlite3-dev,
13 qt5-default,17 qt5-default,
14 qtbase5-dev,18 qtbase5-dev,
1519
=== modified file 'debian/mediascanner2.0.install'
--- debian/mediascanner2.0.install 2013-12-18 10:57:10 +0000
+++ debian/mediascanner2.0.install 2014-05-24 09:41:18 +0000
@@ -1,2 +1,4 @@
1usr/bin/*1usr/bin/*
2usr/lib/*/mediascanner-2.0/mediascanner-dbus-2.0
3usr/share/dbus-1/services/*
2usr/share/upstart/sessions/*4usr/share/upstart/sessions/*
35
=== modified file 'src/mediascanner/Album.cc'
--- src/mediascanner/Album.cc 2014-01-31 08:21:13 +0000
+++ src/mediascanner/Album.cc 2014-05-24 09:41:18 +0000
@@ -23,6 +23,9 @@
2323
24namespace mediascanner {24namespace mediascanner {
2525
26Album::Album() {
27}
28
26Album::Album(const std::string &title, const std::string &artist)29Album::Album(const std::string &title, const std::string &artist)
27 : title(title), artist(artist) {30 : title(title), artist(artist) {
28}31}
2932
=== modified file 'src/mediascanner/Album.hh'
--- src/mediascanner/Album.hh 2014-01-31 08:21:13 +0000
+++ src/mediascanner/Album.hh 2014-05-24 09:41:18 +0000
@@ -27,8 +27,8 @@
27class Album final {27class Album final {
28public:28public:
2929
30 Album();
30 Album(const std::string &title, const std::string &artist);31 Album(const std::string &title, const std::string &artist);
31 Album() = delete;
3232
33 const std::string& getTitle() const noexcept;33 const std::string& getTitle() const noexcept;
34 const std::string& getArtist() const noexcept;34 const std::string& getArtist() const noexcept;
3535
=== modified file 'src/mediascanner/MediaFile.cc'
--- src/mediascanner/MediaFile.cc 2014-05-24 09:41:18 +0000
+++ src/mediascanner/MediaFile.cc 2014-05-24 09:41:18 +0000
@@ -26,6 +26,9 @@
2626
27namespace mediascanner {27namespace mediascanner {
2828
29MediaFile::MediaFile() : p(new MediaFilePrivate) {
30}
31
29MediaFile::MediaFile(const MediaFile &other) :32MediaFile::MediaFile(const MediaFile &other) :
30 p(new MediaFilePrivate(*other.p)) {33 p(new MediaFilePrivate(*other.p)) {
31}34}
3235
=== modified file 'src/mediascanner/MediaFile.hh'
--- src/mediascanner/MediaFile.hh 2014-05-24 09:41:18 +0000
+++ src/mediascanner/MediaFile.hh 2014-05-24 09:41:18 +0000
@@ -32,7 +32,7 @@
32 friend class MediaFileBuilder;32 friend class MediaFileBuilder;
33public:33public:
3434
35 MediaFile() = delete;35 MediaFile();
36 MediaFile(const MediaFile &other);36 MediaFile(const MediaFile &other);
37 MediaFile(const MediaFileBuilder &builder);37 MediaFile(const MediaFileBuilder &builder);
38 MediaFile(MediaFileBuilder &&builder);38 MediaFile(MediaFileBuilder &&builder);
3939
=== modified file 'src/mediascanner/MediaStore.cc'
--- src/mediascanner/MediaStore.cc 2014-05-24 09:41:18 +0000
+++ src/mediascanner/MediaStore.cc 2014-05-24 09:41:18 +0000
@@ -514,7 +514,7 @@
514 return collect_albums(query);514 return collect_albums(query);
515}515}
516516
517vector<std::string> MediaStore::listArtists(bool album_artists, int limit) {517vector<std::string> MediaStore::listArtists(bool album_artists, int limit) const {
518 const char *qs;518 const char *qs;
519519
520 if (album_artists) {520 if (album_artists) {
521521
=== modified file 'src/mediascanner/MediaStore.hh'
--- src/mediascanner/MediaStore.hh 2014-02-28 06:47:48 +0000
+++ src/mediascanner/MediaStore.hh 2014-05-24 09:41:18 +0000
@@ -55,7 +55,7 @@
55 std::string getETag(const std::string &filename) const;55 std::string getETag(const std::string &filename) const;
56 std::vector<MediaFile> listSongs(const std::string& artist="", const std::string& album="", const std::string& album_artist="", int limit=-1) const;56 std::vector<MediaFile> listSongs(const std::string& artist="", const std::string& album="", const std::string& album_artist="", int limit=-1) const;
57 std::vector<Album> listAlbums(const std::string& artist="", const std::string& album_artist="", int limit=-1) const;57 std::vector<Album> listAlbums(const std::string& artist="", const std::string& album_artist="", int limit=-1) const;
58 std::vector<std::string> listArtists(bool album_artists, int limit=-1);58 std::vector<std::string> listArtists(bool album_artists, int limit=-1) const;
5959
60 size_t size() const;60 size_t size() const;
61 void pruneDeleted();61 void pruneDeleted();
6262
=== added directory 'src/ms-dbus'
=== added file 'src/ms-dbus/CMakeLists.txt'
--- src/ms-dbus/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ src/ms-dbus/CMakeLists.txt 2014-05-24 09:41:18 +0000
@@ -0,0 +1,33 @@
1include_directories(..)
2add_definitions(${MEDIASCANNER_CFLAGS} ${DBUSCPP_CFLAGS})
3
4add_library(ms-dbus STATIC
5 dbus-codec.cc
6 service-skeleton.cc
7 service-stub.cc
8)
9
10target_link_libraries(ms-dbus mediascanner ${DBUSCPP_LDFLAGS})
11# Compile with -fPIC, since this code is linked into the QML plugin.
12set_target_properties(ms-dbus PROPERTIES COMPILE_FLAGS "-fPIC")
13
14add_executable(mediascanner-dbus
15 main.cc
16)
17target_link_libraries(mediascanner-dbus ms-dbus)
18set_target_properties(mediascanner-dbus
19 PROPERTIES OUTPUT_NAME "mediascanner-dbus-2.0")
20
21install(
22 TARGETS mediascanner-dbus
23 RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/mediascanner-2.0
24)
25
26configure_file(
27 com.canonical.MediaScanner2.service.in
28 com.canonical.MediaScanner2.service)
29
30install(
31 FILES ${CMAKE_CURRENT_BINARY_DIR}/com.canonical.MediaScanner2.service
32 DESTINATION ${CMAKE_INSTALL_DATADIR}/dbus-1/services
33)
034
=== added file 'src/ms-dbus/com.canonical.MediaScanner2.service.in'
--- src/ms-dbus/com.canonical.MediaScanner2.service.in 1970-01-01 00:00:00 +0000
+++ src/ms-dbus/com.canonical.MediaScanner2.service.in 2014-05-24 09:41:18 +0000
@@ -0,0 +1,3 @@
1[D-BUS Service]
2Name=com.canonical.Thumbnailer
3Exec=@CMAKE_INSTALL_LIBDIR@/mediascanner-2.0/mediascanner-dbus-2.0
04
=== added file 'src/ms-dbus/dbus-codec.cc'
--- src/ms-dbus/dbus-codec.cc 1970-01-01 00:00:00 +0000
+++ src/ms-dbus/dbus-codec.cc 2014-05-24 09:41:18 +0000
@@ -0,0 +1,90 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * James Henstridge <james.henstridge@canonical.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License version 3 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#include <cstdint>
20#include <string>
21
22#include <core/dbus/object.h>
23
24#include <mediascanner/MediaFile.hh>
25#include <mediascanner/MediaFileBuilder.hh>
26#include <mediascanner/Album.hh>
27#include "dbus-codec.hh"
28
29using core::dbus::Message;
30using core::dbus::Codec;
31using mediascanner::MediaFile;
32using mediascanner::MediaFileBuilder;
33using mediascanner::MediaType;
34using mediascanner::Album;
35using std::string;
36
37void Codec<MediaFile>::encode_argument(Message::Writer &out, const MediaFile &file) {
38 auto w = out.open_structure();
39 core::dbus::encode_argument(w, file.getFileName());
40 core::dbus::encode_argument(w, file.getContentType());
41 core::dbus::encode_argument(w, file.getETag());
42 core::dbus::encode_argument(w, file.getTitle());
43 core::dbus::encode_argument(w, file.getAuthor());
44 core::dbus::encode_argument(w, file.getAlbum());
45 core::dbus::encode_argument(w, file.getAlbumArtist());
46 core::dbus::encode_argument(w, file.getDate());
47 core::dbus::encode_argument(w, file.getGenre());
48 core::dbus::encode_argument(w, (int32_t)file.getDiscNumber());
49 core::dbus::encode_argument(w, (int32_t)file.getTrackNumber());
50 core::dbus::encode_argument(w, (int32_t)file.getDuration());
51 core::dbus::encode_argument(w, (int32_t)file.getType());
52 out.close_structure(std::move(w));
53}
54
55void Codec<MediaFile>::decode_argument(Message::Reader &in, MediaFile &file) {
56 auto r = in.pop_structure();
57 string filename, content_type, etag, title, author;
58 string album, album_artist, date, genre;
59 int32_t disc_number, track_number, duration, type;
60 r >> filename >> content_type >> etag >> title >> author
61 >> album >> album_artist >> date >> genre
62 >> disc_number >> track_number >> duration >> type;
63 file = MediaFileBuilder(filename)
64 .setContentType(content_type)
65 .setETag(etag)
66 .setTitle(title)
67 .setAuthor(author)
68 .setAlbum(album)
69 .setAlbumArtist(album_artist)
70 .setDate(date)
71 .setGenre(genre)
72 .setDiscNumber(disc_number)
73 .setTrackNumber(track_number)
74 .setDuration(duration)
75 .setType((MediaType)type);
76}
77
78void Codec<Album>::encode_argument(Message::Writer &out, const Album &album) {
79 auto w = out.open_structure();
80 core::dbus::encode_argument(w, album.getTitle());
81 core::dbus::encode_argument(w, album.getArtist());
82 out.close_structure(std::move(w));
83}
84
85void Codec<Album>::decode_argument(Message::Reader &in, Album &album) {
86 auto r = in.pop_structure();
87 string title, artist;
88 r >> title >> artist;
89 album = Album(title, artist);
90}
091
=== added file 'src/ms-dbus/dbus-codec.hh'
--- src/ms-dbus/dbus-codec.hh 1970-01-01 00:00:00 +0000
+++ src/ms-dbus/dbus-codec.hh 2014-05-24 09:41:18 +0000
@@ -0,0 +1,87 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * James Henstridge <james.henstridge@canonical.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License version 3 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#ifndef MEDIASCANNER_DBUS_CODEC_HH
20#define MEDIASCANNER_DBUS_CODEC_HH
21
22#include <string>
23
24#include <core/dbus/codec.h>
25#include <core/dbus/helper/type_mapper.h>
26
27namespace mediascanner {
28class MediaFile;
29class Album;
30}
31
32namespace core {
33namespace dbus {
34
35template <>
36struct Codec<mediascanner::MediaFile> {
37 static void encode_argument(Message::Writer &out, const mediascanner::MediaFile &file);
38 static void decode_argument(Message::Reader &in, mediascanner::MediaFile &file);
39};
40
41template <>
42struct Codec<mediascanner::Album> {
43 static void encode_argument(Message::Writer &out, const mediascanner::Album &album);
44 static void decode_argument(Message::Reader &in, mediascanner::Album &album);
45};
46
47namespace helper {
48
49template<>
50struct TypeMapper<mediascanner::MediaFile> {
51 constexpr static ArgumentType type_value() {
52 return ArgumentType::structure;
53 }
54 constexpr static bool is_basic_type() {
55 return false;
56 }
57 constexpr static bool requires_signature() {
58 return true;
59 }
60 static const std::string &signature() {
61 static const std::string s = "(sssssssssiiii)";
62 return s;
63 }
64};
65
66template<>
67struct TypeMapper<mediascanner::Album> {
68 constexpr static ArgumentType type_value() {
69 return ArgumentType::structure;
70 }
71 constexpr static bool is_basic_type() {
72 return false;
73 }
74 constexpr static bool requires_signature() {
75 return true;
76 }
77 static const std::string &signature() {
78 static const std::string s = "(ss)";
79 return s;
80 }
81};
82
83}
84
85}
86}
87#endif
088
=== added file 'src/ms-dbus/dbus-interface.hh'
--- src/ms-dbus/dbus-interface.hh 1970-01-01 00:00:00 +0000
+++ src/ms-dbus/dbus-interface.hh 2014-05-24 09:41:18 +0000
@@ -0,0 +1,153 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * James Henstridge <james.henstridge@canonical.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License version 3 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19#ifndef MEDIASCANNER_DBUS_INTERFACE_HH
20#define MEDIASCANNER_DBUS_INTERFACE_HH
21
22#include <chrono>
23#include <string>
24
25#include <core/dbus/object.h>
26#include <core/dbus/service.h>
27
28namespace mediascanner {
29namespace dbus {
30
31struct MediaStoreInterface {
32 inline static const std::string& name() {
33 static std::string s = "com.canonical.MediaScanner2";
34 return s;
35 }
36
37 struct Errors {
38 struct Error {
39 inline static const std::string& name() {
40 static std::string s = "com.canonical.MediaScanner2.Error";
41 return s;
42 }
43 };
44 };
45
46 struct Lookup {
47 typedef MediaStoreInterface Interface;
48
49 inline static const std::string& name() {
50 static std::string s = "Lookup";
51 return s;
52 }
53
54 inline static const std::chrono::milliseconds default_timeout() {
55 return std::chrono::seconds{1};
56 }
57 };
58
59 struct Query {
60 typedef MediaStoreInterface Interface;
61
62 inline static const std::string& name() {
63 static std::string s = "Query";
64 return s;
65 }
66
67 inline static const std::chrono::milliseconds default_timeout() {
68 return std::chrono::seconds{1};
69 }
70 };
71
72 struct QueryAlbums {
73 typedef MediaStoreInterface Interface;
74
75 inline static const std::string& name() {
76 static std::string s = "QueryAlbums";
77 return s;
78 }
79
80 inline static const std::chrono::milliseconds default_timeout() {
81 return std::chrono::seconds{1};
82 }
83 };
84
85 struct GetAlbumSongs {
86 typedef MediaStoreInterface Interface;
87
88 inline static const std::string& name() {
89 static std::string s = "GetAlbumSongs";
90 return s;
91 }
92
93 inline static const std::chrono::milliseconds default_timeout() {
94 return std::chrono::seconds{1};
95 }
96 };
97
98 struct GetETag {
99 typedef MediaStoreInterface Interface;
100
101 inline static const std::string& name() {
102 static std::string s = "GetETag";
103 return s;
104 }
105
106 inline static const std::chrono::milliseconds default_timeout() {
107 return std::chrono::seconds{1};
108 }
109 };
110
111 struct ListSongs {
112 typedef MediaStoreInterface Interface;
113
114 inline static const std::string& name() {
115 static std::string s = "ListSongs";
116 return s;
117 }
118
119 inline static const std::chrono::milliseconds default_timeout() {
120 return std::chrono::seconds{1};
121 }
122 };
123
124 struct ListAlbums {
125 typedef MediaStoreInterface Interface;
126
127 inline static const std::string& name() {
128 static std::string s = "ListAlbums";
129 return s;
130 }
131
132 inline static const std::chrono::milliseconds default_timeout() {
133 return std::chrono::seconds{1};
134 }
135 };
136
137 struct ListArtists {
138 typedef MediaStoreInterface Interface;
139
140 inline static const std::string& name() {
141 static std::string s = "ListArtists";
142 return s;
143 }
144
145 inline static const std::chrono::milliseconds default_timeout() {
146 return std::chrono::seconds{1};
147 }
148 };
149};
150
151}
152}
153#endif
0154
=== added file 'src/ms-dbus/main.cc'
--- src/ms-dbus/main.cc 1970-01-01 00:00:00 +0000
+++ src/ms-dbus/main.cc 2014-05-24 09:41:18 +0000
@@ -0,0 +1,38 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * James Henstridge <james.henstridge@canonical.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License version 3 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <memory>
21#include <core/dbus/bus.h>
22#include <core/dbus/asio/executor.h>
23
24#include <mediascanner/MediaStore.hh>
25#include "service-skeleton.hh"
26
27using namespace mediascanner;
28
29int main(int , char **) {
30 auto bus = std::make_shared<core::dbus::Bus>(core::dbus::WellKnownBus::session);
31 bus->install_executor(core::dbus::asio::make_executor(bus));
32
33 auto store = std::make_shared<MediaStore>(MS_READ_ONLY);
34
35 dbus::ServiceSkeleton service(bus, store);
36 service.run();
37 return 0;
38}
039
=== added file 'src/ms-dbus/service-skeleton.cc'
--- src/ms-dbus/service-skeleton.cc 1970-01-01 00:00:00 +0000
+++ src/ms-dbus/service-skeleton.cc 2014-05-24 09:41:18 +0000
@@ -0,0 +1,232 @@
1#include <stdexcept>
2
3#include <core/dbus/message.h>
4#include <core/dbus/object.h>
5#include <core/dbus/types/object_path.h>
6
7#include <mediascanner/Album.hh>
8#include <mediascanner/MediaFile.hh>
9#include <mediascanner/MediaStore.hh>
10
11#include "dbus-interface.hh"
12#include "dbus-codec.hh"
13#include "service-skeleton.hh"
14
15using core::dbus::Message;
16
17namespace mediascanner {
18namespace dbus {
19
20struct ServiceSkeleton::Private {
21 ServiceSkeleton *impl;
22 std::shared_ptr<MediaStore> store;
23 core::dbus::Object::Ptr object;
24
25 Private(ServiceSkeleton *impl, std::shared_ptr<MediaStore> store) :
26 impl(impl),
27 store(store),
28 object(impl->access_service()->add_object_for_path(
29 core::dbus::traits::Service<MediaStoreService>::object_path())) {
30 object->install_method_handler<MediaStoreInterface::Lookup>(
31 std::bind(
32 &Private::handle_lookup,
33 this,
34 std::placeholders::_1));
35 object->install_method_handler<MediaStoreInterface::Query>(
36 std::bind(
37 &Private::handle_query,
38 this,
39 std::placeholders::_1));
40 object->install_method_handler<MediaStoreInterface::QueryAlbums>(
41 std::bind(
42 &Private::handle_query_albums,
43 this,
44 std::placeholders::_1));
45 object->install_method_handler<MediaStoreInterface::GetAlbumSongs>(
46 std::bind(
47 &Private::handle_get_album_songs,
48 this,
49 std::placeholders::_1));
50 object->install_method_handler<MediaStoreInterface::GetETag>(
51 std::bind(
52 &Private::handle_get_etag,
53 this,
54 std::placeholders::_1));
55 object->install_method_handler<MediaStoreInterface::ListSongs>(
56 std::bind(
57 &Private::handle_list_songs,
58 this,
59 std::placeholders::_1));
60 object->install_method_handler<MediaStoreInterface::ListAlbums>(
61 std::bind(
62 &Private::handle_list_albums,
63 this,
64 std::placeholders::_1));
65 object->install_method_handler<MediaStoreInterface::ListArtists>(
66 std::bind(
67 &Private::handle_list_artists,
68 this,
69 std::placeholders::_1));
70 }
71
72 void handle_lookup(const Message::Ptr &message) {
73 std::string filename;
74 message->reader() >> filename;
75 Message::Ptr reply;
76 try {
77 MediaFile file = store->lookup(filename);
78 reply = Message::make_method_return(message);
79 reply->writer() << file;
80 } catch (const std::exception &e) {
81 reply = Message::make_error(
82 message, MediaStoreInterface::Errors::Error::name(),
83 e.what());
84 }
85 impl->access_bus()->send(reply);
86 }
87
88 void handle_query(const Message::Ptr &message) {
89 std::string query;
90 int32_t type;
91 int32_t limit;
92
93 message->reader() >> query >> type >> limit;
94 Message::Ptr reply;
95 try {
96 auto results = store->query(query, (MediaType)type, limit);
97 reply = Message::make_method_return(message);
98 reply->writer() << results;
99 } catch (const std::exception &e) {
100 reply = Message::make_error(
101 message, MediaStoreInterface::Errors::Error::name(),
102 e.what());
103 }
104 impl->access_bus()->send(reply);
105 }
106
107 void handle_query_albums(const Message::Ptr &message) {
108 std::string query;
109 int32_t limit;
110
111 message->reader() >> query >> limit;
112 Message::Ptr reply;
113 try {
114 auto albums = store->queryAlbums(query, limit);
115 reply = Message::make_method_return(message);
116 reply->writer() << albums;
117 } catch (const std::exception &e) {
118 reply = Message::make_error(
119 message, MediaStoreInterface::Errors::Error::name(),
120 e.what());
121 }
122 impl->access_bus()->send(reply);
123 }
124
125 void handle_get_album_songs(const Message::Ptr &message) {
126 Album album("", "");
127
128 message->reader() >> album;
129 Message::Ptr reply;
130 try {
131 auto results = store->getAlbumSongs(album);
132 reply = Message::make_method_return(message);
133 reply->writer() << results;
134 } catch (const std::exception &e) {
135 reply = Message::make_error(
136 message, MediaStoreInterface::Errors::Error::name(),
137 e.what());
138 }
139 impl->access_bus()->send(reply);
140 }
141
142 void handle_get_etag(const Message::Ptr &message) {
143 std::string filename;
144 message->reader() >> filename;
145
146 Message::Ptr reply;
147 try {
148 std::string etag = store->getETag(filename);
149 reply = Message::make_method_return(message);
150 reply->writer() << etag;
151 } catch (const std::exception &e) {
152 reply = Message::make_error(
153 message, MediaStoreInterface::Errors::Error::name(),
154 e.what());
155 }
156 impl->access_bus()->send(reply);
157 }
158
159 void handle_list_songs(const Message::Ptr &message) {
160 std::string artist, album, album_artist;
161 int32_t limit;
162
163 message->reader() >> artist >> album >> album_artist >> limit;
164 Message::Ptr reply;
165 try {
166 auto results = store->listSongs(artist, album, album_artist, limit);
167 reply = Message::make_method_return(message);
168 reply->writer() << results;
169 } catch (const std::exception &e) {
170 reply = Message::make_error(
171 message, MediaStoreInterface::Errors::Error::name(),
172 e.what());
173 }
174 impl->access_bus()->send(reply);
175 }
176
177 void handle_list_albums(const Message::Ptr &message) {
178 std::string artist, album_artist;
179 int32_t limit;
180
181 message->reader() >> artist >> album_artist >> limit;
182 Message::Ptr reply;
183 try {
184 auto albums = store->listAlbums(artist, album_artist, limit);
185 reply = Message::make_method_return(message);
186 reply->writer() << albums;
187 } catch (const std::exception &e) {
188 reply = Message::make_error(
189 message, MediaStoreInterface::Errors::Error::name(),
190 e.what());
191 }
192 impl->access_bus()->send(reply);
193 }
194
195 void handle_list_artists(const Message::Ptr &message) {
196 bool album_artists;
197 int32_t limit;
198
199 message->reader() >> album_artists >> limit;
200 Message::Ptr reply;
201 try {
202 auto artists = store->listArtists(album_artists, limit);
203 reply = Message::make_method_return(message);
204 reply->writer() << artists;
205 } catch (const std::exception &e) {
206 reply = Message::make_error(
207 message, MediaStoreInterface::Errors::Error::name(),
208 e.what());
209 }
210 impl->access_bus()->send(reply);
211 }
212};
213
214ServiceSkeleton::ServiceSkeleton(core::dbus::Bus::Ptr bus,
215 std::shared_ptr<MediaStore> store) :
216 core::dbus::Skeleton<MediaStoreService>(bus),
217 p(new Private(this, store)) {
218}
219
220ServiceSkeleton::~ServiceSkeleton() {
221}
222
223void ServiceSkeleton::run() {
224 access_bus()->run();
225}
226
227void ServiceSkeleton::stop() {
228 access_bus()->stop();
229}
230
231}
232}
0233
=== added file 'src/ms-dbus/service-skeleton.hh'
--- src/ms-dbus/service-skeleton.hh 1970-01-01 00:00:00 +0000
+++ src/ms-dbus/service-skeleton.hh 2014-05-24 09:41:18 +0000
@@ -0,0 +1,51 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * James Henstridge <james.henstridge@canonical.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License version 3 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef MEDIASCANNER_DBUS_SERVICE_SKELETON_HH
21#define MEDIASCANNER_DBUS_SERVICE_SKELETON_HH
22
23#include <memory>
24#include <core/dbus/bus.h>
25#include <core/dbus/skeleton.h>
26
27#include "service.hh"
28
29namespace mediascanner {
30
31class MediaStore;
32
33namespace dbus {
34
35class ServiceSkeleton : public core::dbus::Skeleton<MediaStoreService> {
36public:
37 ServiceSkeleton(core::dbus::Bus::Ptr bus, std::shared_ptr<MediaStore> store);
38 ~ServiceSkeleton();
39
40 void run();
41 void stop();
42
43private:
44 struct Private;
45 std::unique_ptr<Private> p;
46};
47
48}
49}
50
51#endif
052
=== added file 'src/ms-dbus/service-stub.cc'
--- src/ms-dbus/service-stub.cc 1970-01-01 00:00:00 +0000
+++ src/ms-dbus/service-stub.cc 2014-05-24 09:41:18 +0000
@@ -0,0 +1,103 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * James Henstridge <james.henstridge@canonical.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License version 3 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <stdexcept>
21
22#include <mediascanner/Album.hh>
23#include <mediascanner/MediaFile.hh>
24#include "service-stub.hh"
25#include "dbus-interface.hh"
26#include "dbus-codec.hh"
27
28using std::string;
29
30namespace mediascanner {
31namespace dbus {
32
33struct ServiceStub::Private
34{
35 core::dbus::Object::Ptr object;
36};
37
38ServiceStub::ServiceStub(core::dbus::Bus::Ptr bus)
39 : core::dbus::Stub<MediaStoreService>(bus),
40 p(new Private{access_service()->object_for_path(
41 core::dbus::types::ObjectPath(core::dbus::traits::Service<MediaStoreService>::object_path()))}) {
42}
43
44ServiceStub::~ServiceStub() {
45}
46
47MediaFile ServiceStub::lookup(const string &filename) const {
48 auto result = p->object->invoke_method_synchronously<MediaStoreInterface::Lookup, MediaFile>(filename);
49 if (result.is_error())
50 throw std::runtime_error(result.error().print());
51 return result.value();
52}
53
54std::vector<MediaFile> ServiceStub::query(const string &q, MediaType type, int limit) const {
55 auto result = p->object->invoke_method_synchronously<MediaStoreInterface::Query, std::vector<MediaFile>>(q, (int32_t)type, (int32_t)limit);
56 if (result.is_error())
57 throw std::runtime_error(result.error().print());
58 return result.value();
59}
60
61std::vector<Album> ServiceStub::queryAlbums(const string &core_term, int limit) const {
62 auto result = p->object->invoke_method_synchronously<MediaStoreInterface::QueryAlbums, std::vector<Album>>(core_term, (int32_t)limit);
63 if (result.is_error())
64 throw std::runtime_error(result.error().print());
65 return result.value();
66}
67
68std::vector<MediaFile> ServiceStub::getAlbumSongs(const Album& album) const {
69 auto result = p->object->invoke_method_synchronously<MediaStoreInterface::GetAlbumSongs, std::vector<MediaFile>>(album);
70 if (result.is_error())
71 throw std::runtime_error(result.error().print());
72 return result.value();
73}
74
75string ServiceStub::getETag(const string &filename) const {
76 auto result = p->object->invoke_method_synchronously<MediaStoreInterface::GetETag, string>(filename);
77 if (result.is_error())
78 throw std::runtime_error(result.error().print());
79 return result.value();
80}
81
82std::vector<MediaFile> ServiceStub::listSongs(const string &artist, const string &album, const string &album_artist, int limit) const {
83 auto result = p->object->invoke_method_synchronously<MediaStoreInterface::ListSongs, std::vector<MediaFile>>(artist, album, album_artist, (int32_t)limit);
84 if (result.is_error())
85 throw std::runtime_error(result.error().print());
86 return result.value();
87}
88
89std::vector<Album> ServiceStub::listAlbums(const string &artist, const string &album_artist, int limit) const {
90 auto result = p->object->invoke_method_synchronously<MediaStoreInterface::ListAlbums, std::vector<Album>>(artist, album_artist, (int32_t)limit);
91 if (result.is_error())
92 throw std::runtime_error(result.error().print());
93 return result.value();
94}
95std::vector<string> ServiceStub::listArtists(bool album_artists, int limit) const {
96 auto result = p->object->invoke_method_synchronously<MediaStoreInterface::ListArtists, std::vector<string>>(album_artists, (int32_t)limit);
97 if (result.is_error())
98 throw std::runtime_error(result.error().print());
99 return result.value();
100}
101
102}
103}
0104
=== added file 'src/ms-dbus/service-stub.hh'
--- src/ms-dbus/service-stub.hh 1970-01-01 00:00:00 +0000
+++ src/ms-dbus/service-stub.hh 2014-05-24 09:41:18 +0000
@@ -0,0 +1,61 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * James Henstridge <james.henstridge@canonical.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License version 3 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef MEDIASCANNER_DBUS_SERVICE_STUB_HH
21#define MEDIASCANNER_DBUS_SERVICE_STUB_HH
22
23#include <memory>
24#include <string>
25#include <vector>
26#include <core/dbus/bus.h>
27#include <core/dbus/stub.h>
28
29#include <mediascanner/scannercore.hh>
30#include "service.hh"
31
32namespace mediascanner {
33
34class Album;
35class MediaFile;
36
37namespace dbus {
38
39class ServiceStub : public core::dbus::Stub<MediaStoreService> {
40public:
41 ServiceStub(core::dbus::Bus::Ptr bus);
42 ~ServiceStub();
43
44 MediaFile lookup(const std::string &filename) const;
45 std::vector<MediaFile> query(const std::string &q, MediaType type, int limit=-1) const;
46 std::vector<Album> queryAlbums(const std::string &core_term, int limit=-1) const;
47 std::vector<MediaFile> getAlbumSongs(const Album& album) const;
48 std::string getETag(const std::string &filename) const;
49 std::vector<MediaFile> listSongs(const std::string& artist="", const std::string& album="", const std::string& album_artist="", int limit=-1) const;
50 std::vector<Album> listAlbums(const std::string& artist="", const std::string& album_artist="", int limit=-1) const;
51 std::vector<std::string> listArtists(bool album_artists, int limit=-1) const;
52
53private:
54 struct Private;
55 std::unique_ptr<Private> p;
56};
57
58}
59}
60
61#endif
062
=== added file 'src/ms-dbus/service.hh'
--- src/ms-dbus/service.hh 1970-01-01 00:00:00 +0000
+++ src/ms-dbus/service.hh 2014-05-24 09:41:18 +0000
@@ -0,0 +1,62 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * James Henstridge <james.henstridge@canonical.com>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License version 3 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef MEDIASCANNER_DBUS_SERVICE_HH
21#define MEDIASCANNER_DBUS_SERVICE_HH
22
23#include <core/dbus/traits/service.h>
24
25namespace mediascanner {
26namespace dbus {
27
28class MediaStoreService {
29public:
30 MediaStoreService() {}
31
32 MediaStoreService(const MediaStoreService&) = delete;
33 virtual ~MediaStoreService() = default;
34
35 MediaStoreService& operator=(const MediaStoreService&) = delete;
36 bool operator==(const MediaStoreService&) const = delete;
37};
38
39}
40}
41
42namespace core {
43namespace dbus {
44namespace traits {
45
46template<>
47struct Service<mediascanner::dbus::MediaStoreService> {
48 inline static const std::string& interface_name() {
49 static const std::string iface("com.canonical.MediaScaner2");
50 return iface;
51 }
52 inline static const std::string& object_path() {
53 static const std::string path("/com/canonical/MediaScanner2");
54 return path;
55 }
56};
57
58}
59}
60}
61
62#endif
063
=== modified file 'src/qml/Ubuntu/MediaScanner/CMakeLists.txt'
--- src/qml/Ubuntu/MediaScanner/CMakeLists.txt 2014-03-24 10:04:19 +0000
+++ src/qml/Ubuntu/MediaScanner/CMakeLists.txt 2014-05-24 09:41:18 +0000
@@ -1,4 +1,5 @@
1include_directories(../../..)1include_directories(../../..)
2add_definitions(${DBUSCPP_CFLAGS} -DQT_NO_KEYWORDS)
23
3set(QML_PLUGIN_DIR "${CMAKE_INSTALL_LIBDIR}/qt5/qml/Ubuntu/MediaScanner.0.1")4set(QML_PLUGIN_DIR "${CMAKE_INSTALL_LIBDIR}/qt5/qml/Ubuntu/MediaScanner.0.1")
45
@@ -17,7 +18,7 @@
1718
18set_target_properties(mediascanner-qml PROPERTIES AUTOMOC TRUE)19set_target_properties(mediascanner-qml PROPERTIES AUTOMOC TRUE)
19qt5_use_modules(mediascanner-qml Qml)20qt5_use_modules(mediascanner-qml Qml)
20target_link_libraries(mediascanner-qml mediascanner)21target_link_libraries(mediascanner-qml mediascanner ms-dbus)
2122
22install(23install(
23 TARGETS mediascanner-qml24 TARGETS mediascanner-qml
2425
=== modified file 'src/qml/Ubuntu/MediaScanner/MediaStoreWrapper.cc'
--- src/qml/Ubuntu/MediaScanner/MediaStoreWrapper.cc 2014-02-27 08:01:05 +0000
+++ src/qml/Ubuntu/MediaScanner/MediaStoreWrapper.cc 2014-05-24 09:41:18 +0000
@@ -20,10 +20,24 @@
20#include "MediaStoreWrapper.hh"20#include "MediaStoreWrapper.hh"
21#include <QQmlEngine>21#include <QQmlEngine>
2222
23#include <core/dbus/asio/executor.h>
24#include <ms-dbus/service-stub.hh>
25
23using namespace mediascanner::qml;26using namespace mediascanner::qml;
2427
28static core::dbus::Bus::Ptr the_session_bus() {
29 static core::dbus::Bus::Ptr bus = std::make_shared<core::dbus::Bus>(
30 core::dbus::WellKnownBus::session);
31 static core::dbus::Executor::Ptr executor = core::dbus::asio::make_executor(bus);
32 static std::once_flag once;
33
34 std::call_once(once, []() {bus->install_executor(executor);});
35
36 return bus;
37}
38
25MediaStoreWrapper::MediaStoreWrapper(QObject *parent)39MediaStoreWrapper::MediaStoreWrapper(QObject *parent)
26 : QObject(parent), store(MS_READ_ONLY) {40 : QObject(parent), store(the_session_bus()) {
27}41}
2842
29QList<QObject*> MediaStoreWrapper::query(const QString &q, MediaType type) {43QList<QObject*> MediaStoreWrapper::query(const QString &q, MediaType type) {
3044
=== modified file 'src/qml/Ubuntu/MediaScanner/MediaStoreWrapper.hh'
--- src/qml/Ubuntu/MediaScanner/MediaStoreWrapper.hh 2014-02-27 08:01:05 +0000
+++ src/qml/Ubuntu/MediaScanner/MediaStoreWrapper.hh 2014-05-24 09:41:18 +0000
@@ -24,10 +24,11 @@
24#include <QObject>24#include <QObject>
25#include <QString>25#include <QString>
2626
27#include <mediascanner/MediaStore.hh>27#include <ms-dbus/service-stub.hh>
28#include "MediaFileWrapper.hh"28#include "MediaFileWrapper.hh"
2929
30namespace mediascanner {30namespace mediascanner {
31
31namespace qml {32namespace qml {
3233
33class MediaStoreWrapper : public QObject {34class MediaStoreWrapper : public QObject {
@@ -44,7 +45,7 @@
44 Q_INVOKABLE QList<QObject*> query(const QString &q, MediaType type);45 Q_INVOKABLE QList<QObject*> query(const QString &q, MediaType type);
45 Q_INVOKABLE mediascanner::qml::MediaFileWrapper *lookup(const QString &filename);46 Q_INVOKABLE mediascanner::qml::MediaFileWrapper *lookup(const QString &filename);
4647
47 mediascanner::MediaStore store;48 mediascanner::dbus::ServiceStub store;
48};49};
4950
50}51}
5152
=== modified file 'test/CMakeLists.txt'
--- test/CMakeLists.txt 2014-05-02 08:53:16 +0000
+++ test/CMakeLists.txt 2014-05-24 09:41:18 +0000
@@ -17,7 +17,7 @@
17 set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-Wno-unused-private-field")17 set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-Wno-unused-private-field")
18endif()18endif()
1919
20add_definitions(${MEDIASCANNER_CFLAGS} ${GST_CFLAGS})20add_definitions(${MEDIASCANNER_CFLAGS} ${GST_CFLAGS} ${DBUSCPP_CFLAGS} -DQT_NO_KEYWORDS)
21include_directories(../src)21include_directories(../src)
2222
23configure_file(test_config.h.in test_config.h)23configure_file(test_config.h.in test_config.h)
@@ -43,9 +43,13 @@
43target_link_libraries(test_mfbuilder gtest mediascanner)43target_link_libraries(test_mfbuilder gtest mediascanner)
44add_test(test_mfbuilder test_mfbuilder)44add_test(test_mfbuilder test_mfbuilder)
4545
46add_executable(test_dbus test_dbus.cc)
47target_link_libraries(test_dbus gtest mediascanner ms-dbus)
48add_test(test_dbus test_dbus)
49
46add_executable(test_qml test_qml.cc)50add_executable(test_qml test_qml.cc)
47qt5_use_modules(test_qml QuickTest)51qt5_use_modules(test_qml QuickTest)
48target_link_libraries(test_qml mediascanner)52target_link_libraries(test_qml mediascanner ${DBUSCPP_LDFLAGS})
49add_test(test_qml test_qml -input ${CMAKE_CURRENT_SOURCE_DIR}/qml -import ${CMAKE_BINARY_DIR}/src/qml)53add_test(test_qml test_qml -input ${CMAKE_CURRENT_SOURCE_DIR}/qml -import ${CMAKE_BINARY_DIR}/src/qml)
50set_tests_properties(test_qml54set_tests_properties(test_qml
51 PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=minimal")55 PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=minimal")
5256
=== added file 'test/test_dbus.cc'
--- test/test_dbus.cc 1970-01-01 00:00:00 +0000
+++ test/test_dbus.cc 2014-05-24 09:41:18 +0000
@@ -0,0 +1,67 @@
1#include <gtest/gtest.h>
2#include <core/dbus/message.h>
3#include <core/dbus/object.h>
4#include <core/dbus/types/object_path.h>
5
6#include <mediascanner/Album.hh>
7#include <mediascanner/MediaFile.hh>
8#include <mediascanner/MediaFileBuilder.hh>
9#include <ms-dbus/dbus-codec.hh>
10
11class MediaStoreDBusTests : public ::testing::Test {
12};
13
14TEST_F(MediaStoreDBusTests, mediafile_codec) {
15 auto message = core::dbus::Message::make_method_call(
16 "org.example.Name",
17 core::dbus::types::ObjectPath("/org/example/Path"),
18 "org.example.Interface",
19 "Method");
20
21 mediascanner::MediaFile media = mediascanner::MediaFileBuilder("a")
22 .setContentType("type")
23 .setETag("etag")
24 .setDate("1900")
25 .setTitle("b")
26 .setAuthor("c")
27 .setAlbum("d")
28 .setAlbumArtist("e")
29 .setGenre("f")
30 .setDiscNumber(0)
31 .setTrackNumber(1)
32 .setDuration(5)
33 .setType(mediascanner::AudioMedia);
34 message->writer() << media;
35
36 EXPECT_EQ("(sssssssssiiii)", message->signature());
37 EXPECT_EQ(core::dbus::helper::TypeMapper<mediascanner::MediaFile>::signature(), message->signature());
38
39 mediascanner::MediaFile media2;
40 message->reader() >> media2;
41 EXPECT_EQ(media, media2);
42}
43
44TEST_F(MediaStoreDBusTests, album_codec) {
45 auto message = core::dbus::Message::make_method_call(
46 "org.example.Name",
47 core::dbus::types::ObjectPath("/org/example/Path"),
48 "org.example.Interface",
49 "Method");
50
51 mediascanner::Album album("title", "artist");
52 message->writer() << album;
53
54 EXPECT_EQ("(ss)", message->signature());
55 EXPECT_EQ(core::dbus::helper::TypeMapper<mediascanner::Album>::signature(), message->signature());
56
57 mediascanner::Album album2;
58 message->reader() >> album2;
59 EXPECT_EQ("title", album2.getTitle());
60 EXPECT_EQ("artist", album2.getArtist());
61 EXPECT_EQ(album, album2);
62}
63
64int main(int argc, char **argv) {
65 ::testing::InitGoogleTest(&argc, argv);
66 return RUN_ALL_TESTS();
67}
068
=== modified file 'test/test_qml.cc'
--- test/test_qml.cc 2014-05-24 09:41:18 +0000
+++ test/test_qml.cc 2014-05-24 09:41:18 +0000
@@ -1,12 +1,19 @@
1#include <stdlib.h>1#include <stdlib.h>
2#include <cstdio>
3#include <memory>
2#include <string>4#include <string>
35
6#include <QProcess>
4#include <QtQuickTest/quicktest.h>7#include <QtQuickTest/quicktest.h>
58
9#include <core/dbus/fixture.h>
10
6#include <mediascanner/MediaStore.hh>11#include <mediascanner/MediaStore.hh>
7#include <mediascanner/MediaFile.hh>12#include <mediascanner/MediaFile.hh>
8#include <mediascanner/MediaFileBuilder.hh>13#include <mediascanner/MediaFileBuilder.hh>
914
15#include "test_config.h"
16
10using namespace mediascanner;17using namespace mediascanner;
1118
12class MediaStoreData {19class MediaStoreData {
@@ -18,8 +25,29 @@
18 }25 }
19 setenv("MEDIASCANNER_CACHEDIR", db_path.c_str(), true);26 setenv("MEDIASCANNER_CACHEDIR", db_path.c_str(), true);
20 populate();27 populate();
28
29 // Start up private bus, and start daemon.
30 dbus_fixture.reset(
31 new core::dbus::Fixture(
32 core::dbus::Fixture::default_session_bus_config_file(),
33 core::dbus::Fixture::default_system_bus_config_file()));
34
35 daemon.setProgram(TEST_DIR "/../src/ms-dbus/mediascanner-dbus-2.0");
36 daemon.setProcessChannelMode(QProcess::ForwardedChannels);
37 daemon.start();
38 daemon.closeWriteChannel();
39 if (!daemon.waitForStarted()) {
40 throw std::runtime_error("Failed to start mediascanner-dbus-2.0");
41 }
21 }42 }
22 ~MediaStoreData() {43 ~MediaStoreData() {
44 daemon.kill();
45 if (!daemon.waitForFinished()) {
46 fprintf(stderr, "Failed to stop mediascanner-dbus-2.0\n");
47 }
48
49 dbus_fixture.reset();
50
23 if (system("rm -rf \"$MEDIASCANNER_CACHEDIR\"") == -1) {51 if (system("rm -rf \"$MEDIASCANNER_CACHEDIR\"") == -1) {
24 throw std::runtime_error("rm -rf failed");52 throw std::runtime_error("rm -rf failed");
25 }53 }
@@ -126,6 +154,8 @@
126154
127private:155private:
128 std::string db_path;156 std::string db_path;
157 std::unique_ptr<core::dbus::Fixture> dbus_fixture;
158 QProcess daemon;
129};159};
130160
131MediaStoreData data;161MediaStoreData data;

Subscribers

People subscribed via source and target branches