/**
 * @file Listener.h
 * @author Petr Egert (egertpet@fel.cvut.cz)
 * @brief Contains Listener class declaration
 */

#ifndef LISTENER_H
#define LISTENER_H

#include <winsock2.h>
#include <string>

/// Size of the buffer used for TCP communication
#define BUFFSIZE 8096

#include "Types.h"


namespace VRUT
{
    /**
     * @brief Class providing communication with the VRUT main application
     */
    class Listener
    {
        public:
            ///Default constructor, currently does nothing
            Listener(){}

            ///Default destructor, currently does nothing
            ~Listener(){}

            bool Init(int port);
            void Release();

            void Update();
            void SendCommand(const std::string &command);
            void SendLog(const std::string &message);

            VehicleStatistics statistics;   ///< Contains current vehicle statistics information
            VehicleControls controls;       ///< Contains current vehicle control information

        protected:

        private:
            bool ParseData();

            SOCKET server;  ///< TCP socket of the server (this class)
            SOCKET client;  ///< TCP socket of the connected client

            char recvBuffer[BUFFSIZE];      ///< TCP receive buffer
            char parseBuffer[BUFFSIZE];     ///< Message parsing buffer
            unsigned int parseBufferPos;    ///< Index of the first free position in parseBuffer


    };
};

#endif // LISTENER_H

