/* 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_MODULE
#define OSGCOMPUTE_MODULE 1

#include <vector>
#include <osg/Object>
#include <osg/NodeVisitor>
#include <osgCompute/Export>
#include <osgCompute/Resource>
#include <osgCompute/Callback>

namespace osgCompute
{
    class Context;
    class Module;

    typedef std::vector<osg::ref_ptr<osgCompute::Module> >                          ModuleList;
    typedef std::vector<osg::ref_ptr<osgCompute::Module> >::iterator                ModuleListItr;
    typedef std::vector<osg::ref_ptr<osgCompute::Module> >::const_iterator          ModuleListCnstItr;

    /**
    */
    class LIBRARY_EXPORT Module : public Resource
    {
    public:
        Module() { clearLocal(); }

        virtual bool init();
        virtual void launch() = 0;

        virtual void acceptResource( Resource& resource );
        virtual bool usesResource( const std::string& handle ) const;
        virtual void removeResource( const Resource& resource );
        virtual void removeResource( const std::string& handle );
        virtual Resource* getResource( const std::string& handle );
        virtual const Resource* getResource( const std::string& handle ) const;

        virtual void setUpdateCallback( ModuleCallback* uc );
        virtual ModuleCallback* getUpdateCallback();
        virtual const ModuleCallback* getUpdateCallback() const;
        virtual void setEventCallback( ModuleCallback* ec );
        virtual ModuleCallback* getEventCallback();
        virtual const ModuleCallback* getEventCallback() const;

        virtual void enable();
        virtual void disable();
        virtual bool isEnabled() const;

        virtual void clear();

    protected:
        virtual ~Module() { clearLocal(); }
        void clearLocal();

        virtual void init( const Context& context ) const;
        virtual void clear( const Context& context ) const;

        osg::ref_ptr<ModuleCallback>   _updateCallback;
        osg::ref_ptr<ModuleCallback>   _eventCallback;
        bool                           _enabled;

    private:
        // copy constructor and operator should not be called
        Module( const Module&, const osg::CopyOp& ){}
        Module& operator=( const Module& copy ) { return (*this); }
    };
}

#endif //OSGCOMPUTE_MODULE
