/* 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 <osg/NodeVisitor>
#include <osgCompute/Export>

namespace osgCompute
{
    class Resource;
    class Context;
	class Module;

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

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

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

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

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

	private:

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

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

    /**
    */
    class LIBRARY_EXPORT SubloadCallback : public virtual osg::Object
    {
    public:
        /** Constructor. The object will be initialized with default values. */
        inline 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, unsigned int offset, const Resource& buffer, const Context& context ) const = 0;
        virtual void load( void* mappedPtr, unsigned int mapping, unsigned int offset, const Resource& buffer, const Context& context ) const = 0;

    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; }
    };

    //! 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(); }

        /** Do customized callback code.*/
        virtual void operator()( const osg::Referenced& reference, 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
