source: trunk/tools/runonphone/symbianutils/symbiandevicemanager.h

Last change on this file was 846, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 5.9 KB
RevLine 
[767]1/****************************************************************************
2**
[846]3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
[767]4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the tools applications of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at qt-info@nokia.com.
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef SYMBIANDEVICEMANAGER_H
43#define SYMBIANDEVICEMANAGER_H
44
45#include "symbianutils_global.h"
46
47#include <QtCore/QObject>
48#include <QtCore/QExplicitlySharedDataPointer>
[846]49#include <QtCore/QSharedPointer>
[767]50
51QT_BEGIN_NAMESPACE
52class QDebug;
53class QTextStream;
54QT_END_NAMESPACE
55
[846]56namespace trk {
57 class TrkDevice;
58}
59
[767]60namespace SymbianUtils {
61
62struct SymbianDeviceManagerPrivate;
63class SymbianDeviceData;
64
65enum DeviceCommunicationType {
66 SerialPortCommunication = 0,
67 BlueToothCommunication = 1
68};
69
[846]70// SymbianDevice: Explicitly shared device data and a TrkDevice
71// instance that can be acquired (exclusively) for use.
72// A device removal from the manager will result in the
73// device being closed.
[767]74class SYMBIANUTILS_EXPORT SymbianDevice {
75 explicit SymbianDevice(SymbianDeviceData *data);
76 friend class SymbianDeviceManager;
77public:
[846]78 typedef QSharedPointer<trk::TrkDevice> TrkDevicePtr;
79
[767]80 SymbianDevice();
81 SymbianDevice(const SymbianDevice &rhs);
82 SymbianDevice &operator=(const SymbianDevice &rhs);
83 ~SymbianDevice();
84 int compare(const SymbianDevice &rhs) const;
85
86 DeviceCommunicationType type() const;
87 bool isNull() const;
88 QString portName() const;
89 QString friendlyName() const;
[846]90 QString additionalInformation() const;
91 void setAdditionalInformation(const QString &);
[767]92
[846]93 // Acquire: Mark the device as 'out' and return a shared pointer
94 // unless it is already in use by another owner. The result should not
95 // be passed on further.
96 TrkDevicePtr acquireDevice();
97 // Give back a device and mark it as 'free'.
98 void releaseDevice(TrkDevicePtr *ptr = 0);
99
100 bool isOpen() const;
101
[767]102 // Windows only.
103 QString deviceDesc() const;
104 QString manufacturer() const;
105
106 void format(QTextStream &str) const;
107 QString toString() const;
108
109private:
[846]110 void forcedClose();
111
[767]112 QExplicitlySharedDataPointer<SymbianDeviceData> m_data;
113};
114
[846]115SYMBIANUTILS_EXPORT QDebug operator<<(QDebug d, const SymbianDevice &);
[767]116
117inline bool operator==(const SymbianDevice &d1, const SymbianDevice &d2)
118 { return d1.compare(d2) == 0; }
119inline bool operator!=(const SymbianDevice &d1, const SymbianDevice &d2)
120 { return d1.compare(d2) != 0; }
121inline bool operator<(const SymbianDevice &d1, const SymbianDevice &d2)
122 { return d1.compare(d2) < 0; }
123
124/* SymbianDeviceManager: Singleton that maintains a list of Symbian devices.
125 * and emits change signals.
[846]126 * On Windows, the update slot must be connected to a [delayed] signal
127 * emitted from an event handler listening for WM_DEVICECHANGE.
128 * Device removal will result in the device being closed. */
[767]129class SYMBIANUTILS_EXPORT SymbianDeviceManager : public QObject
130{
131 Q_OBJECT
132public:
133 typedef QList<SymbianDevice> SymbianDeviceList;
[846]134 typedef QSharedPointer<trk::TrkDevice> TrkDevicePtr;
[767]135
136 static const char *linuxBlueToothDeviceRootC;
137
138 // Do not use this constructor, it is just public for Q_GLOBAL_STATIC
139 explicit SymbianDeviceManager(QObject *parent = 0);
140 virtual ~SymbianDeviceManager();
141
142 // Singleton access.
143 static SymbianDeviceManager *instance();
144
145 SymbianDeviceList devices() const;
146 QString toString() const;
147
[846]148 // Acquire a device for use. See releaseDevice().
149 TrkDevicePtr acquireDevice(const QString &port);
150
151 int findByPortName(const QString &p) const;
[767]152 QString friendlyNameForPort(const QString &port) const;
153
154public slots:
155 void update();
[846]156 // Relase a device, make it available for further use.
157 void releaseDevice(const QString &port);
158 void setAdditionalInformation(const QString &port, const QString &ai);
[767]159
160signals:
[846]161 void deviceRemoved(const SymbianUtils::SymbianDevice &d);
162 void deviceAdded(const SymbianUtils::SymbianDevice &d);
[767]163 void updated();
164
165private:
[846]166 void ensureInitialized() const;
[767]167 void update(bool emitSignals);
168 SymbianDeviceList serialPorts() const;
169 SymbianDeviceList blueToothDevices() const;
170
171 SymbianDeviceManagerPrivate *d;
172};
173
[846]174SYMBIANUTILS_EXPORT QDebug operator<<(QDebug d, const SymbianDeviceManager &);
[767]175
176} // namespace SymbianUtils
177
178#endif // SYMBIANDEVICEMANAGER_H
Note: See TracBrowser for help on using the repository browser.