~michihenning/storage-framework/add-mcloud-scope

« back to all changes in this revision

Viewing changes to demo/provider_test/provider-test.cpp

  • Committer: Michi Henning
  • Date: 2016-08-11 04:39:59 UTC
  • mfrom: (45.1.2 devel)
  • Revision ID: michi.henning@canonical.com-20160811043959-oqthzfqqa6lrrz42
Merged devel and resolved conflict.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 */
18
18
 
19
19
#include <unity/storage/provider/DownloadJob.h>
 
20
#include <unity/storage/provider/Exceptions.h>
20
21
#include <unity/storage/provider/ProviderBase.h>
21
22
#include <unity/storage/provider/Server.h>
22
23
#include <unity/storage/provider/TempfileUploadJob.h>
193
194
        Item metadata{"child_id", "root_id", "Child", "etag", ItemType::file, {}};
194
195
        return make_ready_future<Item>(metadata);
195
196
    }
196
 
    return make_exceptional_future<Item>(runtime_error("no such file"));
 
197
    else if (item_id == "child_folder_id")
 
198
    {
 
199
        Item metadata{"child_folder_id", "root_id", "Child_Folder", "etag", ItemType::folder, {}};
 
200
        return make_ready_future<Item>(metadata);
 
201
    }
 
202
    return make_exceptional_future<Item>(NotExistsException("metadata(): no such item: " + item_id, item_id));
197
203
}
198
204
 
199
205
boost::future<Item> MyProvider::create_folder(
234
240
 
235
241
    unique_ptr<DownloadJob> job(new MyDownloadJob(make_job_id()));
236
242
    const char contents[] = "Hello world";
237
 
    write(job->write_socket(), contents, sizeof(contents));
 
243
    if (write(job->write_socket(), contents, sizeof(contents)) != sizeof(contents))
 
244
    {
 
245
        ResourceException e("download(): write failed", errno);
 
246
        job->report_error(make_exception_ptr(e));
 
247
        return make_exceptional_future<unique_ptr<DownloadJob>>(e);
 
248
    }
238
249
    job->report_complete();
239
250
    return make_ready_future(std::move(job));
240
251
}