/* 
 * File:   FsLink.hpp
 * Author: jens
 *
 * Created on 9. Januar 2015, 20:14
 */

#include "../JuceLibraryCode/JuceHeader.h"

#include <windows.h>
#include <FSUIPC_User.h>
#include "IKml.hpp"
#include "IFsLink.hpp"

#ifndef FSLINK_HPP
#define	FSLINK_HPP

class FsLink : public IFsLink, public juce::Timer
{
public:
    enum LinkState 
    {
        ls_init = 0,
        ls_disconnected,
        ls_connected,
        ls_paused,
        ls_recording,
    }; 

    enum FlightState 
    {
        fs_init = 0,
        fs_suspend,
        fs_ground,
        fs_takeoff,
        fs_enroute,
        fs_touchdown,
    }; 

	FsLink(const char *pDocRoot);
    FsLink(const FsLink& orig);
    virtual ~FsLink();
	void addListener(IFsLinkListener *pListener);
	void setKml(IKml *pKml);
	void setUpdateInterval(double seconds);
	void setDumpOffset(uint32_t offset);
	void dump();
	void statisticsLearnStart(uint32_t count);
	void statisticsLearn();
	void statisticsEval();
	
private:
	ListenerList <IFsLinkListener> m_listeners;
	const char *m_docRoot;
	IKml *m_pKml;
    const char *m_pCurrStateStr;
    LinkState m_linkState;
    LinkState m_linkStateNext;
    FlightState m_flightState;
    FlightState m_flightStateNext;
    int m_kmlUpdateInterval;
	int m_kmlUpdateCount;
	uint32_t m_dumpOffset;
	uint32_t m_dumpLearnCount;
    char m_idStr[256];
    char m_fsInstallPath[256];
	FlightData m_flightData;
	static const char *linkStateString[];
	static const char *flightStateString[];

    bool open();
    void close();
    int gatherData();

	const char* getLinkState();
	const char* getFlightState();
	FlightData getFlightData();
	void timerCallback();
};

#endif	/* FSLINK_HPP */

