forked from Skarsnik/QUsb2snes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevicefactory.h
94 lines (84 loc) · 2.82 KB
/
devicefactory.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Copyright (c) 2018 Sylvain "Skarsnik" Colinet.
*
* This file is part of the QUsb2Snes project.
* (see https://github.com/Skarsnik/QUsb2snes).
*
* QUsb2Snes is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* QUsb2Snes is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with QUsb2Snes. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef DEVICEFACTORY_H
#define DEVICEFACTORY_H
#include <QObject>
#include <QMap>
#include "adevice.h"
#include "devices/deviceerror.h"
class DeviceFactory : public QObject
{
Q_OBJECT
public:
struct DeviceStatus {
ADevice::State state;
Error::DeviceError error;
QString overridedErrorString;
QString errorString() const
{
if (!overridedErrorString.isEmpty())
return overridedErrorString;
return Error::deviceErrorString(error);
}
};
struct DeviceFactoryStatus {
QString name;
QStringList deviceNames;
Error::DeviceFactoryStatusEnum status;
Error::DeviceFactoryError generalError;
QMap<QString, DeviceFactory::DeviceStatus> deviceStatus;
QString errorString() const
{
return Error::deviceFactoryErrorString(generalError);
}
QString statusString() const
{
return Error::deviceFactoryStatusString(status);
}
};
enum DeviceFactoryState {
NONE,
BUSYDEVICELIST,
BUSYATTACH
};
explicit DeviceFactory(QObject *parent = nullptr);
virtual QStringList listDevices() = 0;
QList<ADevice*> getDevices();
virtual ADevice* attach(QString deviceName);
virtual bool deleteDevice(ADevice*) = 0;
QString attachError() const;
virtual QString name() const = 0;
virtual bool hasAsyncListDevices();
virtual bool asyncListDevices() = 0;
virtual bool devicesStatus() = 0;
virtual QStringList getDevicesName() const;
//QList<DeviceInfo> deviceInfos();
signals:
void deviceRemoved(ADevice*);
void newDeviceName(QString name);
void devicesListDone();
void deviceStatusDone(DeviceFactory::DeviceFactoryStatus status);
protected:
QList<ADevice*> m_devices;
QString m_attachError;
DeviceFactoryState m_state;
QStringList m_listDeviceNames;
};
#endif // DEVICEFACTORY_H