/* osgCompute - Copyright (C) 2008-2009 SVT Group
 *                                                                     
 * This library 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 3 of
 * the License, or (at your option) any later version.
 *                                                                     
 * This library 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 Lesse General Public License for more details.
 *
 * The full license is in LICENSE file included with this distribution.
*/

#ifndef OSGCOMPUTE_CALLBACK
#define OSGCOMPUTE_CALLBACK 1

#include <osg/Object>
#include <osgCompute/Export>

namespace osg
{
    class NodeVisitor;
}

namespace osgCompute
{
    class Resource;
    class Context;
    class ComputationBin;

    /**
    */
    class LIBRARY_EXPORT SubloadCallback : public virtual osg::Object
    {

    public:

        /** Constructor. The object will be initialized with default values. */
        inline SubloadCallback() : osg::Object() { clearLocal(); }

        /** Restore object to default state. Calls clearLocal(). */
        virtual void clear() { clearLocal(); }

    protected:

        /** Destructor. Release the memory by calling clearLocal(). */
        virtual ~SubloadCallback() { clearLocal(); }
        
        /** Clear local members.*/
        void clearLocal() {}

    private:

        /** Copy constructor. This constructor should not be called. */
        SubloadCallback(const SubloadCallback&, const osg::CopyOp&) {}

        /** Copy operator. This operator should not be called. */
        SubloadCallback &operator=(const SubloadCallback&) { return *this; }
    };

    /**
    */
    class LIBRARY_EXPORT BufferSubloadCallback : public SubloadCallback
    {

    public:

        /** Constructor. The object will be initialized with default values. */
        inline BufferSubloadCallback() : SubloadCallback() { clearLocal(); }

        /** Restore object to default state. Calls clearLocal(). */
        virtual void clear() { clearLocal(); }

        /** Do customized callback code. */
        virtual void subload( void* mappedPtr, unsigned int mapping, const Resource& buffer, const Context& context ) const = 0;
        virtual void load( void* mappedPtr, unsigned int mapping, const Resource& buffer, const Context& context ) const = 0;

    protected:

        /** Destructor. Release the memory by calling clearLocal(). */
        virtual ~BufferSubloadCallback() { clearLocal(); }
        
        /** Clear local members.*/
        void clearLocal() {}

    private:

        /** Copy constructor. This constructor should not be called.*/
        BufferSubloadCallback(const BufferSubloadCallback&, const osg::CopyOp&) {}

        /** Copy operator. This operator should not be called.*/
        BufferSubloadCallback &operator=(const BufferSubloadCallback&) { return *this; }
    };


    //! Resource callback class
    /**
    * Callback class which is used for adding event callbacks or update callbacks to objects of type Resource and Module.<br>
    * This allows users to customize a callback function during the update cycle or the event traversal.
    *
    */
    class LIBRARY_EXPORT ResourceCallback : public virtual osg::Object
    {
    public:
        /** Constructor. The object will be initialized with default values. */
        inline ResourceCallback() { clearLocal(); }

        /** Restore object to default state. Calls clearLocal(). */
        virtual void clear() { clearLocal(); }

        /** Clear object with regard to the given context. */
        virtual void clear( const Context& context ) const {}

        /** Do customized callback code.*/
        virtual void operator()( Resource& resource, osg::NodeVisitor& nv ) = 0;

    protected:

        /** Destructor. Release the memory by calling clearLocal(). */
        virtual ~ResourceCallback() { clearLocal(); }
        
        /** Clear local members.*/
        void clearLocal() {}

    private:

        /** Copy constructor. This constructor should not be called. */
        ResourceCallback( const ResourceCallback&, const osg::CopyOp& ) {}

        /** Copy operator. This operator should not be called. */
        ResourceCallback &operator=(const ResourceCallback &) { return *this; }
    };


    //! Computation callback class
    /**
    * Callback class which is used for adding launch callbacks to computation nodes or modules.<br>
    * This allows users to customize a callback function during the rendering.
    *
    */
    class LIBRARY_EXPORT LaunchCallback : public virtual osg::Object
    {
    public:
        /** Constructor. The object will be initialized with default values. */
        inline LaunchCallback() { clearLocal(); }

        /** Restore object to default state. Calls clearLocal(). */
        virtual void clear() { clearLocal(); }

        /** Clear object with regard to the given context. */
        virtual void clear( const Context& context ) const {}

        /** Do customized callback code.*/
        virtual void operator()( const osg::Object& exObject, const Context& context ) const = 0;

    protected:

        /** Destructor. Release the memory by calling clearLocal(). */
        virtual ~LaunchCallback() { clearLocal(); }

        /** Clear local members.*/
        void clearLocal() {}

    private:

        /** Copy constructor. This constructor should not be called. */
        LaunchCallback( const LaunchCallback&, const osg::CopyOp& ) {}

        /** Copy operator. This operator should not be called. */
        LaunchCallback &operator=(const LaunchCallback &) { return *this; }
    };
}

#endif //OSGCOMPUTE_CALLBACK
