Merge lp:~michihenning/storage-framework/api2 into lp:storage-framework/devel

Proposed by Michi Henning
Status: Merged
Approved by: James Henstridge
Approved revision: 82
Merged at revision: 69
Proposed branch: lp:~michihenning/storage-framework/api2
Merge into: lp:storage-framework/devel
Diff against target: 6643 lines (+6158/-34)
63 files modified
CMakeLists.txt (+4/-3)
debian/changelog (+7/-0)
debian/control (+10/-0)
debian/control.in (+9/-0)
debian/libstorage-framework-qt-client-1-0.install (+1/-1)
debian/libstorage-framework-qt-client-2-0.install (+1/-0)
include/unity/storage/CMakeLists.txt (+4/-0)
include/unity/storage/internal/ItemMetadata.h (+3/-0)
include/unity/storage/internal/dbusmarshal.h (+0/-3)
include/unity/storage/qt/Account.h (+103/-0)
include/unity/storage/qt/AccountsJob.h (+80/-0)
include/unity/storage/qt/CMakeLists.txt (+17/-1)
include/unity/storage/qt/ConflictPolicy.h (+32/-0)
include/unity/storage/qt/Downloader.h (+68/-0)
include/unity/storage/qt/Item.h (+142/-0)
include/unity/storage/qt/ItemJob.h (+75/-0)
include/unity/storage/qt/ItemListJob.h (+77/-0)
include/unity/storage/qt/Runtime.h (+80/-0)
include/unity/storage/qt/StorageError.h (+87/-0)
include/unity/storage/qt/Uploader.h (+72/-0)
include/unity/storage/qt/VoidJob.h (+56/-0)
include/unity/storage/qt/client/CMakeLists.txt (+3/-4)
include/unity/storage/qt/internal/AccountImpl.h (+99/-0)
include/unity/storage/qt/internal/AccountsJobImpl.h (+70/-0)
include/unity/storage/qt/internal/Handler.h (+93/-0)
include/unity/storage/qt/internal/HandlerBase.h (+64/-0)
include/unity/storage/qt/internal/ItemImpl.h (+99/-0)
include/unity/storage/qt/internal/ItemJobImpl.h (+84/-0)
include/unity/storage/qt/internal/ItemListJobImpl.h (+83/-0)
include/unity/storage/qt/internal/RuntimeImpl.h (+85/-0)
include/unity/storage/qt/internal/StorageErrorImpl.h (+85/-0)
include/unity/storage/qt/internal/unmarshal_error.h (+39/-0)
include/unity/storage/qt/internal/validate.h (+44/-0)
src/qt/Account.cpp (+148/-0)
src/qt/AccountsJob.cpp (+68/-0)
src/qt/CMakeLists.txt (+82/-0)
src/qt/Item.cpp (+230/-0)
src/qt/ItemJob.cpp (+62/-0)
src/qt/ItemListJob.cpp (+57/-0)
src/qt/Runtime.cpp (+87/-0)
src/qt/StorageError.cpp (+98/-0)
src/qt/client/CMakeLists.txt (+11/-11)
src/qt/client/storage-framework-qt-client-1.pc.in (+6/-0)
src/qt/client/storage-framework-qt-local-client.pc.in (+0/-6)
src/qt/internal/AccountImpl.cpp (+226/-0)
src/qt/internal/AccountsJobImpl.cpp (+183/-0)
src/qt/internal/HandlerBase.cpp (+59/-0)
src/qt/internal/ItemImpl.cpp (+248/-0)
src/qt/internal/ItemJobImpl.cpp (+138/-0)
src/qt/internal/ItemListJobImpl.cpp (+148/-0)
src/qt/internal/RuntimeImpl.cpp (+168/-0)
src/qt/internal/StorageErrorImpl.cpp (+230/-0)
src/qt/internal/unmarshal_error.cpp (+131/-0)
src/qt/internal/validate.cpp (+170/-0)
tests/CMakeLists.txt (+1/-0)
tests/headers/CMakeLists.txt (+1/-0)
tests/remote-client-v1/CMakeLists.txt (+5/-5)
tests/remote-client-v1/remote-client-v1_test.cpp (+1/-0)
tests/remote-client/CMakeLists.txt (+20/-0)
tests/remote-client/MockProvider.cpp (+237/-0)
tests/remote-client/MockProvider.h (+96/-0)
tests/remote-client/remote-client_test.cpp (+1470/-0)
tests/utils/ProviderFixture.cpp (+1/-0)
To merge this branch: bzr merge lp:~michihenning/storage-framework/api2
Reviewer Review Type Date Requested Status
unity-api-1-bot continuous-integration Approve
James Henstridge Approve
Review via email: mp+304599@code.launchpad.net

Commit message

Started implementation of v2 API.

Description of the change

New API. Bulk of internal implementation is there. Need to flesh out the methods on Item mostly now. Also still a bunch of review comments to apply.

To post a comment you must log in.
Revision history for this message
Xavi Garcia (xavi-garcia-mena) wrote :

As discussed in the standup, a couple of things I saw taking a quick look:

The following signals:
    void statusChanged(Status status) const;
    void error(StorageError const& e) const;
    void finished(Uploader const& uploader) const;
Can be found on the Uploader and UploadJob.

It's a bit confusing if we need to connect to both, or just connection to the one in the Job or the Uploader is just fine.

And the second one is about the signal declaration itself.
I had issues related to this a few weeks ago.

For example the signal:

enum class Status { Loading, Finished, Error };
void statusChanged(Status status) const;

should be:
void statusChanged(UploadJob::Status status) const;

and I should verify, but maybe Qt needs it to be:
void statusChanged(unity::storage::qt::UploadJob::Status status) const;

if not, when creating the moc code it does not understand the enum and we cannot access it from QML or, for example QSignalSpy. In fact the issue I've got was with QSignalSpy, when trying to convert from QVariant to the enum class.

Revision history for this message
Michi Henning (michihenning) wrote :

Thanks for the comments Xavi! I've ditched the upload and download job classes. The uploader and downloader will return a disconnected non-working socket and make it valid once the dbus reply with the file descriptor trickles in.

I've added qualified names to the headers where I think they are needed. Could you let me know whether that looks OK please?

Revision history for this message
Albert Astals Cid (aacid) wrote :

you seem to be missing lots of NOTIFY stuff in the properties
i.e.
 Q_PROPERTY(unity::Storage::qt::StorageError error READ error)
will change at some point i guess?

Other properties seem to be missing CONSTANT, e.g.
 Q_PROPERTY(QString READ description)

QML will complain if using properties that are read but don't have neither CONSTANT nor NOTIFY

Revision history for this message
Lukáš Tinkl (lukas-kde) wrote :

