
/**
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 * 
 * Author: cob
 *
 * This file is part of The iWear Framework.
 * In particular this file is part of the Framework Output
 *
 * 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 __IOWARRIOROUTPUTMODULE_H
#define __IOWARRIOROUTPUTMODULE_H

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

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

#ifndef __SIGNALDATA_H
#include <iwear_output/signaldata.h>
#endif

namespace iwear{

namespace iowarrior{
class IWearIOWarrior;
}
namespace output{
namespace iowarrior{
class IOWarriorSignalDataFunctor;

/**
 * This class IOWarriorOutputModule derives from OutputModule and at least has 
 * to implement the display-function that should contain the main functionality
 * of this module.
 */
class IOWarriorOutputModule : public OutputModule
{

 public:

    static const string NAME;
    
    /**
     * The standard constructor of this module. The module will register itself 
     * at the OutputManager.
     * @param output_manager the manager that is responsible for this module.
     */
    IOWarriorOutputModule(OutputManager* output_manager, Configuration& c, EventDispatcher& ed);

    /**
     * The destructor.
     */
    virtual ~IOWarriorOutputModule();

    /**
     * Inherited from Module and has to be implemened.
     * @param p_state the state to be set.
     * @return if he operation was successful. TODO: return-values?
     */
    virtual uint32_t activate_power_state(power_state p_state);

    /**
     * The most important funtion of this class. Inherited from OutputModule
     * and implemented here.
     * @param data the output data to be displayed.
     */
    virtual display_state display(OutputData* data);

    /**
     * Implements the reaction of the module when the application
     * in focus changes.
     * @param
     */
    virtual void apply_application_focus_change(const uid& application_id);

    /**
     * Stop displaying the output data handed over as parameter.
     * @param data the output data whose display should be stopped.
     */
    virtual bool stop_display(OutputData* data);

    /**
     * Handle method which is called by the consolemodulefunctor which
     * inherits from outputdatafunctor
     */
    virtual void handle_signal_state_changed(IOWarriorSignalDataFunctor* sdf);

    /**
     * Handle method which is called by the consolemodulefunctor which
     * inherits from outputdatafunctor
     */
    virtual void handle_signal_error_occured(IOWarriorSignalDataFunctor* sdf);

 protected:

    display_state set_leds(SignalData* signal_data);
    void set_leds(SignalState signal_state, SignalStateInterval interval);
    uint8_t get_flash_int(SignalStateInterval interval);
    void set_leds(SignalErrorState error_state);

    /**
     * Mapping from the application uid to its signaldata.
     */
    map<const uid*, SignalData*, deref_less<const uid*> > app_to_data;

    /**
     * Mapping from Functor to Data where the functor is registered.
     */
    map<IOWarriorSignalDataFunctor*, SignalData*, 
	deref_less<IOWarriorSignalDataFunctor*> > functor_to_data;

    /**
     * Mapping from Data to Functor.
     */
    map<SignalData*, IOWarriorSignalDataFunctor*, deref_less<SignalData*> > data_to_functor;

    /**
     * The IOWarrior instance we are using.
     */
    iwear::iowarrior::IWearIOWarrior* iowarrior;
};
} // namespace iowarrior
} // namespace output
} // namespace iwear

#endif // __IOWARRIOROUTPUTMODULE_H

