/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 * 
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 * 
 * The Original Code is Komodo code.
 * 
 * The Initial Developer of the Original Code is ActiveState Software Inc.
 * Portions created by ActiveState Software Inc are Copyright (C) 2000-2008
 * ActiveState Software Inc. All Rights Reserved.
 * 
 * Contributor(s):
 *   ActiveState Software Inc
 * 
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 * 
 * ***** END LICENSE BLOCK ***** */

#include "nsISupports.idl"
#include "nsIVariant.idl"

[scriptable, uuid(efa88a1b-34f0-48b1-8e11-f0e5b6eb32bf)]
interface koIAsyncCallback: nsISupports {
        // Results for the callback function call
    const long RESULT_SUCCESSFUL = 0;
    const long RESULT_STOPPED = 1;
    const long RESULT_ERROR = 2;
        // result must be one of the values above
        //   successful - data contains the operation return data
        //   stopped - cancelled before operation could finish, data may be null
        //   error? use data to pass back an error message?
    void callback(in long result, in nsIVariant data);
};

[scriptable, uuid(7e1b0acb-32e5-4738-bda1-fb55a77c977c)]
interface koIAsyncCallbackWithProgress: koIAsyncCallback {
        /**
         * Notify that progress has been made.
         * @param label - The type of progress.
         * @param value - The overall progress value (0-100)
         */
    void onProgress(in AString label, in long value);
};

/**
 * Only Python code should be creating and running koIAsyncOperation's,
 * this is because the code has to run in a separate thread to be properly
 * asynchronous, and multi-threaded JS code will cause runtime crashes.
 * The koIAsyncService will unwrap this object into a python instance and
 * call the instance's run() method.
 */
[scriptable, uuid(d1894983-db75-48ae-be35-02d8e265c164)]
interface koIAsyncOperation: nsISupports {

        // Running means the operation has started and is working to complete
        // it's tasks.
    const long STATUS_RUNNING = 0;
        // Stopping means a request to stop() was called that made this
        // operation try to stop before it was fully completed.
        // Note: There still may be valid results returned.
    const long STATUS_STOPPING = 1;

        // status can be one of the states above
    attribute long status;

        // stop the asynchronous command. Does not have to be implemented,
        // which by default will raise an exception "Cannot be stopped"
    void stop();

        // Method will be called through a koIAsyncService.run() call.
        // If a callback was supplied then this run method *must* always return
        // XPCOM compatible objects or None (as the results will get passed to
        // koIAsyncCallback.callback()). XPCOM compatible objects are XPCOM
        // instances, numbers, booleans, strings  and lists of these previous
        // items.
    void run(out nsIVariant data);
};


[scriptable, uuid(3425ecdd-b439-43e6-8ef2-0271fd2938bf)]
interface koIAsyncService: nsISupports {
        // Return the list of running koIAsyncOperation's
    void getRunningOperations(out unsigned long count,
                              [array, size_is(count), retval] out koIAsyncOperation async_ops);

        // Return whether the uri is has a pending asynchronous operation.
    boolean uriHasPendingOperation(in wstring uri);

        // Return whether the uri is locked by a pending asynchronous operation.
    boolean uriIsLocked(in wstring uri);

        // Return the list of uris that have a running asynchronous operation.
    void getAllRunningUris(out unsigned long count,
                           [array, size_is(count), retval] out wstring uris);

        // Return the list of uris that have a running asynchronous operation
        // and are marked as locked.
    void getAllLockedUris(out unsigned long count,
                          [array, size_is(count), retval] out wstring uris);

        // The "aOp" koIAsyncOperation must be implemented in Python, otherwise
        // this call will raise an exception.
        // If the aOpCallback is defined, this objects "callback" method will
        // automatically called when the koIAsyncOperation run finishes, either
        // through normal operation, cancellation or an unexpected error.
    void run(in wstring name,
             in koIAsyncOperation aOp,
             in koIAsyncCallback aOpCallback,
             in unsigned long count,
             [array, size_is(count)] in wstring affected_uris,
             in boolean lock_these_uris);

        // This is for the icon that gets shown by the asynchronous widgets.
    readonly attribute wstring asynchronous_icon_url;
};
