/* -*-c++-*- */
/* osgEarth - Dynamic map generation toolkit for OpenSceneGraph
 * Copyright 2008-2010 Pelican Mapping
 * http://osgearth.org
 *
 * osgEarth 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.
 *
 * This program 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, see <http://www.gnu.org/licenses/>
 */

#ifndef OSGEARTH_PROGRESS_H
#define OSGEARTH_PROGRESS_H 1

#include <osgEarth/Common>

namespace osgEarth
{
    /**
    * ProgressCallback is a general purpose interface for functions that need to report progress.
    */
    class OSGEARTH_EXPORT ProgressCallback : public osg::Referenced
    {
    public:
        /**
         * Creates a new ProgressCallback
         */
        ProgressCallback();

        /**
        * Callback function that will be called.
        * @param current
        *        The current amount of work to be done.
        * @param total
        *        The total amount of work to be done.
        * @param returns
        *        Returns true if the current task should be cancelled, false otherwise.
        */
        virtual bool reportProgress(double current, double total);

        void cancel() { _canceled = true; }
        bool isCanceled() const { return _canceled; }

        std::string& message() { return _message; }

        /**
         *Whether or not the task should be retried.
         */
        bool needsRetry() const { return _needsRetry;}
        /**
         *Sets whether or not the task should be retried
         */
        void setNeedsRetry( bool needsRetry ) { _needsRetry = needsRetry; }
        
    protected:
        volatile bool _canceled;
        std::string _message;
        volatile bool _needsRetry;
    };

    /**
     * ConsoleProgressCallback is a simple ProgressCallback that reports progress to the console
     */
    class OSGEARTH_EXPORT ConsoleProgressCallback : public ProgressCallback
    {
    public:
        /**
         * Creates a new ConsoleProgressCallback
         */
        ConsoleProgressCallback();

        /**
        * Callback function that will be called.
        * @param current
        *        The current amount of work to be done.
        * @param total
        *        The total amount of work to be done.
        * @param returns
        *        Returns true if the current task should be cancelled, false otherwise.
        */
        virtual bool reportProgress(double current, double total);
    };
}

#endif
