[mtp] Move MTP device handling from kioslave to kiod-module
ClosedPublic

Authored by akrutzler on Sep 4 2018, 7:36 PM.

Details

Summary

Consult T9390 for more information.

BUG: 319880
BUG: 325924
BUG: 336456
BUG: 372860
BUG: 382046
BUG: 383314
BUG: 396527

Closes T9390

Diff Detail

Repository
R320 KIO Extras
Branch
mtp_next
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 3405
Build 3423: arc lint + arc unit
akrutzler requested review of this revision.Sep 4 2018, 7:36 PM
akrutzler created this revision.

From a quick look, the architecture is sound and respects what was discussed in T9390. And indeed it works pretty well, awesome job @akrutzler!

I'd even say this could already be shipped because it's better than what we currently ship. But I do have a few remarks:

  • It should be possible to generate the xml files using qdbuscpp2xml. And we should actually do that and copy the generated files in the shared folder (to be sure there aren't e.g. typos).
  • This diff contains some unrelated changes, which should be moved to different commits. For example, porting to the JSON protocol file, #include changes, etc.
Restricted Application added projects: Dolphin, Frameworks. · View Herald TranscriptSep 22 2018, 3:05 PM
Restricted Application added subscribers: kfm-devel, kde-frameworks-devel. · View Herald Transcript
mtp/kiod_module/kmtpd.json
11

Currently the module is spawned by the ioslave on-demand. But imho it should be possible to browse the device using only dbus, without having to open dolphin first.

Can we try to autostart the module?

dfaure requested changes to this revision.Sep 22 2018, 3:42 PM

This is excellent work, thanks a lot for doing this. I just have "a few" minor comments... ;)

mtp/kio_mtp.cpp
160–161

Don't use Q_FUNC_INFO in code.
Instead, set up your environment with %{function} in QT_MESSAGE_PATTERN.
For instance, mine says

'%{time h:mm:ss.zzz} %{appname}(%{pid}) %{if-category}%{category}: %{endif}%{if-debug}%{function}%{endif}%{if-warning}%{backtrace depth=3}%{endif}%{if-critical}%{backtrace depth=3}%{endif}%{if-fatal}%{backtrace depth=3}%{endif} %{message}'

See https://woboq.com/blog/nice-debug-output-with-qt.html for more info.

191–193

move m_kmtpDaemon.devices to a const local variable, to avoid a detach. Yes this is annoying.

444

and if mtpDevice is nullptr? This code doesn't seem to emit either error or finished, which is a bug.

Or if it can't be null, use Q_ASSERT instead of if() ;)

(Same in most other SlaveBase methods, please check that they all end up with either error() or finished())

455

Let's hope this signal is always ALWAYS emitted, including in all error cases...

mtp/kio_mtp.h
98

class-static private functions pollute the header file for no benefit, they might as well become file-static functions (i.e. remove the declarations from here, and remove the classname from the implementation, and ensure they're at the top of the file).

mtp/kiod_module/kmtpd.cpp
60

qAsConst(m_devices) to avoid a detach

129

this method could probably be const?

154

please clean up the "||||" stuff

164

same

166

There's removeOne(device)

mtp/kiod_module/mtpstorage.cpp
207

Any chance currentDateTimeUtc could be used everywhere? It's much faster than currentDateTime because it doesn't need to do timezone conversions (which use the awful process-global tzset()).

Just a thought, maybe you do need local times.

226

This method could be made much faster by locating the Nth slash and then using left(), to avoid the many reallocations due to multiple appends. Not sure it matters though.

257

Minor: this would be more readable with a MTPStorage * local variable, i.e. splitting this over two lines.

474

Please remove Q_FUNC_INFO everywhere.

500

DBus timeouts are actually configurable, if you need to block until the copy is done, btw.

mtp/kiod_module/mtpstorage.h
117

you know what I think of private class-static methods ;-)

mtp/shared/kmtpstorageinterface.cpp
77

As others said, this file should really be generated by qdbusxml2cpp instead.

