/*
   HARK Library
   Copyright (C) 2021 Honda Research Institute Japan Inc.
 */

#include "hark-lib/datastream.h"
#include "hark-lib/error.h"

namespace hark
{
    DataSink::~DataSink()
    {
    }

    std::string
    DataSink::name() const
    {
        return this->_name;
    }

    void
    DataSink::connect_from(DataSource *source)
    {
#if defined(VERBOSE_DEBUG)
        {
            std::stringstream ss;
            ss << "DataSink::connect_from: from=" << source->parent()->name() << "/" << source->name() << ", to=" << this->parent()->name() << "/" << this->name() << std::endl;
            std::cout << ss.str();
        }
#endif /* #if defined(VERBOSE_DEBUG) */
        if(this->_up_stream){
            std::stringstream ss;
            ss << "DataSink " << this->name() << " is already connected from DataSource " << this->_up_stream->name() << ".";
            throw RuntimeError(ss.str());
        }else{
            this->_up_stream = source;
        }
    }

    FunctionalDataSink::FunctionalDataSink(std::function<void(const data &)> &&f):
        _f(f)
    {
    }

    void
    FunctionalDataSink::clear()
    {
    }

    bool
    FunctionalDataSink::is_sink_ready() const
    {
        return true;
    }

    void
    FunctionalDataSink::push(const data &value)
    {
        this->_f(value);
    }

    void
    FunctionalDataSink::set_delay(size_t delay)
    {
    }

    void
    FunctionalDataSink::notify_receive_data()
    {
    }

}

/* end of file */
