summaryrefslogtreecommitdiffstats
path: root/src/plugins/qnx/mediaplayer/mmreventthread.cpp
diff options
context:
space:
mode:
authorJames McDonnell <jmcdonnell@blackberry.com>2017-05-25 13:19:38 -0400
committerJames McDonnell <jmcdonnell@blackberry.com>2017-09-21 12:42:15 +0000
commit18edbfafae7ffb3271c6659da5ce4a29226aaa28 (patch)
tree2a920a9afaae1d0c71bb3666e0494fc120938d0e /src/plugins/qnx/mediaplayer/mmreventthread.cpp
parentd41bce99a531a7968f8c5bc8ec88965372341bd9 (diff)
Switch to mmr_event_t based monitoring
The switch is necessary because Multimedia for QNX 7.0.0 removes support for PPS based monitoring. PPS itself is deprecated in QNX 7.0.0. QNX 6.6.0 is also switched to mmr_event_t based monitoring since Multimedia for QNX 6.6.0 also supports that type of monitoring. [ChangeLog][QNX] Switch to mmr_event_t based monitoring. PPS based monitoring is not supported by Multimedia for QNX 7.0.0. Change-Id: Id3ce1d8895e8ce492ecdd49cbe88ef5f0d6b0194 Reviewed-by: Michael Brasser <michael.brasser@live.com> Reviewed-by: Christian Stromme <christian.stromme@qt.io>
Diffstat (limited to 'src/plugins/qnx/mediaplayer/mmreventthread.cpp')
-rw-r--r--src/plugins/qnx/mediaplayer/mmreventthread.cpp121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/plugins/qnx/mediaplayer/mmreventthread.cpp b/src/plugins/qnx/mediaplayer/mmreventthread.cpp
new file mode 100644
index 000000000..25f26e216
--- /dev/null
+++ b/src/plugins/qnx/mediaplayer/mmreventthread.cpp
@@ -0,0 +1,121 @@
+/****************************************************************************
+**
+** Copyright (C) 2017 QNX Software Systems. All rights reserved.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part 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 The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL3 included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 3 requirements
+** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 2.0 or (at your option) the GNU General
+** Public license version 3 or any later version approved by the KDE Free
+** Qt Foundation. The licenses are as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-2.0.html and
+** https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "mmreventthread.h"
+
+#include <QtCore/QDebug>
+
+#include <errno.h>
+#include <mm/renderer/events.h>
+#include <sys/neutrino.h>
+
+static const int c_mmrCode = _PULSE_CODE_MINAVAIL + 0;
+static const int c_readCode = _PULSE_CODE_MINAVAIL + 1;
+static const int c_quitCode = _PULSE_CODE_MINAVAIL + 2;
+
+MmrEventThread::MmrEventThread(mmr_context_t *context)
+ : QThread(),
+ m_mmrContext(context)
+{
+ if (Q_UNLIKELY((m_channelId = ChannelCreate(_NTO_CHF_DISCONNECT
+ | _NTO_CHF_UNBLOCK
+ | _NTO_CHF_PRIVATE)) == -1)) {
+ qFatal("MmrEventThread: Can't continue without a channel");
+ }
+
+ if (Q_UNLIKELY((m_connectionId = ConnectAttach(0, 0, m_channelId,
+ _NTO_SIDE_CHANNEL, 0)) == -1)) {
+ ChannelDestroy(m_channelId);
+ qFatal("MmrEventThread: Can't continue without a channel connection");
+ }
+
+ SIGEV_PULSE_INIT(&m_mmrEvent, m_connectionId, SIGEV_PULSE_PRIO_INHERIT, c_mmrCode, 0);
+}
+
+MmrEventThread::~MmrEventThread()
+{
+ // block until thread terminates
+ shutdown();
+
+ ConnectDetach(m_connectionId);
+ ChannelDestroy(m_channelId);
+}
+
+void MmrEventThread::run()
+{
+ int armResult = mmr_event_arm(m_mmrContext, &m_mmrEvent);
+ if (armResult > 0)
+ emit eventPending();
+
+ while (1) {
+ struct _pulse msg;
+ memset(&msg, 0, sizeof(msg));
+ int receiveId = MsgReceive(m_channelId, &msg, sizeof(msg), nullptr);
+ if (receiveId == 0) {
+ if (msg.code == c_mmrCode) {
+ emit eventPending();
+ } else if (msg.code == c_readCode) {
+ armResult = mmr_event_arm(m_mmrContext, &m_mmrEvent);
+ if (armResult > 0)
+ emit eventPending();
+ } else if (msg.code == c_quitCode) {
+ break;
+ } else {
+ qWarning() << Q_FUNC_INFO << "Unexpected pulse" << msg.code;
+ }
+ } else if (receiveId > 0) {
+ qWarning() << Q_FUNC_INFO << "Unexpected message" << msg.code;
+ } else {
+ qWarning() << Q_FUNC_INFO << "MsgReceive error" << strerror(errno);
+ }
+ }
+}
+
+void MmrEventThread::signalRead()
+{
+ MsgSendPulse(m_connectionId, SIGEV_PULSE_PRIO_INHERIT, c_readCode, 0);
+}
+
+void MmrEventThread::shutdown()
+{
+ MsgSendPulse(m_connectionId, SIGEV_PULSE_PRIO_INHERIT, c_quitCode, 0);
+
+ // block until thread terminates
+ wait();
+}