#include "DeviceController.h" #include "JobModule.h" #include "RunnableModule.h" #include "LibraryLoader.h" #include #include #include DeviceController::DeviceController() { m_pModule = nullptr; m_pDataConsumer = nullptr; } void DeviceController::regConsumer(DataConsumer* pDC) { m_pDataConsumer = pDC; } void DeviceController::OnData(std::string name,QVariant val) { // qDebug() << __FILE__ << __LINE__ << name.c_str() << " val = " << val.toString(); if( m_pDataConsumer != nullptr ) { m_pDataConsumer->OnData(name,val); } } void DeviceController::OnSubData(std::string name,std::string val) { if( m_pModule != nullptr ) { m_pModule->OnSubData(name,val); } } void DeviceController::CreateDevice(const DeviceInfo& di) { std::string assemblyName = di.ModuleInfo.AssemblyName; std::string className = di.ModuleInfo.ClassName; BaseModule* pModule = LibraryLoader::load(assemblyName); if( pModule == nullptr ) { qCritical() << __FILE__ << __LINE__ << " load " << assemblyName.c_str() << " failed."; return; } m_pModule = pModule; m_pModule->Setup(di.ModuleInfo); m_pModule->regConsumer(this); if( m_pModule->isInheritedFrom("RunnableModule")) { RunnableModule* pRunable = dynamic_cast(m_pModule); pRunable->Run(); } if( m_pModule->isInheritedFrom("JobModule")) { JobModule* pJob = dynamic_cast(m_pModule); pJob->Process(QObject()); } }