// $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/tiptilt_ctrl/bcu/Interface/Sharknir/Bcu/ThreadedDiagnosticsCollector.h 3765 2021-11-11 10:47:14Z depa $
#pragma once

#include "tiptilt_ctrl/bcu/Interface/Sharknir/Bcu/ActiveDiagnosticsCollector.h"
#include "tiptilt_ctrl/bcu/Interface/Sharknir/Bcu/DiagnosticsDispatcher.h"
#include "tiptilt_ctrl/bcu/Interface/Sharknir/Bcu/DiagnosticsDispatcherFactory.h"

#include "util/SharedPtr.h"

//#include <Nice/Log.h>

#include <IceUtil/Thread.h>


namespace Sharknir { namespace Bcu {

class SlaveDiagnosticsCollectorThread : public IceUtil::Thread
{
public:
    SlaveDiagnosticsCollectorThread(DiagnosticsDispatcherFactoryPtr factory);

    /** @note overridden */
    virtual void run();

    void activate();

    void deactivate();

private:
    DiagnosticsDispatcherPtr dispatcher_;
    DiagnosticsDispatcherFactoryPtr factory_;
    volatile bool isActive_;
};
SHARKNIR_DECLARE_ICE_SP(SlaveDiagnosticsCollectorThread);


class ThreadedDiagnosticsCollector : public ActiveDiagnosticsCollector
{
public:
    // ThreadedDiagnosticsCollector(
    //         const DiagnosticsDispatcherFactoryPtr& slopeDiagDispatcherFactory,
    //         const DiagnosticsDispatcherFactoryPtr& asmDiagDispatcherFactory);
    ThreadedDiagnosticsCollector(
            const DiagnosticsDispatcherFactoryPtr& slopeDiagDispatcherFactory);


    /** @note overridden */
    virtual void start();

    /** @note overridden */
    virtual void terminate();

    /** @note overridden */
    virtual bool isAlive();

    void waitForTermination();

private:
    DiagnosticsDispatcherFactoryPtr slopeBcuDiagDispatcherFactory_;
    IceUtil::ThreadControl slopeBcuDiagCtrl_;
    SlaveDiagnosticsCollectorThreadPtr slopeBcuDiagThread_;
    // DiagnosticsDispatcherFactoryPtr asmBcuDiagDispatcherFactory_;
    // IceUtil::ThreadControl asmBcuDiagCtrl_;
    // SlaveDiagnosticsCollectorThreadPtr asmBcuDiagThread_;
};

SHARKNIR_DECLARE_BOOST_SP(ThreadedDiagnosticsCollector)
}
}
