#include "DataConsumer.h"
#include <QThread>
#include <QDateTime>
#include <QVariant>
#include "LibraryLoader.h"
#include "Client.h"
DataConsumer::DataConsumer()
{

}

DataConsumer::~DataConsumer()
{

}



// void DataConsumer::run()
// {

//     while(!isInterruptionRequested()){
//         qDebug() << __FILE__ << __FUNCTION__;
//         QThread::msleep(1000);
//     }

// }

void DataConsumer::Setup(ConsumerInfo &ci)
{
    std::string assemblyName = ci.AssemblyName;
    dataName = ci.Name;
    Client* pModule = nullptr;
    // = (BaseModule)Assembly.LoadFile(Path.GetFullPath(@".\" + assemblyName)).CreateInstance(className);
    pModule = LibraryLoader::load<Client>(assemblyName);
    if( pModule == nullptr )
    {
        qCritical() << " load " << assemblyName.c_str() << " failed.";
        return;
    }
    if( pModule == nullptr )
    {
        qCritical() << __FILE__ << __LINE__ << " " << assemblyName.c_str() << " load failed.";
        return;
    }

    {
        //Client*
        runable = dynamic_cast<Client*>(pModule);
        runable->Run(ci);
    }
}

std::string DataConsumer::getTypeList()
{
    return "DataStorage::RunnableModule";
}

// void DataConsumer::setLoader(QLibrary *)
// {

// }


void DataConsumer::Run()
{
    //start();
}

void DataConsumer::OnData(const QString&usr ,const QString& key,const QVariant&val)
{
    qDebug() << __FILE__ <<__FUNCTION__<< usr << key << val ;
    runable->OnData(usr, key, val);
}
