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
qqnxscreeneventthread.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 QNX Software Systems. All rights reserved.
2// Copyright (C) 2011 - 2012 Research In Motion
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#include "qqnxglobal.h"
6
9
10#include <QtCore/QDebug>
11
12#include <errno.h>
13#include <unistd.h>
14
15#include <cctype>
16
17static const int c_screenCode = _PULSE_CODE_MINAVAIL + 0;
18static const int c_armCode = _PULSE_CODE_MINAVAIL + 1;
19static const int c_quitCode = _PULSE_CODE_MINAVAIL + 2;
20
21#if !defined(screen_register_event)
22int screen_register_event(screen_context_t, struct sigevent *event)
23{
24 return MsgRegisterEvent(event, -1);
25}
26
27int screen_unregister_event(struct sigevent *event)
28{
29 return MsgUnregisterEvent(event);
30}
31#endif
32
34 : QThread()
35 , m_screenContext(context)
36{
37 m_channelId = ChannelCreate(_NTO_CHF_DISCONNECT | _NTO_CHF_UNBLOCK | _NTO_CHF_PRIVATE);
38 if (m_channelId == -1) {
39 qFatal("QQnxScreenEventThread: Can't continue without a channel");
40 }
41
42 m_connectionId = ConnectAttach(0, 0, m_channelId, _NTO_SIDE_CHANNEL, 0);
43 if (m_connectionId == -1) {
44 ChannelDestroy(m_channelId);
45 qFatal("QQnxScreenEventThread: Can't continue without a channel connection");
46 }
47
48 SIGEV_PULSE_INIT(&m_screenEvent, m_connectionId, SIGEV_PULSE_PRIO_INHERIT, c_screenCode, 0);
49 if (screen_register_event(m_screenContext, &m_screenEvent) == -1) {
50 ConnectDetach(m_connectionId);
51 ChannelDestroy(m_channelId);
52 qFatal("QQnxScreenEventThread: Can't continue without a registered event");
53 }
54
55 screen_notify(m_screenContext, SCREEN_NOTIFY_EVENT, nullptr, &m_screenEvent);
56}
57
59{
60 // block until thread terminates
61 shutdown();
62
63 screen_notify(m_screenContext, SCREEN_NOTIFY_EVENT, nullptr, nullptr);
64 screen_unregister_event(&m_screenEvent);
65 ConnectDetach(m_connectionId);
66 ChannelDestroy(m_channelId);
67}
68
70{
71 qCDebug(lcQpaScreenEvents) << "Screen event thread started";
72
73 while (1) {
74 struct _pulse msg;
75 memset(&msg, 0, sizeof(msg));
76 int receiveId = MsgReceive(m_channelId, &msg, sizeof(msg), nullptr);
77 if (receiveId == 0 && msg.code == c_quitCode)
78 break;
79 else if (receiveId == 0)
80 handlePulse(msg);
81 else if (receiveId > 0)
82 qWarning() << "Unexpected message" << msg.code;
83 else
84 qWarning() << "MsgReceive error" << strerror(errno);
85 }
86
87 qCDebug(lcQpaScreenEvents) << "Screen event thread stopped";
88}
89
91{
92 MsgSendPulse(m_connectionId, SIGEV_PULSE_PRIO_INHERIT, c_armCode, count);
93}
94
95void QQnxScreenEventThread::handleScreenPulse(const struct _pulse &msg)
96{
97 Q_UNUSED(msg);
98
99 ++m_screenPulsesSinceLastArmPulse;
100 if (m_emitNeededOnNextScreenPulse) {
101 m_emitNeededOnNextScreenPulse = false;
103 }
104}
105
106void QQnxScreenEventThread::handleArmPulse(const struct _pulse &msg)
107{
108 if (msg.value.sival_int == 0 && m_screenPulsesSinceLastArmPulse == 0) {
109 m_emitNeededOnNextScreenPulse = true;
110 } else {
111 m_screenPulsesSinceLastArmPulse = 0;
112 m_emitNeededOnNextScreenPulse = false;
114 }
115}
116
117void QQnxScreenEventThread::handlePulse(const struct _pulse &msg)
118{
119 if (msg.code == c_screenCode)
120 handleScreenPulse(msg);
121 else if (msg.code == c_armCode)
122 handleArmPulse(msg);
123 else
124 qWarning() << "Unexpected pulse" << msg.code;
125}
126
127void QQnxScreenEventThread::shutdown()
128{
129 MsgSendPulse(m_connectionId, SIGEV_PULSE_PRIO_INHERIT, c_quitCode, 0);
130
131 qCDebug(lcQpaScreenEvents) << "Screen event thread shutdown begin";
132
133 // block until thread terminates
134 wait();
135
136 qCDebug(lcQpaScreenEvents) << "Screen event thread shutdown end";
137}
QQnxScreenEventThread(screen_context_t context)
bool wait(QDeadlineTimer deadline=QDeadlineTimer(QDeadlineTimer::Forever))
Definition qthread.cpp:1023
static void * context
#define qWarning
Definition qlogging.h:166
#define qFatal
Definition qlogging.h:168
#define qCDebug(category,...)
GLenum GLenum GLsizei count
struct _cl_event * event
static const int c_screenCode
static const int c_armCode
static const int c_quitCode
int screen_register_event(screen_context_t, struct sigevent *event)
int screen_unregister_event(struct sigevent *event)
#define Q_EMIT
#define Q_UNUSED(x)