Use QUDeviceHelper instead of custom code.

Avoid duplicating udev handling code here.

Change-Id: I054b6616ead57aa8947dcf942177dfc8a14a00fe
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
This commit is contained in:
Hannu Lyytinen 2012-04-19 00:34:29 +03:00 committed by The Qt Project
parent d8a6a67579
commit 062974bf1f
9 changed files with 29 additions and 452 deletions

View File

@ -22,9 +22,6 @@ SOURCES = main.cpp \
qkmsdevice.cpp \ qkmsdevice.cpp \
qkmsbackingstore.cpp \ qkmsbackingstore.cpp \
qkmsnativeinterface.cpp \ qkmsnativeinterface.cpp \
qkmsudevlistener.cpp \
qkmsudevhandler.cpp \
qkmsudevdrmhandler.cpp \
qkmsvthandler.cpp qkmsvthandler.cpp
HEADERS = qkmsintegration.h \ HEADERS = qkmsintegration.h \
qkmsscreen.h \ qkmsscreen.h \
@ -34,9 +31,6 @@ HEADERS = qkmsintegration.h \
qkmsdevice.h \ qkmsdevice.h \
qkmsbackingstore.h \ qkmsbackingstore.h \
qkmsnativeinterface.h \ qkmsnativeinterface.h \
qkmsudevlistener.h \
qkmsudevhandler.h \
qkmsudevdrmhandler.h \
qkmsvthandler.h qkmsvthandler.h
OTHER_FILES += \ OTHER_FILES += \

View File

@ -46,8 +46,6 @@
#include "qkmsbackingstore.h" #include "qkmsbackingstore.h"
#include "qkmscontext.h" #include "qkmscontext.h"
#include "qkmsnativeinterface.h" #include "qkmsnativeinterface.h"
#include "qkmsudevlistener.h"
#include "qkmsudevdrmhandler.h"
#include "qkmsvthandler.h" #include "qkmsvthandler.h"
#include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h> #include <QtPlatformSupport/private/qgenericunixeventdispatcher_p.h>
@ -62,18 +60,26 @@ QKmsIntegration::QKmsIntegration()
: QPlatformIntegration(), : QPlatformIntegration(),
m_fontDatabase(new QGenericUnixFontDatabase()), m_fontDatabase(new QGenericUnixFontDatabase()),
m_eventDispatcher(createUnixEventDispatcher()), m_eventDispatcher(createUnixEventDispatcher()),
m_nativeInterface(new QKmsNativeInterface), m_nativeInterface(new QKmsNativeInterface)
m_udevListener(new QKmsUdevListener)
{ {
QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher); QGuiApplicationPrivate::instance()->setEventDispatcher(m_eventDispatcher);
setenv("EGL_PLATFORM", "drm",1); setenv("EGL_PLATFORM", "drm",1);
m_vtHandler = new QKmsVTHandler; m_vtHandler = new QKmsVTHandler;
m_drmHandler = new QKmsUdevDRMHandler(this);
m_udevListener->addHandler(m_drmHandler); m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_DRM, 0);
if (m_deviceDiscovery) {
QStringList devices = m_deviceDiscovery->scanConnectedDevices();
foreach (QString device, devices)
addDevice(device);
connect(m_deviceDiscovery, SIGNAL(deviceDetected(QString)), this, SLOT(addDevice(QString)));
connect(m_deviceDiscovery, SIGNAL(deviceRemoved(QString)), this, SLOT(removeDevice(QString)));
}
} }
QKmsIntegration::~QKmsIntegration() QKmsIntegration::~QKmsIntegration()
{ {
delete m_deviceDiscovery;
foreach (QKmsDevice *device, m_devices) { foreach (QKmsDevice *device, m_devices) {
delete device; delete device;
} }
@ -81,15 +87,18 @@ QKmsIntegration::~QKmsIntegration()
delete screen; delete screen;
} }
delete m_fontDatabase; delete m_fontDatabase;
delete m_udevListener;
delete m_vtHandler; delete m_vtHandler;
} }
QObject *QKmsIntegration::createDevice(const char *path) void QKmsIntegration::addDevice(const QString &deviceNode)
{ {
QKmsDevice *device = new QKmsDevice(path, this); m_devices.append(new QKmsDevice(deviceNode, this));
m_devices.append(device); }
return device;
void QKmsIntegration::removeDevice(const QString &deviceNode)
{
// TODO: support hot-plugging some day?
Q_UNUSED(deviceNode);
} }
bool QKmsIntegration::hasCapability(QPlatformIntegration::Capability cap) const bool QKmsIntegration::hasCapability(QPlatformIntegration::Capability cap) const

View File

