10#include <QtCore/QDebug>
18static const int c_armCode = _PULSE_CODE_MINAVAIL + 1;
21#if !defined(screen_register_event)
24 return MsgRegisterEvent(
event, -1);
29 return MsgUnregisterEvent(
event);
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");
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");
48 SIGEV_PULSE_INIT(&m_screenEvent, m_connectionId, SIGEV_PULSE_PRIO_INHERIT,
c_screenCode, 0);
50 ConnectDetach(m_connectionId);
51 ChannelDestroy(m_channelId);
52 qFatal(
"QQnxScreenEventThread: Can't continue without a registered event");
55 screen_notify(m_screenContext, SCREEN_NOTIFY_EVENT,
nullptr, &m_screenEvent);
63 screen_notify(m_screenContext, SCREEN_NOTIFY_EVENT,
nullptr,
nullptr);
65 ConnectDetach(m_connectionId);
66 ChannelDestroy(m_channelId);
71 qCDebug(lcQpaScreenEvents) <<
"Screen event thread started";
75 memset(&msg, 0,
sizeof(msg));
76 int receiveId = MsgReceive(m_channelId, &msg,
sizeof(msg),
nullptr);
79 else if (receiveId == 0)
81 else if (receiveId > 0)
82 qWarning() <<
"Unexpected message" << msg.code;
84 qWarning() <<
"MsgReceive error" << strerror(errno);
87 qCDebug(lcQpaScreenEvents) <<
"Screen event thread stopped";
92 MsgSendPulse(m_connectionId, SIGEV_PULSE_PRIO_INHERIT,
c_armCode,
count);
95void QQnxScreenEventThread::handleScreenPulse(
const struct _pulse &msg)
99 ++m_screenPulsesSinceLastArmPulse;
100 if (m_emitNeededOnNextScreenPulse) {
101 m_emitNeededOnNextScreenPulse =
false;
106void QQnxScreenEventThread::handleArmPulse(
const struct _pulse &msg)
108 if (msg.value.sival_int == 0 && m_screenPulsesSinceLastArmPulse == 0) {
109 m_emitNeededOnNextScreenPulse =
true;
111 m_screenPulsesSinceLastArmPulse = 0;
112 m_emitNeededOnNextScreenPulse =
false;
117void QQnxScreenEventThread::handlePulse(
const struct _pulse &msg)
120 handleScreenPulse(msg);
124 qWarning() <<
"Unexpected pulse" << msg.code;
127void QQnxScreenEventThread::shutdown()
129 MsgSendPulse(m_connectionId, SIGEV_PULSE_PRIO_INHERIT,
c_quitCode, 0);
131 qCDebug(lcQpaScreenEvents) <<
"Screen event thread shutdown begin";
136 qCDebug(lcQpaScreenEvents) <<
"Screen event thread shutdown end";
QQnxScreenEventThread(screen_context_t context)
void armEventsPending(int count)
bool wait(QDeadlineTimer deadline=QDeadlineTimer(QDeadlineTimer::Forever))
#define qCDebug(category,...)
GLenum GLenum GLsizei count
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)