/**
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is part of The iWear Framework.
 *
 * 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 __IWPOWER_POWEREVENT_H
#define __IWPOWER_POWEREVENT_H

#ifndef __IWEAR_EVENTBASE_H
#include <iwear/eventbase.h>
#endif

#ifndef __IWPOWER_POWER_BASE_H
#include <iwpower/power_base.h>
#endif

#ifndef __IWPOWER_POWER_ENUMS_H
#include <iwpower/power_enums.h>
#endif

#ifndef __IWEAR_FUNCTOR_H
#include <iwear/functor.h>
#endif

extern "C"
{
#include <stdint.h>
}

namespace iwear
{
    namespace sensor
    {
	namespace power
	{

typedef TripleFunctor<psunion,eh_capabilities,bool> PSFunctor;

class PowerEvent : public Event<PSFunctor>
{
friend class PowerManager;
private:
protected:
    eh_capabilities capcheck;
    psunion event_value;

    psunion lower_bound;
    psunion upper_bound;

    /**
     * True if the last state asked for was "triggered". Means entered to be
     * monitored interval. In case its false, the monitored interval was
     * leaved.
     */
    bool last_state : 1;
    bool need_dispatch : 1;
    mutable bool need_deliver : 1;

public:
    PowerEvent( PSFunctor&, eh_capabilities wht);
    PowerEvent( PSFunctor&, eh_capabilities wht, int32_t low 
	    , int32_t up = numeric_limits<int32_t>::max() );
    PowerEvent( PSFunctor&, eh_capabilities wht, float low 
	    , float up = numeric_limits<float>::max() );

    inline bool deliver_needed( void ) const { bool ret = need_deliver;
                                                need_deliver = false; return ret; }

    virtual bool is_triggered( void );
    virtual bool is_triggered( float, bool override = false );
    virtual bool is_triggered( int32_t, bool override = false );

    virtual void dispatch( void );
};

}
}
}
#endif
