Merge lp:~cyphermox/mtp/0.0.3-logging-inotify into lp:mtp
- 0.0.3-logging-inotify
- Merge into trunk
Proposed by
Mathieu Trudel-Lapierre
Status: | Merged |
---|---|
Approved by: | Ricardo Salveti |
Approved revision: | 47 |
Merged at revision: | 43 |
Proposed branch: | lp:~cyphermox/mtp/0.0.3-logging-inotify |
Merge into: | lp:mtp |
Diff against target: |
1854 lines (+438/-225) 20 files modified
CMakeLists.txt (+5/-1) debian/changelog (+9/-0) debian/control (+3/-0) debian/mtp-server.conf (+2/-0) include/MtpDatabase.h (+2/-1) include/MtpTypes.h (+0/-6) libusbhost/src/usbhost.c (+0/-3) server/CMakeLists.txt (+2/-0) server/UbuntuMtpDatabase.h (+223/-68) server/server.cpp (+8/-4) src/MtpDataPacket.cpp (+2/-3) src/MtpDevice.cpp (+28/-27) src/MtpDeviceInfo.cpp (+12/-4) src/MtpObjectInfo.cpp (+22/-12) src/MtpPacket.cpp (+7/-9) src/MtpProperty.cpp (+31/-20) src/MtpServer.cpp (+66/-59) src/MtpStorage.cpp (+3/-1) src/MtpStorageInfo.cpp (+12/-6) tests/MockMtpDatabase.h (+1/-1) |
To merge this branch: | bzr merge lp:~cyphermox/mtp/0.0.3-logging-inotify |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ricardo Salveti (community) | Approve | ||
PS Jenkins bot | continuous-integration | Needs Fixing | |
Review via email: mp+213681@code.launchpad.net |
Commit message
- Do better logging
- Listen to inotify changes for filesystem modifications happening outside the MTP protocol.
Description of the change
- Do better logging
- Listen to inotify changes for filesystem modifications happening outside the MTP protocol.
To post a comment you must log in.
- 47. By Mathieu Trudel-Lapierre
-
Drop useless function read_more_events()
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
review:
Needs Fixing
(continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote : | # |
Works fine, just that as a side effect we don't have a verbose log output by default anymore (but expected).
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2013-09-13 16:37:39 +0000 |
3 | +++ CMakeLists.txt 2014-04-01 15:51:14 +0000 |
4 | @@ -2,6 +2,8 @@ |
5 | |
6 | cmake_minimum_required(VERSION 2.8) |
7 | |
8 | +include(FindPkgConfig) |
9 | + |
10 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") |
11 | |
12 | add_definitions(-DMTP_DEVICE -DMTP_HOST) |
13 | @@ -10,7 +12,8 @@ |
14 | set(MTP_VERSION_MINOR 0) |
15 | set(MTP_VERSION_PATCH 0) |
16 | |
17 | -find_package(Boost REQUIRED COMPONENTS system filesystem unit_test_framework) |
18 | +find_package(Boost REQUIRED COMPONENTS thread system filesystem unit_test_framework) |
19 | +pkg_check_modules(GLOG libglog) |
20 | |
21 | set( |
22 | MTP_HEADERS |
23 | @@ -66,6 +69,7 @@ |
24 | target_link_libraries( |
25 | mtpserver |
26 | android-properties |
27 | + ${GLOG_LIBRARIES} |
28 | ) |
29 | |
30 | set_target_properties( |
31 | |
32 | === modified file 'debian/changelog' |
33 | --- debian/changelog 2014-03-07 19:40:09 +0000 |
34 | +++ debian/changelog 2014-04-01 15:51:14 +0000 |
35 | @@ -1,3 +1,12 @@ |
36 | +mtp (0.0.3+14.04.20140326-0ubuntu1) UNRELEASED; urgency=medium |
37 | + |
38 | + * New release: |
39 | + - Do better logging; with logging levels for verbosity. |
40 | + - Listen to inotify events to know about changes happening on the |
41 | + filesystem but not initiated by the MTP protocol. |
42 | + |
43 | + -- Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> Thu, 27 Mar 2014 11:44:08 -0400 |
44 | + |
45 | mtp (0.0.2+14.04.20140307-0ubuntu1) trusty; urgency=low |
46 | |
47 | [ Oliver Grawert ] |
48 | |
49 | === modified file 'debian/control' |
50 | --- debian/control 2013-09-13 16:37:39 +0000 |
51 | +++ debian/control 2014-04-01 15:51:14 +0000 |
52 | @@ -5,10 +5,13 @@ |
53 | XSBC-Original-Maintainer: Thomas Voß <thomas.voss@canonical.com> |
54 | Build-Depends: debhelper (>= 9), |
55 | cmake, |
56 | + pkg-config, |
57 | libboost-dev, |
58 | + libboost-thread-dev, |
59 | libboost-filesystem-dev, |
60 | libboost-test-dev, |
61 | libandroid-properties-dev, |
62 | + libgoogle-glog-dev, |
63 | Standards-Version: 3.9.4 |
64 | Homepage: http://launchpad.net/mtp |
65 | # If you aren't ~phablet-team but need to upload packaging changes, |
66 | |
67 | === modified file 'debian/mtp-server.conf' |
68 | --- debian/mtp-server.conf 2014-03-07 13:26:41 +0000 |
69 | +++ debian/mtp-server.conf 2014-04-01 15:51:14 +0000 |
70 | @@ -3,6 +3,8 @@ |
71 | start on :sys:android-mtp-on or :sys:android-usb-connected |
72 | stop on desktop-end or :sys:android-mtp-off |
73 | |
74 | +env GOOGLE_LOGTOSTDERR=1 |
75 | + |
76 | respawn |
77 | |
78 | exec /usr/bin/mtp-server |
79 | |
80 | === modified file 'include/MtpDatabase.h' |
81 | --- include/MtpDatabase.h 2013-11-27 17:21:38 +0000 |
82 | +++ include/MtpDatabase.h 2014-04-01 15:51:14 +0000 |
83 | @@ -18,6 +18,7 @@ |
84 | #define _MTP_DATABASE_H |
85 | |
86 | #include "MtpTypes.h" |
87 | +#include "MtpServer.h" |
88 | |
89 | namespace android { |
90 | |
91 | @@ -106,7 +107,7 @@ |
92 | |
93 | virtual MtpProperty* getDevicePropertyDesc(MtpDeviceProperty property) = 0; |
94 | |
95 | - virtual void sessionStarted() = 0; |
96 | + virtual void sessionStarted(MtpServer* server) = 0; |
97 | |
98 | virtual void sessionEnded() = 0; |
99 | }; |
100 | |
101 | === modified file 'include/MtpTypes.h' |
102 | --- include/MtpTypes.h 2013-06-13 10:22:21 +0000 |
103 | +++ include/MtpTypes.h 2014-04-01 15:51:14 +0000 |
104 | @@ -25,12 +25,6 @@ |
105 | #include <thread> |
106 | #include <vector> |
107 | |
108 | -// TODO(tvoss): Find a more sensible approach here. |
109 | -#define ALOGD(log, ...) fprintf(stdout, log, ##__VA_ARGS__) |
110 | -#define ALOGI(log, ...) fprintf(stdout, log, ##__VA_ARGS__) |
111 | -#define ALOGE(log, ...) fprintf(stdout, log, ##__VA_ARGS__) |
112 | -#define ALOGV(log, ...) fprintf(stdout, log, ##__VA_ARGS__) |
113 | - |
114 | namespace android { |
115 | |
116 | typedef int32_t int128_t[4]; |
117 | |
118 | === modified file 'libusbhost/src/usbhost.c' |
119 | --- libusbhost/src/usbhost.c 2013-06-13 10:22:21 +0000 |
120 | +++ libusbhost/src/usbhost.c 2014-04-01 15:51:14 +0000 |
121 | @@ -19,9 +19,6 @@ |
122 | |
123 | #ifdef USE_LIBLOG |
124 | #define LOG_TAG "usbhost" |
125 | -#include "utils/Log.h" |
126 | -#define D ALOGD |
127 | -#else |
128 | #define D printf |
129 | #endif |
130 | |
131 | |
132 | === modified file 'server/CMakeLists.txt' |
133 | --- server/CMakeLists.txt 2013-09-13 16:37:39 +0000 |
134 | +++ server/CMakeLists.txt 2014-04-01 15:51:14 +0000 |
135 | @@ -13,8 +13,10 @@ |
136 | usbhost |
137 | android-properties |
138 | ${Boost_LIBRARIES} |
139 | + ${Boost_thread_LIBRARIES} |
140 | ${Boost_system_LIBRARIES} |
141 | ${Boost_filesystem_LIBRARIES} |
142 | + ${GLOG_LIBRARIES} |
143 | ) |
144 | |
145 | install( |
146 | |
147 | === modified file 'server/UbuntuMtpDatabase.h' |
148 | --- server/UbuntuMtpDatabase.h 2013-12-03 21:18:37 +0000 |
149 | +++ server/UbuntuMtpDatabase.h 2014-04-01 15:51:14 +0000 |
150 | @@ -24,6 +24,7 @@ |
151 | #include <MtpStringBuffer.h> |
152 | #include <MtpObjectInfo.h> |
153 | #include <MtpProperty.h> |
154 | +#include <MtpDebug.h> |
155 | |
156 | #include <cstdlib> |
157 | #include <cstring> |
158 | @@ -33,7 +34,11 @@ |
159 | #include <string> |
160 | #include <tuple> |
161 | #include <exception> |
162 | +#include <sys/inotify.h> |
163 | |
164 | +#include <boost/thread.hpp> |
165 | +#include <boost/asio.hpp> |
166 | +#include <boost/bind.hpp> |
167 | #include <boost/algorithm/string.hpp> |
168 | #include <boost/assign/list_of.hpp> |
169 | #include <boost/foreach.hpp> |
170 | @@ -41,6 +46,9 @@ |
171 | #include <boost/range/adaptors.hpp> |
172 | #include <boost/range/algorithm.hpp> |
173 | |
174 | +#include <glog/logging.h> |
175 | + |
176 | +namespace asio = boost::asio; |
177 | using namespace boost::filesystem; |
178 | |
179 | namespace android |
180 | @@ -55,11 +63,17 @@ |
181 | size_t object_size; |
182 | std::string display_name; |
183 | std::string path; |
184 | + int watch_fd; |
185 | }; |
186 | |
187 | + MtpServer* local_server; |
188 | uint32_t counter; |
189 | std::map<MtpObjectHandle, DbEntry> db; |
190 | std::map<std::string, MtpObjectFormat> formats = boost::assign::map_list_of |
191 | + (".gif", MTP_FORMAT_GIF) |
192 | + (".png", MTP_FORMAT_PNG) |
193 | + (".jpeg", MTP_FORMAT_JFIF) |
194 | + (".tiff", MTP_FORMAT_TIFF) |
195 | (".ogg", MTP_FORMAT_OGG) |
196 | (".mp3", MTP_FORMAT_MP3) |
197 | (".wav", MTP_FORMAT_WAV) |
198 | @@ -67,11 +81,18 @@ |
199 | (".aac", MTP_FORMAT_AAC) |
200 | (".flac", MTP_FORMAT_FLAC); |
201 | |
202 | + boost::thread notifier_thread; |
203 | + boost::thread io_service_thread; |
204 | + |
205 | + asio::io_service io_svc; |
206 | + asio::posix::stream_descriptor stream_desc; |
207 | + asio::streambuf buf; |
208 | + int inotify_fd; |
209 | + |
210 | MtpObjectFormat guess_object_format(std::string extension) |
211 | { |
212 | std::map<std::string, MtpObjectFormat>::iterator it; |
213 | |
214 | - std::cout << __PRETTY_FUNCTION__ << " extension: " << extension << std::endl; |
215 | it = formats.find(extension); |
216 | if (it == formats.end()) { |
217 | boost::to_upper(extension); |
218 | @@ -84,6 +105,58 @@ |
219 | return it->second; |
220 | } |
221 | |
222 | + int setup_dir_inotify(path p) |
223 | + { |
224 | + return inotify_add_watch(inotify_fd, |
225 | + p.string().c_str(), |
226 | + IN_MODIFY | IN_CREATE | IN_DELETE); |
227 | + } |
228 | + |
229 | + |
230 | + void add_file_entry(path p, MtpObjectHandle parent) |
231 | + { |
232 | + MtpObjectHandle handle = counter; |
233 | + DbEntry entry; |
234 | + |
235 | + counter++; |
236 | + |
237 | + if (is_directory(p)) { |
238 | + entry.storage_id = MTP_STORAGE_FIXED_RAM; |
239 | + entry.parent = parent; |
240 | + entry.display_name = std::string(p.filename().string()); |
241 | + entry.path = p.string(); |
242 | + entry.object_format = MTP_FORMAT_ASSOCIATION; |
243 | + entry.object_size = 0; |
244 | + entry.watch_fd = setup_dir_inotify(p); |
245 | + |
246 | + db.insert( std::pair<MtpObjectHandle, DbEntry>(handle, entry) ); |
247 | + |
248 | + if (local_server) |
249 | + local_server->sendObjectAdded(handle); |
250 | + |
251 | + parse_directory (p, handle); |
252 | + } else { |
253 | + try { |
254 | + entry.storage_id = MTP_STORAGE_FIXED_RAM; |
255 | + entry.parent = parent; |
256 | + entry.display_name = std::string(p.filename().string()); |
257 | + entry.path = p.string(); |
258 | + entry.object_format = guess_object_format(p.extension().string()); |
259 | + entry.object_size = file_size(p); |
260 | + |
261 | + VLOG(1) << "Adding \"" << p.string() << "\""; |
262 | + |
263 | + db.insert( std::pair<MtpObjectHandle, DbEntry>(handle, entry) ); |
264 | + |
265 | + if (local_server) |
266 | + local_server->sendObjectAdded(handle); |
267 | + |
268 | + } catch (const filesystem_error& ex) { |
269 | + PLOG(WARNING) << "There was an error reading file properties"; |
270 | + } |
271 | + } |
272 | + } |
273 | + |
274 | void parse_directory(path p, MtpObjectHandle parent) |
275 | { |
276 | DbEntry entry; |
277 | @@ -93,32 +166,7 @@ |
278 | |
279 | for (std::vector<path>::const_iterator it(v.begin()), it_end(v.end()); it != it_end; ++it) |
280 | { |
281 | - MtpObjectHandle handle = counter; |
282 | - |
283 | - counter++; |
284 | - |
285 | - std::cout << " " << *it << " handle: " << handle << " parent: " << parent << std::endl; |
286 | - |
287 | - entry.storage_id = MTP_STORAGE_FIXED_RAM; |
288 | - entry.parent = parent; |
289 | - entry.display_name = std::string(it->filename().string()); |
290 | - entry.path = it->string(); |
291 | - |
292 | - if (is_regular_file (*it)) { |
293 | - entry.object_format = guess_object_format(it->extension().string()); |
294 | - entry.object_size = file_size(*it); |
295 | - |
296 | - std::cout << " format: " << std::hex << entry.object_format << std::endl; |
297 | - |
298 | - db.insert( std::pair<MtpObjectHandle, DbEntry>(handle, entry) ); |
299 | - } else if (is_directory (*it)) { |
300 | - entry.object_format = MTP_FORMAT_ASSOCIATION; |
301 | - entry.object_size = 0; |
302 | - |
303 | - db.insert( std::pair<MtpObjectHandle, DbEntry>(handle, entry) ); |
304 | - |
305 | - parse_directory (*it, handle); |
306 | - } |
307 | + add_file_entry(*it, parent); |
308 | } |
309 | } |
310 | |
311 | @@ -131,45 +179,135 @@ |
312 | try { |
313 | if (exists(p)) { |
314 | if (is_directory(p)) { |
315 | - std::cout << p << " is a directory containing:\n"; |
316 | - |
317 | entry.storage_id = MTP_STORAGE_FIXED_RAM; |
318 | entry.parent = MTP_PARENT_ROOT; |
319 | entry.display_name = std::string(p.filename().string()); |
320 | entry.path = p.string(); |
321 | entry.object_format = MTP_FORMAT_ASSOCIATION; |
322 | entry.object_size = 0; |
323 | + entry.watch_fd = setup_dir_inotify(p); |
324 | |
325 | db.insert( std::pair<MtpObjectHandle, DbEntry>(handle, entry) ); |
326 | |
327 | parse_directory (p, handle); |
328 | } |
329 | } else |
330 | - std::cout << p << " does not exist\n"; |
331 | + LOG(WARNING) << p << " does not exist\n"; |
332 | } |
333 | catch (const filesystem_error& ex) { |
334 | - std::cout << ex.what() << '\n'; |
335 | - } |
336 | - |
337 | + LOG(ERROR) << ex.what(); |
338 | + } |
339 | + |
340 | + } |
341 | + |
342 | + void read_more_notify() |
343 | + { |
344 | + stream_desc.async_read_some(buf.prepare(buf.max_size()), |
345 | + boost::bind(&UbuntuMtpDatabase::inotify_handler, |
346 | + this, |
347 | + asio::placeholders::error, |
348 | + asio::placeholders::bytes_transferred)); |
349 | + } |
350 | + |
351 | + void inotify_handler(const boost::system::error_code&, |
352 | + std::size_t transferred) |
353 | + { |
354 | + size_t processed = 0; |
355 | + |
356 | + while(transferred - processed >= sizeof(inotify_event)) |
357 | + { |
358 | + const char* cdata = processed + asio::buffer_cast<const char*>(buf.data()); |
359 | + const inotify_event* ievent = reinterpret_cast<const inotify_event*>(cdata); |
360 | + MtpObjectHandle parent; |
361 | + |
362 | + processed += sizeof(inotify_event) + ievent->len; |
363 | + |
364 | + BOOST_FOREACH(MtpObjectHandle i, db | boost::adaptors::map_keys) { |
365 | + if (db.at(i).watch_fd == ievent->wd) { |
366 | + parent = i; |
367 | + break; |
368 | + } |
369 | + } |
370 | + |
371 | + path p(db.at(parent).path + "/" + ievent->name); |
372 | + |
373 | + if(ievent->len > 0 && ievent->mask & IN_MODIFY) |
374 | + { |
375 | + VLOG(2) << __PRETTY_FUNCTION__ << ": file modified: " << p.string(); |
376 | + BOOST_FOREACH(MtpObjectHandle i, db | boost::adaptors::map_keys) { |
377 | + if (db.at(i).path == p.string()) { |
378 | + try { |
379 | + VLOG(2) << "new size: " << file_size(p); |
380 | + db.at(i).object_size = file_size(p); |
381 | + } catch (const filesystem_error& ex) { |
382 | + PLOG(WARNING) << "There was an error reading file properties"; |
383 | + } |
384 | + } |
385 | + } |
386 | + } |
387 | + else if(ievent->len > 0 && ievent->mask & IN_CREATE) |
388 | + { |
389 | + VLOG(2) << __PRETTY_FUNCTION__ << ": file created: " << p.string(); |
390 | + |
391 | + /* try to deal with it as if it was a file. */ |
392 | + add_file_entry(p, parent); |
393 | + } |
394 | + else if(ievent->len > 0 && ievent->mask & IN_DELETE) |
395 | + { |
396 | + VLOG(2) << __PRETTY_FUNCTION__ << ": file deleted: " << p.string(); |
397 | + BOOST_FOREACH(MtpObjectHandle i, db | boost::adaptors::map_keys) { |
398 | + if (db.at(i).path == p.string()) { |
399 | + VLOG(2) << "deleting file at handle " << i; |
400 | + deleteFile(i); |
401 | + if (local_server) |
402 | + local_server->sendObjectRemoved(i); |
403 | + break; |
404 | + } |
405 | + } |
406 | + } |
407 | + } |
408 | + |
409 | + read_more_notify(); |
410 | } |
411 | |
412 | public: |
413 | - UbuntuMtpDatabase(const char *dir) : counter(1) |
414 | + UbuntuMtpDatabase(const char *dir): |
415 | + counter(1), |
416 | + stream_desc(io_svc), |
417 | + buf(1024) |
418 | { |
419 | std::string basedir (dir); |
420 | |
421 | + local_server = nullptr; |
422 | + |
423 | + inotify_fd = inotify_init(); |
424 | + if (inotify_fd <= 0) |
425 | + PLOG(FATAL) << "Unable to initialize inotify"; |
426 | + |
427 | + stream_desc.assign(inotify_fd); |
428 | + |
429 | db = std::map<MtpObjectHandle, DbEntry>(); |
430 | |
431 | + notifier_thread = boost::thread(&UbuntuMtpDatabase::read_more_notify, |
432 | + this); |
433 | + |
434 | readFiles(basedir + "/Documents"); |
435 | readFiles(basedir + "/Music"); |
436 | readFiles(basedir + "/Videos"); |
437 | readFiles(basedir + "/Pictures"); |
438 | readFiles(basedir + "/Downloads"); |
439 | - |
440 | - std::cout << __PRETTY_FUNCTION__ << ": object count:" << db.size() << std::endl; |
441 | - } |
442 | - |
443 | - virtual ~UbuntuMtpDatabase() {} |
444 | + |
445 | + LOG(INFO) << "Added " << counter << " entries to the database."; |
446 | + |
447 | + io_service_thread = boost::thread(boost::bind(&asio::io_service::run, &io_svc)); |
448 | + } |
449 | + |
450 | + virtual ~UbuntuMtpDatabase() { |
451 | + io_svc.stop(); |
452 | + notifier_thread.detach(); |
453 | + io_service_thread.join(); |
454 | + close(inotify_fd); |
455 | + } |
456 | |
457 | // called from SendObjectInfo to reserve a database entry for the incoming file |
458 | virtual MtpObjectHandle beginSendObject( |
459 | @@ -186,7 +324,7 @@ |
460 | if (parent == 0) |
461 | return kInvalidObjectHandle; |
462 | |
463 | - std::cout << __PRETTY_FUNCTION__ << ": " << path << " - " << parent << std::endl; |
464 | + VLOG(1) << __PRETTY_FUNCTION__ << ": " << path << " - " << parent; |
465 | |
466 | entry.storage_id = storage; |
467 | entry.parent = parent; |
468 | @@ -211,7 +349,7 @@ |
469 | MtpObjectFormat format, |
470 | bool succeeded) |
471 | { |
472 | - std::cout << __PRETTY_FUNCTION__ << ": " << path << std::endl; |
473 | + VLOG(1) << __PRETTY_FUNCTION__ << ": " << path; |
474 | |
475 | if (!succeeded) { |
476 | db.erase(handle); |
477 | @@ -230,7 +368,7 @@ |
478 | MtpObjectFormat format, |
479 | MtpObjectHandle parent) |
480 | { |
481 | - std::cout << __PRETTY_FUNCTION__ << ": " << storageID << ", " << format << ", " << parent << std::endl; |
482 | + VLOG(1) << __PRETTY_FUNCTION__ << ": " << storageID << ", " << format << ", " << parent; |
483 | MtpObjectHandleList* list = nullptr; |
484 | try |
485 | { |
486 | @@ -255,7 +393,7 @@ |
487 | MtpObjectFormat format, |
488 | MtpObjectHandle parent) |
489 | { |
490 | - std::cout << __PRETTY_FUNCTION__ << ": " << storageID << ", " << format << ", " << parent << std::endl; |
491 | + VLOG(1) << __PRETTY_FUNCTION__ << ": " << storageID << ", " << format << ", " << parent; |
492 | try |
493 | { |
494 | return db.size(); |
495 | @@ -270,7 +408,7 @@ |
496 | // results can be NULL |
497 | virtual MtpObjectFormatList* getSupportedPlaybackFormats() |
498 | { |
499 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
500 | + VLOG(1) << __PRETTY_FUNCTION__; |
501 | static const MtpObjectFormatList list = { |
502 | /* Generic files */ |
503 | MTP_FORMAT_UNDEFINED, |
504 | @@ -298,14 +436,14 @@ |
505 | |
506 | virtual MtpObjectFormatList* getSupportedCaptureFormats() |
507 | { |
508 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
509 | + VLOG(1) << __PRETTY_FUNCTION__; |
510 | static const MtpObjectFormatList list = {MTP_FORMAT_ASSOCIATION, MTP_FORMAT_PNG}; |
511 | return new MtpObjectFormatList{list}; |
512 | } |
513 | |
514 | virtual MtpObjectPropertyList* getSupportedObjectProperties(MtpObjectFormat format) |
515 | { |
516 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
517 | + VLOG(1) << __PRETTY_FUNCTION__; |
518 | /* |
519 | if (format != MTP_FORMAT_PNG) |
520 | return nullptr; |
521 | @@ -329,7 +467,7 @@ |
522 | |
523 | virtual MtpDevicePropertyList* getSupportedDeviceProperties() |
524 | { |
525 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
526 | + VLOG(1) << __PRETTY_FUNCTION__; |
527 | static const MtpDevicePropertyList list = { MTP_DEVICE_PROPERTY_UNDEFINED }; |
528 | return new MtpDevicePropertyList{list}; |
529 | } |
530 | @@ -339,7 +477,10 @@ |
531 | MtpObjectProperty property, |
532 | MtpDataPacket& packet) |
533 | { |
534 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
535 | + VLOG(1) << __PRETTY_FUNCTION__ |
536 | + << " handle: " << handle |
537 | + << " property: " << MtpDebug::getObjectPropCodeName(property); |
538 | + |
539 | switch(property) |
540 | { |
541 | case MTP_PROPERTY_STORAGE_ID: packet.putUInt32(db.at(handle).storage_id); break; |
542 | @@ -366,7 +507,9 @@ |
543 | path oldpath; |
544 | path newpath; |
545 | |
546 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
547 | + VLOG(1) << __PRETTY_FUNCTION__ |
548 | + << " handle: " << handle |
549 | + << " property: " << MtpDebug::getObjectPropCodeName(property); |
550 | |
551 | switch(property) |
552 | { |
553 | @@ -385,13 +528,13 @@ |
554 | db.at(handle).display_name = newname; |
555 | db.at(handle).path = newpath.string(); |
556 | } catch (filesystem_error& fe) { |
557 | - std::cout << "ERROR: " << fe.what() << std::endl; |
558 | + LOG(ERROR) << fe.what(); |
559 | return MTP_RESPONSE_DEVICE_BUSY; |
560 | } catch (std::exception& e) { |
561 | - std::cout << "ERROR: " << e.what() << std::endl; |
562 | + LOG(ERROR) << e.what(); |
563 | return MTP_RESPONSE_GENERAL_ERROR; |
564 | } catch (...) { |
565 | - std::cout << "ERROR: autre exception" << std::endl; |
566 | + LOG(ERROR) << "An unexpected error has occurred"; |
567 | return MTP_RESPONSE_GENERAL_ERROR; |
568 | } |
569 | |
570 | @@ -406,7 +549,7 @@ |
571 | MtpDeviceProperty property, |
572 | MtpDataPacket& packet) |
573 | { |
574 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
575 | + VLOG(1) << __PRETTY_FUNCTION__; |
576 | return MTP_RESPONSE_GENERAL_ERROR; |
577 | } |
578 | |
579 | @@ -414,14 +557,14 @@ |
580 | MtpDeviceProperty property, |
581 | MtpDataPacket& packet) |
582 | { |
583 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
584 | + VLOG(1) << __PRETTY_FUNCTION__; |
585 | return MTP_RESPONSE_OPERATION_NOT_SUPPORTED; |
586 | } |
587 | |
588 | virtual MtpResponseCode resetDeviceProperty( |
589 | MtpDeviceProperty property) |
590 | { |
591 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
592 | + VLOG(1) << __PRETTY_FUNCTION__; |
593 | return MTP_RESPONSE_OPERATION_NOT_SUPPORTED; |
594 | } |
595 | |
596 | @@ -433,7 +576,7 @@ |
597 | int depth, |
598 | MtpDataPacket& packet) |
599 | { |
600 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
601 | + VLOG(2) << __PRETTY_FUNCTION__; |
602 | return MTP_RESPONSE_OPERATION_NOT_SUPPORTED; |
603 | } |
604 | |
605 | @@ -441,7 +584,7 @@ |
606 | MtpObjectHandle handle, |
607 | MtpObjectInfo& info) |
608 | { |
609 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
610 | + VLOG(2) << __PRETTY_FUNCTION__; |
611 | |
612 | info.mHandle = handle; |
613 | info.mStorageID = db.at(handle).storage_id; |
614 | @@ -460,6 +603,9 @@ |
615 | info.mDateModified = 0; |
616 | info.mKeywords = ::strdup("ubuntu,touch"); |
617 | |
618 | + if (VLOG_IS_ON(2)) |
619 | + info.print(); |
620 | + |
621 | return MTP_RESPONSE_OK; |
622 | } |
623 | |
624 | @@ -481,7 +627,7 @@ |
625 | { |
626 | DbEntry entry = db.at(handle); |
627 | |
628 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
629 | + VLOG(1) << __PRETTY_FUNCTION__ << " handle: " << handle; |
630 | |
631 | outFilePath = std::string(entry.path); |
632 | outFileLength = entry.object_size; |
633 | @@ -495,7 +641,10 @@ |
634 | size_t orig_size = db.size(); |
635 | size_t new_size; |
636 | |
637 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
638 | + VLOG(2) << __PRETTY_FUNCTION__ << " handle: " << handle; |
639 | + |
640 | + if (db.at(handle).object_format == MTP_FORMAT_ASSOCIATION) |
641 | + inotify_rm_watch(inotify_fd, db.at(handle).watch_fd); |
642 | |
643 | new_size = db.erase(handle); |
644 | |
645 | @@ -508,6 +657,7 @@ |
646 | if (db.at(i).parent == handle) |
647 | db.erase(i); |
648 | } |
649 | + |
650 | return MTP_RESPONSE_OK; |
651 | } |
652 | else |
653 | @@ -516,7 +666,8 @@ |
654 | |
655 | virtual MtpResponseCode moveFile(MtpObjectHandle handle, MtpObjectHandle new_parent) |
656 | { |
657 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
658 | + VLOG(1) << __PRETTY_FUNCTION__ << " handle: " << handle |
659 | + << " new parent: " << new_parent; |
660 | |
661 | // change parent |
662 | db.at(handle).parent = new_parent; |
663 | @@ -527,7 +678,7 @@ |
664 | /* |
665 | virtual MtpResponseCode copyFile(MtpObjectHandle handle, MtpObjectHandle new_parent) |
666 | { |
667 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
668 | + VLOG(2) << __PRETTY_FUNCTION__; |
669 | |
670 | // duplicate DbEntry |
671 | // change parent |
672 | @@ -538,7 +689,7 @@ |
673 | |
674 | virtual MtpObjectHandleList* getObjectReferences(MtpObjectHandle handle) |
675 | { |
676 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
677 | + VLOG(1) << __PRETTY_FUNCTION__; |
678 | return nullptr; |
679 | } |
680 | |
681 | @@ -546,7 +697,7 @@ |
682 | MtpObjectHandle handle, |
683 | MtpObjectHandleList* references) |
684 | { |
685 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
686 | + VLOG(1) << __PRETTY_FUNCTION__; |
687 | return MTP_RESPONSE_OPERATION_NOT_SUPPORTED; |
688 | } |
689 | |
690 | @@ -554,7 +705,8 @@ |
691 | MtpObjectProperty property, |
692 | MtpObjectFormat format) |
693 | { |
694 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
695 | + VLOG(1) << __PRETTY_FUNCTION__ << MtpDebug::getObjectPropCodeName(property); |
696 | + |
697 | MtpProperty* result = nullptr; |
698 | switch(property) |
699 | { |
700 | @@ -574,18 +726,21 @@ |
701 | |
702 | virtual MtpProperty* getDevicePropertyDesc(MtpDeviceProperty property) |
703 | { |
704 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
705 | + VLOG(1) << __PRETTY_FUNCTION__ << MtpDebug::getDevicePropCodeName(property); |
706 | return new MtpProperty(MTP_DEVICE_PROPERTY_UNDEFINED, MTP_TYPE_UNDEFINED); |
707 | } |
708 | |
709 | - virtual void sessionStarted() |
710 | + virtual void sessionStarted(MtpServer* server) |
711 | { |
712 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
713 | + VLOG(1) << __PRETTY_FUNCTION__; |
714 | + local_server = server; |
715 | } |
716 | |
717 | virtual void sessionEnded() |
718 | { |
719 | - std::cout << __PRETTY_FUNCTION__ << std::endl; |
720 | + VLOG(1) << __PRETTY_FUNCTION__; |
721 | + VLOG(1) << "objects in db at session end: " << db.size(); |
722 | + local_server = nullptr; |
723 | } |
724 | }; |
725 | } |
726 | |
727 | === modified file 'server/server.cpp' |
728 | --- server/server.cpp 2013-09-13 16:37:39 +0000 |
729 | +++ server/server.cpp 2014-04-01 15:51:14 +0000 |
730 | @@ -30,6 +30,7 @@ |
731 | #include <pwd.h> |
732 | |
733 | #include <hybris/properties/properties.h> |
734 | +#include <glog/logging.h> |
735 | |
736 | namespace |
737 | { |
738 | @@ -48,12 +49,16 @@ |
739 | struct passwd *userdata = getpwuid (getuid()); |
740 | char product_name[PROP_VALUE_MAX]; |
741 | int fd = open("/dev/mtp_usb", O_RDWR); |
742 | - |
743 | + |
744 | + google::InitGoogleLogging(argv[0]); |
745 | + |
746 | + LOG(INFO) << "MTP server starting..."; |
747 | + |
748 | if (fd < 0) |
749 | { |
750 | - std::cout << "Error opening /dev/mtp_usb, aborting now..." << std::endl; |
751 | + LOG(FATAL) << "Error opening /dev/mtp_usb, aborting now..."; |
752 | } |
753 | - |
754 | + |
755 | std::shared_ptr<android::MtpServer> server |
756 | { |
757 | new android::MtpServer( |
758 | @@ -90,5 +95,4 @@ |
759 | if (t.joinable()) |
760 | t.join(); |
761 | */ |
762 | - |
763 | } |
764 | |
765 | === modified file 'src/MtpDataPacket.cpp' |
766 | --- src/MtpDataPacket.cpp 2013-06-13 10:22:21 +0000 |
767 | +++ src/MtpDataPacket.cpp 2014-04-01 15:51:14 +0000 |
768 | @@ -14,8 +14,6 @@ |
769 | * limitations under the License. |
770 | */ |
771 | |
772 | -#define LOG_TAG "MtpDataPacket" |
773 | - |
774 | #include <cstdio> |
775 | #include <cstring> |
776 | |
777 | @@ -24,6 +22,7 @@ |
778 | #include <unistd.h> |
779 | |
780 | #include <usbhost/usbhost.h> |
781 | +#include <glog/logging.h> |
782 | |
783 | #include "MtpDataPacket.h" |
784 | #include "MtpStringBuffer.h" |
785 | @@ -421,7 +420,7 @@ |
786 | // Queue a read request. Call readDataWait to wait for result |
787 | int MtpDataPacket::readDataAsync(struct usb_request *req) { |
788 | if (usb_request_queue(req)) { |
789 | - ALOGE("usb_endpoint_queue failed, errno: %d", errno); |
790 | + PLOG(ERROR) << "usb_endpoint_queue failed"; |
791 | return -1; |
792 | } |
793 | return 0; |
794 | |
795 | === modified file 'src/MtpDevice.cpp' |
796 | --- src/MtpDevice.cpp 2013-06-13 10:22:21 +0000 |
797 | +++ src/MtpDevice.cpp 2014-04-01 15:51:14 +0000 |
798 | @@ -38,6 +38,7 @@ |
799 | #include <unistd.h> |
800 | |
801 | #include <usbhost/usbhost.h> |
802 | +#include <glog/logging.h> |
803 | |
804 | namespace android { |
805 | |
806 | @@ -56,7 +57,7 @@ |
807 | MtpDevice* MtpDevice::open(const char* deviceName, int fd) { |
808 | struct usb_device *device = usb_device_new(deviceName, fd); |
809 | if (!device) { |
810 | - ALOGE("usb_device_new failed for %s", deviceName); |
811 | + LOG(ERROR) << "usb_device_new failed for " << deviceName; |
812 | return NULL; |
813 | } |
814 | |
815 | @@ -75,7 +76,7 @@ |
816 | { |
817 | char* manufacturerName = usb_device_get_manufacturer_name(device); |
818 | char* productName = usb_device_get_product_name(device); |
819 | - ALOGD("Found camera: \"%s\" \"%s\"\n", manufacturerName, productName); |
820 | + VLOG(2) << "Found camera: \"" << manufacturerName << " \"" << productName << "\""; |
821 | free(manufacturerName); |
822 | free(productName); |
823 | } else if (interface->bInterfaceClass == 0xFF && |
824 | @@ -93,7 +94,7 @@ |
825 | // Looks like an android style MTP device |
826 | char* manufacturerName = usb_device_get_manufacturer_name(device); |
827 | char* productName = usb_device_get_product_name(device); |
828 | - ALOGD("Found MTP device: \"%s\" \"%s\"\n", manufacturerName, productName); |
829 | + VLOG(2) << "Found MTP device: \"" << manufacturerName << "\" \"" << productName << "\""; |
830 | free(manufacturerName); |
831 | free(productName); |
832 | } |
833 | @@ -137,7 +138,7 @@ |
834 | for (int i = 0; i < 3; i++) { |
835 | ep = (struct usb_endpoint_descriptor *)usb_descriptor_iter_next(&iter); |
836 | if (!ep || ep->bDescriptorType != USB_DT_ENDPOINT) { |
837 | - ALOGE("endpoints not found\n"); |
838 | + LOG(ERROR) << "endpoints not found"; |
839 | usb_device_close(device); |
840 | return NULL; |
841 | } |
842 | @@ -152,13 +153,13 @@ |
843 | } |
844 | } |
845 | if (!ep_in_desc || !ep_out_desc || !ep_intr_desc) { |
846 | - ALOGE("endpoints not found\n"); |
847 | + LOG(ERROR) << "endpoints not found"; |
848 | usb_device_close(device); |
849 | return NULL; |
850 | } |
851 | |
852 | if (usb_device_claim_interface(device, interface->bInterfaceNumber)) { |
853 | - ALOGE("usb_device_claim_interface failed errno: %d\n", errno); |
854 | + PLOG(ERROR) << "usb_device_claim_interface failed"; |
855 | usb_device_close(device); |
856 | return NULL; |
857 | } |
858 | @@ -171,7 +172,7 @@ |
859 | } |
860 | |
861 | usb_device_close(device); |
862 | - ALOGE("device not found"); |
863 | + LOG(ERROR) << "device not found"; |
864 | return NULL; |
865 | } |
866 | |
867 | @@ -235,7 +236,7 @@ |
868 | mDeviceInfo->print(); |
869 | |
870 | if (mDeviceInfo->mDeviceProperties) { |
871 | - ALOGI("***** DEVICE PROPERTIES *****\n"); |
872 | + VLOG(2) << "***** DEVICE PROPERTIES *****"; |
873 | int count = mDeviceInfo->mDeviceProperties->size(); |
874 | for (int i = 0; i < count; i++) { |
875 | MtpDeviceProperty propCode = (*mDeviceInfo->mDeviceProperties)[i]; |
876 | @@ -249,11 +250,11 @@ |
877 | } |
878 | |
879 | if (mDeviceInfo->mPlaybackFormats) { |
880 | - ALOGI("***** OBJECT PROPERTIES *****\n"); |
881 | + VLOG(2) << "***** OBJECT PROPERTIES *****"; |
882 | int count = mDeviceInfo->mPlaybackFormats->size(); |
883 | for (int i = 0; i < count; i++) { |
884 | MtpObjectFormat format = (*mDeviceInfo->mPlaybackFormats)[i]; |
885 | - ALOGI("*** FORMAT: %s\n", MtpDebug::getFormatCodeName(format)); |
886 | + VLOG(2) << "*** FORMAT: " << MtpDebug::getFormatCodeName(format); |
887 | MtpObjectPropertyList* props = getObjectPropsSupported(format); |
888 | if (props) { |
889 | for (int j = 0; j < props->size(); j++) { |
890 | @@ -263,8 +264,8 @@ |
891 | property->print(); |
892 | delete property; |
893 | } else { |
894 | - ALOGE("could not fetch property: %s", |
895 | - MtpDebug::getObjectPropCodeName(prop)); |
896 | + LOG(ERROR) << "could not fetch property: " |
897 | + << MtpDebug::getObjectPropCodeName(prop); |
898 | } |
899 | } |
900 | } |
901 | @@ -587,8 +588,8 @@ |
902 | && mData.readDataHeader(mRequestIn1)) { |
903 | uint32_t length = mData.getContainerLength(); |
904 | if (length - MTP_CONTAINER_HEADER_SIZE != objectSize) { |
905 | - ALOGE("readObject error objectSize: %d, length: %d", |
906 | - objectSize, length); |
907 | + LOG(ERROR) << "readObject error objectSize: " << objectSize |
908 | + << " length: " << length; |
909 | goto fail; |
910 | } |
911 | length -= MTP_CONTAINER_HEADER_SIZE; |
912 | @@ -620,7 +621,7 @@ |
913 | // queue up a read request |
914 | req->buffer_length = (remaining > sizeof(buffer1) ? sizeof(buffer1) : remaining); |
915 | if (mData.readDataAsync(req)) { |
916 | - ALOGE("readDataAsync failed"); |
917 | + LOG(ERROR) << "readDataAsync failed"; |
918 | goto fail; |
919 | } |
920 | } else { |
921 | @@ -630,7 +631,7 @@ |
922 | if (writeBuffer) { |
923 | // write previous buffer |
924 | if (!callback(writeBuffer, offset, writeLength, clientData)) { |
925 | - ALOGE("write failed"); |
926 | + LOG(ERROR) << "write failed"; |
927 | // wait for pending read before failing |
928 | if (req) |
929 | mData.readDataWait(mDevice); |
930 | @@ -669,10 +670,10 @@ |
931 | |
932 | // reads the object's data and writes it to the specified file path |
933 | bool MtpDevice::readObject(MtpObjectHandle handle, const char* destPath, int group, int perm) { |
934 | - ALOGD("readObject: %s", destPath); |
935 | + VLOG(2) << "readObject: " << destPath; |
936 | int fd = ::open(destPath, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); |
937 | if (fd < 0) { |
938 | - ALOGE("open failed for %s", destPath); |
939 | + LOG(ERROR) << "open failed for " << destPath; |
940 | return false; |
941 | } |
942 | |
943 | @@ -721,7 +722,7 @@ |
944 | // queue up a read request |
945 | req->buffer_length = (remaining > sizeof(buffer1) ? sizeof(buffer1) : remaining); |
946 | if (mData.readDataAsync(req)) { |
947 | - ALOGE("readDataAsync failed"); |
948 | + LOG(ERROR) << "readDataAsync failed"; |
949 | goto fail; |
950 | } |
951 | } else { |
952 | @@ -731,7 +732,7 @@ |
953 | if (writeBuffer) { |
954 | // write previous buffer |
955 | if (write(fd, writeBuffer, writeLength) != writeLength) { |
956 | - ALOGE("write failed"); |
957 | + LOG(ERROR) << "write failed"; |
958 | // wait for pending read before failing |
959 | if (req) |
960 | mData.readDataWait(mDevice); |
961 | @@ -768,7 +769,7 @@ |
962 | } |
963 | |
964 | bool MtpDevice::sendRequest(MtpOperationCode operation) { |
965 | - ALOGV("sendRequest: %s\n", MtpDebug::getOperationCodeName(operation)); |
966 | + VLOG(2) << "sendRequest: " << MtpDebug::getOperationCodeName(operation); |
967 | mReceivedResponse = false; |
968 | mRequest.setOperationCode(operation); |
969 | if (mTransactionID > 0) |
970 | @@ -779,7 +780,7 @@ |
971 | } |
972 | |
973 | bool MtpDevice::sendData() { |
974 | - ALOGV("sendData\n"); |
975 | + VLOG(2) << "sendData"; |
976 | mData.setOperationCode(mRequest.getOperationCode()); |
977 | mData.setTransactionID(mRequest.getTransactionID()); |
978 | int ret = mData.write(mRequestOut); |
979 | @@ -790,10 +791,10 @@ |
980 | bool MtpDevice::readData() { |
981 | mData.reset(); |
982 | int ret = mData.read(mRequestIn1); |
983 | - ALOGV("readData returned %d\n", ret); |
984 | + VLOG(2) << "readData returned " << ret; |
985 | if (ret >= MTP_CONTAINER_HEADER_SIZE) { |
986 | if (mData.getContainerType() == MTP_CONTAINER_TYPE_RESPONSE) { |
987 | - ALOGD("got response packet instead of data packet"); |
988 | + VLOG(2) << "got response packet instead of data packet"; |
989 | // we got a response packet rather than data |
990 | // copy it to mResponse |
991 | mResponse.copyFrom(mData); |
992 | @@ -804,7 +805,7 @@ |
993 | return true; |
994 | } |
995 | else { |
996 | - ALOGV("readResponse failed\n"); |
997 | + VLOG(2) << "readResponse failed"; |
998 | return false; |
999 | } |
1000 | } |
1001 | @@ -816,7 +817,7 @@ |
1002 | } |
1003 | |
1004 | MtpResponseCode MtpDevice::readResponse() { |
1005 | - ALOGV("readResponse\n"); |
1006 | + VLOG(2) << "readResponse"; |
1007 | if (mReceivedResponse) { |
1008 | mReceivedResponse = false; |
1009 | return mResponse.getResponseCode(); |
1010 | @@ -830,7 +831,7 @@ |
1011 | mResponse.dump(); |
1012 | return mResponse.getResponseCode(); |
1013 | } else { |
1014 | - ALOGD("readResponse failed\n"); |
1015 | + VLOG(2) << "readResponse failed"; |
1016 | return -1; |
1017 | } |
1018 | } |
1019 | |
1020 | === modified file 'src/MtpDeviceInfo.cpp' |
1021 | --- src/MtpDeviceInfo.cpp 2013-06-13 10:22:21 +0000 |
1022 | +++ src/MtpDeviceInfo.cpp 2014-04-01 15:51:14 +0000 |
1023 | @@ -23,6 +23,8 @@ |
1024 | |
1025 | #include <cstring> |
1026 | |
1027 | +#include <glog/logging.h> |
1028 | + |
1029 | namespace android { |
1030 | |
1031 | MtpDeviceInfo::MtpDeviceInfo() |
1032 | @@ -90,10 +92,16 @@ |
1033 | } |
1034 | |
1035 | void MtpDeviceInfo::print() { |
1036 | - ALOGV("Device Info:\n\tmStandardVersion: %d\n\tmVendorExtensionID: %d\n\tmVendorExtensionVersiony: %d\n", |
1037 | - mStandardVersion, mVendorExtensionID, mVendorExtensionVersion); |
1038 | - ALOGV("\tmVendorExtensionDesc: %s\n\tmFunctionalCode: %d\n\tmManufacturer: %s\n\tmModel: %s\n\tmVersion: %s\n\tmSerial: %s\n", |
1039 | - mVendorExtensionDesc, mFunctionalCode, mManufacturer, mModel, mVersion, mSerial); |
1040 | + VLOG(2) << "Device Info:" |
1041 | + << "\n\tmStandardVersion: " << mStandardVersion |
1042 | + << "\n\tmVendorExtensionID: " << mVendorExtensionID |
1043 | + << "\n\tmVendorExtensionVersion: " << mVendorExtensionVersion |
1044 | + << "\n\tmVendorExtensionDesc: " << mVendorExtensionDesc |
1045 | + << "\n\tmFunctionalCode: " << mFunctionalCode |
1046 | + << "\n\tmManufacturer: " << mManufacturer |
1047 | + << "\n\tmModel: " << mModel |
1048 | + << "\n\tmVersion: " << mVersion |
1049 | + << "\n\tmSerial: " << mSerial; |
1050 | } |
1051 | |
1052 | } // namespace android |
1053 | |
1054 | === modified file 'src/MtpObjectInfo.cpp' |
1055 | --- src/MtpObjectInfo.cpp 2013-06-13 10:22:21 +0000 |
1056 | +++ src/MtpObjectInfo.cpp 2014-04-01 15:51:14 +0000 |
1057 | @@ -22,8 +22,11 @@ |
1058 | #include "MtpStringBuffer.h" |
1059 | #include "MtpUtils.h" |
1060 | |
1061 | +#include <iomanip> |
1062 | #include <cstring> |
1063 | |
1064 | +#include <glog/logging.h> |
1065 | + |
1066 | namespace android { |
1067 | |
1068 | MtpObjectInfo::MtpObjectInfo(MtpObjectHandle handle) |
1069 | @@ -93,18 +96,25 @@ |
1070 | } |
1071 | |
1072 | void MtpObjectInfo::print() { |
1073 | - ALOGD("MtpObject Info %08X: %s\n", mHandle, mName); |
1074 | - ALOGD(" mStorageID: %08X mFormat: %04X mProtectionStatus: %d\n", |
1075 | - mStorageID, mFormat, mProtectionStatus); |
1076 | - ALOGD(" mCompressedSize: %d mThumbFormat: %04X mThumbCompressedSize: %d\n", |
1077 | - mCompressedSize, mFormat, mThumbCompressedSize); |
1078 | - ALOGD(" mThumbPixWidth: %d mThumbPixHeight: %d\n", mThumbPixWidth, mThumbPixHeight); |
1079 | - ALOGD(" mImagePixWidth: %d mImagePixHeight: %d mImagePixDepth: %d\n", |
1080 | - mImagePixWidth, mImagePixHeight, mImagePixDepth); |
1081 | - ALOGD(" mParent: %08X mAssociationType: %04X mAssociationDesc: %04X\n", |
1082 | - mParent, mAssociationType, mAssociationDesc); |
1083 | - ALOGD(" mSequenceNumber: %d mDateCreated: %ld mDateModified: %ld mKeywords: %s\n", |
1084 | - mSequenceNumber, mDateCreated, mDateModified, mKeywords); |
1085 | + VLOG(2) << "MtpObject Info " << mHandle << ": " << mName; |
1086 | + VLOG(2) << " mStorageID: " << std::hex << mStorageID |
1087 | + << " mFormat: " << mFormat << std::dec |
1088 | + << " mProtectionStatus: " << mProtectionStatus; |
1089 | + VLOG(2) << " mCompressedSize: " << mCompressedSize |
1090 | + << " mThumbFormat: " << std::hex << mThumbFormat << std::dec |
1091 | + << " mThumbCompressedSize: " << mThumbCompressedSize; |
1092 | + VLOG(2) << " mThumbPixWidth: " << mThumbPixWidth |
1093 | + << " mThumbPixHeight: " << mThumbPixHeight; |
1094 | + VLOG(2) << " mImagePixWidth: " << mImagePixWidth |
1095 | + << " mImagePixHeight: " << mImagePixHeight |
1096 | + << " mImagePixDepth: " << mImagePixDepth; |
1097 | + VLOG(2) << " mParent: " << std::hex << mParent |
1098 | + << " mAssociationType: " << mAssociationType << std::dec |
1099 | + << " mAssociationDesc: " << mAssociationDesc; |
1100 | + VLOG(2) << " mSequenceNumber: " << mSequenceNumber |
1101 | + << " mDateCreated: " << mDateCreated |
1102 | + << " mDateModified: " << mDateModified |
1103 | + << " mKeywords: " << mKeywords; |
1104 | } |
1105 | |
1106 | } // namespace android |
1107 | |
1108 | === modified file 'src/MtpPacket.cpp' |
1109 | --- src/MtpPacket.cpp 2013-06-13 10:22:21 +0000 |
1110 | +++ src/MtpPacket.cpp 2014-04-01 15:51:14 +0000 |
1111 | @@ -25,6 +25,7 @@ |
1112 | #include <cstring> |
1113 | |
1114 | #include <usbhost/usbhost.h> |
1115 | +#include <glog/logging.h> |
1116 | |
1117 | namespace android { |
1118 | |
1119 | @@ -36,8 +37,7 @@ |
1120 | { |
1121 | mBuffer = (uint8_t *)malloc(bufferSize); |
1122 | if (!mBuffer) { |
1123 | - ALOGE("out of memory!"); |
1124 | - abort(); |
1125 | + LOG(FATAL) << "out of memory!"; |
1126 | } |
1127 | } |
1128 | |
1129 | @@ -57,8 +57,7 @@ |
1130 | int newLength = length + mAllocationIncrement; |
1131 | mBuffer = (uint8_t *)realloc(mBuffer, newLength); |
1132 | if (!mBuffer) { |
1133 | - ALOGE("out of memory!"); |
1134 | - abort(); |
1135 | + LOG(FATAL) << "out of memory!"; |
1136 | } |
1137 | mBufferSize = newLength; |
1138 | } |
1139 | @@ -73,15 +72,14 @@ |
1140 | sprintf(bufptr, "%02X ", mBuffer[i]); |
1141 | bufptr += strlen(bufptr); |
1142 | if (i % DUMP_BYTES_PER_ROW == (DUMP_BYTES_PER_ROW - 1)) { |
1143 | - ALOGV("%s", buffer); |
1144 | + VLOG(3) << buffer; |
1145 | bufptr = buffer; |
1146 | } |
1147 | } |
1148 | if (bufptr != buffer) { |
1149 | // print last line |
1150 | - ALOGV("%s", buffer); |
1151 | + VLOG(3) << buffer; |
1152 | } |
1153 | - ALOGV("\n"); |
1154 | } |
1155 | |
1156 | void MtpPacket::copyFrom(const MtpPacket& src) { |
1157 | @@ -134,7 +132,7 @@ |
1158 | |
1159 | uint32_t MtpPacket::getParameter(int index) const { |
1160 | if (index < 1 || index > 5) { |
1161 | - ALOGE("index %d out of range in MtpPacket::getParameter", index); |
1162 | + LOG(ERROR) << "index " << index << " out of range in MtpPacket::getParameter"; |
1163 | return 0; |
1164 | } |
1165 | return getUInt32(MTP_CONTAINER_PARAMETER_OFFSET + (index - 1) * sizeof(uint32_t)); |
1166 | @@ -142,7 +140,7 @@ |
1167 | |
1168 | void MtpPacket::setParameter(int index, uint32_t value) { |
1169 | if (index < 1 || index > 5) { |
1170 | - ALOGE("index %d out of range in MtpPacket::setParameter", index); |
1171 | + LOG(ERROR) << "index " << index << " out of range in MtpPacket::setParameter"; |
1172 | return; |
1173 | } |
1174 | int offset = MTP_CONTAINER_PARAMETER_OFFSET + (index - 1) * sizeof(uint32_t); |
1175 | |
1176 | === modified file 'src/MtpProperty.cpp' |
1177 | --- src/MtpProperty.cpp 2013-06-13 10:22:21 +0000 |
1178 | +++ src/MtpProperty.cpp 2014-04-01 15:51:14 +0000 |
1179 | @@ -22,9 +22,12 @@ |
1180 | #include "MtpStringBuffer.h" |
1181 | #include "MtpUtils.h" |
1182 | |
1183 | +#include <iomanip> |
1184 | #include <cstring> |
1185 | #include <sstream> |
1186 | |
1187 | +#include <glog/logging.h> |
1188 | + |
1189 | namespace android { |
1190 | |
1191 | MtpProperty::MtpProperty() |
1192 | @@ -94,7 +97,9 @@ |
1193 | mDefaultValue.u.u64 = defaultValue; |
1194 | break; |
1195 | default: |
1196 | - ALOGE("unknown type %04X in MtpProperty::MtpProperty", type); |
1197 | + LOG(ERROR) << "unknown type " |
1198 | + << std::hex << type << std::dec |
1199 | + << " in MtpProperty::MtpProperty"; |
1200 | } |
1201 | } |
1202 | } |
1203 | @@ -270,7 +275,7 @@ |
1204 | mStepSize.u.u64 = step; |
1205 | break; |
1206 | default: |
1207 | - ALOGE("unsupported type for MtpProperty::setRange"); |
1208 | + LOG(ERROR) << "unsupported type for MtpProperty::setRange"; |
1209 | break; |
1210 | } |
1211 | } |
1212 | @@ -309,7 +314,7 @@ |
1213 | mEnumValues[i].u.u64 = value; |
1214 | break; |
1215 | default: |
1216 | - ALOGE("unsupported type for MtpProperty::setEnum"); |
1217 | + LOG(ERROR) << "unsupported type for MtpProperty::setEnum"; |
1218 | break; |
1219 | } |
1220 | } |
1221 | @@ -323,46 +328,48 @@ |
1222 | MtpString buffer; |
1223 | bool deviceProp = isDeviceProperty(); |
1224 | if (deviceProp) |
1225 | - ALOGI(" %s (%04X)", MtpDebug::getDevicePropCodeName(mCode), mCode); |
1226 | + VLOG(2) << MtpDebug::getDevicePropCodeName(mCode) |
1227 | + << " (" << std::hex << mCode << std::dec << ")"; |
1228 | else |
1229 | - ALOGI(" %s (%04X)", MtpDebug::getObjectPropCodeName(mCode), mCode); |
1230 | - ALOGI(" type %04X", mType); |
1231 | - ALOGI(" writeable %s", (mWriteable ? "true" : "false")); |
1232 | - buffer = " default value: "; |
1233 | + VLOG(2) << MtpDebug::getObjectPropCodeName(mCode) |
1234 | + << " (" << std::hex << mCode << std::dec << ")"; |
1235 | + VLOG(2) << mType; |
1236 | + VLOG(2) << "writeable " << (mWriteable ? "true" : "false"); |
1237 | + buffer = "default value: "; |
1238 | print(mDefaultValue, buffer); |
1239 | - ALOGI("%s", buffer.c_str()); |
1240 | + VLOG(2) << buffer.c_str(); |
1241 | if (deviceProp) { |
1242 | - buffer = " current value: "; |
1243 | + buffer = "current value: "; |
1244 | print(mCurrentValue, buffer); |
1245 | - ALOGI("%s", buffer.c_str()); |
1246 | + VLOG(2) << buffer.c_str(); |
1247 | } |
1248 | switch (mFormFlag) { |
1249 | case kFormNone: |
1250 | break; |
1251 | case kFormRange: |
1252 | - buffer = " Range ("; |
1253 | + buffer = "Range ("; |
1254 | print(mMinimumValue, buffer); |
1255 | buffer += ", "; |
1256 | print(mMaximumValue, buffer); |
1257 | buffer += ", "; |
1258 | print(mStepSize, buffer); |
1259 | buffer += ")"; |
1260 | - ALOGI("%s", buffer.c_str()); |
1261 | + VLOG(2) << buffer.c_str(); |
1262 | break; |
1263 | case kFormEnum: |
1264 | - buffer = " Enum { "; |
1265 | + buffer = "Enum { "; |
1266 | for (int i = 0; i < mEnumLength; i++) { |
1267 | print(mEnumValues[i], buffer); |
1268 | buffer += " "; |
1269 | } |
1270 | buffer += "}"; |
1271 | - ALOGI("%s", buffer.c_str()); |
1272 | + VLOG(2) << buffer.c_str(); |
1273 | break; |
1274 | case kFormDateTime: |
1275 | - ALOGI(" DateTime\n"); |
1276 | + VLOG(2) << "DateTime"; |
1277 | break; |
1278 | default: |
1279 | - ALOGI(" form %d\n", mFormFlag); |
1280 | + VLOG(2) << "form " << mFormFlag; |
1281 | break; |
1282 | } |
1283 | } |
1284 | @@ -409,7 +416,7 @@ |
1285 | ss << value.str; |
1286 | break; |
1287 | default: |
1288 | - ALOGE("unsupported type for MtpProperty::print\n"); |
1289 | + LOG(ERROR) << "unsupported type for MtpProperty::print"; |
1290 | break; |
1291 | } |
1292 | |
1293 | @@ -465,7 +472,9 @@ |
1294 | value.str = strdup(stringBuffer); |
1295 | break; |
1296 | default: |
1297 | - ALOGE("unknown type %04X in MtpProperty::readValue", mType); |
1298 | + LOG(ERROR) << "unknown type " |
1299 | + << std::hex << mType << std::dec |
1300 | + << " in MtpProperty::readValue"; |
1301 | } |
1302 | } |
1303 | |
1304 | @@ -520,7 +529,9 @@ |
1305 | packet.putEmptyString(); |
1306 | break; |
1307 | default: |
1308 | - ALOGE("unknown type %04X in MtpProperty::writeValue", mType); |
1309 | + LOG(ERROR) << "unknown type " |
1310 | + << std::hex << mType << std::dec |
1311 | + << " in MtpProperty::writeValue"; |
1312 | } |
1313 | } |
1314 | |
1315 | |
1316 | === modified file 'src/MtpServer.cpp' |
1317 | --- src/MtpServer.cpp 2013-11-27 17:21:38 +0000 |
1318 | +++ src/MtpServer.cpp 2014-04-01 15:51:14 +0000 |
1319 | @@ -14,6 +14,7 @@ |
1320 | * limitations under the License. |
1321 | */ |
1322 | |
1323 | +#include <iomanip> |
1324 | #include <cstdio> |
1325 | #include <cstdlib> |
1326 | #include <cstring> |
1327 | @@ -41,6 +42,8 @@ |
1328 | |
1329 | #include <hybris/properties/properties.h> |
1330 | |
1331 | +#include <glog/logging.h> |
1332 | + |
1333 | namespace android { |
1334 | |
1335 | static const MtpOperationCode kSupportedOperationCodes[] = { |
1336 | @@ -158,12 +161,12 @@ |
1337 | void MtpServer::run() { |
1338 | int fd = mFD; |
1339 | |
1340 | - ALOGV("MtpServer::run fd: %d\n", fd); |
1341 | + VLOG(1) << "MtpServer::run fd: " << fd; |
1342 | |
1343 | while (1) { |
1344 | int ret = mRequest.read(fd); |
1345 | if (ret < 0) { |
1346 | - ALOGV("request read returned %d, errno: %d", ret, errno); |
1347 | + PLOG(ERROR) << "request read returned " << ret; |
1348 | if (errno == ECANCELED) { |
1349 | // return to top of loop and wait for next command |
1350 | continue; |
1351 | @@ -173,7 +176,7 @@ |
1352 | MtpOperationCode operation = mRequest.getOperationCode(); |
1353 | MtpTransactionID transaction = mRequest.getTransactionID(); |
1354 | |
1355 | - ALOGV("operation: %s", MtpDebug::getOperationCodeName(operation)); |
1356 | + VLOG(2) << "operation: " << MtpDebug::getOperationCodeName(operation); |
1357 | mRequest.dump(); |
1358 | |
1359 | // FIXME need to generalize this |
1360 | @@ -184,14 +187,14 @@ |
1361 | if (dataIn) { |
1362 | int ret = mData.read(fd); |
1363 | if (ret < 0) { |
1364 | - ALOGE("data read returned %d, errno: %d", ret, errno); |
1365 | + PLOG(ERROR) << "data read returned " << ret; |
1366 | if (errno == ECANCELED) { |
1367 | // return to top of loop and wait for next command |
1368 | continue; |
1369 | } |
1370 | break; |
1371 | } |
1372 | - ALOGV("received data:"); |
1373 | + VLOG(2) << "received data:"; |
1374 | mData.dump(); |
1375 | } else { |
1376 | mData.reset(); |
1377 | @@ -201,11 +204,11 @@ |
1378 | if (!dataIn && mData.hasData()) { |
1379 | mData.setOperationCode(operation); |
1380 | mData.setTransactionID(transaction); |
1381 | - ALOGV("sending data:"); |
1382 | + VLOG(2) << "sending data:"; |
1383 | mData.dump(); |
1384 | ret = mData.write(fd); |
1385 | if (ret < 0) { |
1386 | - ALOGE("request write returned %d, errno: %d", ret, errno); |
1387 | + PLOG(ERROR) << "request write returned " << ret; |
1388 | if (errno == ECANCELED) { |
1389 | // return to top of loop and wait for next command |
1390 | continue; |
1391 | @@ -215,11 +218,12 @@ |
1392 | } |
1393 | |
1394 | mResponse.setTransactionID(transaction); |
1395 | - ALOGV("sending response %04X", mResponse.getResponseCode()); |
1396 | + VLOG(2) << "sending response " |
1397 | + << std::hex << mResponse.getResponseCode() << std::dec; |
1398 | ret = mResponse.write(fd); |
1399 | mResponse.dump(); |
1400 | if (ret < 0) { |
1401 | - ALOGE("request write returned %d, errno: %d", ret, errno); |
1402 | + PLOG(ERROR) << "request write returned " << ret; |
1403 | if (errno == ECANCELED) { |
1404 | // return to top of loop and wait for next command |
1405 | continue; |
1406 | @@ -227,7 +231,7 @@ |
1407 | break; |
1408 | } |
1409 | } else { |
1410 | - ALOGV("skipping response\n"); |
1411 | + VLOG(2) << "skipping response"; |
1412 | } |
1413 | } |
1414 | |
1415 | @@ -247,33 +251,33 @@ |
1416 | } |
1417 | |
1418 | void MtpServer::sendObjectAdded(MtpObjectHandle handle) { |
1419 | - ALOGV("sendObjectAdded %d\n", handle); |
1420 | + VLOG(1) << "sendObjectAdded " << handle; |
1421 | sendEvent(MTP_EVENT_OBJECT_ADDED, handle, 0, 0); |
1422 | } |
1423 | |
1424 | void MtpServer::sendObjectRemoved(MtpObjectHandle handle) { |
1425 | - ALOGV("sendObjectRemoved %d\n", handle); |
1426 | + VLOG(1) << "sendObjectRemoved " << handle; |
1427 | sendEvent(MTP_EVENT_OBJECT_REMOVED, handle, 0, 0); |
1428 | } |
1429 | |
1430 | void MtpServer::sendObjectInfoChanged(MtpObjectHandle handle) { |
1431 | - ALOGV("sendObjectInfoChanged %d\n", handle); |
1432 | + VLOG(1) << "sendObjectInfoChanged " << handle; |
1433 | sendEvent(MTP_EVENT_OBJECT_INFO_CHANGED, handle, 0, 0); |
1434 | } |
1435 | |
1436 | void MtpServer::sendObjectPropChanged(MtpObjectHandle handle, |
1437 | MtpObjectProperty prop) { |
1438 | - ALOGV("sendObjectPropChanged %d %d\n", handle, prop); |
1439 | + VLOG(1) << "sendObjectPropChanged " << handle << " " << prop; |
1440 | sendEvent(MTP_EVENT_OBJECT_PROP_CHANGED, handle, prop, 0); |
1441 | } |
1442 | |
1443 | void MtpServer::sendStoreAdded(MtpStorageID id) { |
1444 | - ALOGV("sendStoreAdded %08X\n", id); |
1445 | + VLOG(1) << "sendStoreAdded " << std::hex << id << std::dec; |
1446 | sendEvent(MTP_EVENT_STORE_ADDED, id, 0, 0); |
1447 | } |
1448 | |
1449 | void MtpServer::sendStoreRemoved(MtpStorageID id) { |
1450 | - ALOGV("sendStoreRemoved %08X\n", id); |
1451 | + VLOG(1) << "sendStoreRemoved " << std::hex << id << std::dec; |
1452 | sendEvent(MTP_EVENT_STORE_REMOVED, id, 0, 0); |
1453 | } |
1454 | |
1455 | @@ -288,7 +292,7 @@ |
1456 | mEvent.setParameter(2, param2); |
1457 | mEvent.setParameter(3, param3); |
1458 | int ret = mEvent.write(mFD); |
1459 | - ALOGV("mEvent.write returned %d\n", ret); |
1460 | + VLOG(2) << "mEvent.write returned " << ret; |
1461 | } |
1462 | } |
1463 | |
1464 | @@ -317,7 +321,7 @@ |
1465 | return; |
1466 | } |
1467 | } |
1468 | - ALOGE("ObjectEdit not found in removeEditObject"); |
1469 | + LOG(ERROR) << "ObjectEdit not found in removeEditObject"; |
1470 | } |
1471 | |
1472 | void MtpServer::commitEdit(ObjectEdit* edit) { |
1473 | @@ -335,7 +339,7 @@ |
1474 | |
1475 | if (mSendObjectHandle != kInvalidObjectHandle && operation != MTP_OPERATION_SEND_OBJECT) { |
1476 | // FIXME - need to delete mSendObjectHandle from the database |
1477 | - ALOGE("expected SendObject after SendObjectInfo"); |
1478 | + LOG(ERROR) << "expected SendObject after SendObjectInfo"; |
1479 | mSendObjectHandle = kInvalidObjectHandle; |
1480 | } |
1481 | |
1482 | @@ -432,7 +436,7 @@ |
1483 | response = doEndEditObject(); |
1484 | break; |
1485 | default: |
1486 | - ALOGE("got unsupported command %s", MtpDebug::getOperationCodeName(operation)); |
1487 | + LOG(ERROR) << "got unsupported command " << MtpDebug::getOperationCodeName(operation); |
1488 | response = MTP_RESPONSE_OPERATION_NOT_SUPPORTED; |
1489 | break; |
1490 | } |
1491 | @@ -444,7 +448,7 @@ |
1492 | } |
1493 | |
1494 | MtpResponseCode MtpServer::doGetDeviceInfo() { |
1495 | - ALOGV("%s", __PRETTY_FUNCTION__); |
1496 | + VLOG(1) << __PRETTY_FUNCTION__; |
1497 | MtpStringBuffer string; |
1498 | char prop_value[PROP_VALUE_MAX]; |
1499 | |
1500 | @@ -507,7 +511,7 @@ |
1501 | mSessionID = mRequest.getParameter(1); |
1502 | mSessionOpen = true; |
1503 | |
1504 | - mDatabase->sessionStarted(); |
1505 | + mDatabase->sessionStarted(this); |
1506 | |
1507 | return MTP_RESPONSE_OK; |
1508 | } |
1509 | @@ -639,8 +643,8 @@ |
1510 | return MTP_RESPONSE_INVALID_OBJECT_HANDLE; |
1511 | MtpObjectHandle handle = mRequest.getParameter(1); |
1512 | MtpObjectProperty property = mRequest.getParameter(2); |
1513 | - ALOGV("GetObjectPropValue %d %s\n", handle, |
1514 | - MtpDebug::getObjectPropCodeName(property)); |
1515 | + VLOG(2) << "GetObjectPropValue " << handle |
1516 | + << " " << MtpDebug::getObjectPropCodeName(property); |
1517 | |
1518 | return mDatabase->getObjectPropertyValue(handle, property, mData); |
1519 | } |
1520 | @@ -652,8 +656,8 @@ |
1521 | return MTP_RESPONSE_INVALID_OBJECT_HANDLE; |
1522 | MtpObjectHandle handle = mRequest.getParameter(1); |
1523 | MtpObjectProperty property = mRequest.getParameter(2); |
1524 | - ALOGV("SetObjectPropValue %d %s\n", handle, |
1525 | - MtpDebug::getObjectPropCodeName(property)); |
1526 | + VLOG(2) << "SetObjectPropValue " << handle |
1527 | + << " " << MtpDebug::getObjectPropCodeName(property); |
1528 | |
1529 | response = mDatabase->setObjectPropertyValue(handle, property, mData); |
1530 | |
1531 | @@ -664,24 +668,21 @@ |
1532 | |
1533 | MtpResponseCode MtpServer::doGetDevicePropValue() { |
1534 | MtpDeviceProperty property = mRequest.getParameter(1); |
1535 | - ALOGV("GetDevicePropValue %s\n", |
1536 | - MtpDebug::getDevicePropCodeName(property)); |
1537 | + VLOG(1) << "GetDevicePropValue " << MtpDebug::getDevicePropCodeName(property); |
1538 | |
1539 | return mDatabase->getDevicePropertyValue(property, mData); |
1540 | } |
1541 | |
1542 | MtpResponseCode MtpServer::doSetDevicePropValue() { |
1543 | MtpDeviceProperty property = mRequest.getParameter(1); |
1544 | - ALOGV("SetDevicePropValue %s\n", |
1545 | - MtpDebug::getDevicePropCodeName(property)); |
1546 | + VLOG(1) << "SetDevicePropValue " << MtpDebug::getDevicePropCodeName(property); |
1547 | |
1548 | return mDatabase->setDevicePropertyValue(property, mData); |
1549 | } |
1550 | |
1551 | MtpResponseCode MtpServer::doResetDevicePropValue() { |
1552 | MtpDeviceProperty property = mRequest.getParameter(1); |
1553 | - ALOGV("ResetDevicePropValue %s\n", |
1554 | - MtpDebug::getDevicePropCodeName(property)); |
1555 | + VLOG(1) << "ResetDevicePropValue " << MtpDebug::getDevicePropCodeName(property); |
1556 | |
1557 | return mDatabase->resetDeviceProperty(property); |
1558 | } |
1559 | @@ -696,9 +697,11 @@ |
1560 | uint32_t property = mRequest.getParameter(3); |
1561 | int groupCode = mRequest.getParameter(4); |
1562 | int depth = mRequest.getParameter(5); |
1563 | - ALOGV("GetObjectPropList %d format: %s property: %s group: %d depth: %d\n", |
1564 | - handle, MtpDebug::getFormatCodeName(format), |
1565 | - MtpDebug::getObjectPropCodeName(property), groupCode, depth); |
1566 | + VLOG(2) << "GetObjectPropList " << handle |
1567 | + << " format: " << MtpDebug::getFormatCodeName(format) |
1568 | + << " property: " << MtpDebug::getObjectPropCodeName(property) |
1569 | + << " group: " << groupCode |
1570 | + << " depth: " << depth; |
1571 | |
1572 | return mDatabase->getObjectPropertyList(handle, format, property, groupCode, depth, mData); |
1573 | } |
1574 | @@ -766,7 +769,7 @@ |
1575 | |
1576 | // then transfer the file |
1577 | int ret = ioctl(mFD, MTP_SEND_FILE_WITH_HEADER, (unsigned long)&mfr); |
1578 | - ALOGV("MTP_SEND_FILE_WITH_HEADER returned %d\n", ret); |
1579 | + VLOG(2) << "MTP_SEND_FILE_WITH_HEADER returned " << ret; |
1580 | close(mfr.fd); |
1581 | if (ret < 0) { |
1582 | if (errno == ECANCELED) |
1583 | @@ -831,7 +834,7 @@ |
1584 | |
1585 | // transfer the file |
1586 | int ret = ioctl(mFD, MTP_SEND_FILE_WITH_HEADER, (unsigned long)&mfr); |
1587 | - ALOGV("MTP_SEND_FILE_WITH_HEADER returned %d\n", ret); |
1588 | + VLOG(2) << "MTP_SEND_FILE_WITH_HEADER returned " << ret; |
1589 | close(mfr.fd); |
1590 | if (ret < 0) { |
1591 | if (errno == ECANCELED) |
1592 | @@ -886,7 +889,8 @@ |
1593 | mData.getString(modified); // date modified |
1594 | // keywords follow |
1595 | |
1596 | - ALOGV("name: %s format: %04X\n", (const char *)name, format); |
1597 | + VLOG(2) << "name: " << (const char *) name |
1598 | + << " format: " << std::hex << format << std::dec; |
1599 | time_t modifiedTime; |
1600 | if (!parseDateTime(modified, modifiedTime)) |
1601 | modifiedTime = 0; |
1602 | @@ -907,7 +911,8 @@ |
1603 | return MTP_RESPONSE_OBJECT_TOO_LARGE; |
1604 | } |
1605 | |
1606 | - ALOGD("path: %s parent: %d storageID: %08X", path.c_str(), parent, storageID); |
1607 | + VLOG(2) << "path: " << path.c_str() << " parent: " << parent |
1608 | + << " storageID: " << std::hex << storageID << std::dec; |
1609 | MtpObjectHandle handle = mDatabase->beginSendObject(path.c_str(), |
1610 | format, parent, storageID, mSendObjectFileSize, modifiedTime); |
1611 | if (handle == kInvalidObjectHandle) { |
1612 | @@ -946,7 +951,7 @@ |
1613 | int ret, initialData; |
1614 | |
1615 | if (mSendObjectHandle == kInvalidObjectHandle) { |
1616 | - ALOGE("Expected SendObjectInfo before SendObject"); |
1617 | + LOG(ERROR) << "Expected SendObjectInfo before SendObject"; |
1618 | result = MTP_RESPONSE_NO_VALID_OBJECT_INFO; |
1619 | goto done; |
1620 | } |
1621 | @@ -983,10 +988,10 @@ |
1622 | mfr.length = mSendObjectFileSize - initialData; |
1623 | } |
1624 | |
1625 | - ALOGV("receiving %s\n", mSendObjectFilePath.c_str()); |
1626 | + VLOG(2) << "receiving " << mSendObjectFilePath.c_str(); |
1627 | // transfer the file |
1628 | ret = ioctl(mFD, MTP_RECEIVE_FILE, (unsigned long)&mfr); |
1629 | - ALOGV("MTP_RECEIVE_FILE returned %d\n", ret); |
1630 | + VLOG(2) << "MTP_RECEIVE_FILE returned " << ret; |
1631 | } |
1632 | close(mfr.fd); |
1633 | |
1634 | @@ -1013,7 +1018,7 @@ |
1635 | char pathbuf[PATH_MAX]; |
1636 | int pathLength = strlen(path); |
1637 | if (pathLength >= sizeof(pathbuf) - 1) { |
1638 | - ALOGE("path too long: %s\n", path); |
1639 | + LOG(ERROR) << "path too long: " << path; |
1640 | } |
1641 | strcpy(pathbuf, path); |
1642 | if (pathbuf[pathLength - 1] != '/') { |
1643 | @@ -1024,7 +1029,7 @@ |
1644 | |
1645 | DIR* dir = opendir(path); |
1646 | if (!dir) { |
1647 | - ALOGE("opendir %s failed: %s", path, strerror(errno)); |
1648 | + PLOG(ERROR) << "opendir " << path << " failed"; |
1649 | return; |
1650 | } |
1651 | |
1652 | @@ -1039,7 +1044,7 @@ |
1653 | |
1654 | int nameLength = strlen(name); |
1655 | if (nameLength > pathRemaining) { |
1656 | - ALOGE("path %s/%s too long\n", path, name); |
1657 | + LOG(ERROR) << "path " << path << "/" << name << " too long"; |
1658 | continue; |
1659 | } |
1660 | strcpy(fileSpot, name); |
1661 | @@ -1065,7 +1070,7 @@ |
1662 | unlink(path); |
1663 | } |
1664 | } else { |
1665 | - ALOGE("deletePath stat failed for %s: %s", path, strerror(errno)); |
1666 | + PLOG(ERROR) << "deletePath stat failed for " << path; |
1667 | } |
1668 | } |
1669 | |
1670 | @@ -1081,7 +1086,7 @@ |
1671 | int64_t fileLength; |
1672 | int result = mDatabase->getObjectFilePath(handle, filePath, fileLength, format); |
1673 | if (result == MTP_RESPONSE_OK) { |
1674 | - ALOGV("deleting %s", filePath.c_str()); |
1675 | + VLOG(2) << "deleting " << filePath.c_str(); |
1676 | result = mDatabase->deleteFile(handle); |
1677 | // Don't delete the actual files unless the database deletion is allowed |
1678 | if (result == MTP_RESPONSE_OK) { |
1679 | @@ -1105,7 +1110,7 @@ |
1680 | int result = mDatabase->getObjectFilePath(handle, filePath, fileLength, format); |
1681 | result = mDatabase->getObjectFilePath(handle, newPath, fileLength, format); |
1682 | if (result == MTP_RESPONSE_OK) { |
1683 | - ALOGV("moving %s to %s", filePath.c_str(), newPath.c_str()); |
1684 | + VLOG(2) << "moving " << filePath.c_str() << " to " << newPath.c_str(); |
1685 | result = mDatabase->moveFile(handle, newparent); |
1686 | // Don't move the actual files unless the database deletion is allowed |
1687 | if (result == MTP_RESPONSE_OK) { |
1688 | @@ -1119,8 +1124,8 @@ |
1689 | MtpResponseCode MtpServer::doGetObjectPropDesc() { |
1690 | MtpObjectProperty propCode = mRequest.getParameter(1); |
1691 | MtpObjectFormat format = mRequest.getParameter(2); |
1692 | - ALOGV("GetObjectPropDesc %s %s\n", MtpDebug::getObjectPropCodeName(propCode), |
1693 | - MtpDebug::getFormatCodeName(format)); |
1694 | + VLOG(2) << "GetObjectPropDesc " << MtpDebug::getObjectPropCodeName(propCode) |
1695 | + << " " << MtpDebug::getFormatCodeName(format); |
1696 | MtpProperty* property = mDatabase->getObjectPropertyDesc(propCode, format); |
1697 | if (!property) |
1698 | return MTP_RESPONSE_OBJECT_PROP_NOT_SUPPORTED; |
1699 | @@ -1131,7 +1136,7 @@ |
1700 | |
1701 | MtpResponseCode MtpServer::doGetDevicePropDesc() { |
1702 | MtpDeviceProperty propCode = mRequest.getParameter(1); |
1703 | - ALOGV("GetDevicePropDesc %s\n", MtpDebug::getDevicePropCodeName(propCode)); |
1704 | + VLOG(1) << "GetDevicePropDesc " << MtpDebug::getDevicePropCodeName(propCode); |
1705 | MtpProperty* property = mDatabase->getDevicePropertyDesc(propCode); |
1706 | if (!property) |
1707 | return MTP_RESPONSE_DEVICE_PROP_NOT_SUPPORTED; |
1708 | @@ -1151,18 +1156,20 @@ |
1709 | |
1710 | ObjectEdit* edit = getEditObject(handle); |
1711 | if (!edit) { |
1712 | - ALOGE("object not open for edit in doSendPartialObject"); |
1713 | + LOG(ERROR) << "object not open for edit in doSendPartialObject"; |
1714 | return MTP_RESPONSE_GENERAL_ERROR; |
1715 | } |
1716 | |
1717 | // can't start writing past the end of the file |
1718 | if (offset > edit->mSize) { |
1719 | - ALOGD("writing past end of object, offset: %lld, edit->mSize: %lld", offset, edit->mSize); |
1720 | + VLOG(2) << "writing past end of object, offset: " << offset |
1721 | + << " edit->mSize: " << edit->mSize; |
1722 | return MTP_RESPONSE_GENERAL_ERROR; |
1723 | } |
1724 | |
1725 | const char* filePath = edit->mPath.c_str(); |
1726 | - ALOGV("receiving partial %s %lld %lld\n", filePath, offset, length); |
1727 | + VLOG(2) << "receiving partial " << filePath |
1728 | + << " " << offset << " " << length; |
1729 | |
1730 | // read the header, and possibly some data |
1731 | int ret = mData.read(mFD); |
1732 | @@ -1184,7 +1191,7 @@ |
1733 | |
1734 | // transfer the file |
1735 | ret = ioctl(mFD, MTP_RECEIVE_FILE, (unsigned long)&mfr); |
1736 | - ALOGV("MTP_RECEIVE_FILE returned %d", ret); |
1737 | + VLOG(2) << "MTP_RECEIVE_FILE returned " << ret; |
1738 | } |
1739 | if (ret < 0) { |
1740 | mResponse.setParameter(1, 0); |
1741 | @@ -1208,7 +1215,7 @@ |
1742 | MtpObjectHandle handle = mRequest.getParameter(1); |
1743 | ObjectEdit* edit = getEditObject(handle); |
1744 | if (!edit) { |
1745 | - ALOGE("object not open for edit in doTruncateObject"); |
1746 | + LOG(ERROR) << "object not open for edit in doTruncateObject"; |
1747 | return MTP_RESPONSE_GENERAL_ERROR; |
1748 | } |
1749 | |
1750 | @@ -1226,7 +1233,7 @@ |
1751 | MtpResponseCode MtpServer::doBeginEditObject() { |
1752 | MtpObjectHandle handle = mRequest.getParameter(1); |
1753 | if (getEditObject(handle)) { |
1754 | - ALOGE("object already open for edit in doBeginEditObject"); |
1755 | + LOG(ERROR) << "object already open for edit in doBeginEditObject"; |
1756 | return MTP_RESPONSE_GENERAL_ERROR; |
1757 | } |
1758 | |
1759 | @@ -1239,7 +1246,7 @@ |
1760 | |
1761 | int fd = open(path.c_str(), O_RDWR | O_EXCL); |
1762 | if (fd < 0) { |
1763 | - ALOGE("open failed for %s in doBeginEditObject (%d)", path.c_str(), errno); |
1764 | + PLOG(ERROR) << "open failed for " << path.c_str() << " in doBeginEditObject"; |
1765 | return MTP_RESPONSE_GENERAL_ERROR; |
1766 | } |
1767 | |
1768 | @@ -1251,7 +1258,7 @@ |
1769 | MtpObjectHandle handle = mRequest.getParameter(1); |
1770 | ObjectEdit* edit = getEditObject(handle); |
1771 | if (!edit) { |
1772 | - ALOGE("object not open for edit in doEndEditObject"); |
1773 | + LOG(ERROR) << "object not open for edit in doEndEditObject"; |
1774 | return MTP_RESPONSE_GENERAL_ERROR; |
1775 | } |
1776 | |
1777 | |
1778 | === modified file 'src/MtpStorage.cpp' |
1779 | --- src/MtpStorage.cpp 2013-06-13 10:22:21 +0000 |
1780 | +++ src/MtpStorage.cpp 2014-04-01 15:51:14 +0000 |
1781 | @@ -30,6 +30,8 @@ |
1782 | #include <stdio.h> |
1783 | #include <limits.h> |
1784 | |
1785 | +#include <glog/logging.h> |
1786 | + |
1787 | namespace android { |
1788 | |
1789 | MtpStorage::MtpStorage(MtpStorageID id, const char* filePath, |
1790 | @@ -43,7 +45,7 @@ |
1791 | mReserveSpace(reserveSpace), |
1792 | mRemovable(removable) |
1793 | { |
1794 | - ALOGV("MtpStorage id: %d path: %s\n", id, filePath); |
1795 | + VLOG(2) << "MtpStorage id: " << id << " path: " << filePath; |
1796 | } |
1797 | |
1798 | MtpStorage::~MtpStorage() { |
1799 | |
1800 | === modified file 'src/MtpStorageInfo.cpp' |
1801 | --- src/MtpStorageInfo.cpp 2013-06-13 10:22:21 +0000 |
1802 | +++ src/MtpStorageInfo.cpp 2014-04-01 15:51:14 +0000 |
1803 | @@ -16,6 +16,7 @@ |
1804 | |
1805 | #define LOG_TAG "MtpStorageInfo" |
1806 | |
1807 | +#include <iomanip> |
1808 | #include <cstring> |
1809 | |
1810 | #include "MtpDebug.h" |
1811 | @@ -23,6 +24,8 @@ |
1812 | #include "MtpStorageInfo.h" |
1813 | #include "MtpStringBuffer.h" |
1814 | |
1815 | +#include <glog/logging.h> |
1816 | + |
1817 | namespace android { |
1818 | |
1819 | MtpStorageInfo::MtpStorageInfo(MtpStorageID id) |
1820 | @@ -63,12 +66,15 @@ |
1821 | } |
1822 | |
1823 | void MtpStorageInfo::print() { |
1824 | - ALOGD("Storage Info %08X:\n\tmStorageType: %d\n\tmFileSystemType: %d\n\tmAccessCapability: %d\n", |
1825 | - mStorageID, mStorageType, mFileSystemType, mAccessCapability); |
1826 | - ALOGD("\tmMaxCapacity: %lld\n\tmFreeSpaceBytes: %lld\n\tmFreeSpaceObjects: %d\n", |
1827 | - mMaxCapacity, mFreeSpaceBytes, mFreeSpaceObjects); |
1828 | - ALOGD("\tmStorageDescription: %s\n\tmVolumeIdentifier: %s\n", |
1829 | - mStorageDescription, mVolumeIdentifier); |
1830 | + VLOG(2) << "Storage Info " << std::hex << mStorageID << std::dec << ":" |
1831 | + << "\n\tmStorageType: " << mStorageType |
1832 | + << "\n\tmFileSystemType: " << mFileSystemType |
1833 | + << "\n\tmAccessCapability: " << mAccessCapability; |
1834 | + VLOG(2) << "\tmMaxCapacity: " << mMaxCapacity |
1835 | + << "\n\tmFreeSpaceBytes: " << mFreeSpaceBytes |
1836 | + << "\n\tmFreeSpaceObjects: " << mFreeSpaceObjects; |
1837 | + VLOG(2) << "\tmStorageDescription: " << mStorageDescription |
1838 | + << "\n\tmVolumeIdentifier: " << mVolumeIdentifier; |
1839 | } |
1840 | |
1841 | } // namespace android |
1842 | |
1843 | === modified file 'tests/MockMtpDatabase.h' |
1844 | --- tests/MockMtpDatabase.h 2013-11-27 17:21:38 +0000 |
1845 | +++ tests/MockMtpDatabase.h 2014-04-01 15:51:14 +0000 |
1846 | @@ -353,7 +353,7 @@ |
1847 | return new MtpProperty(MTP_DEVICE_PROPERTY_UNDEFINED, MTP_TYPE_UNDEFINED); |
1848 | } |
1849 | |
1850 | - virtual void sessionStarted() |
1851 | + virtual void sessionStarted(MtpServer* server) |
1852 | { |
1853 | std::cout << __PRETTY_FUNCTION__ << std::endl; |
1854 | } |
FAILED: Continuous integration, rev:47 /code.launchpad .net/~mathieu- tl/mtp/ 0.0.3-logging- inotify/ +merge/ 213681/ +edit-commit- message
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https:/
http:// jenkins. qa.ubuntu. com/job/ mtp-ci/ 15/ jenkins. qa.ubuntu. com/job/ mtp-trusty- amd64-ci/ 5 jenkins. qa.ubuntu. com/job/ mtp-trusty- armhf-ci/ 5 jenkins. qa.ubuntu. com/job/ mtp-trusty- armhf-ci/ 5/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ mtp-trusty- i386-ci/ 5
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/mtp- ci/15/rebuild
http://