test_sdk/hw/gtl_hw.cpp

47 lines
1.3 KiB
C++
Raw Permalink Normal View History

#include "gtl_hw.h"
namespace gtl
{
namespace hw
{
hw::hw(QString path, QObject* parent) : QObject(parent)
{
QDir dir(path);
qDebug() << "loading hardware plugins. path:" << dir.absolutePath();
QStringList plugins = dir.entryList(QStringList() << "*.dll", QDir::Files);
for (int i = 0; i < plugins.size(); i++)
{
QPluginLoader loader(dir.absoluteFilePath(plugins[i]));
QObject* obj = loader.instance();
if (obj)
{
if(loader.metaData().value("IID").toString() == "gtlab.hardware")
_instances.insert(qobject_cast<hardware_interface*>(obj)->id(), obj);
else
loader.unload();
}
}
}
QStringList hw::devices() const
{
return _instances.keys();
}
device *hw::create_device(QString device, QObject* parent)
{
QMultiMap<QString, QObject*>::iterator iter_device = _instances.find(device);
if(iter_device == _instances.end())
return NULL;
return qobject_cast<hardware_interface*>(iter_device.value())->create_device(parent);
}
}
}