#pragma once

#include "boost/lockfree/queue.hpp"
#include <functional>

namespace ROSBridge {
namespace Bridge {
namespace lf = ::boost::lockfree;
template <class T>
class PackageBuffer
{
public:
    PackageBuffer();

    void push(T t) {
        buffer.push(t);
        if (_pushCallback)
            _pushCallback();
    }

    T pop() {
        T temp = buffer.pop();
        if (_popCallback)
            _popCallback();
        return temp;
    }

    void setPushCallback(std::function<void(void)> pushCallback) {
        _pushCallback = pushCallback;
    }

    void setPopCallback(std::function<void(void)> popCallback) {
        _popCallback = popCallback;
    }

    bool empty() const { return buffer.empty();}
private:
    lf::queue<T> buffer;
    std::function<void(void)> _popCallback;
    std::function<void(void)> _pushCallback;
};

} // namespace Communicator

} // namespace
