/
breton75
/
modus2
Обзор
Документация
Войти
/
breton75
/
modus2
Код
Запросы
0
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
framework/module/io/sv_module_io_adaptor.cpp
192 строки
4 KB
s.sviridov
Update sv_abstract_module_io.cpp, sv_abstract_module_io.h, and 6 more files...
10 фев 2026, 18:06
10 фев 2026, 18:06
7b3fd08
Код
Авторство
О чём код?
#include "sv_module_io_adaptor.h" modus::module::IOAdaptor::IOAdaptor() : m_io (nullptr), // m_io_buffer (nullptr), m_thread (nullptr) { } modus::module::IOAdaptor::~IOAdaptor() { emit stopAll(); } bool modus::module::IOAdaptor::init(const module::Config& config) //, modus::IOBuffer *iobuffer) { try { m_config = config; me = modus::Token(P_IO, m_config.name); m_io = create_io(); if(!m_io) throw SvException(m_last_error); if(!m_io->configure(&m_config)) throw SvException(m_io->lastError()); return true; } catch (SvException& e) { if(m_io) { delete m_io; m_io = nullptr; } m_last_error = e.error; return false; } } modus::module::AbstractIO* modus::module::IOAdaptor::create_io() { modus::module::AbstractIO* newobject = nullptr; try { QString libpath; if(!modus::AppConfig::getFilePath(m_config.search_paths, m_config.io.lib, libpath)) throw SvException(QString("Не найден файл библиотеки %1").arg(m_config.io.lib)); QLibrary lib(libpath); if(!lib.load()) throw SvException(lib.errorString()); log(QString(" Интерфейс: драйвер загружен (%1)").arg(m_config.io.lib)); typedef modus::module::AbstractIO *(*create_protocol_func)(void); create_protocol_func create = (create_protocol_func)lib.resolve("create"); if (create) newobject = create(); else throw SvException(lib.errorString()); if(!newobject) throw SvException("Неизвестная ошибка при создании объекта ввода/вывода"); log(QString(" Интерфейс: сконфигурирован")); //.arg(m_config.name)); } catch(SvException& e) { if(newobject) delete newobject; newobject = nullptr; m_last_error = e.error; } return newobject; } //modus::IOBuffer* modus::module::IOAdaptor::buffer() const //{ // return m_io->buffer(); //} bool modus::module::IOAdaptor::start() { try { if(!m_io) throw SvException(QString(ERROR_NOT_INITIALIZED).arg(m_config.name)); // if(!m_io->buffer()) // throw SvException(QString(ERROR_NOT_INITIALIZED).arg("io_buffer")); m_thread = new QThread; m_thread->setObjectName(QString(m_io->config()->name).replace(QRegularExpression("[^\\w]{1,}"), "").append("IOThr")); connect(m_thread, &QThread::started, m_io, &modus::module::AbstractIO::start); connect(this, &modus::module::IOAdaptor::stopAll, m_io, &modus::module::AbstractIO::stop); connect(m_io, &modus::module::AbstractIO::finished, m_thread, &QThread::quit); connect(m_thread, &QThread::finished, m_thread, &QThread::deleteLater); connect(m_thread, &QThread::finished, m_io, &QObject::deleteLater); connect(this, &modus::module::IOAdaptor::pause, m_io, &modus::module::AbstractIO::pause); connect(this, &modus::module::IOAdaptor::resume, m_io, &modus::module::AbstractIO::resume); m_io->moveToThread(m_thread); m_thread->start(); return true; } catch (SvException& e) { m_last_error = e.error; return false; } } void modus::module::IOAdaptor::stop() { deleteLogger(); emit stopAll(); } void modus::module::IOAdaptor::createLogger() { if(!m_io) return; deleteLogger(); connect(m_io, &modus::module::AbstractIO::message, this, &modus::module::IOAdaptor::log); } void modus::module::IOAdaptor::deleteLogger() { if(!m_io) return; disconnect(m_io, &modus::module::AbstractIO::message, 0, 0); } const modus::module::Config* modus::module::IOAdaptor::config() const { return &m_config; } const QString modus::module::IOAdaptor::lastError() const { return m_last_error; } void modus::module::IOAdaptor::log(QString text, quint64 level, int type, QByteArray data) { qInfo()<< modus::event::Message(me, text, type, level, data); } /** работа с сигналами, привязанными к модулю **/ /*bool modus::module::IOAdaptor::bindSignal(modus::Signal* signal, modus::SignalBinding binding) { if(!m_protocol) { m_last_error = BIND_NOT_INITIALIZED(signal->config()->name, m_config.name); return false; } if(!m_protocol->bindSignal(signal, binding)) { m_last_error = m_protocol->lastError(); return false; } return true; } */