From b4f8d9a0b1c5aa265d806fbff6db9bbae286f9ed Mon Sep 17 00:00:00 2001 From: Jens Georg Date: Thu, 16 Feb 2012 13:46:36 +0200 Subject: [PATCH] core: Add can_create function to WritableContainer --- src/rygel/rygel-item-creator.vala | 2 +- src/rygel/rygel-writable-container.vala | 17 +++++++++++++++-- tests/rygel-item-creator-test.vala | 4 ++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/rygel/rygel-item-creator.vala b/src/rygel/rygel-item-creator.vala index 1cecd90..4419e8b 100644 --- a/src/rygel/rygel-item-creator.vala +++ b/src/rygel/rygel-item-creator.vala @@ -79,7 +79,7 @@ internal class Rygel.ItemCreator: GLib.Object, Rygel.StateMachine { * modify the UPnP class to something we support and * fetch_container took care of this already. */ - if (!container.create_classes.contains (didl_item.upnp_class) && + if (!container.can_create (this.didl_item.upnp_class) && this.container_id != "DLNA_ORG.AnyContainer") { throw new ContentDirectoryError.BAD_METADATA ("Creating of objects with class %s " + diff --git a/src/rygel/rygel-writable-container.vala b/src/rygel/rygel-writable-container.vala index 6e075cb..bc9097a 100644 --- a/src/rygel/rygel-writable-container.vala +++ b/src/rygel/rygel-writable-container.vala @@ -1,8 +1,9 @@ /* * Copyright (C) 2008 Zeeshan Ali . - * Copyright (C) 2010 Nokia Corporation. + * Copyright (C) 2010-2012 Nokia Corporation. * - * Author: Zeeshan Ali (Khattak) + * Author: Jens Georg + * Zeeshan Ali (Khattak) * * * This file is part of Rygel. @@ -41,6 +42,18 @@ public interface Rygel.WritableContainer : MediaContainer { public abstract ArrayList create_classes { get; set; } /** + * Check if this container claims to be able to create an item with the + * given upnp class. + * + * @param upnp_class The class of an item to check + * + * @return true if it can, false, if not.¨ + */ + public bool can_create (string upnp_class) { + return this.create_classes.contains (upnp_class); + } + + /** * Add a new item directly under this container. * * This doesn't imply creation of file(s) pointed to by item's URI(s), that diff --git a/tests/rygel-item-creator-test.vala b/tests/rygel-item-creator-test.vala index 32de7ed..aa5ec0c 100644 --- a/tests/rygel-item-creator-test.vala +++ b/tests/rygel-item-creator-test.vala @@ -202,6 +202,10 @@ public class Rygel.MediaObjects : Gee.ArrayList { } public class Rygel.WritableContainer : Rygel.MediaContainer { + public bool can_create (string upnp_class) { + return this.create_classes.contains (upnp_class); + } + public async File? get_writable (Cancellable? cancellable = null) { return File.new_for_commandline_arg ("/tmp"); } -- 2.7.4