Debian Codegraph @

src/systeminfo/simulator/qsysteminfoconnection_simulator.cpp

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd and/or its subsidiary(-ies).
4 ** Copyright (C) 2018 BlackBerry Limited. All rights reserved.
5 ** Contact: http://www.qt-project.org/legal
6 **
7 ** This file is part of the QtSystems module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see https://www.qt.io/terms-conditions. For further
16 ** information use the contact form at https://www.qt.io/contact-us.
17 **
18 ** GNU Lesser General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU Lesser
20 ** General Public License version 3 as published by the Free Software
21 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
22 ** packaging of this file. Please review the following information to
23 ** ensure the GNU Lesser General Public License version 3 requirements
24 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25 **
26 ** GNU General Public License Usage
27 ** Alternatively, this file may be used under the terms of the GNU
28 ** General Public License version 2.0 or (at your option) the GNU General
29 ** Public license version 3 or any later version approved by the KDE Free
30 ** Qt Foundation. The licenses are as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32 ** included in the packaging of this file. Please review the following
33 ** information to ensure the GNU General Public License requirements will
34 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35 ** https://www.gnu.org/licenses/gpl-3.0.html.
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 #include "qsysteminfoconnection_simulator_p.h"
42 #include "qsysteminfobackend_simulator_p.h"
43
44 #include <QtSimulator/QtSimulator>
45
46 #include <QTimer>
47 #include <QEventLoop>
48 #include <QMutex>
49 #include <QVersionNumber>
50
51 QT_BEGIN_NAMESPACE
52
53 const QString SERVERNAME(QStringLiteral("SystemInfo.Battery"));
54 const int PORT(0xbeef);
55 const QVersionNumber VERSION(1, 0, 0);
56
57 SystemInfoConnection::SystemInfoConnection(QObject *parent)
58 : QObject(parent)
59 {
60 qt_registerSystemInfoTypes();
61 mConnection = new QSimulatorConnection(SERVERNAME, VERSION);
62 mConnection->addPeerInfo(QLatin1String("name"), QLatin1String("systeminfo battery backend"));
63 mConnection->addPeerInfo(QLatin1String("version"), QLatin1String("1.0.0"));
64 mWorker = mConnection->connectToHost(QSimulatorConnection::simulatorHostName(true), PORT);
65 if (mWorker) {
66 mWorker->addReceiver(this);
67
68 // wait until initial data is received
69 QTimer timer;
70 QEventLoop loop;
71 connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
72 connect(this, &SystemInfoConnection::dataReceived, &loop, &QEventLoop::quit);
73 timer.start(1000);
74 loop.exec();
75 timer.stop();
76 } else
77 qWarning("Could not connect to server");
78 }
79
80 SystemInfoConnection::~SystemInfoConnection()
81 {
82 delete mWorker;
83 }
84
85 void SystemInfoConnection::ensureSimulatorConnection()
86 {
87 static QMutex mutex;
88
89 mutex.lock();
90 static SystemInfoConnection systemInfoConnection;
91 mutex.unlock();
92 }
93
94 void SystemInfoConnection::setBatteryInfoData(const QBatteryInfoData &data)
95 {
96 QBatteryInfoSimulatorBackend *batteryInfoBackend = QBatteryInfoSimulatorBackend::getSimulatorBackend();
97
98 batteryInfoBackend->setMaximumCapacity(data.maximumCapacity);
99 batteryInfoBackend->setRemainingCapacity(data.remainingCapacity);
100 batteryInfoBackend->setCurrentFlow(data.currentFlow);
101 batteryInfoBackend->setCycleCount(data.cycleCount);
102 batteryInfoBackend->setVoltage(data.voltage);
103 batteryInfoBackend->setRemainingChargingTime(data.remainingChargingTime);
104 batteryInfoBackend->setChargerType(data.chargerType);
105 batteryInfoBackend->setChargingState(data.chargingState);
106 batteryInfoBackend->setLevelStatus(data.levelStatus);
107 batteryInfoBackend->setHealth(data.health);
108 batteryInfoBackend->setTemperature(data.temperature);
109 emit dataReceived();
110 }
111
112 QT_END_NAMESPACE