Kstars

driverinfo.cpp
1 /*
2  SPDX-FileCopyrightText: 2012 Jasem Mutlaq <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "driverinfo.h"
8 
9 #include "deviceinfo.h"
10 #include "servermanager.h"
11 
12 #include <basedevice.h>
13 
14 #include <QDebug>
15 
16 DriverInfo::DriverInfo(const QString &inName)
17 {
18  uniqueLabel.clear();
19  name = inName;
20 
21  m_Manufacturer = "Others";
22  hostname = "localhost";
23  port = -1;
24  userPort = -1;
25 }
26 
27 DriverInfo::DriverInfo(DriverInfo *di)
28 {
29  name = di->getName();
30  label = di->getLabel();
31  uniqueLabel = di->getUniqueLabel();
32  exec = di->getExecutable();
33  version = di->getVersion();
34  m_Manufacturer = di->manufacturer();
35  userPort = di->getUserPort();
36  skelFile = di->getSkeletonFile();
37  port = di->getPort();
38  hostname = di->getHost();
39  remotePort = di->getRemotePort();
40  remoteHostname = di->getRemoteHost();
41  type = di->getType();
42  serverState = di->getServerState();
43  clientState = di->getClientState();
44  driverSource = di->getDriverSource();
45  serverManager = di->getServerManager();
46  clientManager = di->getClientManager();
47  auxInfo = di->getAuxInfo();
48  devices = di->getDevices();
49 }
50 
51 DriverInfo *DriverInfo::clone(bool resetClone)
52 {
53  DriverInfo * clone = new DriverInfo(this);
54  if (resetClone)
55  {
56  clone->reset();
57  clone->resetDevices();
58  }
59  return clone;
60 }
61 
62 DriverInfo::~DriverInfo()
63 {
64  qDeleteAll(devices);
65 }
66 
67 void DriverInfo::reset()
68 {
69  serverState = false;
70  clientState = false;
71  serverManager = nullptr;
72  clientManager = nullptr;
73 }
74 
75 QString DriverInfo::getServerBuffer() const
76 {
77  if (serverManager != nullptr)
78  return serverManager->getLogBuffer();
79 
80  return QString();
81 }
82 
83 void DriverInfo::setServerState(bool inState)
84 {
85  if (inState == serverState)
86  return;
87 
88  serverState = inState;
89 
90  if (serverState == false)
91  serverManager = nullptr;
92 
93  emit deviceStateChanged(this);
94 }
95 
96 void DriverInfo::setClientState(bool inState)
97 {
98  //qDebug() << Q_FUNC_INFO << "Request to change " << name << " client status to " << (inState ? "True" : "False") << Qt::endl;
99 
100  if (inState == clientState)
101  return;
102 
103  clientState = inState;
104 
105  if (clientState == false)
106  clientManager = nullptr;
107 
108  //qDebug() << Q_FUNC_INFO << "Client state for this device changed, calling device state changed signal " << Qt::endl;
109 
110  emit deviceStateChanged(this);
111 }
112 
113 void DriverInfo::addDevice(DeviceInfo *idv)
114 {
115  devices.append(idv);
116 }
117 
118 void DriverInfo::removeDevice(DeviceInfo *idv)
119 {
120  devices.removeOne(idv);
121  delete (idv);
122 }
123 
124 DeviceInfo *DriverInfo::getDevice(const QString &deviceName) const
125 {
126  foreach (DeviceInfo *idv, devices)
127  {
128  if (idv->getDeviceName() == deviceName)
129  return idv;
130  }
131 
132  return nullptr;
133 }
134 QVariantMap DriverInfo::getAuxInfo() const
135 {
136  return auxInfo;
137 }
138 
139 void DriverInfo::setAuxInfo(const QVariantMap &value)
140 {
141  auxInfo = value;
142 }
143 
144 void DriverInfo::addAuxInfo(const QString &key, const QVariant &value)
145 {
146  auxInfo[key] = value;
147 }
148 
149 QString DriverInfo::manufacturer() const
150 {
151  return m_Manufacturer;
152 }
153 
154 void DriverInfo::setManufacturer(const QString &Manufacturer)
155 {
156  m_Manufacturer = Manufacturer;
157 }
158 
159 void DriverInfo::setUniqueLabel(const QString &inUniqueLabel)
160 {
161  // N.B. We NEVER set unique label for multiple devices per driver "driver"
162  if (auxInfo.value("mdpd", false).toBool() == true || driverSource >= HOST_SOURCE)
163  return;
164 
165  uniqueLabel = inUniqueLabel;
166 }
167 
168 QJsonObject DriverInfo::startupRule() const
169 {
170  return m_StartupRule;
171 }
172 
173 void DriverInfo::setStartupRule(const QJsonObject &value)
174 {
175  m_StartupRule = value;
176 }
void append(const T &value)
void clear()
Manufacturer
bool removeOne(const T &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 12 2022 04:00:53 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.