Apart from what Albert said above, I see a few high level problems:
- exposing private members in the public headers, that's asking for ABI breakage sooner or later; wrap them using the pimpl idiom and use QScopedPointer to manage them
- QDBus* stuff shouldn't be part of the API (not "consumable" from QML at all)
- if you use custom enums in the signals signatures, you need to Q_DECLARE_METATYPE on them, otherwise they won't work (http://doc.qt.io/qt-5/qmetatype.html#Q_DECLARE_METATYPE)
- a curious question, why do you combine different stuff from C++11, boost and Qt? (like boost::future when there's std::future or even QFuture; std::shared_ptr vs. QSharedPointer etc; or std::map together with QString, when using QMap<QString,QString> would be the logical solution)
- you are using Q_ENUM (http://doc.qt.io/qt-5/qobject.html#Q_ENUM) which is available only from Qt 5.5 -> won't work on vivid; same for Q_GADGET afaik
- for the hash() function, please see http://doc.qt.io/qt-5/qhash.html#the-qhash-hashing-function

Revision history for this message
Michi Henning (michihenning) wrote :

Hi Lukáš,

my apologies, I suspect the message got lost in translation. The *only* headers that matter for the v2 API are the ones in include/unity/storage/qt. Ignore any headers in subduers of this. (The new API does not use boost, does not use futures, etc.

We are not targeting Vivid, so Q_GADGET and Q_ENUM OK.

I'll check the hash function, thanks! The one that is there will do the job with std::unordered_map. I'll have to read up on how the equivalent is meant to work in Qt.

Revision history for this message
Michi Henning (michihenning) wrote :

Hi Lukáš,

my apologies, I suspect the message got lost in translation. The *only* headers that matter for the v2 API are the ones in include/unity/storage/qt. Ignore any headers in subduers of this. (The new API does not use boost, does not use futures, etc.

We are not targeting Vivid, so Q_GADGET and Q_ENUM OK.

I'll check the hash function, thanks! The one that is there will do the job with std::unordered_map. I just had a brief look, and it seems it'll be easy enough to have a Qt-compatible hash function as well, so that'll be easy to fix. Thanks for pointing this out!

Revision history for this message
Michi Henning (michihenning) wrote :

> Ignore any headers in subduers of this.

Bloody auto-correct :-(

That was meant to say "subdirs".

Here is the list of headers as they currently stand, all in include/unity/storage/qt:

Account.h
AccountsJob.h
ConflictPolicy.h
Downloader.h
Item.h
ItemJob.h
ItemListJob.h
Runtime.h
StorageError.h
Uploader.h
VoidJob.h

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:69
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://code.launchpad.net/~michihenning/storage-framework/api2/+merge/304599/+edit-commit-message

https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/110/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/685/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/691
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/504/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/504/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/504/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/504/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/504/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/504/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/504/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/504/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/504/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/110/rebuild

review: Needs Fixing (continuous-integration)
70. By Michi Henning

Comment changes to mark review items.

71. By Michi Henning

Whitespace fixes. Trying qualified name for failing bus_path() call.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:70
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://code.launchpad.net/~michihenning/storage-framework/api2/+merge/304599/+edit-commit-message

https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/111/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/688/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/694
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/507/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/507/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/507/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/507/console
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/507/console
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/507/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/507/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/507/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/507/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/111/rebuild

review: Needs Fixing (continuous-integration)
72. By Michi Henning

Trying this->bus_path();

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:71
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://code.launchpad.net/~michihenning/storage-framework/api2/+merge/304599/+edit-commit-message

https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/112/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/689/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/695
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/508/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/508/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/508/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/508/console
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/508/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/508/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/508/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/508/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/508/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/112/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:72
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://code.launchpad.net/~michihenning/storage-framework/api2/+merge/304599/+edit-commit-message

https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/113/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/690/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/696
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/509/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/509/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/509/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/509/console
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/509/console
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/509/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/509/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/509/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/509/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/113/rebuild

review: Needs Fixing (continuous-integration)
73. By Michi Henning

bus_path() -> impossible_name() for testing.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:73
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://code.launchpad.net/~michihenning/storage-framework/api2/+merge/304599/+edit-commit-message

https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/114/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/692/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/698/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/114/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:73
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://code.launchpad.net/~michihenning/storage-framework/api2/+merge/304599/+edit-commit-message

https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/115/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/693/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/699/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/115/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:73
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://code.launchpad.net/~michihenning/storage-framework/api2/+merge/304599/+edit-commit-message

https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/116/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/694/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/700/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/116/rebuild

review: Needs Fixing (continuous-integration)
74. By Michi Henning

impossible_name() -> object_path()

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :
review: Needs Fixing (continuous-integration)
75. By Michi Henning

Q_ENUM -> Q_ENUIMS for Vivid. Disabled check for connection
state when creating the runtime.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :
review: Needs Fixing (continuous-integration)
76. By Michi Henning

Fixed compilation error on Vivid. More warning suppressions for Arm.

77. By Michi Henning

Fixed wrong location for installing pc file.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :
review: Needs Fixing (continuous-integration)
78. By Michi Henning

Added missing Q_DECLARE_METATYPE

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:77
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/120/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/709/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/715
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/523/console
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/523/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/523
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/523/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/523/console
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/523/console
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/523/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/523/console
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/523/console
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/523/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/120/rebuild

review: Needs Fixing (continuous-integration)
79. By Michi Henning

Another missing Q_DECLARE_METATYPE

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:78
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/121/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/710/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/716
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/524/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/524
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/524/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/524
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/524/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/524/console
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/524/console
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/524/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/524/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/524
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/524/artifact/output/*zip*/output.zip
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/524/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/121/rebuild

review: Needs Fixing (continuous-integration)
80. By Michi Henning

More Q_DECLARE_METATYPE :-(

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

FAILED: Continuous integration, rev:79
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/122/
Executed test runs:
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build/711/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/717
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/525/console
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/525/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/525
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/525/artifact/output/*zip*/output.zip
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/525/console
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/525/console
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/525/console
    FAILURE: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/525/console
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/525
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/525/artifact/output/*zip*/output.zip
    ABORTED: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/525/console

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/122/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:80
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/123/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/712
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/718
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/526
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/526/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/526
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/526/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/526
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/526/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/526
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/526/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/526
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/526/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/526
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/526/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/526
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/526/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/526
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/526/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/526
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/526/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/123/rebuild

review: Approve (continuous-integration)
Revision history for this message
James Henstridge (jamesh) wrote :

As discussed previously, we'll fix most of the issues from yesterday's review post merge.

Things I'd like you to fix before hand though are:

1. You've removed the logic to generate .pc files for the old v1 client libraries and instead used copies with /home/michi/src/storage-framework/api2/build/install/ substituted in as the install prefix. This will cause compile and link failures for any code trying to link to those libraries. Please switch back to generating them from a .pc.in file using configure_file().

2. Don't piggy back on the libstorage-framework-qt-client-1 binary package for the new library: add a new binary package, and add it as a dependency for storage-framework-client-dev. It's better to take the effort to do this now rather than have binary packages built against the new library break when we change things around in future.

2. The headers for the new and old client libraries are mixed together. Ideally they'd be separate, but it probably isn't worth spending time to change, given we want a fairly short change over.

review: Needs Fixing
81. By Michi Henning

Separated old and new header install location.
Added new binary package for v2 client API.
Fix broken pkgconfig files.
Bumped project version.
Updated changelog.

82. By Michi Henning

A few more packaging fixes.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:82
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/124/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/714
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/720
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/528
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/528/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/528
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/528/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/528
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/528/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/528
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/528/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/528
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/528/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/528
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/528/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/528
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/528/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/528
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/528/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/528
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/528/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/124/rebuild

review: Approve (continuous-integration)
Revision history for this message
James Henstridge (jamesh) wrote :

Looks good.

review: Approve
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:84
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/125/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/726
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/732
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/540
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=vivid+overlay/540/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/540
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/540/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/540
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=yakkety/540/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/540
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=vivid+overlay/540/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/540
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/540/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/540
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=yakkety/540/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/540
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=vivid+overlay/540/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/540
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/540/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/540
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=yakkety/540/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/125/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2016-09-03 00:53:43 +0000
+++ CMakeLists.txt 2016-09-21 05:03:46 +0000
@@ -5,13 +5,13 @@
5endif()5endif()
66
7cmake_minimum_required(VERSION 3.0.2)7cmake_minimum_required(VERSION 3.0.2)
8project(storage-framework VERSION "0.1" LANGUAGES C CXX)8project(storage-framework VERSION "0.2" LANGUAGES C CXX)
99
10# These variables should be incremented when we wish to create a new10# These variables should be incremented when we wish to create a new
11# source incompatible version of the the library where users of the11# source incompatible version of the the library where users of the
12# old API could will not compile against the new one. It is not12# old API will not compile against the new one. It is not
13# necessary to increment this for ABI breaks that are source compatible.13# necessary to increment this for ABI breaks that are source compatible.
14set(SF_CLIENT_API_VERSION "1")14set(SF_CLIENT_API_VERSION "2")
15set(SF_PROVIDER_API_VERSION "1")15set(SF_PROVIDER_API_VERSION "1")
1616
17# These two should be incremented when the ABI changes.17# These two should be incremented when the ABI changes.
@@ -132,6 +132,7 @@
132 qt-client-lib-common132 qt-client-lib-common
133 storage-framework-common-internal133 storage-framework-common-internal
134 storage-framework-qt-client134 storage-framework-qt-client
135 storage-framework-qt-client-v2
135 storage-framework-qt-local-client136 storage-framework-qt-local-client
136 sf-provider-objects137 sf-provider-objects
137 storage-framework-provider138 storage-framework-provider
138139
=== modified file 'debian/changelog'
--- debian/changelog 2016-08-04 07:20:09 +0000
+++ debian/changelog 2016-09-21 05:03:46 +0000
@@ -1,3 +1,10 @@
1storage-framework (0.2) UNRELEASED; urgency=medium
2
3 [ Michi Henning ]
4 * Added v2 of the client-side API.
5
6 -- Michi Henning <michi.henning@canonical.com> Wed, 21 Sep 2016 14:36:15 +1000
7
1storage-framework (0.1+16.10.20160804.1-0ubuntu1) yakkety; urgency=medium8storage-framework (0.1+16.10.20160804.1-0ubuntu1) yakkety; urgency=medium
29
3 [ Michi Henning ]10 [ Michi Henning ]
411
=== modified file 'debian/control'
--- debian/control 2016-08-04 07:20:09 +0000
+++ debian/control 2016-09-21 05:03:46 +0000
@@ -49,6 +49,15 @@
49Pre-Depends: ${misc:Pre-Depends},49Pre-Depends: ${misc:Pre-Depends},
50Depends: ${misc:Depends},50Depends: ${misc:Depends},
51 ${shlibs:Depends},51 ${shlibs:Depends},
52Description: Client library for the Storage Framework (API v1, soon to be removed)
53 Runtime support for storage framework clients.
54
55Package: libstorage-framework-qt-client-2-0
56Architecture: any
57Multi-Arch: same
58Pre-Depends: ${misc:Pre-Depends},
59Depends: ${misc:Depends},
60 ${shlibs:Depends},
52Description: Client library for the Storage Framework61Description: Client library for the Storage Framework
53 Runtime support for storage framework clients.62 Runtime support for storage framework clients.
5463
@@ -70,6 +79,7 @@
70Multi-Arch: same79Multi-Arch: same
71Pre-Depends: ${misc:Pre-Depends},80Pre-Depends: ${misc:Pre-Depends},
72Depends: libstorage-framework-qt-client-1-0 (= ${binary:Version}),81Depends: libstorage-framework-qt-client-1-0 (= ${binary:Version}),
82 libstorage-framework-qt-client-2-0 (= ${binary:Version}),
73 libstorage-framework-qt-local-client-1-0 (= ${binary:Version}),83 libstorage-framework-qt-local-client-1-0 (= ${binary:Version}),
74 qtbase5-dev,84 qtbase5-dev,
75 ${misc:Depends},85 ${misc:Depends},
7686
=== modified file 'debian/control.in'
--- debian/control.in 2016-08-02 03:36:58 +0000
+++ debian/control.in 2016-09-21 05:03:46 +0000
@@ -44,6 +44,15 @@
44Pre-Depends: ${misc:Pre-Depends},44Pre-Depends: ${misc:Pre-Depends},
45Depends: ${misc:Depends},45Depends: ${misc:Depends},
46 ${shlibs:Depends},46 ${shlibs:Depends},
47Description: Client library for the Storage Framework (API v1, soon to be removed)
48 Runtime support for storage framework clients.
49
50Package: libstorage-framework-qt-client-2-0
51Architecture: any
52Multi-Arch: same
53Pre-Depends: ${misc:Pre-Depends},
54Depends: ${misc:Depends},
55 ${shlibs:Depends},
47Description: Client library for the Storage Framework56Description: Client library for the Storage Framework
48 Runtime support for storage framework clients.57 Runtime support for storage framework clients.
4958
5059
=== modified file 'debian/libstorage-framework-qt-client-1-0.install'
--- debian/libstorage-framework-qt-client-1-0.install 2016-07-11 04:06:04 +0000
+++ debian/libstorage-framework-qt-client-1-0.install 2016-09-21 05:03:46 +0000
@@ -1,1 +1,1 @@
1usr/lib/*/libstorage-framework-qt-client-*.so.*1usr/lib/*/libstorage-framework-qt-client-1.so.*
22
=== added file 'debian/libstorage-framework-qt-client-2-0.install'
--- debian/libstorage-framework-qt-client-2-0.install 1970-01-01 00:00:00 +0000
+++ debian/libstorage-framework-qt-client-2-0.install 2016-09-21 05:03:46 +0000
@@ -0,0 +1,1 @@
1usr/lib/*/libstorage-framework-qt-client-2.so.*
02
=== modified file 'include/unity/storage/CMakeLists.txt'
--- include/unity/storage/CMakeLists.txt 2016-07-11 03:28:40 +0000
+++ include/unity/storage/CMakeLists.txt 2016-09-21 05:03:46 +0000
@@ -7,5 +7,9 @@
7install(FILES ${common_headers}7install(FILES ${common_headers}
8 DESTINATION ${provider_base_includedir}/${includeprefix})8 DESTINATION ${provider_base_includedir}/${includeprefix})
99
10# Deprecated client API v1 install
11install(FILES ${common_headers}
12 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/storage-framework-client-1/${includeprefix})
13
10add_subdirectory(provider)14add_subdirectory(provider)
11add_subdirectory(qt)15add_subdirectory(qt)
1216
=== modified file 'include/unity/storage/internal/ItemMetadata.h'
--- include/unity/storage/internal/ItemMetadata.h 2016-08-25 23:56:02 +0000
+++ include/unity/storage/internal/ItemMetadata.h 2016-09-21 05:03:46 +0000
@@ -49,3 +49,6 @@
49} // namespace internal49} // namespace internal
50} // namespace storage50} // namespace storage
51} // namespace unity51} // namespace unity
52
53Q_DECLARE_METATYPE(unity::storage::internal::ItemMetadata)
54Q_DECLARE_METATYPE(QList<unity::storage::internal::ItemMetadata>)
5255
=== modified file 'include/unity/storage/internal/dbusmarshal.h'
--- include/unity/storage/internal/dbusmarshal.h 2016-08-11 06:53:25 +0000
+++ include/unity/storage/internal/dbusmarshal.h 2016-09-21 05:03:46 +0000
@@ -39,6 +39,3 @@
39} // namespace internal39} // namespace internal
40} // storage40} // storage
41} // unity41} // unity
42
43Q_DECLARE_METATYPE(unity::storage::internal::ItemMetadata)
44Q_DECLARE_METATYPE(QList<unity::storage::internal::ItemMetadata>)
4542
=== added file 'include/unity/storage/qt/Account.h'
--- include/unity/storage/qt/Account.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/Account.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,103 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <QMetaType>
22
23#include <memory>
24
25namespace unity
26{
27namespace storage
28{
29namespace qt
30{
31namespace internal
32{
33
34class AccountImpl;
35class ItemImpl;
36
37}
38
39class ItemJob;
40class ItemListJob;
41
42class Q_DECL_EXPORT Account final
43{
44 Q_GADGET
45 Q_PROPERTY(bool READ isValid CONSTANT FINAL)
46 Q_PROPERTY(QString READ owner CONSTANT FINAL)
47 Q_PROPERTY(QString READ ownerId CONSTANT FINAL)
48 Q_PROPERTY(QString READ description CONSTANT FINAL)
49
50public:
51 Account();
52 Account(Account const&);
53 Account(Account&&);
54 ~Account();
55 Account& operator=(Account const&);
56 Account& operator=(Account&&);
57
58 bool isValid() const;
59 QString owner() const;
60 QString ownerId() const;
61 QString description() const;
62
63 Q_INVOKABLE ItemListJob* roots() const;
64 Q_INVOKABLE ItemJob* get(QString const& itemId) const;
65
66 bool operator==(Account const&) const;
67 bool operator!=(Account const&) const;
68 bool operator<(Account const&) const;
69 bool operator<=(Account const&) const;
70 bool operator>(Account const&) const;
71 bool operator>=(Account const&) const;
72
73 size_t hash() const;
74
75private:
76 Account(std::shared_ptr<internal::AccountImpl> const& p);
77
78 std::shared_ptr<internal::AccountImpl> p_;
79
80 friend class internal::AccountImpl;
81 friend class internal::ItemImpl;
82};
83
84} // namespace qt
85} // namespace storage
86} // namespace unity
87
88namespace std
89{
90
91template<> struct Q_DECL_EXPORT hash<unity::storage::qt::Account>
92{
93 std::size_t operator()(unity::storage::qt::Account const& a)
94 {
95 return a.hash();
96 }
97};
98
99} // namespace std
100
101// Note: qHash(Account) does *not* return the same hash value is std::hash<Account> because
102// std:hash() returns size_t (typically 64 bits), but qHash() returns uint (typically 32 bits).
103uint Q_DECL_EXPORT qHash(unity::storage::qt::Account const& acc);
0104
=== added file 'include/unity/storage/qt/AccountsJob.h'
--- include/unity/storage/qt/AccountsJob.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/AccountsJob.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,80 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <unity/storage/qt/Account.h>
22#include <unity/storage/qt/StorageError.h>
23
24#include <QMetaType>
25#include <QObject>
26
27namespace unity
28{
29namespace storage
30{
31namespace qt
32{
33namespace internal
34{
35
36class AccountsJobImpl;
37class RuntimeImpl;
38
39} // namespace internal
40
41class Account;
42class Runtime;
43class StorageError;
44
45class Q_DECL_EXPORT AccountsJob final : public QObject
46{
47 Q_OBJECT
48 Q_PROPERTY(bool isValid READ isValid FINAL)
49 Q_PROPERTY(unity::storage::qt::AccountsJob::Status status READ status NOTIFY statusChanged FINAL)
50 Q_PROPERTY(unity::storage::qt::StorageError error READ error FINAL)
51 Q_PROPERTY(QList<unity::storage::qt::Account> accounts READ accounts FINAL)
52
53public:
54 enum Status { Loading, Finished, Error };
55 Q_ENUMS(Status)
56
57 virtual ~AccountsJob();
58
59 bool isValid() const;
60 Status status() const;
61 StorageError error() const;
62 QList<Account> accounts() const;
63
64Q_SIGNALS:
65 void statusChanged(unity::storage::qt::AccountsJob::Status status) const;
66
67private:
68 AccountsJob(std::shared_ptr<internal::RuntimeImpl> const& runtime);
69 AccountsJob(StorageError const& error);
70
71 std::unique_ptr<internal::AccountsJobImpl> const p_;
72
73 friend class internal::RuntimeImpl;
74};
75
76} // namespace qt
77} // namespace storage
78} // namespace unity
79
80Q_DECLARE_METATYPE(unity::storage::qt::AccountsJob::Status)
081
=== modified file 'include/unity/storage/qt/CMakeLists.txt'
--- include/unity/storage/qt/CMakeLists.txt 2016-05-23 02:27:16 +0000
+++ include/unity/storage/qt/CMakeLists.txt 2016-09-21 05:03:46 +0000
@@ -1,1 +1,17 @@
1add_subdirectory(client)1add_subdirectory(client) # Old (v1) API
2
3set(includeprefix unity/storage/qt)
4file(GLOB public_hdrs *.h)
5set(convenience_hdr ${CMAKE_CURRENT_BINARY_DIR}/client-api.h)
6
7add_custom_command(
8 OUTPUT ${convenience_hdr}
9 COMMAND ${CMAKE_SOURCE_DIR}/tools/create_globalheader.py
10 ${convenience_hdr} ${includeprefix} ${CMAKE_CURRENT_SOURCE_DIR}
11 DEPENDS ${public_hdrs})
12
13add_custom_target(qt-client-all-headers ALL DEPENDS ${convenience_hdr})
14
15install(
16 FILES ${public_hdrs} ${convenience_hdr}
17 DESTINATION ${client_base_includedir}/${includeprefix})
218
=== added file 'include/unity/storage/qt/ConflictPolicy.h'
--- include/unity/storage/qt/ConflictPolicy.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/ConflictPolicy.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,32 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21namespace unity
22{
23namespace storage
24{
25namespace qt
26{
27
28enum class ConflictPolicy { ErrorIfConflict, Overwrite };
29
30} // namespace qt
31} // namespace storage
32} // namespace unity
033
=== added file 'include/unity/storage/qt/Downloader.h'
--- include/unity/storage/qt/Downloader.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/Downloader.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,68 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <QIODevice>
22
23namespace unity
24{
25namespace storage
26{
27namespace qt
28{
29
30class Item;
31class StorageError;
32
33class Q_DECL_EXPORT Downloader final : public QIODevice
34{
35 Q_OBJECT
36 Q_PROPERTY(bool isValid READ isValid FINAL) // TODO: Need notify and constant where appropriate
37 Q_PROPERTY(unity::Storage::qt::Downloader::Status status READ status NOTIFY statusChanged FINAL)
38 Q_PROPERTY(unity::Storage::qt::StorageError error READ error FINAL)
39 Q_PROPERTY(unity::Storage::qt::Item item READ item FINAL)
40
41public:
42 enum Status { Loading, Ready, Cancelled, Finished, Error };
43 Q_ENUMS(Status)
44
45 Downloader();
46 virtual ~Downloader();
47
48 bool isValid();
49 Status status() const;
50 StorageError error() const;
51 Item item() const;
52
53 Q_INVOKABLE void finishDownload(); // TODO: finish()
54 Q_INVOKABLE void cancel();
55
56 // TODO: will probably need QML invokable methods for reading and writing to/from QIODevice
57
58Q_SIGNALS:
59 void statusChanged(unity::storage::qt::Downloader::Status status) const;
60
61protected:
62 virtual qint64 readData(char* data, qint64 maxSize) override;
63 virtual qint64 writeData(char const* data, qint64 maxSize) override;
64};
65
66} // namespace qt
67} // namespace storage
68} // namespace unity
069
=== added file 'include/unity/storage/qt/Item.h'
--- include/unity/storage/qt/Item.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/Item.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,142 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <unity/storage/qt/ConflictPolicy.h>
22
23#pragma GCC diagnostic push
24#pragma GCC diagnostic ignored "-Wcast-align"
25#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
26#include <QDateTime>
27#include <QVariantMap>
28#pragma GCC diagnostic pop
29
30#include <memory>
31
32namespace unity
33{
34namespace storage
35{
36namespace qt
37{
38namespace internal
39{
40
41class ItemImpl;
42
43} // namespace internal
44
45class Account;
46class Downloader;
47class IntJob;
48class ItemJob;
49class ItemListJob;
50class Uploader;
51class VoidJob;
52
53class Q_DECL_EXPORT Item final
54{
55 Q_GADGET
56 Q_PROPERTY(QString itemId READ itemId CONSTANT FINAL)
57 Q_PROPERTY(QString name READ name CONSTANT FINAL)
58 Q_PROPERTY(unity::storage::qt::Account account READ account CONSTANT FINAL)
59 Q_PROPERTY(QString etag READ etag CONSTANT FINAL)
60 Q_PROPERTY(unity::storage::qt::Item::Type type READ type CONSTANT FINAL)
61 Q_PROPERTY(QVariantMap metadata READ metadata CONSTANT FINAL)
62 Q_PROPERTY(QDateTime lastModifiedTime READ lastModifiedTime CONSTANT FINAL)
63 Q_PROPERTY(QVector<QString> parentIds READ parentIds CONSTANT FINAL)
64
65public:
66 Item();
67 Item(Item const&);
68 Item(Item&&);
69 ~Item();
70 Item& operator=(Item const&);
71 Item& operator=(Item&&);
72
73 enum Type { File, Folder, Root };
74 Q_ENUMS(Type)
75
76 bool isValid() const;
77 QString itemId() const;
78 QString name() const;
79 Account account() const;
80 QString etag() const;
81 Type type() const;
82 QVariantMap metadata() const;
83 QDateTime lastModifiedTime() const;
84 QVector<QString> parentIds() const; // TODO: should be QList
85
86 Q_INVOKABLE ItemListJob* parents() const;
87 Q_INVOKABLE ItemJob* copy(Item const& newParent, QString const& newName) const;
88 Q_INVOKABLE ItemJob* move(Item const& newParent, QString const& newName) const;
89 Q_INVOKABLE VoidJob* deleteItem() const;
90
91 Q_INVOKABLE Uploader* createUploader(ConflictPolicy policy, qint64 sizeInBytes) const;
92 Q_INVOKABLE Downloader* createDownloader() const;
93
94 Q_INVOKABLE ItemListJob* list() const;
95 Q_INVOKABLE ItemListJob* lookup(QString const& name) const;
96 Q_INVOKABLE ItemJob* createFolder(QString const& name) const;
97 Q_INVOKABLE Uploader* createFile(QString const& name) const;
98
99 Q_INVOKABLE IntJob* freeSpaceBytes() const;
100 Q_INVOKABLE IntJob* usedSpaceBytes() const;
101
102 bool operator==(Item const&) const;
103 bool operator!=(Item const&) const;
104 bool operator<(Item const&) const;
105 bool operator<=(Item const&) const;
106 bool operator>(Item const&) const;
107 bool operator>=(Item const&) const;
108
109 size_t hash() const;
110
111private:
112 Item(std::shared_ptr<internal::ItemImpl> const&);
113
114 std::shared_ptr<internal::ItemImpl> p_;
115
116 friend class internal::ItemImpl;
117};
118
119} // namespace qt
120} // namespace storage
121} // namespace unity
122
123Q_DECLARE_METATYPE(unity::storage::qt::Item)
124Q_DECLARE_METATYPE(QList<unity::storage::qt::Item>)
125Q_DECLARE_METATYPE(unity::storage::qt::Item::Type)
126
127namespace std
128{
129
130template<> struct Q_DECL_EXPORT hash<unity::storage::qt::Item>
131{
132 std::size_t operator()(unity::storage::qt::Item const& i)
133 {
134 return i.hash();
135 }
136};
137
138} // namespace std
139
140// Note: qHash(Item) does *not* return the same hash value is std::hash<Item> because
141// std:hash() returns size_t (typically 64 bits), but qHash() returns uint (typically 32 bits).
142uint Q_DECL_EXPORT qHash(unity::storage::qt::Item const& i);
0143
=== added file 'include/unity/storage/qt/ItemJob.h'
--- include/unity/storage/qt/ItemJob.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/ItemJob.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,75 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <unity/storage/qt/Item.h>
22
23#include <QObject>
24
25namespace unity
26{
27namespace storage
28{
29namespace qt
30{
31namespace internal
32{
33
34class ItemJobImpl;
35
36} // namespace internal
37
38class Item;
39class StorageError;
40
41class Q_DECL_EXPORT ItemJob final : public QObject
42{
43 Q_OBJECT
44 Q_PROPERTY(bool isValid READ isValid FINAL)
45 Q_PROPERTY(unity::storage::qt::ItemJob::Status status READ status NOTIFY statusChanged FINAL)
46 Q_PROPERTY(unity::storage::qt::StorageError error READ error FINAL)
47 Q_PROPERTY(unity::storage::qt::Item item READ item FINAL)
48
49public:
50 virtual ~ItemJob();
51
52 enum Status { Loading, Finished, Error };
53 Q_ENUMS(Status)
54
55 bool isValid() const;
56 Status status() const;
57 StorageError error() const;
58 Item item() const;
59
60Q_SIGNALS:
61 void statusChanged(unity::storage::qt::ItemJob::Status status) const;
62
63private:
64 ItemJob(std::unique_ptr<internal::ItemJobImpl> p);
65
66 std::unique_ptr<internal::ItemJobImpl> const p_;
67
68 friend class internal::ItemJobImpl;
69};
70
71} // namespace qt
72} // namespace storage
73} // namespace unity
74
75Q_DECLARE_METATYPE(unity::storage::qt::ItemJob::Status)
076
=== added file 'include/unity/storage/qt/ItemListJob.h'
--- include/unity/storage/qt/ItemListJob.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/ItemListJob.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,77 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#pragma GCC diagnostic push
22#pragma GCC diagnostic ignored "-Wcast-align"
23#include <QObject>
24#pragma GCC diagnostic pop
25
26#include <memory>
27
28namespace unity
29{
30namespace storage
31{
32namespace qt
33{
34namespace internal
35{
36
37class ItemListJobImpl;
38
39} // namespace internal
40
41class Item;
42class StorageError;
43
44class Q_DECL_EXPORT ItemListJob final : public QObject
45{
46 Q_OBJECT
47 Q_PROPERTY(bool isValid READ isValid FINAL)
48 Q_PROPERTY(unity::storage::qt::ItemListJob::Status status READ status NOTIFY statusChanged FINAL)
49 Q_PROPERTY(unity::storage::qt::StorageError error READ error FINAL)
50
51public:
52 virtual ~ItemListJob();
53
54 enum Status { Loading, Finished, Error };
55 Q_ENUMS(Status)
56
57 bool isValid() const;
58 Status status() const;
59 StorageError error() const;
60
61Q_SIGNALS:
62 void statusChanged(unity::storage::qt::ItemListJob::Status status) const;
63 void itemsReady(QList<unity::storage::qt::Item> const& items) const;
64
65private:
66 ItemListJob(std::unique_ptr<internal::ItemListJobImpl> p);
67
68 std::unique_ptr<internal::ItemListJobImpl> const p_;
69
70 friend class internal::ItemListJobImpl;
71};
72
73} // namespace qt
74} // namespace storage
75} // namespace unity
76
77Q_DECLARE_METATYPE(unity::storage::qt::ItemListJob::Status)
078
=== added file 'include/unity/storage/qt/Runtime.h'
--- include/unity/storage/qt/Runtime.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/Runtime.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,80 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <unity/storage/qt/Account.h>
22#include <unity/storage/qt/StorageError.h>
23
24#pragma GCC diagnostic push
25#pragma GCC diagnostic ignored "-Wcast-align"
26#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
27#include <QDBusConnection>
28#pragma GCC diagnostic pop
29
30#include <memory>
31
32class QDBusConnection;
33
34namespace unity
35{
36namespace storage
37{
38namespace qt
39{
40namespace internal
41{
42
43class RuntimeImpl;
44
45} // namespace internal
46
47class AccountsJob;
48
49class Q_DECL_EXPORT Runtime final : public QObject
50{
51 Q_PROPERTY(bool isValid READ isValid FINAL)
52 Q_PROPERTY(unity::storage::StorageError error READ FINAL)
53 Q_PROPERTY(QDBusConnection connection READ connection FINAL)
54public:
55 Runtime(QObject* parent = nullptr);
56 Runtime(QDBusConnection const& bus, QObject* parent = nullptr);
57 virtual ~Runtime();
58
59 bool isValid() const;
60 StorageError error() const;
61 QDBusConnection connection() const;
62 StorageError shutdown();
63 Q_INVOKABLE AccountsJob* accounts() const;
64
65 // TODO: Get rid of two-argument version and default trailing params.
66 // TODO: can be const methods.
67 Account make_test_account(QString const& bus_name, QString const& object_path);
68 Account make_test_account(QString const& bus_name,
69 QString const& object_path,
70 QString const& owner_id,
71 QString const& owner,
72 QString const& description);
73
74private:
75 std::shared_ptr<internal::RuntimeImpl> p_;
76};
77
78} // namespace qt
79} // namespace storage
80} // namespace unity
081
=== added file 'include/unity/storage/qt/StorageError.h'
--- include/unity/storage/qt/StorageError.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/StorageError.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,87 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <QMetaType>
22#include <QString>
23
24#include <memory>
25
26namespace unity
27{
28namespace storage
29{
30namespace qt
31{
32namespace internal
33{
34
35class StorageErrorImpl;
36
37}
38
39class Q_DECL_EXPORT StorageError final
40{
41 Q_GADGET
42 Q_PROPERTY(unity::storage::qt::StorageError::Type type READ type FINAL)
43 Q_PROPERTY(QString name READ name FINAL)
44 Q_PROPERTY(QString message READ message FINAL)
45 Q_PROPERTY(QString errorString READ errorString FINAL)
46
47 Q_PROPERTY(QString itemId READ itemId FINAL)
48 Q_PROPERTY(QString itemName READ itemName FINAL)
49 Q_PROPERTY(int errorCode READ errorCode FINAL)
50
51public:
52 StorageError();
53 StorageError(StorageError const&);
54 StorageError(StorageError&&);
55 ~StorageError();
56 StorageError& operator=(StorageError const&);
57 StorageError& operator=(StorageError&&);
58
59 enum Type
60 {
61 NoError, LocalCommsError, RemoteCommsError, Deleted, RuntimeDestroyed, NotExists,
62 Exists, Conflict, PermissionDenied, Cancelled, LogicError, InvalidArgument, ResourceError,
63 QuotaExceeded,
64 __LAST_STORAGE_ERROR
65 };
66 Q_ENUMS(Type)
67
68 Type type() const;
69 QString name() const;
70 QString message() const;
71 QString errorString() const;
72
73 QString itemId() const;
74 QString itemName() const;
75 int errorCode() const;
76
77private:
78 StorageError(std::unique_ptr<internal::StorageErrorImpl>);
79
80 std::unique_ptr<internal::StorageErrorImpl> p_;
81
82 friend class internal::StorageErrorImpl;
83};
84
85} // namespace qt
86} // namespace storage
87} // namespace unity
088
=== added file 'include/unity/storage/qt/Uploader.h'
--- include/unity/storage/qt/Uploader.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/Uploader.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,72 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <unity/storage/common.h>
22
23#include <QIODevice>
24
25namespace unity
26{
27namespace storage
28{
29namespace qt
30{
31
32class Item;
33class StorageError;
34
35class Q_DECL_EXPORT Uploader final : public QIODevice
36{
37 Q_OBJECT
38 Q_PROPERTY(bool isValid READ isValid FINAL) // TODO: Need notify
39 Q_PROPERTY(unity::storage::qt::Uploader::Status status READ status FINAL)
40 Q_PROPERTY(unity::storage::qt::StorageError READ error FINAL)
41 Q_PROPERTY(unity::storage::qt::ConflictPolicy policy READ policy FINAL)
42 Q_PROPERTY(qint64 sizeInBytes READ sizeInBytes FINAL)
43 Q_PROPERTY(unity::storage::qt::Item item READ item FINAL)
44
45public:
46 enum Status { Loading, Cancelled, Finished, Error };
47 Q_ENUMS(Status)
48
49 Uploader();
50 virtual ~Uploader();
51
52 bool isValid() const;
53 Status status() const;
54 StorageError error() const;
55 ConflictPolicy policy() const;
56 qint64 sizeInBytes() const;
57 Item item() const;
58
59 Q_INVOKABLE void finishUpload();
60 Q_INVOKABLE void cancel();
61
62Q_SIGNALS:
63 void statusChanged(unity::storage::qt::Uploader::Status status) const;
64
65protected:
66 virtual qint64 readData(char* data, qint64 maxSize) override;
67 virtual qint64 writeData(char const* data, qint64 maxSize) override;
68};
69
70} // namespace qt
71} // namespace storage
72} // namespace unity
073
=== added file 'include/unity/storage/qt/VoidJob.h'
--- include/unity/storage/qt/VoidJob.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/VoidJob.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,56 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <QObject>
22
23namespace unity
24{
25namespace storage
26{
27namespace qt
28{
29
30class StorageError;
31
32class Q_DECL_EXPORT VoidJob final : public QObject
33{
34 // TODO: notify, CONSTANT where needed
35 Q_OBJECT
36 Q_PROPERTY(bool READ isValid FINAL)
37 Q_PROPERTY(unity::storage::qt::VoidJob::Status READ status NOTIFY statusChanged FINAL)
38 Q_PROPERTY(unity::storage::qt::StorageError READ error FINAL)
39
40public:
41 virtual ~VoidJob();
42
43 enum Status { Loading, Finished, Error };
44 Q_ENUMS(Status)
45
46 bool isValid() const;
47 Status status() const;
48 StorageError error() const;
49
50Q_SIGNALS:
51 void statusChanged(unity::storage::qt::VoidJob::Status status) const;
52};
53
54} // namespace qt
55} // namespace storage
56} // namespace unity
057
=== modified file 'include/unity/storage/qt/client/CMakeLists.txt'
--- include/unity/storage/qt/client/CMakeLists.txt 2016-07-11 03:28:40 +0000
+++ include/unity/storage/qt/client/CMakeLists.txt 2016-09-21 05:03:46 +0000
@@ -8,8 +8,7 @@
8 ${convenience_hdr} ${includeprefix} ${CMAKE_CURRENT_SOURCE_DIR}8 ${convenience_hdr} ${includeprefix} ${CMAKE_CURRENT_SOURCE_DIR}
9 DEPENDS ${public_hdrs})9 DEPENDS ${public_hdrs})
1010
11add_custom_target(qt-client-all-headers ALL DEPENDS ${convenience_hdr})11add_custom_target(qt-client-all-headers-v1 ALL DEPENDS ${convenience_hdr})
1212
13install(13install(FILES ${public_hdrs} ${convenience_hdr}
14 FILES ${public_hdrs} ${convenience_hdr}14 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/storage-framework-client-1/${includeprefix})
15 DESTINATION ${client_base_includedir}/${includeprefix})
1615
=== added directory 'include/unity/storage/qt/internal'
=== added file 'include/unity/storage/qt/internal/AccountImpl.h'
--- include/unity/storage/qt/internal/AccountImpl.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/internal/AccountImpl.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,99 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <unity/storage/qt/Item.h>
22
23#include <QString>
24
25#include <memory>
26
27class ProviderInterface;
28
29namespace unity
30{
31namespace storage
32{
33namespace qt
34{
35namespace internal
36{
37
38class RuntimeImpl;
39
40class AccountImpl : public std::enable_shared_from_this<AccountImpl>
41{
42public:
43 AccountImpl();
44 AccountImpl(AccountImpl const&) = default;
45 AccountImpl(AccountImpl&&) = default;
46 ~AccountImpl() = default;
47 AccountImpl& operator=(AccountImpl const&) = default;
48 AccountImpl& operator=(AccountImpl&&) = default;
49
50 QString ownerId() const;
51 QString owner() const;
52 QString description() const;
53
54 ItemListJob* roots() const;
55 ItemJob* get(QString const& itemId) const;
56
57 bool operator==(AccountImpl const&) const;
58 bool operator!=(AccountImpl const&) const;
59 bool operator<(AccountImpl const&) const;
60 bool operator<=(AccountImpl const&) const;
61 bool operator>(AccountImpl const&) const;
62 bool operator>=(AccountImpl const&) const;
63
64 size_t hash() const;
65
66 //std::shared_ptr<RuntimeImpl> runtime() const;
67 std::shared_ptr<ProviderInterface> provider() const;
68
69 static Account make_account(std::shared_ptr<RuntimeImpl> const& runtime,
70 QString const& bus_name,
71 QString const& object_path,
72 QString const& owner_id,
73 QString const& owner,
74 QString const& description);
75
76private:
77 AccountImpl(std::shared_ptr<RuntimeImpl> const& runtime,
78 QString const& bus_name,
79 QString const& object_path,
80 QString const& owner_id,
81 QString const& owner,
82 QString const& description);
83
84 bool is_valid_;
85 QString bus_name_;
86 QString object_path_;
87 QString owner_id_;
88 QString owner_;
89 QString description_;
90 std::weak_ptr<RuntimeImpl> runtime_;
91 std::shared_ptr<ProviderInterface> provider_;
92
93 friend class unity::storage::qt::Account;
94};
95
96} // namespace internal
97} // namespace qt
98} // namespace storage
99} // namespace unity
0100
=== added file 'include/unity/storage/qt/internal/AccountsJobImpl.h'
--- include/unity/storage/qt/internal/AccountsJobImpl.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/internal/AccountsJobImpl.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,70 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <unity/storage/qt/AccountsJob.h>
22
23#include <QTimer>
24
25namespace unity
26{
27namespace storage
28{
29namespace qt
30{
31namespace internal
32{
33
34class AccountsJobImpl : public QObject
35{
36 Q_OBJECT
37public:
38 AccountsJobImpl(AccountsJob* public_instance, std::shared_ptr<RuntimeImpl> const& runtime);
39 AccountsJobImpl(AccountsJob* public_instance, StorageError const& error);
40 virtual ~AccountsJobImpl() = default;
41
42 bool isValid() const;
43 AccountsJob::Status status() const;
44 StorageError error() const;
45 QList<Account> accounts() const;
46
47private Q_SLOTS:
48 void manager_ready();
49 void timeout();
50
51private:
52 std::shared_ptr<RuntimeImpl> get_runtime(QString const& method) const;
53 void initialize_accounts();
54 AccountsJob::Status emit_status_changed(AccountsJob::Status new_status) const;
55
56 AccountsJob* const public_instance_;
57
58 AccountsJob::Status status_;
59 StorageError error_;
60 QList<unity::storage::qt::Account> accounts_;
61 std::weak_ptr<RuntimeImpl> const runtime_;
62 QTimer timer_;
63
64 friend class unity::storage::qt::AccountsJob;
65};
66
67} // namespace internal
68} // namespace qt
69} // namespace storage
70} // namespace unity
071
=== added file 'include/unity/storage/qt/internal/Handler.h'
--- include/unity/storage/qt/internal/Handler.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/internal/Handler.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,93 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <unity/storage/qt/internal/HandlerBase.h>
22#include <unity/storage/qt/internal/StorageErrorImpl.h>
23#include <unity/storage/qt/internal/unmarshal_error.h>
24
25#include <QDBusPendingReply>
26#include <QDebug>
27
28#include <cassert>
29
30namespace unity
31{
32namespace storage
33{
34namespace qt
35{
36namespace internal
37{
38
39template<typename T>
40class Handler : public HandlerBase
41{
42public:
43 template<typename ... DBusArgs>
44 Handler(QObject* parent,
45 QDBusPendingReply<DBusArgs...> const& reply,
46 std::function<void(decltype(reply)&)> const& success_closure,
47 std::function<void(StorageError const&)> const& error_closure)
48 : HandlerBase(parent,
49 reply,
50 [this, success_closure, error_closure](QDBusPendingCallWatcher& call)
51 {
52 if (call.isError())
53 {
54 auto e = unmarshal_error(call);
55 switch (e.type())
56 {
57 case StorageError::NoError:
58 {
59 // LCOV_EXCL_START
60 QString msg = "impossible provider exception: " + e.errorString();
61 qCritical() << msg;
62 e = StorageErrorImpl::local_comms_error(msg);
63 break;
64 // LCOV_EXCL_STOP
65 }
66 case StorageError::LocalCommsError:
67 case StorageError::RemoteCommsError:
68 case StorageError::ResourceError:
69 {
70 // Log these errors because they are unexpected.
71 qCritical() << "provider exception:" << e.errorString();
72 break;
73 }
74 default:
75 {
76 // All other errors are not logged.
77 break;
78 }
79 }
80 error_closure(e);
81 return;
82 }
83 QDBusPendingReply<DBusArgs...> r = call;
84 success_closure(call);
85 })
86 {
87 }
88};
89
90} // namespace internal
91} // namespace qt
92} // namespace storage
93} // namespace unity
094
=== added file 'include/unity/storage/qt/internal/HandlerBase.h'
--- include/unity/storage/qt/internal/HandlerBase.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/internal/HandlerBase.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,64 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#pragma GCC diagnostic push
22#pragma GCC diagnostic ignored "-Wcast-align"
23#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
24#pragma GCC diagnostic ignored "-Wswitch-default"
25#include <QDBusPendingCallWatcher>
26#include <QObject>
27#pragma GCC diagnostic pop
28
29#include <functional>
30
31class QDBusPendingCall;
32
33namespace unity
34{
35namespace storage
36{
37namespace qt
38{
39namespace internal
40{
41
42class HandlerBase : public QObject
43{
44 Q_OBJECT
45
46public:
47 HandlerBase(QObject* parent,
48 QDBusPendingCall const& call,
49 std::function<void(QDBusPendingCallWatcher&)> const& closure);
50
51public Q_SLOTS:
52 void finished(QDBusPendingCallWatcher* call);
53
54protected:
55 QDBusPendingCallWatcher watcher_;
56
57private:
58 std::function<void(QDBusPendingCallWatcher&)> closure_;
59};
60
61} // namespace internal
62} // namespace qt
63} // namespace storage
64} // namespace unity
065
=== added file 'include/unity/storage/qt/internal/ItemImpl.h'
--- include/unity/storage/qt/internal/ItemImpl.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/internal/ItemImpl.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,99 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <unity/storage/internal/ItemMetadata.h>
22#include <unity/storage/qt/Account.h>
23#include <unity/storage/qt/Item.h>
24
25namespace unity
26{
27namespace storage
28{
29namespace qt
30{
31namespace internal
32{
33
34class AccountImpl;
35class RuntimeImpl;
36
37class ItemImpl : public std::enable_shared_from_this<ItemImpl>
38{
39public:
40 ItemImpl();
41 ItemImpl(storage::internal::ItemMetadata const& md,
42 std::shared_ptr<AccountImpl> const& account);
43 ItemImpl(ItemImpl const&) = default;
44 ItemImpl(ItemImpl&&) = delete;
45 ~ItemImpl() = default;
46 ItemImpl& operator=(ItemImpl const&) = default;
47 ItemImpl& operator=(ItemImpl&&) = delete;
48
49 QString itemId() const;
50 QString name() const;
51 Account account() const;
52 //Item root() const;
53 QString etag() const;
54 Item::Type type() const;
55 QVariantMap metadata() const;
56 QDateTime lastModifiedTime() const;
57 QVector<QString> parentIds() const;
58
59 ItemListJob* parents() const;
60 ItemJob* copy(Item const& newParent, QString const& newName) const;
61 ItemJob* move(Item const& newParent, QString const& newName) const;
62 VoidJob* deleteItem() const;
63 Uploader* createUploader(ConflictPolicy policy, qint64 sizeInBytes) const;
64 Downloader* createDownloader() const;
65 ItemListJob* list() const;
66 ItemListJob* lookup(QString const& name) const;
67 ItemJob* createFolder(QString const& name) const;
68 Uploader* createFile(QString const& name) const;
69 IntJob* freeSpaceBytes() const;
70 IntJob* usedSpaceBytes() const;
71
72 bool operator==(ItemImpl const&) const;
73 bool operator!=(ItemImpl const&) const;
74 bool operator<(ItemImpl const&) const;
75 bool operator<=(ItemImpl const&) const;
76 bool operator>(ItemImpl const&) const;
77 bool operator>=(ItemImpl const&) const;
78
79 size_t hash() const;
80
81 static Item make_item(QString const& method,
82 storage::internal::ItemMetadata const& md,
83 std::shared_ptr<AccountImpl> const& account);
84
85private:
86 //std::shared_ptr<RuntimeImpl> get_runtime(QString const& method) const;
87
88 bool is_valid_;
89 storage::internal::ItemMetadata md_;
90 std::shared_ptr<AccountImpl> account_;
91 //std::shared_ptr<RootImpl> root_;
92
93 friend class unity::storage::qt::Item;
94};
95
96} // namespace internal
97} // namespace qt
98} // namespace storage
99} // namespace unity
0100
=== added file 'include/unity/storage/qt/internal/ItemJobImpl.h'
--- include/unity/storage/qt/internal/ItemJobImpl.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/internal/ItemJobImpl.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,84 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <unity/storage/qt/ItemJob.h>
22
23#include <unity/storage/qt/Account.h>
24#include <unity/storage/qt/internal/Handler.h>
25#include <unity/storage/qt/StorageError.h>
26
27namespace unity
28{
29namespace storage
30{
31namespace internal
32{
33
34class ItemMetadata;
35
36}
37
38namespace qt
39{
40namespace internal
41{
42
43class RuntimeImpl;
44
45class ItemJobImpl : public QObject
46{
47 Q_OBJECT
48public:
49 virtual ~ItemJobImpl() = default;
50
51 bool isValid() const;
52 ItemJob::Status status() const;
53 StorageError error() const;
54 Item item() const;
55
56 static ItemJob* make_item_job(std::shared_ptr<AccountImpl> const& account,
57 QString const& method,
58 QDBusPendingReply<storage::internal::ItemMetadata> const& reply,
59 std::function<void(storage::internal::ItemMetadata const&)> const& validate);
60 static ItemJob* make_item_job(StorageError const& e);
61
62private:
63 ItemJobImpl(std::shared_ptr<AccountImpl> const& account,
64 QString const& method,
65 QDBusPendingReply<storage::internal::ItemMetadata> const& reply,
66 std::function<void(storage::internal::ItemMetadata const&)> const& validate);
67 ItemJobImpl(StorageError const& e);
68
69 ItemJob::Status emit_status_changed(ItemJob::Status new_status) const;
70
71 ItemJob* public_instance_;
72
73 ItemJob::Status status_;
74 StorageError error_;
75 QString method_;
76 std::shared_ptr<AccountImpl> account_;
77 std::function<void(storage::internal::ItemMetadata const&)> validate_;
78 Item item_;
79};
80
81} // namespace internal
82} // namespace qt
83} // namespace storage
84} // namespace unity
085
=== added file 'include/unity/storage/qt/internal/ItemListJobImpl.h'
--- include/unity/storage/qt/internal/ItemListJobImpl.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/internal/ItemListJobImpl.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,83 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <unity/storage/qt/ItemListJob.h>
22
23#include <unity/storage/qt/Account.h>
24#include <unity/storage/qt/internal/Handler.h>
25#include <unity/storage/qt/StorageError.h>
26
27namespace unity
28{
29namespace storage
30{
31namespace internal
32{
33
34class ItemMetadata;
35
36}
37
38namespace qt
39{
40namespace internal
41{
42
43class RuntimeImpl;
44
45class ItemListJobImpl : public QObject
46{
47 Q_OBJECT
48public:
49 virtual ~ItemListJobImpl() = default;
50
51 bool isValid() const;
52 ItemListJob::Status status() const;
53 StorageError error() const;
54
55 static ItemListJob* make_item_list_job(std::shared_ptr<AccountImpl> const& account,
56 QString const& method,
57 QDBusPendingReply<QList<storage::internal::ItemMetadata>> const& reply,
58 std::function<void(storage::internal::ItemMetadata const&)> const& validate);
59 static ItemListJob* make_item_list_job(StorageError const& error);
60
61private:
62 ItemListJobImpl(std::shared_ptr<AccountImpl> const& account,
63 QString const& method,
64 QDBusPendingReply<QList<storage::internal::ItemMetadata>> const& reply,
65 std::function<void(storage::internal::ItemMetadata const&)> const& validate);
66 ItemListJobImpl(StorageError const& error);
67
68 ItemListJob::Status emit_status_changed(ItemListJob::Status new_status) const;
69 void emit_items_ready(QList<unity::storage::qt::Item> const& items) const;
70
71 ItemListJob* public_instance_;
72
73 ItemListJob::Status status_;
74 StorageError error_;
75 QString method_;
76 std::shared_ptr<AccountImpl> account_;
77 std::function<void(storage::internal::ItemMetadata const&)> validate_;
78};
79
80} // namespace internal
81} // namespace qt
82} // namespace storage
83} // namespace unity
084
=== added file 'include/unity/storage/qt/internal/RuntimeImpl.h'
--- include/unity/storage/qt/internal/RuntimeImpl.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/internal/RuntimeImpl.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,85 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <unity/storage/qt/Account.h>
22#include <unity/storage/qt/StorageError.h>
23
24#include <OnlineAccounts/Manager>
25
26#pragma GCC diagnostic push
27#pragma GCC diagnostic ignored "-Wcast-align"
28#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
29#include <QDBusConnection>
30#pragma GCC diagnostic pop
31
32namespace unity
33{
34namespace storage
35{
36namespace qt
37{
38
39class AccountsJob;
40class Runtime;
41
42namespace internal
43{
44
45class RuntimeImpl : public std::enable_shared_from_this<RuntimeImpl>
46{
47public:
48 RuntimeImpl();
49 RuntimeImpl(QDBusConnection const& bus);
50 RuntimeImpl(RuntimeImpl const&) = delete;
51 RuntimeImpl(RuntimeImpl&&) = delete;
52 ~RuntimeImpl();
53 RuntimeImpl& operator=(RuntimeImpl const&) = delete;
54 RuntimeImpl& operator=(RuntimeImpl&&) = delete;
55
56 bool isValid() const;
57 StorageError error() const;
58 QDBusConnection connection() const;
59 AccountsJob* accounts() const;
60 StorageError shutdown();
61
62 std::shared_ptr<OnlineAccounts::Manager> accounts_manager() const;
63
64 Account make_test_account(QString const& bus_name,
65 QString const& object_path);
66
67 Account make_test_account(QString const& bus_name,
68 QString const& object_path,
69 QString const& owner_id,
70 QString const& owner,
71 QString const& description);
72
73private:
74 bool is_valid_;
75 StorageError error_;
76 QDBusConnection conn_;
77 std::shared_ptr<OnlineAccounts::Manager> accounts_manager_;
78
79 friend class unity::storage::qt::Runtime;
80};
81
82} // namespace internal
83} // namespace qt
84} // namespace storage
85} // namespace unity
086
=== added file 'include/unity/storage/qt/internal/StorageErrorImpl.h'
--- include/unity/storage/qt/internal/StorageErrorImpl.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/internal/StorageErrorImpl.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,85 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <unity/storage/qt/StorageError.h>
22
23namespace unity
24{
25namespace storage
26{
27namespace qt
28{
29namespace internal
30{
31
32class StorageErrorImpl
33{
34public:
35 StorageErrorImpl();
36 StorageErrorImpl(StorageError::Type type, QString const& msg);
37 StorageErrorImpl(StorageError::Type type, QString const& msg, QString const& item_id);
38 StorageErrorImpl(StorageError::Type type, QString const& msg, QString const& item_id, QString const& item_name);
39 StorageErrorImpl(StorageError::Type type, QString const& msg, int error_code);
40 StorageErrorImpl(StorageErrorImpl const&) = default;
41 StorageErrorImpl(StorageErrorImpl&&) = default;
42 ~StorageErrorImpl() = default;
43 StorageErrorImpl& operator=(StorageErrorImpl const&) = default;
44 StorageErrorImpl& operator=(StorageErrorImpl&&) = default;
45
46 StorageError::Type type() const;
47 QString name() const;
48 QString message() const;
49 QString errorString() const;
50
51 QString itemId() const;
52 QString itemName() const;
53 int errorCode() const;
54
55 // Generic factory for errors that don't require extra arguments.
56 static StorageError make_error(StorageError::Type, QString const& msg);
57
58 // Factories to make things more convenient and ensure consistency.
59 static StorageError local_comms_error(QString const& msg);
60 static StorageError remote_comms_error(QString const& msg);
61 static StorageError deleted_error(QString const& msg, QString const& item_id);
62 static StorageError runtime_destroyed_error(QString const& msg);
63 static StorageError not_exists_error(QString const& msg, QString const& key);
64 static StorageError exists_error(QString const& msg, QString const& item_id, QString const& item_name);
65 static StorageError conflict_error(QString const& msg);
66 static StorageError permission_error(QString const& msg);
67 static StorageError cancelled_error(QString const& msg);
68 static StorageError logic_error(QString const& msg);
69 static StorageError invalid_argument_error(QString const& msg);
70 static StorageError resource_error(QString const& msg, int error_code);
71
72private:
73 StorageError::Type type_;
74 QString name_;
75 QString message_;
76 QString item_id_;
77 QString item_name_;
78 int error_code_;
79};
80
81
82} // namespace internal
83} // namespace qt
84} // namespace storage
85} // namespace unity
086
=== added file 'include/unity/storage/qt/internal/unmarshal_error.h'
--- include/unity/storage/qt/internal/unmarshal_error.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/internal/unmarshal_error.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,39 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <unity/storage/qt/StorageError.h>
22
23class QDBusPendingCallWatcher;
24
25namespace unity
26{
27namespace storage
28{
29namespace qt
30{
31namespace internal
32{
33
34StorageError unmarshal_error(QDBusPendingCallWatcher const& call);
35
36} // namespace internal
37} // namespace qt
38} // storage
39} // unity
040
=== added file 'include/unity/storage/qt/internal/validate.h'
--- include/unity/storage/qt/internal/validate.h 1970-01-01 00:00:00 +0000
+++ include/unity/storage/qt/internal/validate.h 2016-09-21 05:03:46 +0000
@@ -0,0 +1,44 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#pragma once
20
21#include <QString>
22
23namespace unity
24{
25namespace storage
26{
27namespace internal
28{
29
30class ItemMetadata;
31
32} // namespace internal
33
34namespace qt
35{
36namespace internal
37{
38
39void validate(QString const& method, unity::storage::internal::ItemMetadata const& md);
40
41} // namespace internal
42} // namespace qt
43} // namespace storage
44} // namespace unity
045
=== added file 'src/qt/Account.cpp'
--- src/qt/Account.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/Account.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,148 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/Account.h>
20
21#include <unity/storage/qt/internal/AccountImpl.h>
22
23#include <cassert>
24
25using namespace std;
26
27namespace unity
28{
29namespace storage
30{
31namespace qt
32{
33
34Account::Account()
35 : p_(make_shared<internal::AccountImpl>())
36{
37}
38
39Account::Account(shared_ptr<internal::AccountImpl> const& p)
40 : p_(p)
41{
42 assert(p);
43}
44
45Account::Account(Account const& other)
46 : p_(other.p_)
47{
48}
49
50Account::Account(Account&& other)
51 : p_(make_shared<internal::AccountImpl>())
52{
53 p_->is_valid_ = false;
54 swap(p_, other.p_);
55}
56
57Account::~Account() = default;
58
59Account& Account::operator=(Account const& other)
60{
61 if (this == &other)
62 {
63 return *this;
64 }
65 p_ = other.p_;
66 return *this;
67}
68
69Account& Account::operator=(Account&& other)
70{
71 p_->is_valid_ = false;
72 swap(p_, other.p_);
73 return *this;
74}
75
76bool Account::isValid() const
77{
78 return p_->is_valid_;
79}
80
81QString Account::owner() const
82{
83 return p_->owner();
84}
85
86QString Account::ownerId() const
87{
88 return p_->ownerId();
89}
90
91QString Account::description() const
92{
93 return p_->description();
94}
95
96ItemListJob* Account::roots() const
97{
98 return p_->roots();
99}
100
101ItemJob* Account::get(QString const& itemId) const
102{
103 return p_->get(itemId);
104}
105
106bool Account::operator==(Account const& other) const
107{
108 return p_->operator==(*other.p_);
109}
110
111bool Account::operator!=(Account const& other) const
112{
113 return p_->operator!=(*other.p_);
114}
115
116bool Account::operator<(Account const& other) const
117{
118 return p_->operator<(*other.p_);
119}
120
121bool Account::operator<=(Account const& other) const
122{
123 return p_->operator<=(*other.p_);
124}
125
126bool Account::operator>(Account const& other) const
127{
128 return p_->operator>(*other.p_);
129}
130
131bool Account::operator>=(Account const& other) const
132{
133 return p_->operator>=(*other.p_);
134}
135
136size_t Account::hash() const
137{
138 return p_->hash();
139}
140
141} // namespace qt
142} // namespace storage
143} // namespace unity
144
145uint qHash(unity::storage::qt::Account const& acc)
146{
147 return acc.hash();
148}
0149
=== added file 'src/qt/AccountsJob.cpp'
--- src/qt/AccountsJob.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/AccountsJob.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,68 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/AccountsJob.h>
20
21#include <unity/storage/qt/Account.h>
22#include <unity/storage/qt/internal/AccountsJobImpl.h>
23
24using namespace unity::storage::qt;
25using namespace std;
26
27namespace unity
28{
29namespace storage
30{
31namespace qt
32{
33
34AccountsJob::AccountsJob(shared_ptr<internal::RuntimeImpl> const& runtime)
35 : p_(new internal::AccountsJobImpl(this, runtime))
36{
37}
38
39AccountsJob::AccountsJob(StorageError const& error)
40 : p_(new internal::AccountsJobImpl(this, error))
41{
42}
43
44AccountsJob::~AccountsJob() = default;
45
46bool AccountsJob::isValid() const
47{
48 return p_->isValid();
49}
50
51AccountsJob::Status AccountsJob::status() const
52{
53 return p_->status();
54}
55
56StorageError AccountsJob::error() const
57{
58 return p_->error();
59}
60
61QList<Account> AccountsJob::accounts() const
62{
63 return p_->accounts();
64}
65
66} // namespace qt
67} // namespace storage
68} // namespace unity
069
=== modified file 'src/qt/CMakeLists.txt'
--- src/qt/CMakeLists.txt 2016-06-08 03:57:50 +0000
+++ src/qt/CMakeLists.txt 2016-09-21 05:03:46 +0000
@@ -1,1 +1,83 @@
1add_subdirectory(client)1add_subdirectory(client)
2
3set_source_files_properties(${CMAKE_SOURCE_DIR}/data/provider.xml PROPERTIES
4 CLASSNAME ProviderInterface
5 INCLUDE unity/storage/internal/dbusmarshal.h
6)
7
8qt5_add_dbus_interface(generated_files
9 ${CMAKE_SOURCE_DIR}/data/provider.xml
10 ProviderInterface
11)
12set_source_files_properties(${generated_files} PROPERTIES
13 COMPILE_FLAGS "-Wno-ctor-dtor-privacy -Wmissing-field-initializers"
14 GENERATED TRUE
15)
16
17# Sources for remote client V2 library.
18set(QT_CLIENT_LIB_V2_SRC
19 Account.cpp
20 AccountsJob.cpp
21 Item.cpp
22 ItemJob.cpp
23 ItemListJob.cpp
24 Runtime.cpp
25 StorageError.cpp
26 internal/AccountImpl.cpp
27 internal/AccountsJobImpl.cpp
28 internal/HandlerBase.cpp
29 internal/ItemImpl.cpp
30 internal/ItemJobImpl.cpp
31 internal/ItemListJobImpl.cpp
32 internal/RuntimeImpl.cpp
33 internal/StorageErrorImpl.cpp
34 internal/unmarshal_error.cpp
35 internal/validate.cpp
36 ${generated_files}
37 ${CMAKE_SOURCE_DIR}/include/unity/storage/qt/AccountsJob.h
38 ${CMAKE_SOURCE_DIR}/include/unity/storage/qt/Item.h
39 ${CMAKE_SOURCE_DIR}/include/unity/storage/qt/ItemJob.h
40 ${CMAKE_SOURCE_DIR}/include/unity/storage/qt/ItemListJob.h
41 ${CMAKE_SOURCE_DIR}/include/unity/storage/qt/Runtime.h
42 ${CMAKE_SOURCE_DIR}/include/unity/storage/qt/internal/AccountsJobImpl.h
43 ${CMAKE_SOURCE_DIR}/include/unity/storage/qt/internal/HandlerBase.h
44 ${CMAKE_SOURCE_DIR}/include/unity/storage/qt/internal/ItemJobImpl.h
45 ${CMAKE_SOURCE_DIR}/include/unity/storage/qt/internal/ItemListJobImpl.h
46)
47
48add_library(storage-framework-qt-client-v2 SHARED
49 ${QT_CLIENT_LIB_V2_SRC}
50 ${generated_files}
51)
52target_include_directories(storage-framework-qt-client-v2 PRIVATE
53 ${Qt5DBus_INCLUDE_DIRS}
54 ${Qt5Network_INCLUDE_DIRS}
55 ${ONLINEACCOUNTS_DEPS_INCLUDE_DIRS}
56)
57set_target_properties(storage-framework-qt-client-v2 PROPERTIES
58 AUTOMOC TRUE
59 LINK_FLAGS "-Wl,--no-undefined"
60 OUTPUT_NAME "storage-framework-qt-client-${SF_CLIENT_API_VERSION}"
61 SOVERSION ${SF_CLIENT_SOVERSION}
62 VERSION ${SF_CLIENT_LIBVERSION}
63)
64target_link_libraries(storage-framework-qt-client-v2
65 storage-framework-common-internal
66 Qt5::Core
67 Qt5::DBus
68 Qt5::Network
69 ${ONLINEACCOUNTS_DEPS_LDFLAGS}
70)
71install(
72 TARGETS storage-framework-qt-client-v2
73 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
74)
75
76configure_file(
77 storage-framework-qt-client.pc.in
78 storage-framework-qt-client-${SF_CLIENT_API_VERSION}.pc
79)
80install(
81 FILES ${CMAKE_CURRENT_BINARY_DIR}/storage-framework-qt-client-${SF_CLIENT_API_VERSION}.pc
82 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
83)
284
=== added file 'src/qt/Item.cpp'
--- src/qt/Item.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/Item.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,230 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/Item.h>
20#include <unity/storage/qt/internal/ItemImpl.h>
21
22#include <cassert>
23#include <QDebug> // TODO: remove this
24
25using namespace std;
26
27namespace unity
28{
29namespace storage
30{
31namespace qt
32{
33
34Item::Item()
35 : p_(make_shared<internal::ItemImpl>())
36{
37}
38
39Item::Item(shared_ptr<internal::ItemImpl> const& p)
40 : p_(p)
41{
42 assert(p);
43}
44
45Item::Item(Item const& other)
46 : p_(other.p_)
47{
48}
49
50Item::Item(Item&& other)
51{
52 p_->is_valid_ = false;
53 swap(p_, other.p_);
54}
55
56Item::~Item() = default;
57
58Item& Item::operator=(Item const& other)
59{
60 if (this == &other)
61 {
62 return *this;
63 }
64 p_ = other.p_;
65 return *this;
66}
67
68Item& Item::operator=(Item&& other)
69{
70 p_->is_valid_ = false;
71 swap(p_, other.p_);
72 return *this;
73}
74
75bool Item::isValid() const
76{
77 return p_->is_valid_;
78}
79
80QString Item::itemId() const
81{
82 return p_->itemId();
83}
84
85QString Item::name() const
86{
87 return p_->name();
88}
89
90Account Item::account() const
91{
92 return p_->account();
93}
94
95#if 0
96Item Item::root() const
97{
98
99 return p_->root();
100}
101#endif
102
103QString Item::etag() const
104{
105 return p_->etag();
106}
107
108Item::Type Item::type() const
109{
110 return p_->type();
111}
112
113QVariantMap Item::metadata() const
114{
115 return p_->metadata();
116}
117
118QDateTime Item::lastModifiedTime() const
119{
120 return p_->lastModifiedTime();
121}
122
123QVector<QString> Item::parentIds() const
124{
125 return p_->parentIds();
126}
127
128ItemListJob* Item::parents() const
129{
130 return p_->parents();
131}
132
133ItemJob* Item::copy(Item const& newParent, QString const& newName) const
134{
135 return p_->copy(newParent, newName);
136}
137
138ItemJob* Item::move(Item const& newParent, QString const& newName) const
139{
140 return p_->move(newParent, newName);
141}
142
143VoidJob* Item::deleteItem() const
144{
145 return p_->deleteItem();
146}
147
148Uploader* Item::createUploader(ConflictPolicy policy, qint64 sizeInBytes) const
149{
150 return p_->createUploader(policy, sizeInBytes);
151}
152
153Downloader* Item::createDownloader() const
154{
155 return p_->createDownloader();
156}
157
158ItemListJob* Item::list() const
159{
160 return p_->list();
161}
162
163ItemListJob* Item::lookup(QString const& name) const
164{
165 return p_->lookup(name);
166}
167
168ItemJob* Item::createFolder(QString const& name) const
169{
170 return p_->createFolder(name);
171}
172
173Uploader* Item::createFile(QString const& name) const
174{
175 return p_->createFile(name);
176}
177
178IntJob* Item::freeSpaceBytes() const
179{
180 return p_->freeSpaceBytes();
181}
182
183IntJob* Item::usedSpaceBytes() const
184{
185 return p_->usedSpaceBytes();
186}
187
188bool Item::operator==(Item const& other) const
189{
190 return p_->operator==(*other.p_);
191}
192
193bool Item::operator!=(Item const& other) const
194{
195 return p_->operator!=(*other.p_);
196}
197
198bool Item::operator<(Item const& other) const
199{
200 return p_->operator<(*other.p_);
201}
202
203bool Item::operator<=(Item const& other) const
204{
205 return p_->operator<=(*other.p_);
206}
207
208bool Item::operator>(Item const& other) const
209{
210 return p_->operator>(*other.p_);
211}
212
213bool Item::operator>=(Item const& other) const
214{
215 return p_->operator>=(*other.p_);
216}
217
218size_t Item::hash() const
219{
220 return p_->hash();
221}
222
223} // namespace qt
224} // namespace storage
225} // namespace unity
226
227uint qHash(unity::storage::qt::Item const& i)
228{
229 return i.hash();
230}
0231
=== added file 'src/qt/ItemJob.cpp'
--- src/qt/ItemJob.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/ItemJob.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,62 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/ItemJob.h>
20
21#include <unity/storage/qt/internal/ItemJobImpl.h>
22
23using namespace unity::storage::qt;
24using namespace std;
25
26namespace unity
27{
28namespace storage
29{
30namespace qt
31{
32
33ItemJob::ItemJob(unique_ptr<internal::ItemJobImpl> p)
34 : p_(move(p))
35{
36}
37
38ItemJob::~ItemJob() = default;
39
40bool ItemJob::isValid() const
41{
42 return p_->isValid();
43}
44
45ItemJob::Status ItemJob::status() const
46{
47 return p_->status();
48}
49
50StorageError ItemJob::error() const
51{
52 return p_->error();
53}
54
55Item ItemJob::item() const
56{
57 return p_->item();
58}
59
60} // namespace qt
61} // namespace storage
62} // namespace unity
063
=== added file 'src/qt/ItemListJob.cpp'
--- src/qt/ItemListJob.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/ItemListJob.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,57 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/ItemListJob.h>
20
21#include <unity/storage/qt/internal/ItemListJobImpl.h>
22
23using namespace unity::storage::qt;
24using namespace std;
25
26namespace unity
27{
28namespace storage
29{
30namespace qt
31{
32
33ItemListJob::ItemListJob(unique_ptr<internal::ItemListJobImpl> p)
34 : p_(move(p))
35{
36}
37
38ItemListJob::~ItemListJob() = default;
39
40bool ItemListJob::isValid() const
41{
42 return p_->isValid();
43}
44
45ItemListJob::Status ItemListJob::status() const
46{
47 return p_->status();
48}
49
50StorageError ItemListJob::error() const
51{
52 return p_->error();
53}
54
55} // namespace qt
56} // namespace storage
57} // namespace unity
058
=== added file 'src/qt/Runtime.cpp'
--- src/qt/Runtime.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/Runtime.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,87 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/Runtime.h>
20
21#include <unity/storage/qt/internal/RuntimeImpl.h>
22
23using namespace std;
24
25namespace unity
26{
27namespace storage
28{
29namespace qt
30{
31
32Runtime::Runtime(QObject* parent)
33 : QObject(parent)
34 , p_(new internal::RuntimeImpl)
35{
36}
37
38Runtime::Runtime(QDBusConnection const& bus, QObject* parent)
39 : QObject(parent)
40 , p_(new internal::RuntimeImpl(bus))
41{
42}
43
44Runtime::~Runtime() = default;
45
46bool Runtime::isValid() const
47{
48 return p_->isValid();
49}
50
51StorageError Runtime::error() const
52{
53 return p_->error();
54}
55
56QDBusConnection Runtime::connection() const
57{
58 return p_->connection();
59}
60
61StorageError Runtime::shutdown()
62{
63 return p_->shutdown();
64}
65
66AccountsJob* Runtime::accounts() const
67{
68 return p_->accounts();
69}
70
71Account Runtime::make_test_account(QString const& bus_name, QString const& object_path)
72{
73 return p_->make_test_account(bus_name, object_path);
74}
75
76Account Runtime::make_test_account(QString const& bus_name,
77 QString const& object_path,
78 QString const& owner_id,
79 QString const& owner,
80 QString const& description)
81{
82 return p_->make_test_account(bus_name, object_path, owner_id, owner, description);
83}
84
85} // namespace qt
86} // namespace storage
87} // namespace unity
088
=== added file 'src/qt/StorageError.cpp'
--- src/qt/StorageError.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/StorageError.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,98 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/StorageError.h>
20#include <unity/storage/qt/internal/StorageErrorImpl.h>
21
22#include <cassert>
23#include <memory>
24
25using namespace std;
26
27namespace unity
28{
29namespace storage
30{
31namespace qt
32{
33
34StorageError::StorageError()
35 : p_(new internal::StorageErrorImpl)
36{
37}
38
39StorageError::StorageError(StorageError const& other)
40 : p_(new internal::StorageErrorImpl(*other.p_))
41{
42}
43
44StorageError::StorageError(StorageError&&) = default;
45
46StorageError::StorageError(unique_ptr<internal::StorageErrorImpl> p)
47 : p_(move(p))
48{
49}
50
51StorageError::~StorageError() = default;
52
53StorageError& StorageError::operator=(StorageError const& other)
54{
55 *p_ = *other.p_;
56 return *this;
57}
58
59StorageError& StorageError::operator=(StorageError&&) = default;
60
61StorageError::Type StorageError::type() const
62{
63 return p_->type();
64}
65
66QString StorageError::name() const
67{
68 return p_->name();
69}
70
71QString StorageError::message() const
72{
73 return p_->message();
74}
75
76QString StorageError::errorString() const
77{
78 return p_->errorString();
79}
80
81QString StorageError::itemId() const
82{
83 return p_->itemId();
84}
85
86QString StorageError::itemName() const
87{
88 return p_->itemName();
89}
90
91int StorageError::errorCode() const
92{
93 return p_->errorCode();
94}
95
96} // namespace qt
97} // namespace storage
98} // namespace unity
099
=== modified file 'src/qt/client/CMakeLists.txt'
--- src/qt/client/CMakeLists.txt 2016-08-11 06:53:25 +0000
+++ src/qt/client/CMakeLists.txt 2016-09-21 05:03:46 +0000
@@ -50,9 +50,9 @@
50set_target_properties(storage-framework-qt-local-client PROPERTIES50set_target_properties(storage-framework-qt-local-client PROPERTIES
51 AUTOMOC TRUE51 AUTOMOC TRUE
52 LINK_FLAGS "-Wl,--no-undefined"52 LINK_FLAGS "-Wl,--no-undefined"
53 OUTPUT_NAME "storage-framework-qt-local-client-${SF_CLIENT_API_VERSION}"53 OUTPUT_NAME "storage-framework-qt-local-client-1"
54 SOVERSION ${SF_CLIENT_SOVERSION}54 SOVERSION 0
55 VERSION ${SF_CLIENT_LIBVERSION}55 VERSION 0.0.1
56)56)
57target_link_libraries(storage-framework-qt-local-client57target_link_libraries(storage-framework-qt-local-client
58 storage-framework-common-internal58 storage-framework-common-internal
@@ -70,10 +70,10 @@
7070
71configure_file(71configure_file(
72 storage-framework-qt-local-client.pc.in72 storage-framework-qt-local-client.pc.in
73 storage-framework-qt-local-client-${SF_CLIENT_API_VERSION}.pc73 storage-framework-qt-local-client-1.pc
74)74)
75install(75install(
76 FILES ${CMAKE_CURRENT_BINARY_DIR}/storage-framework-qt-local-client-${SF_CLIENT_API_VERSION}.pc76 FILES ${CMAKE_CURRENT_BINARY_DIR}/storage-framework-qt-local-client-1.pc
77 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig77 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
78)78)
7979
@@ -104,9 +104,9 @@
104set_target_properties(storage-framework-qt-client PROPERTIES104set_target_properties(storage-framework-qt-client PROPERTIES
105 AUTOMOC TRUE105 AUTOMOC TRUE
106 LINK_FLAGS "-Wl,--no-undefined"106 LINK_FLAGS "-Wl,--no-undefined"
107 OUTPUT_NAME "storage-framework-qt-client-${SF_CLIENT_API_VERSION}"107 OUTPUT_NAME "storage-framework-qt-client-1"
108 SOVERSION ${SF_CLIENT_SOVERSION}108 SOVERSION 0
109 VERSION ${SF_CLIENT_LIBVERSION}109 VERSION 0.0.1
110)110)
111target_link_libraries(storage-framework-qt-client111target_link_libraries(storage-framework-qt-client
112 storage-framework-common-internal112 storage-framework-common-internal
@@ -122,10 +122,10 @@
122)122)
123123
124configure_file(124configure_file(
125 storage-framework-qt-client.pc.in125 storage-framework-qt-client-1.pc.in
126 storage-framework-qt-client-${SF_CLIENT_API_VERSION}.pc126 storage-framework-qt-client-1.pc
127)127)
128install(128install(
129 FILES ${CMAKE_CURRENT_BINARY_DIR}/storage-framework-qt-client-${SF_CLIENT_API_VERSION}.pc129 FILES ${CMAKE_CURRENT_BINARY_DIR}/storage-framework-qt-client-1.pc
130 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig130 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
131)131)
132132
=== added file 'src/qt/client/storage-framework-qt-client-1.pc.in'
--- src/qt/client/storage-framework-qt-client-1.pc.in 1970-01-01 00:00:00 +0000
+++ src/qt/client/storage-framework-qt-client-1.pc.in 2016-09-21 05:03:46 +0000
@@ -0,0 +1,6 @@
1Name: storage-framework-qt-client-1
2Description: A Qt client library for the storage framework (soon to be deprecated)
3Version: 0.1
4Requires.private: Qt5Core Qt5Network
5Cflags: -I@CMAKE_INSTALL_FULL_INCLUDEDIR@/storage-framework-client-1
6Libs: -L@CMAKE_INSTALL_FULL_LIBDIR@ -lstorage-framework-qt-client-1
07
=== added file 'src/qt/client/storage-framework-qt-local-client.pc.in'
--- src/qt/client/storage-framework-qt-local-client.pc.in 1970-01-01 00:00:00 +0000
+++ src/qt/client/storage-framework-qt-local-client.pc.in 2016-09-21 05:03:46 +0000
@@ -0,0 +1,6 @@
1Name: storage-framework-qt-local-client-1
2Description: A Qt client library for the storage framework (soon to be deprecated)
3Version: @PROJECT_VERSION@
4Requires.private: Qt5Core Qt5Network
5Cflags: -I@CMAKE_INSTALL_FULL_INCLUDEDIR@/storage-framework-client-1
6Libs: -L@CMAKE_INSTALL_FULL_LIBDIR@ -lstorage-framework-qt-local-client-1
07
=== removed file 'src/qt/client/storage-framework-qt-local-client.pc.in'
--- src/qt/client/storage-framework-qt-local-client.pc.in 2016-07-11 03:28:40 +0000
+++ src/qt/client/storage-framework-qt-local-client.pc.in 1970-01-01 00:00:00 +0000
@@ -1,6 +0,0 @@
1Name: storage-framework-qt-local-client-@SF_CLIENT_API_VERSION@
2Description: A Qt client library for the storage framework
3Version: @PROJECT_VERSION@
4Requires.private: Qt5Core Qt5Network
5Cflags: -I@CMAKE_INSTALL_FULL_INCLUDEDIR@/storage-framework-client-@SF_CLIENT_API_VERSION@
6Libs: -L@CMAKE_INSTALL_FULL_LIBDIR@ -lstorage-framework-qt-local-client-@SF_CLIENT_API_VERSION@
70
=== added directory 'src/qt/internal'
=== added file 'src/qt/internal/AccountImpl.cpp'
--- src/qt/internal/AccountImpl.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/internal/AccountImpl.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,226 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/internal/AccountImpl.h>
20
21#include "ProviderInterface.h"
22#include <unity/storage/qt/Account.h>
23#include <unity/storage/qt/internal/ItemImpl.h>
24#include <unity/storage/qt/internal/ItemJobImpl.h>
25#include <unity/storage/qt/internal/ItemListJobImpl.h>
26#include <unity/storage/qt/internal/RuntimeImpl.h>
27#include <unity/storage/qt/Runtime.h>
28
29#include <boost/functional/hash.hpp>
30
31#include <cassert>
32
33using namespace std;
34
35namespace unity
36{
37namespace storage
38{
39namespace qt
40{
41namespace internal
42{
43
44AccountImpl::AccountImpl()
45 : is_valid_(false)
46{
47}
48
49AccountImpl::AccountImpl(shared_ptr<RuntimeImpl> const& runtime,
50 QString const& bus_name,
51 QString const& object_path,
52 QString const& owner_id,
53 QString const& owner,
54 QString const& description)
55 : is_valid_(true)
56 , bus_name_(bus_name)
57 , object_path_(object_path)
58 , owner_id_(owner_id)
59 , owner_(owner)
60 , description_(description)
61 , runtime_(runtime)
62 , provider_(new ProviderInterface(bus_name, object_path, runtime->connection()))
63{
64 assert(!bus_name.isEmpty());
65 assert(!object_path.isEmpty());
66}
67
68QString AccountImpl::owner() const
69{
70 return is_valid_ ? owner_ : "";
71}
72
73QString AccountImpl::ownerId() const
74{
75 return is_valid_ ? owner_id_ : "";
76}
77
78QString AccountImpl::description() const
79{
80 return is_valid_ ? description_ : "";
81}
82
83ItemListJob* AccountImpl::roots() const
84{
85 auto runtime = runtime_.lock();
86 if (!runtime || !runtime->isValid())
87 {
88 auto e = StorageErrorImpl::runtime_destroyed_error("Account::roots(): Runtime was destroyed previously");
89 return ItemListJobImpl::make_item_list_job(e);
90 }
91
92 auto validate = [](storage::internal::ItemMetadata const& md)
93 {
94 if (md.type != ItemType::root)
95 {
96 QString msg = "provider returned non-root item type: " + QString::number(int(md.type));
97 qCritical() << msg;
98 throw StorageErrorImpl::local_comms_error(msg);
99 }
100 };
101
102 QString method = "Account::roots()";
103 auto reply = provider_->Roots();
104 auto This = const_pointer_cast<AccountImpl>(shared_from_this());
105 return ItemListJobImpl::make_item_list_job(This, method, reply, validate);
106}
107
108ItemJob* AccountImpl::get(QString const& itemId) const
109{
110 auto runtime = runtime_.lock();
111 if (!runtime || !runtime->isValid())
112 {
113 auto e = StorageErrorImpl::runtime_destroyed_error("Account::get(): Runtime was destroyed previously");
114 return ItemJobImpl::make_item_job(e);
115 }
116
117 // TODO: use defaulted param?
118 auto validate = [](storage::internal::ItemMetadata const&)
119 {
120 };
121
122 QString method = "Item::get()";
123 auto reply = provider_->Metadata(itemId);
124 auto This = const_pointer_cast<AccountImpl>(shared_from_this());
125 return ItemJobImpl::make_item_job(This, method, reply, validate);
126}
127
128bool AccountImpl::operator==(AccountImpl const& other) const
129{
130 if (is_valid_)
131 {
132 return other.is_valid_
133 && owner_ == other.owner_
134 && owner_id_ == other.owner_id_
135 && description_ == other.description_;
136 }
137 return !other.is_valid_;
138}
139
140bool AccountImpl::operator!=(AccountImpl const& other) const
141{
142 return !operator==(other);
143}
144
145bool AccountImpl::operator<(AccountImpl const& other) const
146{
147 if (!is_valid_)
148 {
149 return other.is_valid_;
150 }
151 if (is_valid_ && !other.is_valid_)
152 {
153 return false;
154 }
155 assert(is_valid_ && other.is_valid_);
156 if (owner_id_ < other.owner_id_)
157 {
158 return true;
159 }
160 if (owner_id_ > other.owner_id_)
161 {
162 return false;
163 }
164 if (owner_ < other.owner_)
165 {
166 return true;
167 }
168 if (owner_ > other.owner_)
169 {
170 return false;
171 }
172 if (description_ < other.description_)
173 {
174 return true;
175 }
176 return false;
177}
178
179bool AccountImpl::operator<=(AccountImpl const& other) const
180{
181 return operator<(other) || operator==(other);
182}
183
184bool AccountImpl::operator>(AccountImpl const& other) const
185{
186 return !operator<=(other);
187}
188
189bool AccountImpl::operator>=(AccountImpl const& other) const
190{
191 return !operator<(other);
192}
193
194shared_ptr<ProviderInterface> AccountImpl::provider() const
195{
196 return provider_;
197}
198
199size_t AccountImpl::hash() const
200{
201 if (!is_valid_)
202 {
203 return 0;
204 }
205 size_t hash = 0;
206 boost::hash_combine(hash, qHash(owner_));
207 boost::hash_combine(hash, qHash(owner_id_));
208 boost::hash_combine(hash, qHash(description_));
209 return hash;
210}
211
212Account AccountImpl::make_account(shared_ptr<RuntimeImpl> const& runtime,
213 QString const& bus_name,
214 QString const& object_path,
215 QString const& owner_id,
216 QString const& owner,
217 QString const& description)
218{
219 shared_ptr<AccountImpl> p(new AccountImpl(runtime, bus_name, object_path, owner_id, owner, description));
220 return Account(p);
221}
222
223} // namespace internal
224} // namespace qt
225} // namespace storage
226} // namespace unity
0227
=== added file 'src/qt/internal/AccountsJobImpl.cpp'
--- src/qt/internal/AccountsJobImpl.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/internal/AccountsJobImpl.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,183 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/internal/AccountsJobImpl.h>
20
21#include <unity/storage/qt/internal/AccountImpl.h>
22#include <unity/storage/qt/internal/RuntimeImpl.h>
23#include <unity/storage/qt/internal/StorageErrorImpl.h>
24
25#include <OnlineAccounts/Account>
26
27#include <cassert>
28
29using namespace std;
30
31namespace unity
32{
33namespace storage
34{
35namespace qt
36{
37namespace internal
38{
39
40namespace
41{
42
43// TODO: We retrieve the accounts directly from online accounts until we have a working registry.
44
45static map<QString, QString> const BUS_NAMES =
46{
47 { "google-drive-scope", "com.canonical.StorageFramework.Provider.ProviderTest" },
48 { "com.canonical.scopes.mcloud_mcloud_mcloud", "com.canonical.StorageFramework.Provider.McloudProvider" }
49};
50
51} // namespace
52
53AccountsJobImpl::AccountsJobImpl(AccountsJob* public_instance, shared_ptr<RuntimeImpl> const& runtime)
54 : public_instance_(public_instance)
55 , status_(AccountsJob::Loading)
56 , runtime_(runtime)
57{
58 assert(public_instance);
59 assert(runtime);
60
61 initialize_accounts();
62}
63
64AccountsJobImpl::AccountsJobImpl(AccountsJob* public_instance, StorageError const& error)
65 : public_instance_(public_instance)
66 , status_(AccountsJob::Loading)
67 , error_(error)
68{
69 assert(public_instance);
70 assert(error.type() != StorageError::NoError);
71
72 status_ = emit_status_changed(AccountsJob::Error);
73}
74
75bool AccountsJobImpl::isValid() const
76{
77 return status_ != AccountsJob::Status::Error;
78}
79
80AccountsJob::Status AccountsJobImpl::status() const
81{
82 return status_;
83}
84
85StorageError AccountsJobImpl::error() const
86{
87 return error_;
88}
89
90QList<Account> AccountsJobImpl::accounts() const
91{
92 auto runtime = get_runtime("AccountsJob::accounts()");
93 if (!runtime)
94 {
95 return QList<Account>();
96 }
97 if (status_ != AccountsJob::Finished)
98 {
99 return QList<Account>();
100 }
101 return accounts_;
102}
103
104void AccountsJobImpl::manager_ready()
105{
106 timer_.stop();
107 disconnect(this);
108 initialize_accounts();
109}
110
111// LCOV_EXCL_START
112void AccountsJobImpl::timeout()
113{
114 disconnect(this);
115 error_ = StorageErrorImpl::local_comms_error("AccountsJob(): timeout retrieving Online accounts");
116 status_ = emit_status_changed(AccountsJob::Error);
117}
118// LCOV_EXCL_STOP
119
120AccountsJob::Status AccountsJobImpl::emit_status_changed(AccountsJob::Status new_status) const
121{
122 if (status_ == AccountsJob::Loading) // Once in a final state, we don't emit the signal again.
123 {
124 // We defer emission of the signal so the client gets a chance to connect to the signal
125 // in case we emit the signal from the constructor.
126 QMetaObject::invokeMethod(public_instance_,
127 "statusChanged",
128 Qt::QueuedConnection,
129 Q_ARG(unity::storage::qt::AccountsJob::Status, new_status));
130 }
131 return new_status;
132}
133
134shared_ptr<RuntimeImpl> AccountsJobImpl::get_runtime(QString const& method) const
135{
136 auto runtime = runtime_.lock();
137 if (!runtime || !runtime->isValid())
138 {
139 QString msg = method + ": Runtime was destroyed previously";
140 auto This = const_cast<AccountsJobImpl*>(this);
141 This->error_ = StorageErrorImpl::runtime_destroyed_error(msg);
142 This->status_ = emit_status_changed(AccountsJob::Error);
143 }
144 return runtime;
145}
146
147void AccountsJobImpl::initialize_accounts()
148{
149 auto runtime = get_runtime("AccountsJob()");
150 assert(runtime);
151
152 auto manager = runtime->accounts_manager();
153 if (!manager->isReady())
154 {
155 connect(manager.get(), &OnlineAccounts::Manager::ready, this, &AccountsJobImpl::manager_ready);
156 connect(&timer_, &QTimer::timeout, this, &AccountsJobImpl::timeout);
157 timer_.setSingleShot(true);
158 timer_.start(30000); // TODO: Need config for this eventually.
159 return;
160 }
161
162 for (auto const map_entry : BUS_NAMES)
163 {
164 auto service_id = map_entry.first;
165 for (auto const& a : manager->availableAccounts(service_id))
166 {
167 auto object_path = QStringLiteral("/provider/%1").arg(a->id());
168 auto bus_name = map_entry.second;
169 accounts_.append(AccountImpl::make_account(runtime,
170 bus_name,
171 object_path,
172 a->serviceId(),
173 "",
174 a->displayName()));
175 }
176 }
177 status_ = emit_status_changed(AccountsJob::Finished);
178}
179
180} // namespace internal
181} // namespace qt
182} // namespace storage
183} // namespace unity
0184
=== added file 'src/qt/internal/HandlerBase.cpp'
--- src/qt/internal/HandlerBase.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/internal/HandlerBase.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,59 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/internal/HandlerBase.h>
20
21#pragma GCC diagnostic push
22#pragma GCC diagnostic ignored "-Wctor-dtor-privacy"
23#include <QFuture>
24#pragma GCC diagnostic pop
25
26#include <cassert>
27
28using namespace std;
29
30namespace unity
31{
32namespace storage
33{
34namespace qt
35{
36namespace internal
37{
38
39HandlerBase::HandlerBase(QObject* parent,
40 QDBusPendingCall const& call,
41 function<void(QDBusPendingCallWatcher&)> const& closure)
42 : QObject(parent)
43 , watcher_(call)
44 , closure_(closure)
45{
46 assert(closure);
47 connect(&watcher_, &QDBusPendingCallWatcher::finished, this, &HandlerBase::finished);
48}
49
50void HandlerBase::finished(QDBusPendingCallWatcher* call)
51{
52 deleteLater();
53 closure_(*call);
54}
55
56} // namespace internal
57} // namespace qt
58} // namespace storage
59} // namespace unity
060
=== added file 'src/qt/internal/ItemImpl.cpp'
--- src/qt/internal/ItemImpl.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/internal/ItemImpl.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,248 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/internal/ItemImpl.h>
20
21#include "ProviderInterface.h"
22#include <unity/storage/provider/metadata_keys.h>
23#include <unity/storage/qt/internal/AccountImpl.h>
24#include <unity/storage/qt/internal/ItemJobImpl.h>
25#include <unity/storage/qt/internal/RuntimeImpl.h>
26#include <unity/storage/qt/internal/validate.h>
27
28#include <cassert>
29
30using namespace std;
31
32namespace unity
33{
34namespace storage
35{
36namespace qt
37{
38namespace internal
39{
40
41ItemImpl::ItemImpl()
42 : is_valid_(false)
43{
44 md_.type = storage::ItemType::file;
45}
46
47ItemImpl::ItemImpl(storage::internal::ItemMetadata const& md,
48 std::shared_ptr<AccountImpl> const& account)
49 : is_valid_(true)
50 , md_(md)
51 , account_(account)
52{
53 assert(account);
54}
55
56QString ItemImpl::itemId() const
57{
58 return is_valid_ ? md_.item_id : "";
59}
60
61QString ItemImpl::name() const
62{
63 return is_valid_ ? md_.name : "";
64}
65
66Account ItemImpl::account() const
67{
68 return is_valid_ ? account_ : Account();
69}
70
71#if 0
72Item ItemImpl::root() const
73{
74 return is_valid_ ? root_ : Item();
75}
76#endif
77
78QString ItemImpl::etag() const
79{
80 return is_valid_ ? md_.etag : "";
81}
82
83Item::Type ItemImpl::type() const
84{
85 switch (md_.type)
86 {
87 case storage::ItemType::file:
88 return Item::File;
89 case storage::ItemType::folder:
90 return Item::Folder;
91 case storage::ItemType::root:
92 return Item::Root;
93 default:
94 abort(); // LCOV_EXCL_LINE // Impossible
95 }
96}
97
98QVariantMap ItemImpl::metadata() const
99{
100 // TODO: Need to agree on metadata representation.
101 return is_valid_ ? QVariantMap() : QVariantMap();
102}
103
104QDateTime ItemImpl::lastModifiedTime() const
105{
106 return is_valid_ ? QDateTime::fromString(md_.metadata.value(provider::LAST_MODIFIED_TIME).toString(), Qt::ISODate)
107 : QDateTime();
108}
109
110QVector<QString> ItemImpl::parentIds() const
111{
112 return is_valid_ ? md_.parent_ids : QVector<QString>();
113}
114
115ItemListJob* ItemImpl::parents() const
116{
117 return nullptr; // TODO
118}
119
120ItemJob* ItemImpl::copy(Item const& newParent, QString const& newName) const
121{
122 return nullptr; // TODO
123}
124
125ItemJob* ItemImpl::move(Item const& newParent, QString const& newName) const
126{
127 return nullptr; // TODO
128}
129
130VoidJob* ItemImpl::deleteItem() const
131{
132 return nullptr; // TODO
133}
134
135Uploader* ItemImpl::createUploader(ConflictPolicy policy, qint64 sizeInBytes) const
136{
137 return nullptr; // TODO
138}
139
140Downloader* ItemImpl::createDownloader() const
141{
142 return nullptr; // TODO
143}
144
145ItemListJob* ItemImpl::list() const
146{
147 return nullptr; // TODO
148}
149
150ItemListJob* ItemImpl::lookup(QString const& name) const
151{
152 return nullptr; // TODO
153}
154
155ItemJob* ItemImpl::createFolder(QString const& name) const
156{
157 return nullptr; // TODO
158}
159
160Uploader* ItemImpl::createFile(QString const& name) const
161{
162 return nullptr; // TODO
163}
164
165IntJob* ItemImpl::freeSpaceBytes() const
166{
167 return nullptr; // TODO
168}
169
170IntJob* ItemImpl::usedSpaceBytes() const
171{
172 return nullptr; // TODO
173}
174
175bool ItemImpl::operator==(ItemImpl const& other) const
176{
177 if (is_valid_)
178 {
179 return other.is_valid_ && md_.item_id == other.md_.item_id;
180 }
181 return !other.is_valid_;
182}
183
184bool ItemImpl::operator!=(ItemImpl const& other) const
185{
186 return !operator==(other);
187}
188
189bool ItemImpl::operator<(ItemImpl const& other) const
190{
191 if (is_valid_)
192 {
193 return other.is_valid_ && md_.item_id < other.md_.item_id;
194 }
195 return other.is_valid_;
196}
197
198bool ItemImpl::operator<=(ItemImpl const& other) const
199{
200 return operator<(other) or operator==(other);
201}
202
203bool ItemImpl::operator>(ItemImpl const& other) const
204{
205 return !operator<=(other);
206}
207
208bool ItemImpl::operator>=(ItemImpl const& other) const
209{
210 return !operator<(other);
211}
212
213size_t ItemImpl::hash() const
214{
215 if (!is_valid_)
216 {
217 return 0;
218 }
219 return qHash(md_.item_id);
220}
221
222Item ItemImpl::make_item(QString const& method,
223 storage::internal::ItemMetadata const& md,
224 std::shared_ptr<AccountImpl> const& account)
225{
226 validate(method, md); // Throws if no good.
227 auto p = make_shared<ItemImpl>(md, account);
228 return Item(p);
229}
230
231#if 0
232shared_ptr<RuntimeImpl> ItemImpl::get_runtime(QString const& method) const
233{
234 auto runtime = account_->runtime_.lock();
235 if (!runtime || !runtime->isValid())
236 {
237 QString msg = method + ": Runtime was destroyed previously";
238 auto This = const_cast<ItemImpl*>(this);
239 This->error_ = StorageErrorImpl::runtime_destroyed_error(msg);
240 }
241 return runtime;
242}
243#endif
244
245} // namespace internal
246} // namespace qt
247} // namespace storage
248} // namespace unity
0249
=== added file 'src/qt/internal/ItemJobImpl.cpp'
--- src/qt/internal/ItemJobImpl.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/internal/ItemJobImpl.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,138 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/internal/ItemJobImpl.h>
20
21#include <unity/storage/internal/dbusmarshal.h>
22#include <unity/storage/internal/ItemMetadata.h>
23#include <unity/storage/qt/internal/Handler.h>
24#include <unity/storage/qt/internal/ItemImpl.h>
25
26using namespace std;
27
28namespace unity
29{
30namespace storage
31{
32namespace qt
33{
34namespace internal
35{
36
37ItemJobImpl::ItemJobImpl(shared_ptr<AccountImpl> const& account,
38 QString const& method,
39 QDBusPendingReply<storage::internal::ItemMetadata> const& reply,
40 std::function<void(storage::internal::ItemMetadata const&)> const& validate)
41 : status_(ItemJob::Loading)
42 , method_(method)
43 , account_(account)
44 , validate_(validate)
45{
46 assert(!method.isEmpty());
47 assert(account);
48 assert(validate);
49
50 auto process_reply = [this](decltype(reply)& r)
51 {
52 auto metadata = r.value();
53 try
54 {
55 validate_(metadata);
56 item_ = ItemImpl::make_item(method_, metadata, account_);
57 status_ = emit_status_changed(ItemJob::Finished);
58 }
59 catch (StorageError const& e)
60 {
61 // Bad metadata received from provider, validate_() or make_item() have logged it.
62 error_ = e;
63 status_ = emit_status_changed(ItemJob::Error);
64 }
65 };
66
67 auto process_error = [this](StorageError const& error)
68 {
69 error_ = error;
70 status_ = emit_status_changed(ItemJob::Error);
71 };
72
73 new Handler<storage::internal::ItemMetadata>(this, reply, process_reply, process_error);
74}
75
76ItemJobImpl::ItemJobImpl(StorageError const& error)
77 : status_(ItemJob::Loading)
78 , error_(error)
79{
80}
81
82bool ItemJobImpl::isValid() const
83{
84 return status_ != ItemJob::Status::Error;
85}
86
87ItemJob::Status ItemJobImpl::status() const
88{
89 return status_;
90}
91
92StorageError ItemJobImpl::error() const
93{
94 return error_;
95}
96
97Item ItemJobImpl::item() const
98{
99 return Item(); // TODO
100}
101
102ItemJob* ItemJobImpl::make_item_job(shared_ptr<AccountImpl> const& account,
103 QString const& method,
104 QDBusPendingReply<storage::internal::ItemMetadata> const& reply,
105 std::function<void(storage::internal::ItemMetadata const&)> const& validate)
106{
107 unique_ptr<ItemJobImpl> impl(new ItemJobImpl(account, method, reply, validate));
108 auto job = new ItemJob(move(impl));
109 job->p_->public_instance_ = job;
110 return job;
111}
112
113ItemJob* ItemJobImpl::make_item_job(StorageError const& error)
114{
115 unique_ptr<ItemJobImpl> impl(new ItemJobImpl(error));
116 auto job = new ItemJob(move(impl));
117 job->p_->public_instance_ = job;
118 job->p_->status_ = job->p_->emit_status_changed(ItemJob::Error);
119 return job;
120}
121
122ItemJob::Status ItemJobImpl::emit_status_changed(ItemJob::Status new_status) const
123{
124 // TODO: should be an assert!
125 if (status_ == ItemJob::Loading) // Once in a final state, we don't emit the signal again.
126 {
127 QMetaObject::invokeMethod(public_instance_,
128 "statusChanged",
129 Qt::QueuedConnection,
130 Q_ARG(unity::storage::qt::ItemJob::Status, new_status));
131 }
132 return new_status;
133}
134
135} // namespace internal
136} // namespace qt
137} // namespace storage
138} // namespace unity
0139
=== added file 'src/qt/internal/ItemListJobImpl.cpp'
--- src/qt/internal/ItemListJobImpl.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/internal/ItemListJobImpl.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,148 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/internal/ItemListJobImpl.h>
20
21#include <unity/storage/internal/dbusmarshal.h>
22#include <unity/storage/internal/ItemMetadata.h>
23#include <unity/storage/qt/internal/Handler.h>
24#include <unity/storage/qt/internal/ItemImpl.h>
25
26using namespace std;
27
28namespace unity
29{
30namespace storage
31{
32namespace qt
33{
34namespace internal
35{
36
37ItemListJobImpl::ItemListJobImpl(shared_ptr<AccountImpl> const& account,
38 QString const& method,
39 QDBusPendingReply<QList<storage::internal::ItemMetadata>> const& reply,
40 std::function<void(storage::internal::ItemMetadata const&)> const& validate)
41 : status_(ItemListJob::Loading)
42 , method_(method)
43 , account_(account)
44 , validate_(validate)
45{
46 assert(!method.isEmpty());
47 assert(account);
48 assert(validate);
49
50 auto process_reply = [this](decltype(reply)& r)
51 {
52 QList<Item> items;
53 auto metadata = r.value();
54 for (auto const& md : metadata)
55 {
56 try
57 {
58 validate_(md);
59 auto item = ItemImpl::make_item(method_, md, account_);
60 items.append(item);
61 }
62 catch (StorageError const&)
63 {
64 // Bad metadata received from provider, validate_() or make_item() have logged it.
65 }
66 }
67 emit_items_ready(items);
68 status_ = emit_status_changed(ItemListJob::Finished);
69 };
70
71 auto process_error = [this](StorageError const& error)
72 {
73 error_ = error;
74 status_ = emit_status_changed(ItemListJob::Error);
75 };
76
77 new Handler<QList<storage::internal::ItemMetadata>>(this, reply, process_reply, process_error);
78}
79
80ItemListJobImpl::ItemListJobImpl(StorageError const& error)
81 : status_(ItemListJob::Loading)
82 , error_(error)
83{
84}
85
86bool ItemListJobImpl::isValid() const
87{
88 return status_ != ItemListJob::Status::Error;
89}
90
91ItemListJob::Status ItemListJobImpl::status() const
92{
93 return status_;
94}
95
96StorageError ItemListJobImpl::error() const
97{
98 return error_;
99}
100
101ItemListJob* ItemListJobImpl::make_item_list_job(
102 shared_ptr<AccountImpl> const& account,
103 QString const& method,
104 QDBusPendingReply<QList<storage::internal::ItemMetadata>> const& reply,
105 std::function<void(storage::internal::ItemMetadata const&)> const& validate)
106{
107 unique_ptr<ItemListJobImpl> impl(new ItemListJobImpl(account, method, reply, validate));
108 auto job = new ItemListJob(move(impl));
109 job->p_->public_instance_ = job;
110 return job;
111}
112
113ItemListJob* ItemListJobImpl::make_item_list_job(StorageError const& error)
114{
115 unique_ptr<ItemListJobImpl> impl(new ItemListJobImpl(error));
116 auto job = new ItemListJob(move(impl));
117 job->p_->public_instance_ = job;
118 job->p_->status_ = job->p_->emit_status_changed(ItemListJob::Error);
119 return job;
120}
121
122ItemListJob::Status ItemListJobImpl::emit_status_changed(ItemListJob::Status new_status) const
123{
124 // TODO: use assert
125 if (status_ == ItemListJob::Loading) // Once in a final state, we don't emit the signal again.
126 {
127 // We defer emission of the signal so the client gets a chance to connect to the signal
128 // in case we emit the signal from the constructor.
129 QMetaObject::invokeMethod(public_instance_,
130 "statusChanged",
131 Qt::QueuedConnection,
132 Q_ARG(unity::storage::qt::ItemListJob::Status, new_status));
133 }
134 return new_status;
135}
136
137void ItemListJobImpl::emit_items_ready(QList<Item> const& items) const
138{
139 QMetaObject::invokeMethod(public_instance_,
140 "itemsReady",
141 Qt::QueuedConnection,
142 Q_ARG(QList<unity::storage::qt::Item>, items));
143}
144
145} // namespace internal
146} // namespace qt
147} // namespace storage
148} // namespace unity
0149
=== added file 'src/qt/internal/RuntimeImpl.cpp'
--- src/qt/internal/RuntimeImpl.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/internal/RuntimeImpl.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,168 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/internal/RuntimeImpl.h>
20
21#include <unity/storage/internal/dbusmarshal.h>
22#include <unity/storage/qt/AccountsJob.h>
23#include <unity/storage/qt/internal/AccountImpl.h>
24#include <unity/storage/qt/internal/StorageErrorImpl.h>
25#include <unity/storage/qt/Item.h>
26#include <unity/storage/qt/ItemJob.h>
27#include <unity/storage/qt/ItemListJob.h>
28#include <unity/storage/qt/Runtime.h>
29
30#include <QDBusError>
31#include <QDBusMetaType>
32
33using namespace std;
34
35namespace unity
36{
37namespace storage
38{
39namespace qt
40{
41namespace internal
42{
43namespace
44{
45
46void register_meta_types()
47{
48 qRegisterMetaType<unity::storage::qt::AccountsJob::Status>();
49 qRegisterMetaType<unity::storage::qt::Item>();
50 qRegisterMetaType<QList<unity::storage::qt::Item>>();
51 qRegisterMetaType<unity::storage::qt::ItemJob::Status>();
52 qRegisterMetaType<unity::storage::qt::ItemListJob::Status>();
53
54 qDBusRegisterMetaType<unity::storage::internal::ItemMetadata>();
55 qDBusRegisterMetaType<QList<unity::storage::internal::ItemMetadata>>();
56}
57
58}
59
60// TODO: chain the two constructors.
61RuntimeImpl::RuntimeImpl()
62 : is_valid_(true)
63 , conn_(QDBusConnection::sessionBus())
64 , accounts_manager_(new OnlineAccounts::Manager("", conn_))
65{
66 register_meta_types();
67
68#if 0
69 if (!conn_.isConnected())
70 {
71 // LCOV_EXCL_START
72 is_valid_ = false;
73 QString msg = "Runtime(): cannot connect to session bus: " + conn_.lastError().message();
74 error_ = StorageErrorImpl::local_comms_error(msg);
75 // LCOV_EXCL_STOP
76 }
77#endif
78}
79
80RuntimeImpl::RuntimeImpl(QDBusConnection const& bus)
81 : is_valid_(true)
82 , conn_(bus)
83 , accounts_manager_(new OnlineAccounts::Manager("", conn_))
84{
85 register_meta_types();
86
87#if 0
88 if (!conn_.isConnected())
89 {
90 is_valid_ = false;
91 QString msg = "Runtime(): DBus connection is not connected";
92 error_ = StorageErrorImpl::local_comms_error(msg);
93 }
94#endif
95}
96
97RuntimeImpl::~RuntimeImpl()
98{
99 shutdown();
100}
101
102bool RuntimeImpl::isValid() const
103{
104 return is_valid_;
105}
106
107StorageError RuntimeImpl::error() const
108{
109 return error_;
110}
111
112QDBusConnection RuntimeImpl::connection() const
113{
114 return conn_;
115}
116
117AccountsJob* RuntimeImpl::accounts() const
118{
119 if (!is_valid_)
120 {
121 QString msg = "Runtime::accounts(): Runtime was destroyed previously";
122 return new AccountsJob(StorageErrorImpl::runtime_destroyed_error(msg));
123 }
124 auto This = const_cast<RuntimeImpl*>(this);
125 return new AccountsJob(This->shared_from_this());
126}
127
128StorageError RuntimeImpl::shutdown()
129{
130 if (is_valid_)
131 {
132 conn_.disconnectFromBus(conn_.name());
133 is_valid_ = false;
134 return StorageError();
135 }
136 error_ = StorageErrorImpl::runtime_destroyed_error("Runtime::shutdown(): Runtime was destroyed previously");
137 return error_;
138}
139
140shared_ptr<OnlineAccounts::Manager> RuntimeImpl::accounts_manager() const
141{
142 return accounts_manager_;
143}
144
145Account RuntimeImpl::make_test_account(QString const& bus_name,
146 QString const& object_path)
147{
148 return make_test_account(bus_name, object_path, "", "", "");
149}
150
151Account RuntimeImpl::make_test_account(QString const& bus_name,
152 QString const& object_path,
153 QString const& owner_id,
154 QString const& owner,
155 QString const& description)
156{
157 return AccountImpl::make_account(shared_from_this(),
158 bus_name,
159 object_path,
160 owner_id,
161 owner,
162 description);
163}
164
165} // namespace internal
166} // namespace qt
167} // namespace storage
168} // namespace unity
0169
=== added file 'src/qt/internal/StorageErrorImpl.cpp'
--- src/qt/internal/StorageErrorImpl.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/internal/StorageErrorImpl.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,230 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/internal/StorageErrorImpl.h>
20
21#include <cassert>
22#include <memory>
23
24using namespace std;
25
26namespace unity
27{
28namespace storage
29{
30namespace qt
31{
32namespace internal
33{
34
35namespace
36{
37
38static char const * const ERROR_NAMES[StorageError::__LAST_STORAGE_ERROR] =
39{
40 "NoError", "LocalCommsError", "RemoteCommsError", "Deleted", "RuntimeDestroyed", "NotExists",
41 "Exists", "Conflict", "PermissionDenied", "Cancelled", "LogicError", "InvalidArgument", "ResourceError"
42};
43
44} // namespace
45
46StorageErrorImpl::StorageErrorImpl()
47 : type_(StorageError::Type::NoError)
48 , name_(ERROR_NAMES[type_])
49 , message_("No error")
50 , error_code_(0)
51{
52}
53
54StorageErrorImpl::StorageErrorImpl(StorageError::Type type, QString const& msg)
55 : type_(type)
56 , name_(ERROR_NAMES[type_])
57 , message_(msg)
58 , error_code_(0)
59{
60 assert( type == StorageError::Type::LocalCommsError
61 || type == StorageError::Type::RemoteCommsError
62 || type == StorageError::Type::RuntimeDestroyed
63 || type == StorageError::Type::Conflict
64 || type == StorageError::Type::PermissionDenied
65 || type == StorageError::Type::Cancelled
66 || type == StorageError::Type::LogicError
67 || type == StorageError::Type::InvalidArgument);
68 assert(!msg.isEmpty());
69}
70
71StorageErrorImpl::StorageErrorImpl(StorageError::Type type, QString const& msg, QString const& key)
72 : type_(type)
73 , name_(ERROR_NAMES[type_])
74 , message_(msg)
75 , error_code_(0)
76{
77 assert( type == StorageError::Type::Deleted
78 || type == StorageError::Type::NotExists);
79 assert(!msg.isEmpty());
80
81 item_id_ = key;
82 if (type == StorageError::Type::NotExists)
83 {
84 item_name_ = key;
85 }
86}
87
88StorageErrorImpl::StorageErrorImpl(StorageError::Type type,
89 QString const& msg,
90 QString const& item_id,
91 QString const& item_name)
92 : type_(type)
93 , name_(ERROR_NAMES[type_])
94 , message_(msg)
95 , item_id_(item_id)
96 , item_name_(item_name)
97 , error_code_(0)
98{
99 assert(type == StorageError::Type::Exists);
100 assert(!msg.isEmpty());
101 assert(!item_id.isEmpty());
102 assert(!item_name.isEmpty());
103}
104
105StorageErrorImpl::StorageErrorImpl(StorageError::Type type, QString const& msg, int error_code)
106 : type_(type)
107 , message_(msg)
108 , error_code_(error_code)
109{
110 assert(type == StorageError::Type::ResourceError);
111 assert(!msg.isEmpty());
112}
113
114StorageError::Type StorageErrorImpl::type() const
115{
116 return type_;
117}
118
119QString StorageErrorImpl::name() const
120{
121 return name_;
122}
123
124QString StorageErrorImpl::message() const
125{
126 return message_;
127}
128
129QString StorageErrorImpl::errorString() const
130{
131 return name_ + ": " + message_;
132}
133
134QString StorageErrorImpl::itemId() const
135{
136 return item_id_;
137}
138
139QString StorageErrorImpl::itemName() const
140{
141 return item_name_;
142}
143
144int StorageErrorImpl::errorCode() const
145{
146 return error_code_;
147}
148
149StorageError StorageErrorImpl::make_error(StorageError::Type type, QString const& msg)
150{
151 unique_ptr<StorageErrorImpl> p(new StorageErrorImpl(type, msg));
152 return StorageError(move(p));
153}
154
155StorageError StorageErrorImpl::local_comms_error(QString const& msg)
156{
157 unique_ptr<StorageErrorImpl> p(new StorageErrorImpl(StorageError::Type::LocalCommsError, msg));
158 return StorageError(move(p));
159}
160
161StorageError StorageErrorImpl::remote_comms_error(QString const& msg)
162{
163 unique_ptr<StorageErrorImpl> p(new StorageErrorImpl(StorageError::Type::RemoteCommsError, msg));
164 return StorageError(move(p));
165}
166
167StorageError StorageErrorImpl::deleted_error(QString const& msg, QString const& item_id)
168{
169 unique_ptr<StorageErrorImpl> p(new StorageErrorImpl(StorageError::Type::Deleted, msg, item_id));
170 return StorageError(move(p));
171}
172
173StorageError StorageErrorImpl::runtime_destroyed_error(QString const& msg)
174{
175 unique_ptr<StorageErrorImpl> p(new StorageErrorImpl(StorageError::Type::RuntimeDestroyed, msg));
176 return StorageError(move(p));
177}
178
179StorageError StorageErrorImpl::not_exists_error(QString const& msg, QString const& key)
180{
181 unique_ptr<StorageErrorImpl> p(new StorageErrorImpl(StorageError::Type::NotExists, msg, key));
182 return StorageError(move(p));
183}
184
185StorageError StorageErrorImpl::exists_error(QString const& msg, QString const& item_id, QString const& item_name)
186{
187 unique_ptr<StorageErrorImpl> p(new StorageErrorImpl(StorageError::Type::Exists, msg, item_id, item_name));
188 return StorageError(move(p));
189}
190
191StorageError StorageErrorImpl::conflict_error(QString const& msg)
192{
193 unique_ptr<StorageErrorImpl> p(new StorageErrorImpl(StorageError::Type::Conflict, msg));
194 return StorageError(move(p));
195}
196
197StorageError StorageErrorImpl::permission_error(QString const& msg)
198{
199 unique_ptr<StorageErrorImpl> p(new StorageErrorImpl(StorageError::Type::PermissionDenied, msg));
200 return StorageError(move(p));
201}
202
203StorageError StorageErrorImpl::cancelled_error(QString const& msg)
204{
205 unique_ptr<StorageErrorImpl> p(new StorageErrorImpl(StorageError::Type::Cancelled, msg));
206 return StorageError(move(p));
207}
208
209StorageError StorageErrorImpl::logic_error(QString const& msg)
210{
211 unique_ptr<StorageErrorImpl> p(new StorageErrorImpl(StorageError::Type::LogicError, msg));
212 return StorageError(move(p));
213}
214
215StorageError StorageErrorImpl::invalid_argument_error(QString const& msg)
216{
217 unique_ptr<StorageErrorImpl> p(new StorageErrorImpl(StorageError::Type::InvalidArgument, msg));
218 return StorageError(move(p));
219}
220
221StorageError StorageErrorImpl::resource_error(QString const& msg, int error_code)
222{
223 unique_ptr<StorageErrorImpl> p(new StorageErrorImpl(StorageError::Type::ResourceError, msg, error_code));
224 return StorageError(move(p));
225}
226
227} // namespace internal
228} // namespace qt
229} // namespace storage
230} // namespace unity
0231
=== added file 'src/qt/internal/unmarshal_error.cpp'
--- src/qt/internal/unmarshal_error.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/internal/unmarshal_error.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,131 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/internal/unmarshal_error.h>
20
21#include <unity/storage/internal/dbus_error.h>
22#include <unity/storage/qt/internal/StorageErrorImpl.h>
23
24#include <QDBusPendingReply>
25
26#include <cassert>
27#include <map>
28
29using namespace unity::storage::internal;
30using namespace std;
31
32namespace unity
33{
34namespace storage
35{
36namespace qt
37{
38namespace internal
39{
40namespace
41{
42
43template<StorageError::Type T>
44StorageError make_error(QDBusPendingCallWatcher const& call)
45{
46 QDBusPendingReply<QString> reply = call;
47 auto msg = reply.argumentAt<0>();
48 return StorageErrorImpl::make_error(T, msg);
49}
50
51template<>
52StorageError make_error<StorageError::NotExists>(QDBusPendingCallWatcher const& call)
53{
54 QDBusPendingReply<QString, QString> reply = call;
55 auto msg = reply.argumentAt<0>();
56 auto key = reply.argumentAt<1>();
57 return StorageErrorImpl::not_exists_error(msg, key);
58}
59
60template<>
61StorageError make_error<StorageError::Exists>(QDBusPendingCallWatcher const& call)
62{
63 QDBusPendingReply<QString, QString, QString> reply = call;
64 auto msg = reply.argumentAt<0>();
65 auto id = reply.argumentAt<1>();
66 auto name = reply.argumentAt<2>();
67 return StorageErrorImpl::exists_error(msg, id, name);
68}
69
70template<>
71StorageError make_error<StorageError::ResourceError>(QDBusPendingCallWatcher const& call)
72{
73 QDBusPendingReply<QString, int> reply = call;
74 auto msg = reply.argumentAt<0>();
75 auto error_code = reply.argumentAt<1>();
76 return StorageErrorImpl::resource_error(msg, error_code);
77}
78
79static const map<QString, function<StorageError(QDBusPendingCallWatcher const& call)>> exception_factories =
80{
81 { "RemoteCommsException", make_error<StorageError::RemoteCommsError> },
82 { "NotExistsException", make_error<StorageError::NotExists> },
83 { "ExistsException", make_error<StorageError::Exists> },
84 { "ConflictException", make_error<StorageError::Conflict> },
85 { "PermissionException", make_error<StorageError::PermissionDenied> },
86 { "CancelledException", make_error<StorageError::Cancelled> },
87 { "LogicException", make_error<StorageError::LogicError> },
88 { "InvalidArgumentException", make_error<StorageError::InvalidArgument> },
89 { "ResourceException", make_error<StorageError::ResourceError> },
90 { "QuotaException", make_error<StorageError::QuotaExceeded> },
91 { "UnknownException", make_error<StorageError::LocalCommsError> } // Yes, LocalCommsError is intentional
92};
93
94} // namespace
95
96StorageError unmarshal_error(QDBusPendingCallWatcher const& call)
97{
98 assert(call.isError());
99
100 int err = call.error().type();
101 if (err != QDBusError::Other)
102 {
103 // Some DBus error that doesn't represent a StorageError.
104 return StorageErrorImpl::local_comms_error(call.error().message());
105 }
106
107 auto exception_type = call.error().name();
108 if (!exception_type.startsWith(DBUS_ERROR_PREFIX))
109 {
110 // Some error with the wrong prefix (should never happen unless the server is broken).
111 QString msg = "unmarshal_exception(): unknown exception type received from server: " + exception_type
112 + ": " + call.error().message();
113 return StorageErrorImpl::local_comms_error(msg);
114 }
115 exception_type = exception_type.remove(0, strlen(DBUS_ERROR_PREFIX));
116
117 auto factory_it = exception_factories.find(exception_type);
118 if (factory_it == exception_factories.end())
119 {
120 // Some StorageError that we don't recognize.
121 QString msg = "unmarshal_exception(): unknown exception type received from server: " + exception_type
122 + ": " + call.error().message();
123 return StorageErrorImpl::local_comms_error(msg);
124 }
125 return factory_it->second(call);
126}
127
128} // namespace internal
129} // namespace qt
130} // namespace storage
131} // namespace unity
0132
=== added file 'src/qt/internal/validate.cpp'
--- src/qt/internal/validate.cpp 1970-01-01 00:00:00 +0000
+++ src/qt/internal/validate.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,170 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include <unity/storage/qt/internal/validate.h>
20
21#include <unity/storage/internal/ItemMetadata.h>
22#include <unity/storage/provider/metadata_keys.h>
23#include <unity/storage/qt/internal/StorageErrorImpl.h>
24
25#include <QDateTime>
26#include <QDebug>
27#include <QString>
28
29using namespace unity::storage::internal;
30using namespace std;
31
32namespace unity
33{
34namespace storage
35{
36namespace qt
37{
38namespace internal
39{
40
41namespace
42{
43
44// Check that actual type and value match the expect type and value for a particular metadata entry.
45
46void validate_type_and_value(QString const& prefix,
47 QMapIterator<QString, QVariant> actual,
48 unordered_map<string, provider::MetadataType>::const_iterator known)
49{
50 using namespace unity::storage::provider;
51
52 switch (known->second)
53 {
54 case MetadataType::iso_8601_date_time:
55 {
56 if (actual.value().type() != QVariant::String)
57 {
58 QString msg = prefix + actual.key() + ": expected value of type String, but received value of type "
59 + actual.value().typeName();
60 throw StorageErrorImpl::local_comms_error(msg);
61 }
62 QDateTime dt = QDateTime::fromString(actual.value().toString(), Qt::ISODate);
63 if (!dt.isValid())
64 {
65 QString msg = prefix + actual.key() + ": value \"" + actual.value().toString()
66 + "\" does not parse as ISO-8601 date";
67 throw StorageErrorImpl::local_comms_error(msg);
68 }
69 auto timespec = dt.timeSpec();
70 if (timespec == Qt::LocalTime)
71 {
72 QString msg = prefix + actual.key() + ": value \"" + actual.value().toString()
73 + "\" lacks a time zone specification";
74 throw StorageErrorImpl::local_comms_error(msg);
75 }
76 break;
77 }
78 case MetadataType::int64:
79 {
80 if (actual.value().type() != QVariant::LongLong)
81 {
82 QString msg = prefix + actual.key() + ": expected value of type LongLong, but received value of type "
83 + actual.value().typeName();
84 throw StorageErrorImpl::local_comms_error(msg);
85 }
86 break;
87 }
88 default:
89 {
90 abort(); // Impossible. // LCOV_EXCL_LINE
91 }
92 }
93}
94
95} // namespace
96
97void validate(QString const& method, ItemMetadata const& md)
98{
99 using namespace unity::storage::provider;
100
101 QString prefix = method + ": received invalid metadata from provider: ";
102
103 // Basic sanity checks for mandatory fields.
104 if (md.item_id.isEmpty())
105 {
106 throw StorageErrorImpl::local_comms_error(prefix + "item_id cannot be empty");
107 }
108 if (md.type != ItemType::root)
109 {
110 if (md.parent_ids.isEmpty())
111 {
112 throw StorageErrorImpl::local_comms_error(prefix + "file or folder must have at least one parent ID");
113 }
114 for (int i = 0; i < md.parent_ids.size(); ++i)
115 {
116 if (md.parent_ids.at(i).isEmpty())
117 {
118 throw StorageErrorImpl::local_comms_error(prefix + "parent_id of file or folder cannot be empty");
119 }
120 }
121 }
122 if (md.type == ItemType::root && !md.parent_ids.isEmpty())
123 {
124 throw StorageErrorImpl::local_comms_error(prefix + "metadata: parent_ids of root must be empty");
125 }
126 if (md.name.isEmpty())
127 {
128 throw StorageErrorImpl::local_comms_error(prefix + "name cannot be empty");
129 }
130 if (md.etag.isEmpty())
131 {
132 throw StorageErrorImpl::local_comms_error(prefix + "etag cannot be empty");
133 }
134
135 // Sanity check metadata to make sure only known metadata keys appear.
136 QMapIterator<QString, QVariant> actual(md.metadata);
137 while (actual.hasNext())
138 {
139 actual.next();
140 auto known = known_metadata.find(actual.key().toStdString());
141 if (known == known_metadata.end())
142 {
143 qWarning() << prefix << "unknown metadata key:" << actual.key();
144 }
145 else
146 {
147 validate_type_and_value(prefix, actual, known);
148 }
149 }
150
151 // Sanity check metadata to make sure that mandatory fields are present.
152 if (md.type == ItemType::file)
153 {
154 if (!md.metadata.contains(SIZE_IN_BYTES))
155 {
156 QString msg = prefix + "missing key " + SIZE_IN_BYTES + " in metadata for " + md.item_id;
157 throw StorageErrorImpl::local_comms_error(msg);
158 }
159 if (!md.metadata.contains(LAST_MODIFIED_TIME))
160 {
161 QString msg = prefix + "missing key " + LAST_MODIFIED_TIME + " in metadata for " + md.item_id;
162 throw StorageErrorImpl::local_comms_error(msg);
163 }
164 }
165}
166
167} // namespace internal
168} // namespace qt
169} // namespace storage
170} // namespace unity
0171
=== renamed file 'src/qt/client/storage-framework-qt-client.pc.in' => 'src/qt/storage-framework-qt-client.pc.in'
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2016-08-11 04:20:06 +0000
+++ tests/CMakeLists.txt 2016-09-21 05:03:46 +0000
@@ -14,6 +14,7 @@
14set(unit_test_dirs14set(unit_test_dirs
15 local-client15 local-client
16 remote-client16 remote-client
17 remote-client-v1
17 provider-AccountData18 provider-AccountData
18 provider-DBusPeerCache19 provider-DBusPeerCache
19 provider-ProviderInterface20 provider-ProviderInterface
2021
=== modified file 'tests/headers/CMakeLists.txt'
--- tests/headers/CMakeLists.txt 2016-08-22 04:35:33 +0000
+++ tests/headers/CMakeLists.txt 2016-09-21 05:03:46 +0000
@@ -7,6 +7,7 @@
7set(subdirs7set(subdirs
8 unity/storage8 unity/storage
9 unity/storage/provider9 unity/storage/provider
10 unity/storage/qt
10 unity/storage/qt/client11 unity/storage/qt/client
11 unity/storage/qt/client/internal/local_client12 unity/storage/qt/client/internal/local_client
12 unity/storage/qt/client/internal/remote_client13 unity/storage/qt/client/internal/remote_client
1314
=== added directory 'tests/remote-client'
=== renamed directory 'tests/remote-client' => 'tests/remote-client-v1'
=== modified file 'tests/remote-client-v1/CMakeLists.txt'
--- tests/remote-client/CMakeLists.txt 2016-08-18 04:54:24 +0000
+++ tests/remote-client-v1/CMakeLists.txt 2016-09-21 05:03:46 +0000
@@ -1,10 +1,10 @@
1add_executable(remote-client_test remote-client_test.cpp MockProvider.cpp)1add_executable(remote-client-v1_test remote-client-v1_test.cpp MockProvider.cpp)
2set_target_properties(remote-client_test PROPERTIES AUTOMOC TRUE)2set_target_properties(remote-client-v1_test PROPERTIES AUTOMOC TRUE)
33
4add_definitions(-DTEST_DIR="${CMAKE_CURRENT_BINARY_DIR}" -DBOOST_THREAD_VERSION=4)4add_definitions(-DTEST_DIR="${CMAKE_CURRENT_BINARY_DIR}" -DBOOST_THREAD_VERSION=4)
5include_directories(${GLIB_DEPS_INCLUDE_DIRS})5include_directories(${GLIB_DEPS_INCLUDE_DIRS})
66
7target_link_libraries(remote-client_test7target_link_libraries(remote-client-v1_test
8 storage-framework-provider8 storage-framework-provider
9 storage-framework-qt-client9 storage-framework-qt-client
10 Qt5::Network10 Qt5::Network
@@ -14,7 +14,7 @@
14 testutils14 testutils
15 gtest15 gtest
16)16)
17add_test(remote-client remote-client_test)17add_test(remote-client-v1 remote-client-v1_test)
18add_dependencies(remote-client_test qt-client-all-headers provider-test)18add_dependencies(remote-client-v1_test qt-client-all-headers provider-test)
1919
20set(UNIT_TEST_TARGETS ${UNIT_TEST_TARGETS} PARENT_SCOPE)20set(UNIT_TEST_TARGETS ${UNIT_TEST_TARGETS} PARENT_SCOPE)
2121
=== renamed file 'tests/remote-client/remote-client_test.cpp' => 'tests/remote-client-v1/remote-client-v1_test.cpp'
--- tests/remote-client/remote-client_test.cpp 2016-09-02 02:56:52 +0000
+++ tests/remote-client-v1/remote-client-v1_test.cpp 2016-09-21 05:03:46 +0000
@@ -81,6 +81,7 @@
81 void SetUp() override81 void SetUp() override
82 {82 {
83 runtime_ = Runtime::create(connection());83 runtime_ = Runtime::create(connection());
84 //acc_ = runtime_->make_test_account(service_connection_->baseService(), impossible_name());
84 acc_ = runtime_->make_test_account(bus_name(), object_path());85 acc_ = runtime_->make_test_account(bus_name(), object_path());
85 }86 }
8687
8788
=== added file 'tests/remote-client/CMakeLists.txt'
--- tests/remote-client/CMakeLists.txt 1970-01-01 00:00:00 +0000
+++ tests/remote-client/CMakeLists.txt 2016-09-21 05:03:46 +0000
@@ -0,0 +1,20 @@
1add_executable(remote-client_test remote-client_test.cpp MockProvider.cpp)
2set_target_properties(remote-client_test PROPERTIES AUTOMOC TRUE)
3
4add_definitions(-DTEST_DIR="${CMAKE_CURRENT_BINARY_DIR}" -DBOOST_THREAD_VERSION=4)
5include_directories(${GLIB_DEPS_INCLUDE_DIRS})
6
7target_link_libraries(remote-client_test
8 storage-framework-provider
9 storage-framework-qt-client-v2
10 Qt5::Network
11 Qt5::Test
12 ${Boost_LIBRARIES}
13 ${GLIB_DEPS_LIBRARIES}
14 testutils
15 gtest
16)
17add_test(remote-client remote-client_test)
18add_dependencies(remote-client_test qt-client-all-headers provider-test)
19
20set(UNIT_TEST_TARGETS ${UNIT_TEST_TARGETS} PARENT_SCOPE)
021
=== added file 'tests/remote-client/MockProvider.cpp'
--- tests/remote-client/MockProvider.cpp 1970-01-01 00:00:00 +0000
+++ tests/remote-client/MockProvider.cpp 2016-09-21 05:03:46 +0000
@@ -0,0 +1,237 @@
1/*
2 * Copyright (C) 2016 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors: Michi Henning <michi.henning@canonical.com>
17 */
18
19#include "MockProvider.h"
20
21#include <unity/storage/provider/Exceptions.h>
22#include <unity/storage/provider/metadata_keys.h>
23
24#include <boost/thread.hpp>
25#include <boost/thread/future.hpp>
26
27#include <chrono>
28#include <thread>
29#include <inttypes.h>
30
31using namespace unity::storage;
32using namespace unity::storage::provider;
33using namespace std;
34
35using boost::make_exceptional_future;
36using boost::make_ready_future;
37
38MockProvider::MockProvider()
39{
40}
41
42MockProvider::MockProvider(string const& cmd)
43 : cmd_(cmd)
44{
45}
46
47boost::future<ItemList> MockProvider::roots(Context const&)
48{
49 cerr << "roots CALLED" << endl;
50 ItemList roots =
51 {
52 {"root_id", {}, "Root", "etag", ItemType::root, {}}
53 };
54 return make_ready_future<ItemList>(roots);
55}
56
57boost::future<tuple<ItemList,string>> MockProvider::list(
58 string const& item_id, string const& page_token,
59 Context const&)
60{
61 if (item_id != "root_id")
62 {
63 string msg = string("Item::list(): no such item: \"") + item_id + "\"";
64 return make_exceptional_future<tuple<ItemList,string>>(NotExistsException(msg, item_id));
65 }
66 if (page_token != "")
67 {
68 string msg = string("Item::list(): invalid page token: \"") + page_token + "\"";
69 return make_exceptional_future<tuple<ItemList,string>>(LogicException("invalid page token"));
70 }
71 ItemList children =
72 {
73 {
74 "child_id", { "root_id" }, "Child", "etag", ItemType::file,
75 { { SIZE_IN_BYTES, 0 }, { LAST_MODIFIED_TIME, "2007-04-05T14:30Z" } }
76 }
77 };
78 boost::promise<tuple<ItemList,string>> p;
79 p.set_value(make_tuple(children, string()));
80 return p.get_future();
81}
82
83boost::future<ItemList> MockProvider::lookup(
84 string const& parent_id, string const& name, Context const&)
85{
86 if (parent_id != "root_id")
87 {
88 string msg = string("Folder::lookup(): no such item: \"") + parent_id + "\"";
89 return make_exceptional_future<ItemList>(NotExistsException(msg, parent_id));
90 }
91 if (name != "Child")
92 {
93 string msg = string("Folder::lookup(): no such item: \"") + name + "\"";
94 return make_exceptional_future<ItemList>(NotExistsException(msg, name));
95 }
96 ItemList children =
97 {
98 { "child_id", { "root_id" }, "Child", "etag", ItemType::file,
99 { { SIZE_IN_BYTES, 0 }, { LAST_MODIFIED_TIME, "2007-04-05T14:30Z" } } }
100 };
101 return make_ready_future<ItemList>(children);
102}
103
104boost::future<Item> MockProvider::metadata(string const& item_id, Context const&)
105{
106 if (item_id == "root_id")
107 {
108 Item metadata{"root_id", {}, "Root", "etag", ItemType::root, {}};
109 return make_ready_future<Item>(metadata);
110 }
111 else if (item_id == "child_id")
112 {
113 Item metadata
114 {
115 "child_id", { "root_id" }, "Child", "etag", ItemType::file,
116 { { SIZE_IN_BYTES, 0 }, { LAST_MODIFIED_TIME, "2007-04-05T14:30Z" } }
117 };
118 return make_ready_future<Item>(metadata);
119 }
120 else if (item_id == "child_folder_id")
121 {
122 Item metadata{"child_folder_id", { "root_id" }, "Child_Folder", "etag", ItemType::folder, {}};
123 return make_ready_future<Item>(metadata);
124 }
125 return make_exceptional_future<Item>(NotExistsException("metadata(): no such item: " + item_id, item_id));
126}
127
128boost::future<Item> MockProvider::create_folder(
129 string const& parent_id, string const& name,
130 Context const&)
131{
132 Item metadata{"new_folder_id", { parent_id }, name, "etag", ItemType::folder, {}};
133 return make_ready_future<Item>(metadata);
134}
135
136string make_job_id()
137{
138 static int last_job_id = 0;
139 return to_string(++last_job_id);
140}
141
142boost::future<unique_ptr<UploadJob>> MockProvider::create_file(
143 string const&, string const&,
144 int64_t, string const&, bool, Context const&)
145{
146 return make_ready_future<unique_ptr<UploadJob>>(new MockUploadJob(make_job_id()));
147}
148
149boost::future<unique_ptr<UploadJob>> MockProvider::update(
150 string const&, int64_t, string const&, Context const&)
151{
152 return make_ready_future<unique_ptr<UploadJob>>(new MockUploadJob(make_job_id()));
153}
154
155boost::future<unique_ptr<DownloadJob>> MockProvider::download(
156 string const&, Context const&)
157{
158 unique_ptr<DownloadJob> job(new MockDownloadJob(make_job_id()));
159 const char contents[] = "Hello world";
160 if (write(job->write_socket(), contents, sizeof(contents)) != sizeof(contents))
161 {
162 ResourceException e("download(): write failed", errno);
163 job->report_error(make_exception_ptr(e));
164 return make_exceptional_future<unique_ptr<DownloadJob>>(e);
165 }
166 job->report_complete();
167 return make_ready_future(std::move(job));
168}
169
170boost::future<void> MockProvider::delete_item(
171 string const&, Context const&)
172{
173 return make_ready_future();
174}
175
176boost::future<Item> MockProvider::move(
177 string const& item_id, string const& new_parent_id,
178 string const& new_name, Context const&)
179{
180 Item metadata{item_id, { new_parent_id }, new_name, "etag", ItemType::file, {}};
181 return make_ready_future(metadata);
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches

to all changes: