/** \file
 *
 *  Contains the SendDataComponent class definition.
 *
 *  Copyright (c) 2017 MBARI
 *  MBARI Proprietary Information.  All Rights Reserved
 */

#ifndef SENDDESTINATION_H_
#define SENDDESTINATION_H_

class SendDestination;
class Unit;

#include "data/DataValue.h"
#include "logger/Logger.h"
#include "utils/FastMap.h"
#include "utils/RingBuffer.h"
#include "utils/Str.h"

/**
 *  Encapuslates a destination for data flowing out from vehicle
 *
 *  \ingroup supervisor
 */

class SendData
{
public:
    static RingBuffer<SendData*>* GetBuffer( const Str& scheme );
    static void Push( SendDestination* destination, DataValue* value, const Unit* unit, bool freeValue, Logger* logger = NULL );
    static SendData* Pop( const Str& scheme );
    static bool DataToSend( const Str& scheme );

    ~SendData();

    SendDestination* getDestination()
    {
        return destination_;
    }

    DataValue* getValue()
    {
        return value_;
    }

    const Unit* getUnit()
    {
        return unit_;
    }

protected:

    static FastMap<const Str, RingBuffer<SendData*>* > RingBuffers_;

    SendData( SendDestination* destination, DataValue* value, const Unit* unit, bool freeValue );
    SendDestination* destination_;
    DataValue* value_;
    const Unit* unit_;
    bool freeValue_;

};

class SendDestination
{
public:
    SendDestination( const Str& destinationUri, bool requirePath, Logger& logger, const Syslog::Severity logSeverity );

    // Copy constructor
    SendDestination( const SendDestination &destination );

    const Str& getScheme()
    {
        return scheme_;
    }

    const int getHostId()
    {
        return hostId_;
    }

    const Str& getHost()
    {
        return host_;
    }

    const Str& getPath()
    {
        return path_;
    }

    const bool hasError()
    {
        return error_;
    }

protected:
    Str scheme_;
    int hostId_;
    Str host_;
    Str path_;
    bool error_;
};

#endif /* SENDDESTINATION_H_ */
