123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #include "DeviceController.h"
- #include "JobModule.h"
- #include "RunnableModule.h"
- #include "LibraryLoader.h"
- #include <QtCore/QDebug>
- #include <typeinfo>
- #include <type_traits>
- 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<BaseModule>(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<RunnableModule*>(m_pModule);
- pRunable->Run();
- }
- if( m_pModule->isInheritedFrom("JobModule"))
- {
- JobModule* pJob = dynamic_cast<JobModule*>(m_pModule);
- pJob->Process(QObject());
- }
- }
|