~michihenning/storage-framework/stand-alone-provider-headers

« back to all changes in this revision

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

  • Committer: Michi Henning
  • Date: 2016-08-23 23:45:34 UTC
  • mfrom: (53.1.4 devel)
  • Revision ID: michi.henning@canonical.com-20160823234534-4owayhnhcp67g39q
Merged devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
140
140
boost::future<ItemList> MyProvider::roots(Context const& ctx)
141
141
{
142
142
    printf("roots() called by %s (%d)\n", ctx.security_label.c_str(), ctx.pid);
 
143
    fflush(stdout);
143
144
    ItemList roots = {
144
145
        {"root_id", {}, "Root", "etag", ItemType::root, {}},
145
146
    };
151
152
    Context const& ctx)
152
153
{
153
154
    printf("list('%s', '%s') called by %s (%d)\n", item_id.c_str(), page_token.c_str(), ctx.security_label.c_str(), ctx.pid);
 
155
    fflush(stdout);
154
156
    if (item_id != "root_id")
155
157
    {
156
158
        string msg = string("Item::list(): no such item: \"") + item_id + "\"";
159
161
    if (page_token != "")
160
162
    {
161
163
        string msg = string("Item::list(): invalid page token: \"") + page_token + "\"";
162
 
        return make_exceptional_future<tuple<ItemList,string>>(msg);
 
164
        return make_exceptional_future<tuple<ItemList,string>>(LogicException(msg));
163
165
    }
164
166
    ItemList children =
165
167
    {
177
179
    string const& parent_id, string const& name, Context const& ctx)
178
180
{
179
181
    printf("lookup('%s', '%s') called by %s (%d)\n", parent_id.c_str(), name.c_str(), ctx.security_label.c_str(), ctx.pid);
 
182
    fflush(stdout);
180
183
    if (parent_id != "root_id")
181
184
    {
182
185
        string msg = string("Folder::lookup(): no such item: \"") + parent_id + "\"";
199
202
                                         Context const& ctx)
200
203
{
201
204
    printf("metadata('%s') called by %s (%d)\n", item_id.c_str(), ctx.security_label.c_str(), ctx.pid);
 
205
    fflush(stdout);
202
206
    if (item_id == "root_id")
203
207
    {
204
208
        Item metadata{"root_id", {}, "Root", "etag", ItemType::root, {}};
226
230
    Context const& ctx)
227
231
{
228
232
    printf("create_folder('%s', '%s') called by %s (%d)\n", parent_id.c_str(), name.c_str(), ctx.security_label.c_str(), ctx.pid);
 
233
    fflush(stdout);
229
234
    Item metadata{"new_folder_id", { parent_id }, name, "etag", ItemType::folder, {}};
230
235
    return make_ready_future<Item>(metadata);
231
236
}
242
247
    Context const& ctx)
243
248
{
244
249
    printf("create_file('%s', '%s', %" PRId64 ", '%s', %d) called by %s (%d)\n", parent_id.c_str(), name.c_str(), size, content_type.c_str(), allow_overwrite, ctx.security_label.c_str(), ctx.pid);
 
250
    fflush(stdout);
245
251
    return make_ready_future(unique_ptr<UploadJob>(new MyUploadJob(make_job_id())));
246
252
}
247
253
 
249
255
    string const& item_id, int64_t size, string const& old_etag, Context const& ctx)
250
256
{
251
257
    printf("update('%s', %" PRId64 ", '%s') called by %s (%d)\n", item_id.c_str(), size, old_etag.c_str(), ctx.security_label.c_str(), ctx.pid);
 
258
    fflush(stdout);
252
259
    return make_ready_future(unique_ptr<UploadJob>(new MyUploadJob(make_job_id())));
253
260
}
254
261
 
256
263
    string const& item_id, Context const& ctx)
257
264
{
258
265
    printf("download('%s') called by %s (%d)\n", item_id.c_str(), ctx.security_label.c_str(), ctx.pid);
 
266
    fflush(stdout);
259
267
 
260
268
    unique_ptr<DownloadJob> job(new MyDownloadJob(make_job_id()));
261
269
    const char contents[] = "Hello world";
273
281
    string const& item_id, Context const& ctx)
274
282
{
275
283
    printf("delete('%s') called by %s (%d)\n", item_id.c_str(), ctx.security_label.c_str(), ctx.pid);
 
284
    fflush(stdout);
276
285
    return make_ready_future();
277
286
}
278
287
 
281
290
    string const& new_name, Context const& ctx)
282
291
{
283
292
    printf("move('%s', '%s', '%s') called by %s (%d)\n", item_id.c_str(), new_parent_id.c_str(), new_name.c_str(), ctx.security_label.c_str(), ctx.pid);
 
293
    fflush(stdout);
284
294
    Item metadata{item_id, { new_parent_id }, new_name, "etag", ItemType::file, {}};
285
295
    return make_ready_future(metadata);
286
296
}
290
300
    string const& new_name, Context const& ctx)
291
301
{
292
302
    printf("copy('%s', '%s', '%s') called by %s (%d)\n", item_id.c_str(), new_parent_id.c_str(), new_name.c_str(), ctx.security_label.c_str(), ctx.pid);
 
303
    fflush(stdout);
293
304
    Item metadata{"new_item_id", { new_parent_id }, new_name, "etag", ItemType::file, {}};
294
305
    return make_ready_future(metadata);
295
306
}
297
308
boost::future<void> MyUploadJob::cancel()
298
309
{
299
310
    printf("cancel_upload('%s')\n", upload_id().c_str());
 
311
    fflush(stdout);
300
312
    return make_ready_future();
301
313
}
302
314
 
303
315
boost::future<Item> MyUploadJob::finish()
304
316
{
305
317
    printf("finish_upload('%s')\n", upload_id().c_str());
 
318
    fflush(stdout);
306
319
 
307
320
    string old_filename = file_name();
308
321
    string new_filename = upload_id() + ".txt";
309
322
    printf("Linking %s to %s\n", old_filename.c_str(), new_filename.c_str());
 
323
    fflush(stdout);
310
324
    unlink(new_filename.c_str());
311
325
    link(old_filename.c_str(), new_filename.c_str());
312
326
 
321
335
boost::future<void> MyDownloadJob::cancel()
322
336
{
323
337
    printf("cancel_download('%s')\n", download_id().c_str());
 
338
    fflush(stdout);
324
339
    return make_ready_future();
325
340
}
326
341
 
327
342
boost::future<void> MyDownloadJob::finish()
328
343
{
329
344
    printf("finish_download('%s')\n", download_id().c_str());
 
345
    fflush(stdout);
330
346
 
331
347
    return make_ready_future();
332
348
}