File indexing completed on 2024-11-03 06:37:38

0001 /*
0002     SPDX-FileCopyrightText: 2012 Jasem Mutlaq <mutlaqja@ikarustech.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "driverinfo.h"
0008 
0009 #include "deviceinfo.h"
0010 #include "servermanager.h"
0011 
0012 #include <basedevice.h>
0013 
0014 #include <QDebug>
0015 
0016 DriverInfo::DriverInfo(const QString &inName)
0017 {
0018     uniqueLabel.clear();
0019     name = inName;
0020 
0021     m_Manufacturer = "Others";
0022     hostname = "localhost";
0023     port     = -1;
0024     userPort = -1;
0025 }
0026 
0027 DriverInfo::DriverInfo(DriverInfo *driver)
0028 {
0029     name          = driver->getName();
0030     label         = driver->getLabel();
0031     uniqueLabel   = driver->getUniqueLabel();
0032     exec          = driver->getExecutable();
0033     version       = driver->getVersion();
0034     m_Manufacturer = driver->manufacturer();
0035     userPort      = driver->getUserPort();
0036     skelFile      = driver->getSkeletonFile();
0037     port          = driver->getPort();
0038     hostname      = driver->getHost();
0039     remotePort    = driver->getRemotePort();
0040     remoteHostname = driver->getRemoteHost();
0041     type          = driver->getType();
0042     serverState   = driver->getServerState();
0043     clientState   = driver->getClientState();
0044     driverSource  = driver->getDriverSource();
0045     serverManager = driver->getServerManager();
0046     clientManager = driver->getClientManager();
0047     auxInfo       = driver->getAuxInfo();
0048     devices       = driver->getDevices();
0049 }
0050 
0051 QSharedPointer<DriverInfo> DriverInfo::clone(bool resetClone)
0052 {
0053     QSharedPointer<DriverInfo> clone(new DriverInfo(this));
0054     if (resetClone)
0055     {
0056         clone->reset();
0057         clone->resetDevices();
0058     }
0059     return clone;
0060 }
0061 
0062 DriverInfo::~DriverInfo()
0063 {
0064     qDeleteAll(devices);
0065 }
0066 
0067 void DriverInfo::reset()
0068 {
0069     serverState   = false;
0070     clientState   = false;
0071     serverManager = nullptr;
0072     clientManager = nullptr;
0073 }
0074 
0075 QString DriverInfo::getServerBuffer() const
0076 {
0077     if (serverManager != nullptr)
0078         return serverManager->getLogBuffer();
0079 
0080     return QString();
0081 }
0082 
0083 void DriverInfo::setServerState(bool inState)
0084 {
0085     if (inState == serverState)
0086         return;
0087 
0088     serverState = inState;
0089 
0090     if (serverState == false)
0091         serverManager = nullptr;
0092 
0093     emit deviceStateChanged();
0094 }
0095 
0096 void DriverInfo::setClientState(bool inState)
0097 {
0098     if (inState == clientState)
0099         return;
0100 
0101     clientState = inState;
0102 
0103     if (clientState == false)
0104         clientManager = nullptr;
0105 
0106     emit deviceStateChanged();
0107 }
0108 
0109 void DriverInfo::addDevice(DeviceInfo *idv)
0110 {
0111     devices.append(idv);
0112 }
0113 
0114 void DriverInfo::removeDevice(DeviceInfo *idv)
0115 {
0116     devices.removeOne(idv);
0117     delete (idv);
0118 }
0119 
0120 DeviceInfo *DriverInfo::getDevice(const QString &deviceName) const
0121 {
0122     foreach (DeviceInfo *idv, devices)
0123     {
0124         if (idv->getDeviceName() == deviceName)
0125             return idv;
0126     }
0127 
0128     return nullptr;
0129 }
0130 QVariantMap DriverInfo::getAuxInfo() const
0131 {
0132     return auxInfo;
0133 }
0134 
0135 void DriverInfo::setAuxInfo(const QVariantMap &value)
0136 {
0137     auxInfo = value;
0138 }
0139 
0140 void DriverInfo::addAuxInfo(const QString &key, const QVariant &value)
0141 {
0142     auxInfo[key] = value;
0143 }
0144 
0145 QString DriverInfo::manufacturer() const
0146 {
0147     return m_Manufacturer;
0148 }
0149 
0150 void DriverInfo::setManufacturer(const QString &Manufacturer)
0151 {
0152     m_Manufacturer = Manufacturer;
0153 }
0154 
0155 void DriverInfo::setUniqueLabel(const QString &inUniqueLabel)
0156 {
0157     // N.B. We NEVER set unique label for multiple devices per driver "driver"
0158     if (auxInfo.value("mdpd", false).toBool() == true || driverSource >= HOST_SOURCE)
0159         return;
0160 
0161     uniqueLabel = inUniqueLabel;
0162 }
0163 
0164 QJsonObject DriverInfo::startupRule() const
0165 {
0166     return m_StartupRule;
0167 }
0168 
0169 void DriverInfo::setStartupRule(const QJsonObject &value)
0170 {
0171     m_StartupRule = value;
0172 }