/**
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is a part of The iWear Framework.
 * In particular is this file a part of the RouteTracker application
 *
 * 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 __DATACOLLECTOR_H
#define __DATACOLLECTOR_H

#ifndef __THREAD_H
#include <iwear/thread.h>
#endif

#ifndef __INPUTENUMS_H
#include <iwear_input/inputenums.h>
#endif

#ifndef __SENSORMANAGER_H
#include <iwsens/sensormanager.h>
#endif

#ifndef __SENSOR_ENUM_H
#include <iwsens/sensor_enum.h>
#endif

#ifndef __STOPWATCH_H
#include <iwear/stopwatch.h>
#endif

#include <vector>

using namespace std;


namespace iwear{
namespace routetracker{

    class RTDatabase; // TODO: Xin, Tobias, Roman

class DataCollector : public Thread{

private:
    iwear::sensor::SensorManager* sensman;
    float delay;
    const set<iwear::sensor::datasensor_type>& data_sensors;
    RTDatabase& dbi;
    int actual_waypoint_id;
    bool stop_now;
    
    void write_into_actual_waypoint(const iwear::sensor::datasensor_type& sensortype, 
				    const double& sensor_value);

    void create_new_waypoint();

protected:

    virtual void Run( void );

public:

    /**
     * Constructor for the data collector thread belonging to the route
     * tracker application.
     *
     * @param sensman the instance of the SensorManager.
     * @param delay delay between two waypoints in seconds.
     * @param data_sensors the sensors the data is gathered from
     * @param dbi a reference to the database
     */
    DataCollector( iwear::sensor::SensorManager* sensman, 
	    EventDispatcher& ed,
		   float delay, 
		   const set<iwear::sensor::datasensor_type>& data_sensors, 
		   RTDatabase& dbi);
    ~DataCollector( void );

    const int get_actual_waypoint_id( void ) const{
	return actual_waypoint_id;
    }

    void stop_data_collector(void){
	stop_now = true;
    }

}; // class DataCollector
} // namespace routetracker
} // namespace iwear

#endif // __DATACOLLECTOR_H
