Merge lp:~jamesh/mediascanner2/dbus-transport into lp:mediascanner2
- dbus-transport
- Merge into trunk
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 |
Related bugs: |
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.
PS Jenkins bot (ps-jenkins) wrote : | # |
- 252. By James Henstridge
-
Build-Depend on libdbus-1-dev.
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:252
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
- 253. By James Henstridge
-
Build-Depend on libproperties-
cpp-dev.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:253
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
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_
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.
- 254. By James Henstridge
-
Add a comment explaining why the helper D-Bus library is linked with -fPIC.
James Henstridge (jamesh) wrote : | # |
I've added a comment to the make file.
I've filed a bug report here:
https:/
For reference, here is the class that required the default constructors:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:254
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
- 255. By James Henstridge
-
Remove some excess debug logging.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:255
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'CMakeLists.txt' | |||
2 | --- CMakeLists.txt 2014-03-28 03:43:17 +0000 | |||
3 | +++ CMakeLists.txt 2014-05-24 09:41:18 +0000 | |||
4 | @@ -15,6 +15,7 @@ | |||
5 | 15 | sqlite3 | 15 | sqlite3 |
6 | 16 | ) | 16 | ) |
7 | 17 | pkg_check_modules(GST gstreamer-1.0 gstreamer-pbutils-1.0 REQUIRED) | 17 | pkg_check_modules(GST gstreamer-1.0 gstreamer-pbutils-1.0 REQUIRED) |
8 | 18 | pkg_check_modules(DBUSCPP dbus-cpp REQUIRED) | ||
9 | 18 | find_package(Threads REQUIRED) | 19 | find_package(Threads REQUIRED) |
10 | 19 | find_package(Qt5Core REQUIRED) | 20 | find_package(Qt5Core REQUIRED) |
11 | 20 | 21 | ||
12 | @@ -32,6 +33,7 @@ | |||
13 | 32 | 33 | ||
14 | 33 | add_subdirectory(src/mediascanner) | 34 | add_subdirectory(src/mediascanner) |
15 | 34 | add_subdirectory(src/daemon) | 35 | add_subdirectory(src/daemon) |
16 | 36 | add_subdirectory(src/ms-dbus) | ||
17 | 35 | add_subdirectory(src/qml/Ubuntu/MediaScanner) | 37 | add_subdirectory(src/qml/Ubuntu/MediaScanner) |
18 | 36 | add_subdirectory(src/utils) | 38 | add_subdirectory(src/utils) |
19 | 37 | add_subdirectory(test) | 39 | add_subdirectory(test) |
20 | 38 | 40 | ||
21 | === modified file 'debian/control' | |||
22 | --- debian/control 2014-03-28 03:43:17 +0000 | |||
23 | +++ debian/control 2014-05-24 09:41:18 +0000 | |||
24 | @@ -4,11 +4,15 @@ | |||
25 | 4 | Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com> | 4 | Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com> |
26 | 5 | Standards-Version: 3.9.5 | 5 | Standards-Version: 3.9.5 |
27 | 6 | Build-Depends: cmake, | 6 | Build-Depends: cmake, |
28 | 7 | dbus, | ||
29 | 7 | debhelper (>= 9), | 8 | debhelper (>= 9), |
30 | 9 | libdbus-1-dev, | ||
31 | 10 | libdbus-cpp-dev (>= 3.0.0), | ||
32 | 8 | libglib2.0-dev, | 11 | libglib2.0-dev, |
33 | 9 | libgstreamer-plugins-base1.0-dev, | 12 | libgstreamer-plugins-base1.0-dev, |
34 | 10 | libgstreamer1.0-dev, | 13 | libgstreamer1.0-dev, |
35 | 11 | libgtest-dev, | 14 | libgtest-dev, |
36 | 15 | libproperties-cpp-dev, | ||
37 | 12 | libsqlite3-dev, | 16 | libsqlite3-dev, |
38 | 13 | qt5-default, | 17 | qt5-default, |
39 | 14 | qtbase5-dev, | 18 | qtbase5-dev, |
40 | 15 | 19 | ||
41 | === modified file 'debian/mediascanner2.0.install' | |||
42 | --- debian/mediascanner2.0.install 2013-12-18 10:57:10 +0000 | |||
43 | +++ debian/mediascanner2.0.install 2014-05-24 09:41:18 +0000 | |||
44 | @@ -1,2 +1,4 @@ | |||
45 | 1 | usr/bin/* | 1 | usr/bin/* |
46 | 2 | usr/lib/*/mediascanner-2.0/mediascanner-dbus-2.0 | ||
47 | 3 | usr/share/dbus-1/services/* | ||
48 | 2 | usr/share/upstart/sessions/* | 4 | usr/share/upstart/sessions/* |
49 | 3 | 5 | ||
50 | === modified file 'src/mediascanner/Album.cc' | |||
51 | --- src/mediascanner/Album.cc 2014-01-31 08:21:13 +0000 | |||
52 | +++ src/mediascanner/Album.cc 2014-05-24 09:41:18 +0000 | |||
53 | @@ -23,6 +23,9 @@ | |||
54 | 23 | 23 | ||
55 | 24 | namespace mediascanner { | 24 | namespace mediascanner { |
56 | 25 | 25 | ||
57 | 26 | Album::Album() { | ||
58 | 27 | } | ||
59 | 28 | |||
60 | 26 | Album::Album(const std::string &title, const std::string &artist) | 29 | Album::Album(const std::string &title, const std::string &artist) |
61 | 27 | : title(title), artist(artist) { | 30 | : title(title), artist(artist) { |
62 | 28 | } | 31 | } |
63 | 29 | 32 | ||
64 | === modified file 'src/mediascanner/Album.hh' | |||
65 | --- src/mediascanner/Album.hh 2014-01-31 08:21:13 +0000 | |||
66 | +++ src/mediascanner/Album.hh 2014-05-24 09:41:18 +0000 | |||
67 | @@ -27,8 +27,8 @@ | |||
68 | 27 | class Album final { | 27 | class Album final { |
69 | 28 | public: | 28 | public: |
70 | 29 | 29 | ||
71 | 30 | Album(); | ||
72 | 30 | Album(const std::string &title, const std::string &artist); | 31 | Album(const std::string &title, const std::string &artist); |
73 | 31 | Album() = delete; | ||
74 | 32 | 32 | ||
75 | 33 | const std::string& getTitle() const noexcept; | 33 | const std::string& getTitle() const noexcept; |
76 | 34 | const std::string& getArtist() const noexcept; | 34 | const std::string& getArtist() const noexcept; |
77 | 35 | 35 | ||
78 | === modified file 'src/mediascanner/MediaFile.cc' | |||
79 | --- src/mediascanner/MediaFile.cc 2014-05-24 09:41:18 +0000 | |||
80 | +++ src/mediascanner/MediaFile.cc 2014-05-24 09:41:18 +0000 | |||
81 | @@ -26,6 +26,9 @@ | |||
82 | 26 | 26 | ||
83 | 27 | namespace mediascanner { | 27 | namespace mediascanner { |
84 | 28 | 28 | ||
85 | 29 | MediaFile::MediaFile() : p(new MediaFilePrivate) { | ||
86 | 30 | } | ||
87 | 31 | |||
88 | 29 | MediaFile::MediaFile(const MediaFile &other) : | 32 | MediaFile::MediaFile(const MediaFile &other) : |
89 | 30 | p(new MediaFilePrivate(*other.p)) { | 33 | p(new MediaFilePrivate(*other.p)) { |
90 | 31 | } | 34 | } |
91 | 32 | 35 | ||
92 | === modified file 'src/mediascanner/MediaFile.hh' | |||
93 | --- src/mediascanner/MediaFile.hh 2014-05-24 09:41:18 +0000 | |||
94 | +++ src/mediascanner/MediaFile.hh 2014-05-24 09:41:18 +0000 | |||
95 | @@ -32,7 +32,7 @@ | |||
96 | 32 | friend class MediaFileBuilder; | 32 | friend class MediaFileBuilder; |
97 | 33 | public: | 33 | public: |
98 | 34 | 34 | ||
100 | 35 | MediaFile() = delete; | 35 | MediaFile(); |
101 | 36 | MediaFile(const MediaFile &other); | 36 | MediaFile(const MediaFile &other); |
102 | 37 | MediaFile(const MediaFileBuilder &builder); | 37 | MediaFile(const MediaFileBuilder &builder); |
103 | 38 | MediaFile(MediaFileBuilder &&builder); | 38 | MediaFile(MediaFileBuilder &&builder); |
104 | 39 | 39 | ||
105 | === modified file 'src/mediascanner/MediaStore.cc' | |||
106 | --- src/mediascanner/MediaStore.cc 2014-05-24 09:41:18 +0000 | |||
107 | +++ src/mediascanner/MediaStore.cc 2014-05-24 09:41:18 +0000 | |||
108 | @@ -514,7 +514,7 @@ | |||
109 | 514 | return collect_albums(query); | 514 | return collect_albums(query); |
110 | 515 | } | 515 | } |
111 | 516 | 516 | ||
113 | 517 | vector<std::string> MediaStore::listArtists(bool album_artists, int limit) { | 517 | vector<std::string> MediaStore::listArtists(bool album_artists, int limit) const { |
114 | 518 | const char *qs; | 518 | const char *qs; |
115 | 519 | 519 | ||
116 | 520 | if (album_artists) { | 520 | if (album_artists) { |
117 | 521 | 521 | ||
118 | === modified file 'src/mediascanner/MediaStore.hh' | |||
119 | --- src/mediascanner/MediaStore.hh 2014-02-28 06:47:48 +0000 | |||
120 | +++ src/mediascanner/MediaStore.hh 2014-05-24 09:41:18 +0000 | |||
121 | @@ -55,7 +55,7 @@ | |||
122 | 55 | std::string getETag(const std::string &filename) const; | 55 | std::string getETag(const std::string &filename) const; |
123 | 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; |
124 | 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; |
126 | 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; |
127 | 59 | 59 | ||
128 | 60 | size_t size() const; | 60 | size_t size() const; |
129 | 61 | void pruneDeleted(); | 61 | void pruneDeleted(); |
130 | 62 | 62 | ||
131 | === added directory 'src/ms-dbus' | |||
132 | === added file 'src/ms-dbus/CMakeLists.txt' | |||
133 | --- src/ms-dbus/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
134 | +++ src/ms-dbus/CMakeLists.txt 2014-05-24 09:41:18 +0000 | |||
135 | @@ -0,0 +1,33 @@ | |||
136 | 1 | include_directories(..) | ||
137 | 2 | add_definitions(${MEDIASCANNER_CFLAGS} ${DBUSCPP_CFLAGS}) | ||
138 | 3 | |||
139 | 4 | add_library(ms-dbus STATIC | ||
140 | 5 | dbus-codec.cc | ||
141 | 6 | service-skeleton.cc | ||
142 | 7 | service-stub.cc | ||
143 | 8 | ) | ||
144 | 9 | |||
145 | 10 | target_link_libraries(ms-dbus mediascanner ${DBUSCPP_LDFLAGS}) | ||
146 | 11 | # Compile with -fPIC, since this code is linked into the QML plugin. | ||
147 | 12 | set_target_properties(ms-dbus PROPERTIES COMPILE_FLAGS "-fPIC") | ||
148 | 13 | |||
149 | 14 | add_executable(mediascanner-dbus | ||
150 | 15 | main.cc | ||
151 | 16 | ) | ||
152 | 17 | target_link_libraries(mediascanner-dbus ms-dbus) | ||
153 | 18 | set_target_properties(mediascanner-dbus | ||
154 | 19 | PROPERTIES OUTPUT_NAME "mediascanner-dbus-2.0") | ||
155 | 20 | |||
156 | 21 | install( | ||
157 | 22 | TARGETS mediascanner-dbus | ||
158 | 23 | RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/mediascanner-2.0 | ||
159 | 24 | ) | ||
160 | 25 | |||
161 | 26 | configure_file( | ||
162 | 27 | com.canonical.MediaScanner2.service.in | ||
163 | 28 | com.canonical.MediaScanner2.service) | ||
164 | 29 | |||
165 | 30 | install( | ||
166 | 31 | FILES ${CMAKE_CURRENT_BINARY_DIR}/com.canonical.MediaScanner2.service | ||
167 | 32 | DESTINATION ${CMAKE_INSTALL_DATADIR}/dbus-1/services | ||
168 | 33 | ) | ||
169 | 0 | 34 | ||
170 | === added file 'src/ms-dbus/com.canonical.MediaScanner2.service.in' | |||
171 | --- src/ms-dbus/com.canonical.MediaScanner2.service.in 1970-01-01 00:00:00 +0000 | |||
172 | +++ src/ms-dbus/com.canonical.MediaScanner2.service.in 2014-05-24 09:41:18 +0000 | |||
173 | @@ -0,0 +1,3 @@ | |||
174 | 1 | [D-BUS Service] | ||
175 | 2 | Name=com.canonical.Thumbnailer | ||
176 | 3 | Exec=@CMAKE_INSTALL_LIBDIR@/mediascanner-2.0/mediascanner-dbus-2.0 | ||
177 | 0 | 4 | ||
178 | === added file 'src/ms-dbus/dbus-codec.cc' | |||
179 | --- src/ms-dbus/dbus-codec.cc 1970-01-01 00:00:00 +0000 | |||
180 | +++ src/ms-dbus/dbus-codec.cc 2014-05-24 09:41:18 +0000 | |||
181 | @@ -0,0 +1,90 @@ | |||
182 | 1 | /* | ||
183 | 2 | * Copyright (C) 2013 Canonical, Ltd. | ||
184 | 3 | * | ||
185 | 4 | * Authors: | ||
186 | 5 | * James Henstridge <james.henstridge@canonical.com> | ||
187 | 6 | * | ||
188 | 7 | * This program is free software: you can redistribute it and/or modify | ||
189 | 8 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
190 | 9 | * published by the Free Software Foundation. | ||
191 | 10 | * | ||
192 | 11 | * This program is distributed in the hope that it will be useful, | ||
193 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
194 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
195 | 14 | * GNU Lesser General Public License for more details. | ||
196 | 15 | * | ||
197 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
198 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
199 | 18 | */ | ||
200 | 19 | #include <cstdint> | ||
201 | 20 | #include <string> | ||
202 | 21 | |||
203 | 22 | #include <core/dbus/object.h> | ||
204 | 23 | |||
205 | 24 | #include <mediascanner/MediaFile.hh> | ||
206 | 25 | #include <mediascanner/MediaFileBuilder.hh> | ||
207 | 26 | #include <mediascanner/Album.hh> | ||
208 | 27 | #include "dbus-codec.hh" | ||
209 | 28 | |||
210 | 29 | using core::dbus::Message; | ||
211 | 30 | using core::dbus::Codec; | ||
212 | 31 | using mediascanner::MediaFile; | ||
213 | 32 | using mediascanner::MediaFileBuilder; | ||
214 | 33 | using mediascanner::MediaType; | ||
215 | 34 | using mediascanner::Album; | ||
216 | 35 | using std::string; | ||
217 | 36 | |||
218 | 37 | void Codec<MediaFile>::encode_argument(Message::Writer &out, const MediaFile &file) { | ||
219 | 38 | auto w = out.open_structure(); | ||
220 | 39 | core::dbus::encode_argument(w, file.getFileName()); | ||
221 | 40 | core::dbus::encode_argument(w, file.getContentType()); | ||
222 | 41 | core::dbus::encode_argument(w, file.getETag()); | ||
223 | 42 | core::dbus::encode_argument(w, file.getTitle()); | ||
224 | 43 | core::dbus::encode_argument(w, file.getAuthor()); | ||
225 | 44 | core::dbus::encode_argument(w, file.getAlbum()); | ||
226 | 45 | core::dbus::encode_argument(w, file.getAlbumArtist()); | ||
227 | 46 | core::dbus::encode_argument(w, file.getDate()); | ||
228 | 47 | core::dbus::encode_argument(w, file.getGenre()); | ||
229 | 48 | core::dbus::encode_argument(w, (int32_t)file.getDiscNumber()); | ||
230 | 49 | core::dbus::encode_argument(w, (int32_t)file.getTrackNumber()); | ||
231 | 50 | core::dbus::encode_argument(w, (int32_t)file.getDuration()); | ||
232 | 51 | core::dbus::encode_argument(w, (int32_t)file.getType()); | ||
233 | 52 | out.close_structure(std::move(w)); | ||
234 | 53 | } | ||
235 | 54 | |||
236 | 55 | void Codec<MediaFile>::decode_argument(Message::Reader &in, MediaFile &file) { | ||
237 | 56 | auto r = in.pop_structure(); | ||
238 | 57 | string filename, content_type, etag, title, author; | ||
239 | 58 | string album, album_artist, date, genre; | ||
240 | 59 | int32_t disc_number, track_number, duration, type; | ||
241 | 60 | r >> filename >> content_type >> etag >> title >> author | ||
242 | 61 | >> album >> album_artist >> date >> genre | ||
243 | 62 | >> disc_number >> track_number >> duration >> type; | ||
244 | 63 | file = MediaFileBuilder(filename) | ||
245 | 64 | .setContentType(content_type) | ||
246 | 65 | .setETag(etag) | ||
247 | 66 | .setTitle(title) | ||
248 | 67 | .setAuthor(author) | ||
249 | 68 | .setAlbum(album) | ||
250 | 69 | .setAlbumArtist(album_artist) | ||
251 | 70 | .setDate(date) | ||
252 | 71 | .setGenre(genre) | ||
253 | 72 | .setDiscNumber(disc_number) | ||
254 | 73 | .setTrackNumber(track_number) | ||
255 | 74 | .setDuration(duration) | ||
256 | 75 | .setType((MediaType)type); | ||
257 | 76 | } | ||
258 | 77 | |||
259 | 78 | void Codec<Album>::encode_argument(Message::Writer &out, const Album &album) { | ||
260 | 79 | auto w = out.open_structure(); | ||
261 | 80 | core::dbus::encode_argument(w, album.getTitle()); | ||
262 | 81 | core::dbus::encode_argument(w, album.getArtist()); | ||
263 | 82 | out.close_structure(std::move(w)); | ||
264 | 83 | } | ||
265 | 84 | |||
266 | 85 | void Codec<Album>::decode_argument(Message::Reader &in, Album &album) { | ||
267 | 86 | auto r = in.pop_structure(); | ||
268 | 87 | string title, artist; | ||
269 | 88 | r >> title >> artist; | ||
270 | 89 | album = Album(title, artist); | ||
271 | 90 | } | ||
272 | 0 | 91 | ||
273 | === added file 'src/ms-dbus/dbus-codec.hh' | |||
274 | --- src/ms-dbus/dbus-codec.hh 1970-01-01 00:00:00 +0000 | |||
275 | +++ src/ms-dbus/dbus-codec.hh 2014-05-24 09:41:18 +0000 | |||
276 | @@ -0,0 +1,87 @@ | |||
277 | 1 | /* | ||
278 | 2 | * Copyright (C) 2013 Canonical, Ltd. | ||
279 | 3 | * | ||
280 | 4 | * Authors: | ||
281 | 5 | * James Henstridge <james.henstridge@canonical.com> | ||
282 | 6 | * | ||
283 | 7 | * This program is free software: you can redistribute it and/or modify | ||
284 | 8 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
285 | 9 | * published by the Free Software Foundation. | ||
286 | 10 | * | ||
287 | 11 | * This program is distributed in the hope that it will be useful, | ||
288 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
289 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
290 | 14 | * GNU Lesser General Public License for more details. | ||
291 | 15 | * | ||
292 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
293 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
294 | 18 | */ | ||
295 | 19 | #ifndef MEDIASCANNER_DBUS_CODEC_HH | ||
296 | 20 | #define MEDIASCANNER_DBUS_CODEC_HH | ||
297 | 21 | |||
298 | 22 | #include <string> | ||
299 | 23 | |||
300 | 24 | #include <core/dbus/codec.h> | ||
301 | 25 | #include <core/dbus/helper/type_mapper.h> | ||
302 | 26 | |||
303 | 27 | namespace mediascanner { | ||
304 | 28 | class MediaFile; | ||
305 | 29 | class Album; | ||
306 | 30 | } | ||
307 | 31 | |||
308 | 32 | namespace core { | ||
309 | 33 | namespace dbus { | ||
310 | 34 | |||
311 | 35 | template <> | ||
312 | 36 | struct Codec<mediascanner::MediaFile> { | ||
313 | 37 | static void encode_argument(Message::Writer &out, const mediascanner::MediaFile &file); | ||
314 | 38 | static void decode_argument(Message::Reader &in, mediascanner::MediaFile &file); | ||
315 | 39 | }; | ||
316 | 40 | |||
317 | 41 | template <> | ||
318 | 42 | struct Codec<mediascanner::Album> { | ||
319 | 43 | static void encode_argument(Message::Writer &out, const mediascanner::Album &album); | ||
320 | 44 | static void decode_argument(Message::Reader &in, mediascanner::Album &album); | ||
321 | 45 | }; | ||
322 | 46 | |||
323 | 47 | namespace helper { | ||
324 | 48 | |||
325 | 49 | template<> | ||
326 | 50 | struct TypeMapper<mediascanner::MediaFile> { | ||
327 | 51 | constexpr static ArgumentType type_value() { | ||
328 | 52 | return ArgumentType::structure; | ||
329 | 53 | } | ||
330 | 54 | constexpr static bool is_basic_type() { | ||
331 | 55 | return false; | ||
332 | 56 | } | ||
333 | 57 | constexpr static bool requires_signature() { | ||
334 | 58 | return true; | ||
335 | 59 | } | ||
336 | 60 | static const std::string &signature() { | ||
337 | 61 | static const std::string s = "(sssssssssiiii)"; | ||
338 | 62 | return s; | ||
339 | 63 | } | ||
340 | 64 | }; | ||
341 | 65 | |||
342 | 66 | template<> | ||
343 | 67 | struct TypeMapper<mediascanner::Album> { | ||
344 | 68 | constexpr static ArgumentType type_value() { | ||
345 | 69 | return ArgumentType::structure; | ||
346 | 70 | } | ||
347 | 71 | constexpr static bool is_basic_type() { | ||
348 | 72 | return false; | ||
349 | 73 | } | ||
350 | 74 | constexpr static bool requires_signature() { | ||
351 | 75 | return true; | ||
352 | 76 | } | ||
353 | 77 | static const std::string &signature() { | ||
354 | 78 | static const std::string s = "(ss)"; | ||
355 | 79 | return s; | ||
356 | 80 | } | ||
357 | 81 | }; | ||
358 | 82 | |||
359 | 83 | } | ||
360 | 84 | |||
361 | 85 | } | ||
362 | 86 | } | ||
363 | 87 | #endif | ||
364 | 0 | 88 | ||
365 | === added file 'src/ms-dbus/dbus-interface.hh' | |||
366 | --- src/ms-dbus/dbus-interface.hh 1970-01-01 00:00:00 +0000 | |||
367 | +++ src/ms-dbus/dbus-interface.hh 2014-05-24 09:41:18 +0000 | |||
368 | @@ -0,0 +1,153 @@ | |||
369 | 1 | /* | ||
370 | 2 | * Copyright (C) 2013 Canonical, Ltd. | ||
371 | 3 | * | ||
372 | 4 | * Authors: | ||
373 | 5 | * James Henstridge <james.henstridge@canonical.com> | ||
374 | 6 | * | ||
375 | 7 | * This program is free software: you can redistribute it and/or modify | ||
376 | 8 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
377 | 9 | * published by the Free Software Foundation. | ||
378 | 10 | * | ||
379 | 11 | * This program is distributed in the hope that it will be useful, | ||
380 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
381 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
382 | 14 | * GNU Lesser General Public License for more details. | ||
383 | 15 | * | ||
384 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
385 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
386 | 18 | */ | ||
387 | 19 | #ifndef MEDIASCANNER_DBUS_INTERFACE_HH | ||
388 | 20 | #define MEDIASCANNER_DBUS_INTERFACE_HH | ||
389 | 21 | |||
390 | 22 | #include <chrono> | ||
391 | 23 | #include <string> | ||
392 | 24 | |||
393 | 25 | #include <core/dbus/object.h> | ||
394 | 26 | #include <core/dbus/service.h> | ||
395 | 27 | |||
396 | 28 | namespace mediascanner { | ||
397 | 29 | namespace dbus { | ||
398 | 30 | |||
399 | 31 | struct MediaStoreInterface { | ||
400 | 32 | inline static const std::string& name() { | ||
401 | 33 | static std::string s = "com.canonical.MediaScanner2"; | ||
402 | 34 | return s; | ||
403 | 35 | } | ||
404 | 36 | |||
405 | 37 | struct Errors { | ||
406 | 38 | struct Error { | ||
407 | 39 | inline static const std::string& name() { | ||
408 | 40 | static std::string s = "com.canonical.MediaScanner2.Error"; | ||
409 | 41 | return s; | ||
410 | 42 | } | ||
411 | 43 | }; | ||
412 | 44 | }; | ||
413 | 45 | |||
414 | 46 | struct Lookup { | ||
415 | 47 | typedef MediaStoreInterface Interface; | ||
416 | 48 | |||
417 | 49 | inline static const std::string& name() { | ||
418 | 50 | static std::string s = "Lookup"; | ||
419 | 51 | return s; | ||
420 | 52 | } | ||
421 | 53 | |||
422 | 54 | inline static const std::chrono::milliseconds default_timeout() { | ||
423 | 55 | return std::chrono::seconds{1}; | ||
424 | 56 | } | ||
425 | 57 | }; | ||
426 | 58 | |||
427 | 59 | struct Query { | ||
428 | 60 | typedef MediaStoreInterface Interface; | ||
429 | 61 | |||
430 | 62 | inline static const std::string& name() { | ||
431 | 63 | static std::string s = "Query"; | ||
432 | 64 | return s; | ||
433 | 65 | } | ||
434 | 66 | |||
435 | 67 | inline static const std::chrono::milliseconds default_timeout() { | ||
436 | 68 | return std::chrono::seconds{1}; | ||
437 | 69 | } | ||
438 | 70 | }; | ||
439 | 71 | |||
440 | 72 | struct QueryAlbums { | ||
441 | 73 | typedef MediaStoreInterface Interface; | ||
442 | 74 | |||
443 | 75 | inline static const std::string& name() { | ||
444 | 76 | static std::string s = "QueryAlbums"; | ||
445 | 77 | return s; | ||
446 | 78 | } | ||
447 | 79 | |||
448 | 80 | inline static const std::chrono::milliseconds default_timeout() { | ||
449 | 81 | return std::chrono::seconds{1}; | ||
450 | 82 | } | ||
451 | 83 | }; | ||
452 | 84 | |||
453 | 85 | struct GetAlbumSongs { | ||
454 | 86 | typedef MediaStoreInterface Interface; | ||
455 | 87 | |||
456 | 88 | inline static const std::string& name() { | ||
457 | 89 | static std::string s = "GetAlbumSongs"; | ||
458 | 90 | return s; | ||
459 | 91 | } | ||
460 | 92 | |||
461 | 93 | inline static const std::chrono::milliseconds default_timeout() { | ||
462 | 94 | return std::chrono::seconds{1}; | ||
463 | 95 | } | ||
464 | 96 | }; | ||
465 | 97 | |||
466 | 98 | struct GetETag { | ||
467 | 99 | typedef MediaStoreInterface Interface; | ||
468 | 100 | |||
469 | 101 | inline static const std::string& name() { | ||
470 | 102 | static std::string s = "GetETag"; | ||
471 | 103 | return s; | ||
472 | 104 | } | ||
473 | 105 | |||
474 | 106 | inline static const std::chrono::milliseconds default_timeout() { | ||
475 | 107 | return std::chrono::seconds{1}; | ||
476 | 108 | } | ||
477 | 109 | }; | ||
478 | 110 | |||
479 | 111 | struct ListSongs { | ||
480 | 112 | typedef MediaStoreInterface Interface; | ||
481 | 113 | |||
482 | 114 | inline static const std::string& name() { | ||
483 | 115 | static std::string s = "ListSongs"; | ||
484 | 116 | return s; | ||
485 | 117 | } | ||
486 | 118 | |||
487 | 119 | inline static const std::chrono::milliseconds default_timeout() { | ||
488 | 120 | return std::chrono::seconds{1}; | ||
489 | 121 | } | ||
490 | 122 | }; | ||
491 | 123 | |||
492 | 124 | struct ListAlbums { | ||
493 | 125 | typedef MediaStoreInterface Interface; | ||
494 | 126 | |||
495 | 127 | inline static const std::string& name() { | ||
496 | 128 | static std::string s = "ListAlbums"; | ||
497 | 129 | return s; | ||
498 | 130 | } | ||
499 | 131 | |||
500 | 132 | inline static const std::chrono::milliseconds default_timeout() { | ||
501 | 133 | return std::chrono::seconds{1}; | ||
502 | 134 | } | ||
503 | 135 | }; | ||
504 | 136 | |||
505 | 137 | struct ListArtists { | ||
506 | 138 | typedef MediaStoreInterface Interface; | ||
507 | 139 | |||
508 | 140 | inline static const std::string& name() { | ||
509 | 141 | static std::string s = "ListArtists"; | ||
510 | 142 | return s; | ||
511 | 143 | } | ||
512 | 144 | |||
513 | 145 | inline static const std::chrono::milliseconds default_timeout() { | ||
514 | 146 | return std::chrono::seconds{1}; | ||
515 | 147 | } | ||
516 | 148 | }; | ||
517 | 149 | }; | ||
518 | 150 | |||
519 | 151 | } | ||
520 | 152 | } | ||
521 | 153 | #endif | ||
522 | 0 | 154 | ||
523 | === added file 'src/ms-dbus/main.cc' | |||
524 | --- src/ms-dbus/main.cc 1970-01-01 00:00:00 +0000 | |||
525 | +++ src/ms-dbus/main.cc 2014-05-24 09:41:18 +0000 | |||
526 | @@ -0,0 +1,38 @@ | |||
527 | 1 | /* | ||
528 | 2 | * Copyright (C) 2013 Canonical, Ltd. | ||
529 | 3 | * | ||
530 | 4 | * Authors: | ||
531 | 5 | * James Henstridge <james.henstridge@canonical.com> | ||
532 | 6 | * | ||
533 | 7 | * This program is free software: you can redistribute it and/or modify | ||
534 | 8 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
535 | 9 | * published by the Free Software Foundation. | ||
536 | 10 | * | ||
537 | 11 | * This program is distributed in the hope that it will be useful, | ||
538 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
539 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
540 | 14 | * GNU Lesser General Public License for more details. | ||
541 | 15 | * | ||
542 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
543 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
544 | 18 | */ | ||
545 | 19 | |||
546 | 20 | #include <memory> | ||
547 | 21 | #include <core/dbus/bus.h> | ||
548 | 22 | #include <core/dbus/asio/executor.h> | ||
549 | 23 | |||
550 | 24 | #include <mediascanner/MediaStore.hh> | ||
551 | 25 | #include "service-skeleton.hh" | ||
552 | 26 | |||
553 | 27 | using namespace mediascanner; | ||
554 | 28 | |||
555 | 29 | int main(int , char **) { | ||
556 | 30 | auto bus = std::make_shared<core::dbus::Bus>(core::dbus::WellKnownBus::session); | ||
557 | 31 | bus->install_executor(core::dbus::asio::make_executor(bus)); | ||
558 | 32 | |||
559 | 33 | auto store = std::make_shared<MediaStore>(MS_READ_ONLY); | ||
560 | 34 | |||
561 | 35 | dbus::ServiceSkeleton service(bus, store); | ||
562 | 36 | service.run(); | ||
563 | 37 | return 0; | ||
564 | 38 | } | ||
565 | 0 | 39 | ||
566 | === added file 'src/ms-dbus/service-skeleton.cc' | |||
567 | --- src/ms-dbus/service-skeleton.cc 1970-01-01 00:00:00 +0000 | |||
568 | +++ src/ms-dbus/service-skeleton.cc 2014-05-24 09:41:18 +0000 | |||
569 | @@ -0,0 +1,232 @@ | |||
570 | 1 | #include <stdexcept> | ||
571 | 2 | |||
572 | 3 | #include <core/dbus/message.h> | ||
573 | 4 | #include <core/dbus/object.h> | ||
574 | 5 | #include <core/dbus/types/object_path.h> | ||
575 | 6 | |||
576 | 7 | #include <mediascanner/Album.hh> | ||
577 | 8 | #include <mediascanner/MediaFile.hh> | ||
578 | 9 | #include <mediascanner/MediaStore.hh> | ||
579 | 10 | |||
580 | 11 | #include "dbus-interface.hh" | ||
581 | 12 | #include "dbus-codec.hh" | ||
582 | 13 | #include "service-skeleton.hh" | ||
583 | 14 | |||
584 | 15 | using core::dbus::Message; | ||
585 | 16 | |||
586 | 17 | namespace mediascanner { | ||
587 | 18 | namespace dbus { | ||
588 | 19 | |||
589 | 20 | struct ServiceSkeleton::Private { | ||
590 | 21 | ServiceSkeleton *impl; | ||
591 | 22 | std::shared_ptr<MediaStore> store; | ||
592 | 23 | core::dbus::Object::Ptr object; | ||
593 | 24 | |||
594 | 25 | Private(ServiceSkeleton *impl, std::shared_ptr<MediaStore> store) : | ||
595 | 26 | impl(impl), | ||
596 | 27 | store(store), | ||
597 | 28 | object(impl->access_service()->add_object_for_path( | ||
598 | 29 | core::dbus::traits::Service<MediaStoreService>::object_path())) { | ||
599 | 30 | object->install_method_handler<MediaStoreInterface::Lookup>( | ||
600 | 31 | std::bind( | ||
601 | 32 | &Private::handle_lookup, | ||
602 | 33 | this, | ||
603 | 34 | std::placeholders::_1)); | ||
604 | 35 | object->install_method_handler<MediaStoreInterface::Query>( | ||
605 | 36 | std::bind( | ||
606 | 37 | &Private::handle_query, | ||
607 | 38 | this, | ||
608 | 39 | std::placeholders::_1)); | ||
609 | 40 | object->install_method_handler<MediaStoreInterface::QueryAlbums>( | ||
610 | 41 | std::bind( | ||
611 | 42 | &Private::handle_query_albums, | ||
612 | 43 | this, | ||
613 | 44 | std::placeholders::_1)); | ||
614 | 45 | object->install_method_handler<MediaStoreInterface::GetAlbumSongs>( | ||
615 | 46 | std::bind( | ||
616 | 47 | &Private::handle_get_album_songs, | ||
617 | 48 | this, | ||
618 | 49 | std::placeholders::_1)); | ||
619 | 50 | object->install_method_handler<MediaStoreInterface::GetETag>( | ||
620 | 51 | std::bind( | ||
621 | 52 | &Private::handle_get_etag, | ||
622 | 53 | this, | ||
623 | 54 | std::placeholders::_1)); | ||
624 | 55 | object->install_method_handler<MediaStoreInterface::ListSongs>( | ||
625 | 56 | std::bind( | ||
626 | 57 | &Private::handle_list_songs, | ||
627 | 58 | this, | ||
628 | 59 | std::placeholders::_1)); | ||
629 | 60 | object->install_method_handler<MediaStoreInterface::ListAlbums>( | ||
630 | 61 | std::bind( | ||
631 | 62 | &Private::handle_list_albums, | ||
632 | 63 | this, | ||
633 | 64 | std::placeholders::_1)); | ||
634 | 65 | object->install_method_handler<MediaStoreInterface::ListArtists>( | ||
635 | 66 | std::bind( | ||
636 | 67 | &Private::handle_list_artists, | ||
637 | 68 | this, | ||
638 | 69 | std::placeholders::_1)); | ||
639 | 70 | } | ||
640 | 71 | |||
641 | 72 | void handle_lookup(const Message::Ptr &message) { | ||
642 | 73 | std::string filename; | ||
643 | 74 | message->reader() >> filename; | ||
644 | 75 | Message::Ptr reply; | ||
645 | 76 | try { | ||
646 | 77 | MediaFile file = store->lookup(filename); | ||
647 | 78 | reply = Message::make_method_return(message); | ||
648 | 79 | reply->writer() << file; | ||
649 | 80 | } catch (const std::exception &e) { | ||
650 | 81 | reply = Message::make_error( | ||
651 | 82 | message, MediaStoreInterface::Errors::Error::name(), | ||
652 | 83 | e.what()); | ||
653 | 84 | } | ||
654 | 85 | impl->access_bus()->send(reply); | ||
655 | 86 | } | ||
656 | 87 | |||
657 | 88 | void handle_query(const Message::Ptr &message) { | ||
658 | 89 | std::string query; | ||
659 | 90 | int32_t type; | ||
660 | 91 | int32_t limit; | ||
661 | 92 | |||
662 | 93 | message->reader() >> query >> type >> limit; | ||
663 | 94 | Message::Ptr reply; | ||
664 | 95 | try { | ||
665 | 96 | auto results = store->query(query, (MediaType)type, limit); | ||
666 | 97 | reply = Message::make_method_return(message); | ||
667 | 98 | reply->writer() << results; | ||
668 | 99 | } catch (const std::exception &e) { | ||
669 | 100 | reply = Message::make_error( | ||
670 | 101 | message, MediaStoreInterface::Errors::Error::name(), | ||
671 | 102 | e.what()); | ||
672 | 103 | } | ||
673 | 104 | impl->access_bus()->send(reply); | ||
674 | 105 | } | ||
675 | 106 | |||
676 | 107 | void handle_query_albums(const Message::Ptr &message) { | ||
677 | 108 | std::string query; | ||
678 | 109 | int32_t limit; | ||
679 | 110 | |||
680 | 111 | message->reader() >> query >> limit; | ||
681 | 112 | Message::Ptr reply; | ||
682 | 113 | try { | ||
683 | 114 | auto albums = store->queryAlbums(query, limit); | ||
684 | 115 | reply = Message::make_method_return(message); | ||
685 | 116 | reply->writer() << albums; | ||
686 | 117 | } catch (const std::exception &e) { | ||
687 | 118 | reply = Message::make_error( | ||
688 | 119 | message, MediaStoreInterface::Errors::Error::name(), | ||
689 | 120 | e.what()); | ||
690 | 121 | } | ||
691 | 122 | impl->access_bus()->send(reply); | ||
692 | 123 | } | ||
693 | 124 | |||
694 | 125 | void handle_get_album_songs(const Message::Ptr &message) { | ||
695 | 126 | Album album("", ""); | ||
696 | 127 | |||
697 | 128 | message->reader() >> album; | ||
698 | 129 | Message::Ptr reply; | ||
699 | 130 | try { | ||
700 | 131 | auto results = store->getAlbumSongs(album); | ||
701 | 132 | reply = Message::make_method_return(message); | ||
702 | 133 | reply->writer() << results; | ||
703 | 134 | } catch (const std::exception &e) { | ||
704 | 135 | reply = Message::make_error( | ||
705 | 136 | message, MediaStoreInterface::Errors::Error::name(), | ||
706 | 137 | e.what()); | ||
707 | 138 | } | ||
708 | 139 | impl->access_bus()->send(reply); | ||
709 | 140 | } | ||
710 | 141 | |||
711 | 142 | void handle_get_etag(const Message::Ptr &message) { | ||
712 | 143 | std::string filename; | ||
713 | 144 | message->reader() >> filename; | ||
714 | 145 | |||
715 | 146 | Message::Ptr reply; | ||
716 | 147 | try { | ||
717 | 148 | std::string etag = store->getETag(filename); | ||
718 | 149 | reply = Message::make_method_return(message); | ||
719 | 150 | reply->writer() << etag; | ||
720 | 151 | } catch (const std::exception &e) { | ||
721 | 152 | reply = Message::make_error( | ||
722 | 153 | message, MediaStoreInterface::Errors::Error::name(), | ||
723 | 154 | e.what()); | ||
724 | 155 | } | ||
725 | 156 | impl->access_bus()->send(reply); | ||
726 | 157 | } | ||
727 | 158 | |||
728 | 159 | void handle_list_songs(const Message::Ptr &message) { | ||
729 | 160 | std::string artist, album, album_artist; | ||
730 | 161 | int32_t limit; | ||
731 | 162 | |||
732 | 163 | message->reader() >> artist >> album >> album_artist >> limit; | ||
733 | 164 | Message::Ptr reply; | ||
734 | 165 | try { | ||
735 | 166 | auto results = store->listSongs(artist, album, album_artist, limit); | ||
736 | 167 | reply = Message::make_method_return(message); | ||
737 | 168 | reply->writer() << results; | ||
738 | 169 | } catch (const std::exception &e) { | ||
739 | 170 | reply = Message::make_error( | ||
740 | 171 | message, MediaStoreInterface::Errors::Error::name(), | ||
741 | 172 | e.what()); | ||
742 | 173 | } | ||
743 | 174 | impl->access_bus()->send(reply); | ||
744 | 175 | } | ||
745 | 176 | |||
746 | 177 | void handle_list_albums(const Message::Ptr &message) { | ||
747 | 178 | std::string artist, album_artist; | ||
748 | 179 | int32_t limit; | ||
749 | 180 | |||
750 | 181 | message->reader() >> artist >> album_artist >> limit; | ||
751 | 182 | Message::Ptr reply; | ||
752 | 183 | try { | ||
753 | 184 | auto albums = store->listAlbums(artist, album_artist, limit); | ||
754 | 185 | reply = Message::make_method_return(message); | ||
755 | 186 | reply->writer() << albums; | ||
756 | 187 | } catch (const std::exception &e) { | ||
757 | 188 | reply = Message::make_error( | ||
758 | 189 | message, MediaStoreInterface::Errors::Error::name(), | ||
759 | 190 | e.what()); | ||
760 | 191 | } | ||
761 | 192 | impl->access_bus()->send(reply); | ||
762 | 193 | } | ||
763 | 194 | |||
764 | 195 | void handle_list_artists(const Message::Ptr &message) { | ||
765 | 196 | bool album_artists; | ||
766 | 197 | int32_t limit; | ||
767 | 198 | |||
768 | 199 | message->reader() >> album_artists >> limit; | ||
769 | 200 | Message::Ptr reply; | ||
770 | 201 | try { | ||
771 | 202 | auto artists = store->listArtists(album_artists, limit); | ||
772 | 203 | reply = Message::make_method_return(message); | ||
773 | 204 | reply->writer() << artists; | ||
774 | 205 | } catch (const std::exception &e) { | ||
775 | 206 | reply = Message::make_error( | ||
776 | 207 | message, MediaStoreInterface::Errors::Error::name(), | ||
777 | 208 | e.what()); | ||
778 | 209 | } | ||
779 | 210 | impl->access_bus()->send(reply); | ||
780 | 211 | } | ||
781 | 212 | }; | ||
782 | 213 | |||
783 | 214 | ServiceSkeleton::ServiceSkeleton(core::dbus::Bus::Ptr bus, | ||
784 | 215 | std::shared_ptr<MediaStore> store) : | ||
785 | 216 | core::dbus::Skeleton<MediaStoreService>(bus), | ||
786 | 217 | p(new Private(this, store)) { | ||
787 | 218 | } | ||
788 | 219 | |||
789 | 220 | ServiceSkeleton::~ServiceSkeleton() { | ||
790 | 221 | } | ||
791 | 222 | |||
792 | 223 | void ServiceSkeleton::run() { | ||
793 | 224 | access_bus()->run(); | ||
794 | 225 | } | ||
795 | 226 | |||
796 | 227 | void ServiceSkeleton::stop() { | ||
797 | 228 | access_bus()->stop(); | ||
798 | 229 | } | ||
799 | 230 | |||
800 | 231 | } | ||
801 | 232 | } | ||
802 | 0 | 233 | ||
803 | === added file 'src/ms-dbus/service-skeleton.hh' | |||
804 | --- src/ms-dbus/service-skeleton.hh 1970-01-01 00:00:00 +0000 | |||
805 | +++ src/ms-dbus/service-skeleton.hh 2014-05-24 09:41:18 +0000 | |||
806 | @@ -0,0 +1,51 @@ | |||
807 | 1 | /* | ||
808 | 2 | * Copyright (C) 2013 Canonical, Ltd. | ||
809 | 3 | * | ||
810 | 4 | * Authors: | ||
811 | 5 | * James Henstridge <james.henstridge@canonical.com> | ||
812 | 6 | * | ||
813 | 7 | * This program is free software: you can redistribute it and/or modify | ||
814 | 8 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
815 | 9 | * published by the Free Software Foundation. | ||
816 | 10 | * | ||
817 | 11 | * This program is distributed in the hope that it will be useful, | ||
818 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
819 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
820 | 14 | * GNU Lesser General Public License for more details. | ||
821 | 15 | * | ||
822 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
823 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
824 | 18 | */ | ||
825 | 19 | |||
826 | 20 | #ifndef MEDIASCANNER_DBUS_SERVICE_SKELETON_HH | ||
827 | 21 | #define MEDIASCANNER_DBUS_SERVICE_SKELETON_HH | ||
828 | 22 | |||
829 | 23 | #include <memory> | ||
830 | 24 | #include <core/dbus/bus.h> | ||
831 | 25 | #include <core/dbus/skeleton.h> | ||
832 | 26 | |||
833 | 27 | #include "service.hh" | ||
834 | 28 | |||
835 | 29 | namespace mediascanner { | ||
836 | 30 | |||
837 | 31 | class MediaStore; | ||
838 | 32 | |||
839 | 33 | namespace dbus { | ||
840 | 34 | |||
841 | 35 | class ServiceSkeleton : public core::dbus::Skeleton<MediaStoreService> { | ||
842 | 36 | public: | ||
843 | 37 | ServiceSkeleton(core::dbus::Bus::Ptr bus, std::shared_ptr<MediaStore> store); | ||
844 | 38 | ~ServiceSkeleton(); | ||
845 | 39 | |||
846 | 40 | void run(); | ||
847 | 41 | void stop(); | ||
848 | 42 | |||
849 | 43 | private: | ||
850 | 44 | struct Private; | ||
851 | 45 | std::unique_ptr<Private> p; | ||
852 | 46 | }; | ||
853 | 47 | |||
854 | 48 | } | ||
855 | 49 | } | ||
856 | 50 | |||
857 | 51 | #endif | ||
858 | 0 | 52 | ||
859 | === added file 'src/ms-dbus/service-stub.cc' | |||
860 | --- src/ms-dbus/service-stub.cc 1970-01-01 00:00:00 +0000 | |||
861 | +++ src/ms-dbus/service-stub.cc 2014-05-24 09:41:18 +0000 | |||
862 | @@ -0,0 +1,103 @@ | |||
863 | 1 | /* | ||
864 | 2 | * Copyright (C) 2013 Canonical, Ltd. | ||
865 | 3 | * | ||
866 | 4 | * Authors: | ||
867 | 5 | * James Henstridge <james.henstridge@canonical.com> | ||
868 | 6 | * | ||
869 | 7 | * This program is free software: you can redistribute it and/or modify | ||
870 | 8 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
871 | 9 | * published by the Free Software Foundation. | ||
872 | 10 | * | ||
873 | 11 | * This program is distributed in the hope that it will be useful, | ||
874 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
875 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
876 | 14 | * GNU Lesser General Public License for more details. | ||
877 | 15 | * | ||
878 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
879 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
880 | 18 | */ | ||
881 | 19 | |||
882 | 20 | #include <stdexcept> | ||
883 | 21 | |||
884 | 22 | #include <mediascanner/Album.hh> | ||
885 | 23 | #include <mediascanner/MediaFile.hh> | ||
886 | 24 | #include "service-stub.hh" | ||
887 | 25 | #include "dbus-interface.hh" | ||
888 | 26 | #include "dbus-codec.hh" | ||
889 | 27 | |||
890 | 28 | using std::string; | ||
891 | 29 | |||
892 | 30 | namespace mediascanner { | ||
893 | 31 | namespace dbus { | ||
894 | 32 | |||
895 | 33 | struct ServiceStub::Private | ||
896 | 34 | { | ||
897 | 35 | core::dbus::Object::Ptr object; | ||
898 | 36 | }; | ||
899 | 37 | |||
900 | 38 | ServiceStub::ServiceStub(core::dbus::Bus::Ptr bus) | ||
901 | 39 | : core::dbus::Stub<MediaStoreService>(bus), | ||
902 | 40 | p(new Private{access_service()->object_for_path( | ||
903 | 41 | core::dbus::types::ObjectPath(core::dbus::traits::Service<MediaStoreService>::object_path()))}) { | ||
904 | 42 | } | ||
905 | 43 | |||
906 | 44 | ServiceStub::~ServiceStub() { | ||
907 | 45 | } | ||
908 | 46 | |||
909 | 47 | MediaFile ServiceStub::lookup(const string &filename) const { | ||
910 | 48 | auto result = p->object->invoke_method_synchronously<MediaStoreInterface::Lookup, MediaFile>(filename); | ||
911 | 49 | if (result.is_error()) | ||
912 | 50 | throw std::runtime_error(result.error().print()); | ||
913 | 51 | return result.value(); | ||
914 | 52 | } | ||
915 | 53 | |||
916 | 54 | std::vector<MediaFile> ServiceStub::query(const string &q, MediaType type, int limit) const { | ||
917 | 55 | auto result = p->object->invoke_method_synchronously<MediaStoreInterface::Query, std::vector<MediaFile>>(q, (int32_t)type, (int32_t)limit); | ||
918 | 56 | if (result.is_error()) | ||
919 | 57 | throw std::runtime_error(result.error().print()); | ||
920 | 58 | return result.value(); | ||
921 | 59 | } | ||
922 | 60 | |||
923 | 61 | std::vector<Album> ServiceStub::queryAlbums(const string &core_term, int limit) const { | ||
924 | 62 | auto result = p->object->invoke_method_synchronously<MediaStoreInterface::QueryAlbums, std::vector<Album>>(core_term, (int32_t)limit); | ||
925 | 63 | if (result.is_error()) | ||
926 | 64 | throw std::runtime_error(result.error().print()); | ||
927 | 65 | return result.value(); | ||
928 | 66 | } | ||
929 | 67 | |||
930 | 68 | std::vector<MediaFile> ServiceStub::getAlbumSongs(const Album& album) const { | ||
931 | 69 | auto result = p->object->invoke_method_synchronously<MediaStoreInterface::GetAlbumSongs, std::vector<MediaFile>>(album); | ||
932 | 70 | if (result.is_error()) | ||
933 | 71 | throw std::runtime_error(result.error().print()); | ||
934 | 72 | return result.value(); | ||
935 | 73 | } | ||
936 | 74 | |||
937 | 75 | string ServiceStub::getETag(const string &filename) const { | ||
938 | 76 | auto result = p->object->invoke_method_synchronously<MediaStoreInterface::GetETag, string>(filename); | ||
939 | 77 | if (result.is_error()) | ||
940 | 78 | throw std::runtime_error(result.error().print()); | ||
941 | 79 | return result.value(); | ||
942 | 80 | } | ||
943 | 81 | |||
944 | 82 | std::vector<MediaFile> ServiceStub::listSongs(const string &artist, const string &album, const string &album_artist, int limit) const { | ||
945 | 83 | auto result = p->object->invoke_method_synchronously<MediaStoreInterface::ListSongs, std::vector<MediaFile>>(artist, album, album_artist, (int32_t)limit); | ||
946 | 84 | if (result.is_error()) | ||
947 | 85 | throw std::runtime_error(result.error().print()); | ||
948 | 86 | return result.value(); | ||
949 | 87 | } | ||
950 | 88 | |||
951 | 89 | std::vector<Album> ServiceStub::listAlbums(const string &artist, const string &album_artist, int limit) const { | ||
952 | 90 | auto result = p->object->invoke_method_synchronously<MediaStoreInterface::ListAlbums, std::vector<Album>>(artist, album_artist, (int32_t)limit); | ||
953 | 91 | if (result.is_error()) | ||
954 | 92 | throw std::runtime_error(result.error().print()); | ||
955 | 93 | return result.value(); | ||
956 | 94 | } | ||
957 | 95 | std::vector<string> ServiceStub::listArtists(bool album_artists, int limit) const { | ||
958 | 96 | auto result = p->object->invoke_method_synchronously<MediaStoreInterface::ListArtists, std::vector<string>>(album_artists, (int32_t)limit); | ||
959 | 97 | if (result.is_error()) | ||
960 | 98 | throw std::runtime_error(result.error().print()); | ||
961 | 99 | return result.value(); | ||
962 | 100 | } | ||
963 | 101 | |||
964 | 102 | } | ||
965 | 103 | } | ||
966 | 0 | 104 | ||
967 | === added file 'src/ms-dbus/service-stub.hh' | |||
968 | --- src/ms-dbus/service-stub.hh 1970-01-01 00:00:00 +0000 | |||
969 | +++ src/ms-dbus/service-stub.hh 2014-05-24 09:41:18 +0000 | |||
970 | @@ -0,0 +1,61 @@ | |||
971 | 1 | /* | ||
972 | 2 | * Copyright (C) 2013 Canonical, Ltd. | ||
973 | 3 | * | ||
974 | 4 | * Authors: | ||
975 | 5 | * James Henstridge <james.henstridge@canonical.com> | ||
976 | 6 | * | ||
977 | 7 | * This program is free software: you can redistribute it and/or modify | ||
978 | 8 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
979 | 9 | * published by the Free Software Foundation. | ||
980 | 10 | * | ||
981 | 11 | * This program is distributed in the hope that it will be useful, | ||
982 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
983 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
984 | 14 | * GNU Lesser General Public License for more details. | ||
985 | 15 | * | ||
986 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
987 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
988 | 18 | */ | ||
989 | 19 | |||
990 | 20 | #ifndef MEDIASCANNER_DBUS_SERVICE_STUB_HH | ||
991 | 21 | #define MEDIASCANNER_DBUS_SERVICE_STUB_HH | ||
992 | 22 | |||
993 | 23 | #include <memory> | ||
994 | 24 | #include <string> | ||
995 | 25 | #include <vector> | ||
996 | 26 | #include <core/dbus/bus.h> | ||
997 | 27 | #include <core/dbus/stub.h> | ||
998 | 28 | |||
999 | 29 | #include <mediascanner/scannercore.hh> | ||
1000 | 30 | #include "service.hh" | ||
1001 | 31 | |||
1002 | 32 | namespace mediascanner { | ||
1003 | 33 | |||
1004 | 34 | class Album; | ||
1005 | 35 | class MediaFile; | ||
1006 | 36 | |||
1007 | 37 | namespace dbus { | ||
1008 | 38 | |||
1009 | 39 | class ServiceStub : public core::dbus::Stub<MediaStoreService> { | ||
1010 | 40 | public: | ||
1011 | 41 | ServiceStub(core::dbus::Bus::Ptr bus); | ||
1012 | 42 | ~ServiceStub(); | ||
1013 | 43 | |||
1014 | 44 | MediaFile lookup(const std::string &filename) const; | ||
1015 | 45 | std::vector<MediaFile> query(const std::string &q, MediaType type, int limit=-1) const; | ||
1016 | 46 | std::vector<Album> queryAlbums(const std::string &core_term, int limit=-1) const; | ||
1017 | 47 | std::vector<MediaFile> getAlbumSongs(const Album& album) const; | ||
1018 | 48 | std::string getETag(const std::string &filename) const; | ||
1019 | 49 | std::vector<MediaFile> listSongs(const std::string& artist="", const std::string& album="", const std::string& album_artist="", int limit=-1) const; | ||
1020 | 50 | std::vector<Album> listAlbums(const std::string& artist="", const std::string& album_artist="", int limit=-1) const; | ||
1021 | 51 | std::vector<std::string> listArtists(bool album_artists, int limit=-1) const; | ||
1022 | 52 | |||
1023 | 53 | private: | ||
1024 | 54 | struct Private; | ||
1025 | 55 | std::unique_ptr<Private> p; | ||
1026 | 56 | }; | ||
1027 | 57 | |||
1028 | 58 | } | ||
1029 | 59 | } | ||
1030 | 60 | |||
1031 | 61 | #endif | ||
1032 | 0 | 62 | ||
1033 | === added file 'src/ms-dbus/service.hh' | |||
1034 | --- src/ms-dbus/service.hh 1970-01-01 00:00:00 +0000 | |||
1035 | +++ src/ms-dbus/service.hh 2014-05-24 09:41:18 +0000 | |||
1036 | @@ -0,0 +1,62 @@ | |||
1037 | 1 | /* | ||
1038 | 2 | * Copyright (C) 2013 Canonical, Ltd. | ||
1039 | 3 | * | ||
1040 | 4 | * Authors: | ||
1041 | 5 | * James Henstridge <james.henstridge@canonical.com> | ||
1042 | 6 | * | ||
1043 | 7 | * This program is free software: you can redistribute it and/or modify | ||
1044 | 8 | * it under the terms of the GNU Lesser General Public License version 3 as | ||
1045 | 9 | * published by the Free Software Foundation. | ||
1046 | 10 | * | ||
1047 | 11 | * This program is distributed in the hope that it will be useful, | ||
1048 | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
1049 | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
1050 | 14 | * GNU Lesser General Public License for more details. | ||
1051 | 15 | * | ||
1052 | 16 | * You should have received a copy of the GNU Lesser General Public License | ||
1053 | 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
1054 | 18 | */ | ||
1055 | 19 | |||
1056 | 20 | #ifndef MEDIASCANNER_DBUS_SERVICE_HH | ||
1057 | 21 | #define MEDIASCANNER_DBUS_SERVICE_HH | ||
1058 | 22 | |||
1059 | 23 | #include <core/dbus/traits/service.h> | ||
1060 | 24 | |||
1061 | 25 | namespace mediascanner { | ||
1062 | 26 | namespace dbus { | ||
1063 | 27 | |||
1064 | 28 | class MediaStoreService { | ||
1065 | 29 | public: | ||
1066 | 30 | MediaStoreService() {} | ||
1067 | 31 | |||
1068 | 32 | MediaStoreService(const MediaStoreService&) = delete; | ||
1069 | 33 | virtual ~MediaStoreService() = default; | ||
1070 | 34 | |||
1071 | 35 | MediaStoreService& operator=(const MediaStoreService&) = delete; | ||
1072 | 36 | bool operator==(const MediaStoreService&) const = delete; | ||
1073 | 37 | }; | ||
1074 | 38 | |||
1075 | 39 | } | ||
1076 | 40 | } | ||
1077 | 41 | |||
1078 | 42 | namespace core { | ||
1079 | 43 | namespace dbus { | ||
1080 | 44 | namespace traits { | ||
1081 | 45 | |||
1082 | 46 | template<> | ||
1083 | 47 | struct Service<mediascanner::dbus::MediaStoreService> { | ||
1084 | 48 | inline static const std::string& interface_name() { | ||
1085 | 49 | static const std::string iface("com.canonical.MediaScaner2"); | ||
1086 | 50 | return iface; | ||
1087 | 51 | } | ||
1088 | 52 | inline static const std::string& object_path() { | ||
1089 | 53 | static const std::string path("/com/canonical/MediaScanner2"); | ||
1090 | 54 | return path; | ||
1091 | 55 | } | ||
1092 | 56 | }; | ||
1093 | 57 | |||
1094 | 58 | } | ||
1095 | 59 | } | ||
1096 | 60 | } | ||
1097 | 61 | |||
1098 | 62 | #endif | ||
1099 | 0 | 63 | ||
1100 | === modified file 'src/qml/Ubuntu/MediaScanner/CMakeLists.txt' | |||
1101 | --- src/qml/Ubuntu/MediaScanner/CMakeLists.txt 2014-03-24 10:04:19 +0000 | |||
1102 | +++ src/qml/Ubuntu/MediaScanner/CMakeLists.txt 2014-05-24 09:41:18 +0000 | |||
1103 | @@ -1,4 +1,5 @@ | |||
1104 | 1 | include_directories(../../..) | 1 | include_directories(../../..) |
1105 | 2 | add_definitions(${DBUSCPP_CFLAGS} -DQT_NO_KEYWORDS) | ||
1106 | 2 | 3 | ||
1107 | 3 | set(QML_PLUGIN_DIR "${CMAKE_INSTALL_LIBDIR}/qt5/qml/Ubuntu/MediaScanner.0.1") | 4 | set(QML_PLUGIN_DIR "${CMAKE_INSTALL_LIBDIR}/qt5/qml/Ubuntu/MediaScanner.0.1") |
1108 | 4 | 5 | ||
1109 | @@ -17,7 +18,7 @@ | |||
1110 | 17 | 18 | ||
1111 | 18 | set_target_properties(mediascanner-qml PROPERTIES AUTOMOC TRUE) | 19 | set_target_properties(mediascanner-qml PROPERTIES AUTOMOC TRUE) |
1112 | 19 | qt5_use_modules(mediascanner-qml Qml) | 20 | qt5_use_modules(mediascanner-qml Qml) |
1114 | 20 | target_link_libraries(mediascanner-qml mediascanner) | 21 | target_link_libraries(mediascanner-qml mediascanner ms-dbus) |
1115 | 21 | 22 | ||
1116 | 22 | install( | 23 | install( |
1117 | 23 | TARGETS mediascanner-qml | 24 | TARGETS mediascanner-qml |
1118 | 24 | 25 | ||
1119 | === modified file 'src/qml/Ubuntu/MediaScanner/MediaStoreWrapper.cc' | |||
1120 | --- src/qml/Ubuntu/MediaScanner/MediaStoreWrapper.cc 2014-02-27 08:01:05 +0000 | |||
1121 | +++ src/qml/Ubuntu/MediaScanner/MediaStoreWrapper.cc 2014-05-24 09:41:18 +0000 | |||
1122 | @@ -20,10 +20,24 @@ | |||
1123 | 20 | #include "MediaStoreWrapper.hh" | 20 | #include "MediaStoreWrapper.hh" |
1124 | 21 | #include <QQmlEngine> | 21 | #include <QQmlEngine> |
1125 | 22 | 22 | ||
1126 | 23 | #include <core/dbus/asio/executor.h> | ||
1127 | 24 | #include <ms-dbus/service-stub.hh> | ||
1128 | 25 | |||
1129 | 23 | using namespace mediascanner::qml; | 26 | using namespace mediascanner::qml; |
1130 | 24 | 27 | ||
1131 | 28 | static core::dbus::Bus::Ptr the_session_bus() { | ||
1132 | 29 | static core::dbus::Bus::Ptr bus = std::make_shared<core::dbus::Bus>( | ||
1133 | 30 | core::dbus::WellKnownBus::session); | ||
1134 | 31 | static core::dbus::Executor::Ptr executor = core::dbus::asio::make_executor(bus); | ||
1135 | 32 | static std::once_flag once; | ||
1136 | 33 | |||
1137 | 34 | std::call_once(once, []() {bus->install_executor(executor);}); | ||
1138 | 35 | |||
1139 | 36 | return bus; | ||
1140 | 37 | } | ||
1141 | 38 | |||
1142 | 25 | MediaStoreWrapper::MediaStoreWrapper(QObject *parent) | 39 | MediaStoreWrapper::MediaStoreWrapper(QObject *parent) |
1144 | 26 | : QObject(parent), store(MS_READ_ONLY) { | 40 | : QObject(parent), store(the_session_bus()) { |
1145 | 27 | } | 41 | } |
1146 | 28 | 42 | ||
1147 | 29 | QList<QObject*> MediaStoreWrapper::query(const QString &q, MediaType type) { | 43 | QList<QObject*> MediaStoreWrapper::query(const QString &q, MediaType type) { |
1148 | 30 | 44 | ||
1149 | === modified file 'src/qml/Ubuntu/MediaScanner/MediaStoreWrapper.hh' | |||
1150 | --- src/qml/Ubuntu/MediaScanner/MediaStoreWrapper.hh 2014-02-27 08:01:05 +0000 | |||
1151 | +++ src/qml/Ubuntu/MediaScanner/MediaStoreWrapper.hh 2014-05-24 09:41:18 +0000 | |||
1152 | @@ -24,10 +24,11 @@ | |||
1153 | 24 | #include <QObject> | 24 | #include <QObject> |
1154 | 25 | #include <QString> | 25 | #include <QString> |
1155 | 26 | 26 | ||
1157 | 27 | #include <mediascanner/MediaStore.hh> | 27 | #include <ms-dbus/service-stub.hh> |
1158 | 28 | #include "MediaFileWrapper.hh" | 28 | #include "MediaFileWrapper.hh" |
1159 | 29 | 29 | ||
1160 | 30 | namespace mediascanner { | 30 | namespace mediascanner { |
1161 | 31 | |||
1162 | 31 | namespace qml { | 32 | namespace qml { |
1163 | 32 | 33 | ||
1164 | 33 | class MediaStoreWrapper : public QObject { | 34 | class MediaStoreWrapper : public QObject { |
1165 | @@ -44,7 +45,7 @@ | |||
1166 | 44 | Q_INVOKABLE QList<QObject*> query(const QString &q, MediaType type); | 45 | Q_INVOKABLE QList<QObject*> query(const QString &q, MediaType type); |
1167 | 45 | Q_INVOKABLE mediascanner::qml::MediaFileWrapper *lookup(const QString &filename); | 46 | Q_INVOKABLE mediascanner::qml::MediaFileWrapper *lookup(const QString &filename); |
1168 | 46 | 47 | ||
1170 | 47 | mediascanner::MediaStore store; | 48 | mediascanner::dbus::ServiceStub store; |
1171 | 48 | }; | 49 | }; |
1172 | 49 | 50 | ||
1173 | 50 | } | 51 | } |
1174 | 51 | 52 | ||
1175 | === modified file 'test/CMakeLists.txt' | |||
1176 | --- test/CMakeLists.txt 2014-05-02 08:53:16 +0000 | |||
1177 | +++ test/CMakeLists.txt 2014-05-24 09:41:18 +0000 | |||
1178 | @@ -17,7 +17,7 @@ | |||
1179 | 17 | set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-Wno-unused-private-field") | 17 | set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-Wno-unused-private-field") |
1180 | 18 | endif() | 18 | endif() |
1181 | 19 | 19 | ||
1183 | 20 | add_definitions(${MEDIASCANNER_CFLAGS} ${GST_CFLAGS}) | 20 | add_definitions(${MEDIASCANNER_CFLAGS} ${GST_CFLAGS} ${DBUSCPP_CFLAGS} -DQT_NO_KEYWORDS) |
1184 | 21 | include_directories(../src) | 21 | include_directories(../src) |
1185 | 22 | 22 | ||
1186 | 23 | configure_file(test_config.h.in test_config.h) | 23 | configure_file(test_config.h.in test_config.h) |
1187 | @@ -43,9 +43,13 @@ | |||
1188 | 43 | target_link_libraries(test_mfbuilder gtest mediascanner) | 43 | target_link_libraries(test_mfbuilder gtest mediascanner) |
1189 | 44 | add_test(test_mfbuilder test_mfbuilder) | 44 | add_test(test_mfbuilder test_mfbuilder) |
1190 | 45 | 45 | ||
1191 | 46 | add_executable(test_dbus test_dbus.cc) | ||
1192 | 47 | target_link_libraries(test_dbus gtest mediascanner ms-dbus) | ||
1193 | 48 | add_test(test_dbus test_dbus) | ||
1194 | 49 | |||
1195 | 46 | add_executable(test_qml test_qml.cc) | 50 | add_executable(test_qml test_qml.cc) |
1196 | 47 | qt5_use_modules(test_qml QuickTest) | 51 | qt5_use_modules(test_qml QuickTest) |
1198 | 48 | target_link_libraries(test_qml mediascanner) | 52 | target_link_libraries(test_qml mediascanner ${DBUSCPP_LDFLAGS}) |
1199 | 49 | add_test(test_qml test_qml -input ${CMAKE_CURRENT_SOURCE_DIR}/qml -import ${CMAKE_BINARY_DIR}/src/qml) | 53 | add_test(test_qml test_qml -input ${CMAKE_CURRENT_SOURCE_DIR}/qml -import ${CMAKE_BINARY_DIR}/src/qml) |
1200 | 50 | set_tests_properties(test_qml | 54 | set_tests_properties(test_qml |
1201 | 51 | PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=minimal") | 55 | PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=minimal") |
1202 | 52 | 56 | ||
1203 | === added file 'test/test_dbus.cc' | |||
1204 | --- test/test_dbus.cc 1970-01-01 00:00:00 +0000 | |||
1205 | +++ test/test_dbus.cc 2014-05-24 09:41:18 +0000 | |||
1206 | @@ -0,0 +1,67 @@ | |||
1207 | 1 | #include <gtest/gtest.h> | ||
1208 | 2 | #include <core/dbus/message.h> | ||
1209 | 3 | #include <core/dbus/object.h> | ||
1210 | 4 | #include <core/dbus/types/object_path.h> | ||
1211 | 5 | |||
1212 | 6 | #include <mediascanner/Album.hh> | ||
1213 | 7 | #include <mediascanner/MediaFile.hh> | ||
1214 | 8 | #include <mediascanner/MediaFileBuilder.hh> | ||
1215 | 9 | #include <ms-dbus/dbus-codec.hh> | ||
1216 | 10 | |||
1217 | 11 | class MediaStoreDBusTests : public ::testing::Test { | ||
1218 | 12 | }; | ||
1219 | 13 | |||
1220 | 14 | TEST_F(MediaStoreDBusTests, mediafile_codec) { | ||
1221 | 15 | auto message = core::dbus::Message::make_method_call( | ||
1222 | 16 | "org.example.Name", | ||
1223 | 17 | core::dbus::types::ObjectPath("/org/example/Path"), | ||
1224 | 18 | "org.example.Interface", | ||
1225 | 19 | "Method"); | ||
1226 | 20 | |||
1227 | 21 | mediascanner::MediaFile media = mediascanner::MediaFileBuilder("a") | ||
1228 | 22 | .setContentType("type") | ||
1229 | 23 | .setETag("etag") | ||
1230 | 24 | .setDate("1900") | ||
1231 | 25 | .setTitle("b") | ||
1232 | 26 | .setAuthor("c") | ||
1233 | 27 | .setAlbum("d") | ||
1234 | 28 | .setAlbumArtist("e") | ||
1235 | 29 | .setGenre("f") | ||
1236 | 30 | .setDiscNumber(0) | ||
1237 | 31 | .setTrackNumber(1) | ||
1238 | 32 | .setDuration(5) | ||
1239 | 33 | .setType(mediascanner::AudioMedia); | ||
1240 | 34 | message->writer() << media; | ||
1241 | 35 | |||
1242 | 36 | EXPECT_EQ("(sssssssssiiii)", message->signature()); | ||
1243 | 37 | EXPECT_EQ(core::dbus::helper::TypeMapper<mediascanner::MediaFile>::signature(), message->signature()); | ||
1244 | 38 | |||
1245 | 39 | mediascanner::MediaFile media2; | ||
1246 | 40 | message->reader() >> media2; | ||
1247 | 41 | EXPECT_EQ(media, media2); | ||
1248 | 42 | } | ||
1249 | 43 | |||
1250 | 44 | TEST_F(MediaStoreDBusTests, album_codec) { | ||
1251 | 45 | auto message = core::dbus::Message::make_method_call( | ||
1252 | 46 | "org.example.Name", | ||
1253 | 47 | core::dbus::types::ObjectPath("/org/example/Path"), | ||
1254 | 48 | "org.example.Interface", | ||
1255 | 49 | "Method"); | ||
1256 | 50 | |||
1257 | 51 | mediascanner::Album album("title", "artist"); | ||
1258 | 52 | message->writer() << album; | ||
1259 | 53 | |||
1260 | 54 | EXPECT_EQ("(ss)", message->signature()); | ||
1261 | 55 | EXPECT_EQ(core::dbus::helper::TypeMapper<mediascanner::Album>::signature(), message->signature()); | ||
1262 | 56 | |||
1263 | 57 | mediascanner::Album album2; | ||
1264 | 58 | message->reader() >> album2; | ||
1265 | 59 | EXPECT_EQ("title", album2.getTitle()); | ||
1266 | 60 | EXPECT_EQ("artist", album2.getArtist()); | ||
1267 | 61 | EXPECT_EQ(album, album2); | ||
1268 | 62 | } | ||
1269 | 63 | |||
1270 | 64 | int main(int argc, char **argv) { | ||
1271 | 65 | ::testing::InitGoogleTest(&argc, argv); | ||
1272 | 66 | return RUN_ALL_TESTS(); | ||
1273 | 67 | } | ||
1274 | 0 | 68 | ||
1275 | === modified file 'test/test_qml.cc' | |||
1276 | --- test/test_qml.cc 2014-05-24 09:41:18 +0000 | |||
1277 | +++ test/test_qml.cc 2014-05-24 09:41:18 +0000 | |||
1278 | @@ -1,12 +1,19 @@ | |||
1279 | 1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
1280 | 2 | #include <cstdio> | ||
1281 | 3 | #include <memory> | ||
1282 | 2 | #include <string> | 4 | #include <string> |
1283 | 3 | 5 | ||
1284 | 6 | #include <QProcess> | ||
1285 | 4 | #include <QtQuickTest/quicktest.h> | 7 | #include <QtQuickTest/quicktest.h> |
1286 | 5 | 8 | ||
1287 | 9 | #include <core/dbus/fixture.h> | ||
1288 | 10 | |||
1289 | 6 | #include <mediascanner/MediaStore.hh> | 11 | #include <mediascanner/MediaStore.hh> |
1290 | 7 | #include <mediascanner/MediaFile.hh> | 12 | #include <mediascanner/MediaFile.hh> |
1291 | 8 | #include <mediascanner/MediaFileBuilder.hh> | 13 | #include <mediascanner/MediaFileBuilder.hh> |
1292 | 9 | 14 | ||
1293 | 15 | #include "test_config.h" | ||
1294 | 16 | |||
1295 | 10 | using namespace mediascanner; | 17 | using namespace mediascanner; |
1296 | 11 | 18 | ||
1297 | 12 | class MediaStoreData { | 19 | class MediaStoreData { |
1298 | @@ -18,8 +25,29 @@ | |||
1299 | 18 | } | 25 | } |
1300 | 19 | setenv("MEDIASCANNER_CACHEDIR", db_path.c_str(), true); | 26 | setenv("MEDIASCANNER_CACHEDIR", db_path.c_str(), true); |
1301 | 20 | populate(); | 27 | populate(); |
1302 | 28 | |||
1303 | 29 | // Start up private bus, and start daemon. | ||
1304 | 30 | dbus_fixture.reset( | ||
1305 | 31 | new core::dbus::Fixture( | ||
1306 | 32 | core::dbus::Fixture::default_session_bus_config_file(), | ||
1307 | 33 | core::dbus::Fixture::default_system_bus_config_file())); | ||
1308 | 34 | |||
1309 | 35 | daemon.setProgram(TEST_DIR "/../src/ms-dbus/mediascanner-dbus-2.0"); | ||
1310 | 36 | daemon.setProcessChannelMode(QProcess::ForwardedChannels); | ||
1311 | 37 | daemon.start(); | ||
1312 | 38 | daemon.closeWriteChannel(); | ||
1313 | 39 | if (!daemon.waitForStarted()) { | ||
1314 | 40 | throw std::runtime_error("Failed to start mediascanner-dbus-2.0"); | ||
1315 | 41 | } | ||
1316 | 21 | } | 42 | } |
1317 | 22 | ~MediaStoreData() { | 43 | ~MediaStoreData() { |
1318 | 44 | daemon.kill(); | ||
1319 | 45 | if (!daemon.waitForFinished()) { | ||
1320 | 46 | fprintf(stderr, "Failed to stop mediascanner-dbus-2.0\n"); | ||
1321 | 47 | } | ||
1322 | 48 | |||
1323 | 49 | dbus_fixture.reset(); | ||
1324 | 50 | |||
1325 | 23 | if (system("rm -rf \"$MEDIASCANNER_CACHEDIR\"") == -1) { | 51 | if (system("rm -rf \"$MEDIASCANNER_CACHEDIR\"") == -1) { |
1326 | 24 | throw std::runtime_error("rm -rf failed"); | 52 | throw std::runtime_error("rm -rf failed"); |
1327 | 25 | } | 53 | } |
1328 | @@ -126,6 +154,8 @@ | |||
1329 | 126 | 154 | ||
1330 | 127 | private: | 155 | private: |
1331 | 128 | std::string db_path; | 156 | std::string db_path; |
1332 | 157 | std::unique_ptr<core::dbus::Fixture> dbus_fixture; | ||
1333 | 158 | QProcess daemon; | ||
1334 | 129 | }; | 159 | }; |
1335 | 130 | 160 | ||
1336 | 131 | MediaStoreData data; | 161 | MediaStoreData data; |
FAILED: Continuous integration, rev:251 jenkins. qa.ubuntu. com/job/ mediascanner2- ci/73/ jenkins. qa.ubuntu. com/job/ mediascanner2- utopic- amd64-ci/ 14/console jenkins. qa.ubuntu. com/job/ mediascanner2- utopic- armhf-ci/ 14/console jenkins. qa.ubuntu. com/job/ mediascanner2- utopic- i386-ci/ 14/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/mediascanne r2-ci/73/ rebuild
http://