#include <boost/python.hpp>
#include <boost/python/extract.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <string>
#include <RTSMonitoringTask.h>
#include <RelGILLock.h>
#include <GILLock.h>


struct RTService
{
 private:
     /* data */

    RTSMonitoringTask rtsMonTask;
    RTSCoproHelper rtsCopro;

 public:

    //  RT_Service(/* args */) {
    //  }

    //  ~RT_Service() {}

    bool isCoproRunning(){
        PyRelinquishGIL scoped;
        return rtsCopro.Copro_isFwRunning();
    }

    bool initCoproFW(std::string fwPath, std::string fwName){
        PyRelinquishGIL scoped;
        return rtsCopro.Copro_init(fwPath, fwName);
    }

    bool initLogChannel(){
        PyRelinquishGIL scoped;
        return rtsCopro.Copro_initLogChannel();
    }

    bool readLogChannel(){
        PyRelinquishGIL scoped;
        return rtsCopro.Copro_readLogChannel();
    }

    
    boost::python::list getMonitoringStates() {
        //TODO ask the M4Core for the Monitpring Status
        PyRelinquishGIL scoped;        
        boost::python::list list;        
        return list;
    }

    // we need all parameters like id, samplerate, sampletime, downtime, later: HW-channels with the configurations
    bool startMonitoring(int samplerate, int sampleperiod, int downtime, std::string status) { 
        PyRelinquishGIL scoped;
        //TODO ML: add this to the M4Core
        if (rtsMonTask.Init()) {
            return rtsMonTask.Start(samplerate, sampleperiod, downtime);
        }
        return false;
    }
    // we need all parameters like id, samplerate, sampletime, downtime, later: HW-channels with the configurations
    bool stopMonitoring(std::string id) { 
        PyRelinquishGIL scoped;
        //TODO ML: add this to the M4Core
        if (rtsMonTask.Init()) {
            return rtsMonTask.Stop(id);
        }
        return false;
    }


};



using namespace boost::python;

BOOST_PYTHON_MODULE(rt_service)
{

    namespace python = boost::python;
    // python::class_<RTSMonScript, boost::noncopyable>("RTSMonitoring", python::no_init)
    //     .add_property("id", &RTSMonitoring::GetId, &RTSMonitoring::SetId)
    //     .add_property("samplerate", &RTSMonitoring::GetSampleRate, &RTSMonitoring::SetId)
    //     .add_property("samplePeriod", &RTSMonitoring::GetSamplePeriod, &RTSMonitoring::SetId)
    //     .add_property("downtime", &RTSMonitoring::GetDownTime, &RTSMonitoring::SetId)

    //     .def("add2Script", pure_virtual(&RTSMonitoring::add2Script))
    // ;

    // class_<std::vector<RTSMonitoring*>>("RTSMonitoringList")
    //     .def(vector_indexing_suite<std::vector<RTSMonitoring*>>())
    //     ;

    // def("add2Script", +[](RTSMonitoring* object) {
    //     return object->add2Script();
    // });


    class_<RTService>("RT_Service")
        .def("isCoproRunning", &RTService::isCoproRunning)
        .def("initCoproFW", &RTService::initCoproFW)
        .def("initLogChannel", &RTService::initLogChannel)
        .def("readLogChannel", &RTService::readLogChannel)
        .def("getAllMonitoringStat", &RTService::getMonitoringStates)
        .def("startMonitoring", &RTService::startMonitoring)  
        .def("stopMonitoring", &RTService::stopMonitoring)        
    ;
};


/** 
 *  startmonitoring()
 *  stopmonitoring(id)

        .def("createMonitoring", &RTService::createMonitoring)
        .def("setMonitoringStatus", &RTService::setMonitoringStatus)
        .def("getMonitoringStatus", &RTService::getMonitoringState)



*/
