Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qqnxmediaeventthread.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 QNX Software Systems. All rights reserved.
2// Copyright (C) 2021 The Qt Company
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
6
7#include <QtCore/QDebug>
8
9#include <errno.h>
10#include <mm/renderer/types.h>
11#include <sys/neutrino.h>
12
13extern "C" {
14// ### Include mm/renderer/events.h once we have it
16 struct sigevent const *sev);
17}
18
20
21static const int c_mmrCode = _PULSE_CODE_MINAVAIL + 0;
22static const int c_readCode = _PULSE_CODE_MINAVAIL + 1;
23static const int c_quitCode = _PULSE_CODE_MINAVAIL + 2;
24
26 : QThread(),
27 m_mmrContext(context)
28{
29 if (Q_UNLIKELY((m_channelId = ChannelCreate(_NTO_CHF_DISCONNECT
30 | _NTO_CHF_UNBLOCK
31 | _NTO_CHF_PRIVATE)) == -1)) {
32 qFatal("QQnxMediaEventThread: Can't continue without a channel");
33 }
34
35 if (Q_UNLIKELY((m_connectionId = ConnectAttach(0, 0, m_channelId,
36 _NTO_SIDE_CHANNEL, 0)) == -1)) {
37 ChannelDestroy(m_channelId);
38 qFatal("QQnxMediaEventThread: Can't continue without a channel connection");
39 }
40
41 SIGEV_PULSE_INIT(&m_mmrEvent, m_connectionId, SIGEV_PULSE_PRIO_INHERIT, c_mmrCode, 0);
42}
43
45{
46 // block until thread terminates
47 shutdown();
48
49 ConnectDetach(m_connectionId);
50 ChannelDestroy(m_channelId);
51}
52
54{
55 int armResult = mmr_event_arm(m_mmrContext, &m_mmrEvent);
56 if (armResult > 0)
58
59 while (1) {
60 struct _pulse msg;
61 memset(&msg, 0, sizeof(msg));
62 int receiveId = MsgReceive(m_channelId, &msg, sizeof(msg), nullptr);
63 if (receiveId == 0) {
64 if (msg.code == c_mmrCode) {
66 } else if (msg.code == c_readCode) {
67 armResult = mmr_event_arm(m_mmrContext, &m_mmrEvent);
68 if (armResult > 0)
70 } else if (msg.code == c_quitCode) {
71 break;
72 } else {
73 qWarning() << Q_FUNC_INFO << "Unexpected pulse" << msg.code;
74 }
75 } else if (receiveId > 0) {
76 qWarning() << Q_FUNC_INFO << "Unexpected message" << msg.code;
77 } else {
78 qWarning() << Q_FUNC_INFO << "MsgReceive error" << strerror(errno);
79 }
80 }
81}
82
84{
85 MsgSendPulse(m_connectionId, SIGEV_PULSE_PRIO_INHERIT, c_readCode, 0);
86}
87
88void QQnxMediaEventThread::shutdown()
89{
90 MsgSendPulse(m_connectionId, SIGEV_PULSE_PRIO_INHERIT, c_quitCode, 0);
91
92 // block until thread terminates
93 wait();
94}
95
97
98#include "moc_qqnxmediaeventthread_p.cpp"
QQnxMediaEventThread(mmr_context_t *context)
bool wait(QDeadlineTimer deadline=QDeadlineTimer(QDeadlineTimer::Forever))
Definition qthread.cpp:1023
Combined button and popup list for selecting options.
static void * context
#define Q_UNLIKELY(x)
#define Q_FUNC_INFO
#define qWarning
Definition qlogging.h:166
#define qFatal
Definition qlogging.h:168
static const int c_readCode
static const int c_quitCode
int mmr_event_arm(mmr_context_t *ctxt, struct sigevent const *sev)
static QT_BEGIN_NAMESPACE const int c_mmrCode
typedefQT_BEGIN_NAMESPACE struct mmr_context mmr_context_t
static const int c_quitCode
#define emit