This revision now requires changes to proceed.Sep 22 2018, 3:42 PM
dfaure added inline comments.Sep 22 2018, 3:45 PM
mtp/kiod_module/kmtpd.json
11

I don't understand what you mean here. How is a user supposed to "use only dbus"? ;-) Is this really about increasing overhead for every Plasma user (even those who never use mtp) for the benefit of an hypothetical command-line user?
I'm pretty sure qdbus can trigger on-demand loading too, even, since that's done by the dbus server, when using a dbus service file.

In case this is what you meant: please don't load the module at plasma startup. On demand is perfect. And it can be on demand of other apps than kioslaves, in case any app wants to do some MTP stuff (e.g. Amarok).

Thanks for the review. I will address your comments and hopefully have a patch ready in the next days. :)

akrutzler updated this revision to Diff 42450.Sep 27 2018, 10:23 PM
akrutzler marked 13 inline comments as done.
  • Rebase
  • Remove unrelated changes
  • Remove Q_FUNC_INFO
  • Remove private static methods from header file
  • Use currentDateTimeUtc instead of currentDateTime
  • Generate D-Bus interface with qdbusxml2cpp
akrutzler added inline comments.Sep 27 2018, 10:23 PM
mtp/kiod_module/mtpstorage.cpp
500

In my previous approach I increased the timeout to 10 minutes. This worked fine until I downloaded a file of about 10GB or so from my phone -> timeout. It's hard to find a proper timeout which is why I chose the async way. :)

mlaurent requested changes to this revision.Sep 30 2018, 6:41 AM
mlaurent added a subscriber: mlaurent.
mlaurent added inline comments.
mtp/kiod_module/mtpstorage.cpp
177

QString() directly no ?

189

Same

241

same

mtp/shared/kmtpdinterface.h
43

explicit

This revision now requires changes to proceed.Sep 30 2018, 6:41 AM
akrutzler updated this revision to Diff 42685.Oct 1 2018, 6:49 PM
akrutzler marked 5 inline comments as done.
  • Use QString() directly instead of QStringLiteral("")
  • Use explicit specifier
  • Call either finished or error in slave methods
akrutzler added inline comments.Oct 1 2018, 6:50 PM
mtp/kiod_module/mtpstorage.cpp
177

Of course, thanks! :)

dfaure accepted this revision.Oct 4 2018, 11:45 AM

Great stuff. Only found some typos and very minor things, feel free to fix and push.

mtp/kiod_module/mtpdevice.cpp
119

Technically this is missing a

list.reserve(m_storages.count())

but I guess these lists are pretty small in practice...

mtp/kiod_module/mtpstorage.cpp
31

Prepend "static" to all these class-level functions (so they don't get exported, and so that the compiler knows they are only usable in this file, which can lead to more optimizations like inlining).

mtp/shared/kmtpdeviceinterface.cpp
35

m_storages.reserve(storageNames.count())

mtp/shared/kmtpstorageinterface.cpp
33

s/listening/listing/ ?

mtp/shared/org.kde.kmtp.daemon.xml
40

s/deamon/daemon/

akrutzler updated this revision to Diff 43074.Oct 7 2018, 7:03 PM
akrutzler marked 4 inline comments as done.
  • Rebase
  • Reserve memory for lists/vectors in advance.
  • Prepend "static" to all class-level functions
  • Fix typos
akrutzler retitled this revision from [RFC] kio_mtp: Move MTP device handling from kioslave to kiod-module to [mtp] Move MTP device handling from kioslave to kiod-module.Oct 7 2018, 7:07 PM

Great! Is there anything else left to do @elvisangelaccio and @mlaurent before I land this?

elvisangelaccio accepted this revision.Oct 7 2018, 7:22 PM

Awesome job, Andreas <3

ngraham edited the summary of this revision. (Show Details)Oct 7 2018, 7:23 PM
mlaurent accepted this revision.Oct 8 2018, 5:04 AM
This revision is now accepted and ready to land.Oct 8 2018, 5:04 AM
This revision was automatically updated to reflect the committed changes.