@ -44,17 +44,18 @@
#include <qpa/qplatformintegration.h> #include <qpa/qplatformintegration.h>
#include <qpa/qplatformnativeinterface.h> #include <qpa/qplatformnativeinterface.h>
#include <QtPlatformSupport/private/qdevicediscovery_p.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QKmsScreen; class QKmsScreen;
class QKmsDevice; class QKmsDevice;
class QKmsUdevListener;
class QKmsUdevDRMHandler;
class QKmsVTHandler; class QKmsVTHandler;
class QKmsIntegration : public QPlatformIntegration class QKmsIntegration : public QObject, public QPlatformIntegration
{ {
Q_OBJECT
public: public:
QKmsIntegration(); QKmsIntegration();
~QKmsIntegration(); ~QKmsIntegration();
@ -73,6 +74,10 @@ public:
void addScreen(QKmsScreen *screen); void addScreen(QKmsScreen *screen);
QObject *createDevice(const char *); QObject *createDevice(const char *);
private slots:
void addDevice(const QString &deviceNode);
void removeDevice(const QString &deviceNode);
private: private:
QStringList findDrmDevices(); QStringList findDrmDevices();
@ -81,9 +86,8 @@ private:
QPlatformFontDatabase *m_fontDatabase; QPlatformFontDatabase *m_fontDatabase;
QAbstractEventDispatcher *m_eventDispatcher; QAbstractEventDispatcher *m_eventDispatcher;
QPlatformNativeInterface *m_nativeInterface; QPlatformNativeInterface *m_nativeInterface;
QKmsUdevListener *m_udevListener;
QKmsUdevDRMHandler *m_drmHandler;
QKmsVTHandler *m_vtHandler; QKmsVTHandler *m_vtHandler;
QDeviceDiscovery *m_deviceDiscovery;
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -1,66 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtCore/QRegExp>
#include <qkmsintegration.h>
#include <qkmsudevdrmhandler.h>
QT_BEGIN_NAMESPACE
QKmsUdevDRMHandler::QKmsUdevDRMHandler(QKmsIntegration *integration)
: m_integration(integration)
{
}
QObject *QKmsUdevDRMHandler::create(struct udev_device *device)
{
if (strcmp(udev_device_get_subsystem(device), "drm"))
return 0;
QRegExp regexp("^card\\d+$");
if (!regexp.exactMatch(udev_device_get_sysname(device)))
return 0;
return m_integration->createDevice(udev_device_get_devnode(device));
}
QT_END_NAMESPACE

View File

@ -1,66 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QKMSUDEVDRMHANDLER_H
#define QKMSUDEVDRMHANDLER_H
#include <QObject>
#include <qkmsudevhandler.h>
QT_BEGIN_NAMESPACE
class QKmsIntegration;
class QKmsUdevDRMHandler : public QKmsUdevHandler
{
public:
QKmsUdevDRMHandler(QKmsIntegration *integration);
QObject *create(struct udev_device *device);
private:
QKmsIntegration *m_integration;
};
QT_END_NAMESPACE
#endif // QKMSUDEVDRMHANDLER_H

View File

@ -1,55 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <qkmsudevhandler.h>
QT_BEGIN_NAMESPACE
QKmsUdevHandler::QKmsUdevHandler(QObject *parent)
: QObject(parent)
{
}
QKmsUdevHandler::~QKmsUdevHandler()
{
}
QT_END_NAMESPACE

View File

@ -1,64 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QKMSUDEVHANDLER_H
#define QKMSUDEVHANDLER_H
#include <QObject>
#include <libudev.h>
QT_BEGIN_NAMESPACE
class QKmsUdevHandler : public QObject
{
Q_OBJECT
public:
QKmsUdevHandler(QObject *parent = 0);
virtual ~QKmsUdevHandler();
virtual QObject *create(struct udev_device *) = 0;
};
QT_END_NAMESPACE
#endif // QKMSUDEVHANDLER_H

View File

@ -1,101 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <qkmsudevlistener.h>
QT_BEGIN_NAMESPACE
QKmsUdevListener::QKmsUdevListener(QObject *parent)
: QObject(parent)
{
m_udev = udev_new();
}
QKmsUdevListener::~QKmsUdevListener()
{
udev_unref(m_udev);
}
void QKmsUdevListener::addHandler(QKmsUdevHandler *handler)
{
m_handlers.removeAll((QKmsUdevHandler *) 0);
m_handlers.removeAll(handler);
m_handlers.prepend(handler);
scan();
}
bool QKmsUdevListener::create(struct udev_device *device)
{
foreach (QKmsUdevHandler *handler, m_handlers) {
if (!handler)
continue;
QObject *obj = handler->create(device);
if (obj) {
m_devices[udev_device_get_syspath(device)] = obj;
return true;
}
}
return false;
}
void QKmsUdevListener::scan()
{
struct udev_enumerate *e;
struct udev_list_entry *entry;
e = udev_enumerate_new(m_udev);
udev_enumerate_scan_devices(e);
udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) {
const char *path = udev_list_entry_get_name(entry);
if (m_devices.contains(path))
continue;
struct udev_device *device = udev_device_new_from_syspath(m_udev, path);
create(device);
udev_device_unref(device);
}
udev_enumerate_unref(e);
}
QT_END_NAMESPACE

View File

@ -1,78 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QKMSUDEVLISTENER_H
#define QKMSUDEVLISTENER_H
#include <QObject>
#include <QMap>
#include <QList>
#include <QPointer>
#include <QString>
#include <qkmsudevhandler.h>
#include <libudev.h>
QT_BEGIN_NAMESPACE
class QKmsUdevListener : public QObject
{
Q_OBJECT
public:
QKmsUdevListener(QObject *parent = 0);
~QKmsUdevListener();
void addHandler(QKmsUdevHandler *);
private:
QList<QPointer<QKmsUdevHandler> > m_handlers;
QMap<QString, QPointer<QObject> > m_devices;
struct udev *m_udev;
void scan();
bool create(struct udev_device *);
};
QT_END_NAMESPACE
#endif // QKMSUDEVLISTENER_H