<commit_before>/*
 * Copyright (C) 2008 <NAME> <<EMAIL>>.
 *
 * Author: <NAME> <<EMAIL>>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

using GUPnP;

/**
 * Represents a container (folder) for media items and containers. Provides
 * basic serialization (to DIDLLiteWriter) implementation. Deriving classes
 * are supposed to provide working implementations of get_children and
 * find_object.
 */
public abstract class Rygel.MediaContainer : MediaObject {
    public uint child_count;
    public uint32 update_id;

    public MediaContainer (string          id,
                           MediaContainer? parent,
                           string          title,
                           uint            child_count) {
        this.id = id;
        this.parent = parent;
        this.title = title;
        this.child_count = child_count;
        this.update_id = 0;
    }

    public MediaContainer.root (string title,
                                uint   child_count) {
        this ("0", null, title, child_count);
    }

    /**
     * Fetches the list of media objects directly under this container and
     * calls callback once the result is ready.
     *
     * @param offet zero-based index of the first item to return
     * @param max_count maximum number of objects to return
     * @param cancellable optional cancellable for this operation
     * @param callback function to call when result is ready
     */
    public abstract void get_children (uint               offset,
                                       uint               max_count,
                                       Cancellable?       cancellable,
                                       AsyncReadyCallback callback);

    /**
     * Finishes the operation started by #get_children.
     *
     * @param res an AsyncResult
     *
     * return A list of media objects.
     */
    public abstract Gee.List<MediaObject>? get_children_finish (
                                                    AsyncResult res)
                                                    throws Error;

   /**
    * Recursively searches for media object with the given id in this
    * container and calls callback when the result is available.
    *
    * @param id ID of the media object to search for
    * @param cancellable optional cancellable for this operation
    * @param callback function to call when result is ready
    *
    */
    public abstract void find_object (string             id,
                                      Cancellable?       cancellable,
                                      AsyncReadyCallback callback);

    /**
     * Finishes the search operation started by #find_object.
     *
     * @param res an AsyncResult
     *
     * return the found media object.
     */
    public abstract MediaObject? find_object_finish (AsyncResult res)
                                                     throws Error;
}
<commit_msg>Provide a mechanism for container to signal updates.<commit_after>/*
 * Copyright (C) 2008 <NAME> <<EMAIL>>.
 *
 * Author: <NAME> <<EMAIL>>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

using GUPnP;

/**
 * Represents a container (folder) for media items and containers. Provides
 * basic serialization (to DIDLLiteWriter) implementation. Deriving classes
 * are supposed to provide working implementations of get_children and
 * find_object.
 */
public abstract class Rygel.MediaContainer : MediaObject {
    /**
     * container_updated signal that is emitted if a child container under the
     * tree of this container gets updated.
     *
     * @param container the container that just got updated.
     */
    public signal void container_updated (MediaContainer container);

    public uint child_count;
    public uint32 update_id;

    public MediaContainer (string          id,
                           MediaContainer? parent,
                           string          title,
                           uint            child_count) {
        this.id = id;
        this.parent = parent;
        this.title = title;
        this.child_count = child_count;
        this.update_id = 0;

        this.container_updated += on_container_updated;
    }

    public MediaContainer.root (string title,
                                uint   child_count) {
        this ("0", null, title, child_count);
    }

    /**
     * Fetches the list of media objects directly under this container and
     * calls callback once the result is ready.
     *
     * @param offet zero-based index of the first item to return
     * @param max_count maximum number of objects to return
     * @param cancellable optional cancellable for this operation
     * @param callback function to call when result is ready
     */
    public abstract void get_children (uint               offset,
                                       uint               max_count,
                                       Cancellable?       cancellable,
                                       AsyncReadyCallback callback);

    /**
     * Finishes the operation started by #get_children.
     *
     * @param res an AsyncResult
     *
     * return A list of media objects.
     */
    public abstract Gee.List<MediaObject>? get_children_finish (
                                                    AsyncResult res)
                                                    throws Error;

   /**
    * Recursively searches for media object with the given id in this
    * container and calls callback when the result is available.
    *
    * @param id ID of the media object to search for
    * @param cancellable optional cancellable for this operation
    * @param callback function to call when result is ready
    *
    */
    public abstract void find_object (string             id,
                                      Cancellable?       cancellable,
                                      AsyncReadyCallback callback);

    /**
     * Finishes the search operation started by #find_object.
     *
     * @param res an AsyncResult
     *
     * return the found media object.
     */
    public abstract MediaObject? find_object_finish (AsyncResult res)
                                                     throws Error;

    /**
     * Method to be be called each time this container is updated (metadata
     * changes for this container, items under it gets removed/added or their
     * metadata changes etc).
     *
     * @param container the container that just got updated.
     */
    public void updated () {
        this.update_id++;

        // Emit the signal that will start the bump-up process for this event.
        this.container_updated (this);
    }

    /**
     * handler for container_updated signal on this container. We only forward
     * it to the parent, hoping someone will get it from the root container
     * and act upon it.
     *
     * @param container the container that just got updated.
     */
    private void on_container_updated (MediaContainer container) {
        if (this.parent != null) {
            this.parent.container_updated (container);
        }
    }
}

{'fraction_non_alphanumeric': 0.05932700199319967, 'fraction_numerical': 0.0046898815804900925, 'mean_word_length': 1.8807835190813915, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7642852', 'n_tokens_mistral': 2020, 'n_tokens_neox': 1957, 'n_words': 873}