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

#if !defined(_HARKLIB_NODE_SUBSCRIBER_FL_AC_H_INCLUDED_)
#define _HARKLIB_NODE_SUBSCRIBER_FL_AC_H_INCLUDED_ 1

#if HARKLIB_MOSQUITTO_AVAILABLE

#include "hark-lib/hark-lib.h"
#include "hark-lib/node.h"

#undef PUBLISHER // bad work, will fix later.
#include "hark-lib/extlib/HARK_MQTT.hpp"
#include "hark-lib/extlib/HARK_FLAC.hpp"
#include "hark-lib/extlib/HARK_UUID.hpp"

// using namespace FD;
using namespace HARK_MQTT;
using namespace HARKSF;
using namespace HARK_FLAC;

namespace hark
{
namespace node
{
    class SubscriberFLAC: public NodeDef
    {
    public:
        SubscriberFLAC();
        virtual void reset();
        virtual bool operator () (size_t count, InputDataBundle &input, OutputDataBundle &output);

    private:
        void saveSubscribedData(std::vector<unsigned char>vec);
        void saveDecodedData(std::vector<float>pcm_vec, bool isLast);

    private:
        bool param_b_enable_save_subscribed;
        std::string param_s_subscribed_filename_prefix;
        bool param_b_enable_save_decoded;
        std::string param_s_decoded_filename_prefix;
        int param_i_length;
        int param_i_advance;
        int param_i_keepalive;
        int param_i_timeout;
        bool isDebug;

        mqtt_subscriber *mqttobj;
        RequestServer::DecodeServer *decoder_p;
        int recv_size;
        int decode_size;
        bool recv_completed;
        bool exit_flag;
        time_t last_recieved;
        time_t started;
        mqtt_publisher *state_publisher;

        int total_channels;
        std::deque<std::vector<float>>frame_buffer;
    };
}
}

#endif /* #if HARKLIB_MOSQUITTO_AVAILABLE */
#endif /* #if !defined(_HARKLIB_NODE_SUBSCRIBER_FL_AC_H_INCLUDED_) */

/* end of file */
