// {{{ the iWear header 
/**
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is part of The iWear Framework.
 * In particular this file is part of the Framework Core Library
 *
 * The iWear Framework is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by the
 * Free Software Foundation as in version 2 of the License.

 * 
 * The iWear Framework 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 General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * The iWear Framework; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
// }}}

#ifndef __FRAMEWORK_H
#define __FRAMEWORK_H

#include <queue>
#include <deque>

#ifndef __BASEMODULEMANAGER_H
#include <iwear/basemodulemanager.h>
#endif

#ifndef __OUTPUTMODULE_H
#include <iwear_output/outputmanager.h>
#endif

#ifndef __INPUTMODULE_H
#include <iwear_input/inputmodule.h>
#endif

#ifndef __DATASENSOR_H
#include <iwsens/datasensor.h>
#endif

#ifndef __APPLICATIONBASE_H
#include <iwear_uiservices/applicationbase.h>
#endif

using namespace std;
using namespace iwear::uiservices;
using namespace iwear::output;
using namespace iwear::input;
using namespace iwear::sensor;



namespace iwear{
namespace sensor {
namespace power{
    class PowerManager;
}
class SensorSurveillance;
}
class ModuleHandle;

class AutoLoader
{
private:
protected:
    
    BaseModuleManager* basemodulemanager;

    Configuration* configuration;

    InputManager* inputmanager;

    ServiceManager* servicemanager;

    SensorManager* sensormanager;

    SensorHandler* sensorhandler;

    power::PowerManager* powermanager;

    EventDispatcher* eventdispatcher;

    OutputManager* outputmanager;

    SensorSurveillance* sensorsurveillance;

public:
    AutoLoader();

    virtual ~AutoLoader();

    BaseModuleManager* get_basemodulemanager( void );

    Configuration* get_configuration( void );

    InputManager* get_inputmanager( void );

    ServiceManager* get_servicemanager( void );

    SensorManager* get_sensormanager( void );

    SensorHandler* get_sensorhandler( void );

    power::PowerManager* get_powermanager( void );

    EventDispatcher* get_evendispatcher( void );

    OutputManager* get_outputmanager( void );

    SensorSurveillance* get_sensorsurveillance( void );
};

class Framework
{

public:

    /**
     * Constructor for the framework structure
     */
    Framework(BaseModuleManager& bmm);

    /**
     * Destructor for the framework structure
     */
    virtual ~Framework(void);

    /**
     * This method is used to call Init() && Start() on
     * the applications which belong directly to the iWear
     * framework.
     */
    void launch_framework_applications( void );

    /**
     * This method is used to dynamically load the sensor
     * module plugins which are available in the framework
     */
    void launch_sensors( void );

    /**
     * This method is used to delete all registered
     * application & input/output module instances.
     * This method needs to be used with absolute care.
     * You definitly NEED to be SURE none of the instances
     * is still in use!
     */
    void cleanup_framework( void );

    inline void push(ApplicationBase* app){
	this->applications.push_back(app);
    }

    inline void push(InputModule* mod){
	this->input_modules.push(mod);
    }

    inline void push(OutputModule* mod){
	this->output_modules.push(mod);
    }

protected:

    BaseModuleManager &bmm;

    deque<ApplicationBase*> applications;

    queue<InputModule*> input_modules;

    queue<OutputModule*> output_modules;

    queue<std::pair<DataSensor*, ModuleHandle*> > sensors;

};

} // namespace iwear

#endif // __FRAMEWORK_H

