46 #include "private/qthread_p.h" 49 #include <bps/event.h> 53 #ifdef QEVENTDISPATCHERBLACKBERRY_DEBUG 54 #define qEventDispatcherDebug qDebug() << QThread::currentThread() 56 #define qEventDispatcherDebug QT_NO_QDEBUG_MACRO() 96 : count(0), readfds(0), writefds(0), exceptfds(0)
115 bool firstReady = (ioData->
count == 0);
118 if (io_events & BPS_IO_INPUT) {
124 if (io_events & BPS_IO_OUTPUT) {
130 if (io_events & BPS_IO_EXCEPT) {
144 qWarning(
"QEventDispatcherBlackberry: bps_event_create failed");
150 result = bps_push_event(event);
152 qWarning(
"QEventDispatcherBlackberry: bps_push_event failed");
153 bps_event_destroy(event);
166 int result = bps_initialize();
168 qFatal(
"QEventDispatcherBlackberry: bps_initialize failed");
173 qWarning(
"QEventDispatcherBlackberry: bps_channel_create failed");
181 qWarning(
"QEventDispatcherBlackberry: bps_register_domain failed");
189 qWarning(
"QEventDispatcherBlackberry: bps_channel_destroy failed");
228 int sockfd = notifier->
socket();
234 qWarning() <<
"QEventDispatcherBlackberry: cannot register QSocketNotifier (fd too high)" 243 bps_remove_fd(sockfd);
248 io_events |= BPS_IO_INPUT;
252 io_events |= BPS_IO_OUTPUT;
257 io_events |= BPS_IO_EXCEPT;
261 const int result = bps_add_fd(sockfd, io_events, &
bpsIOHandler,
d->ioData.data());
263 qWarning() <<
"QEventDispatcherBlackberry: bps_add_fd failed";
273 int sockfd = notifier->
socket();
278 qWarning() <<
"QEventDispatcherBlackberry: cannot unregister QSocketNotifier" << sockfd;
287 int result = bps_remove_fd(sockfd);
289 qWarning() <<
"QEventDispatcherBlackberry: bps_remove_fd failed" << sockfd;
291 const int io_events =
ioEvents(sockfd);
294 result = bps_add_fd(sockfd, io_events, &
bpsIOHandler,
d->ioData.data());
296 qWarning(
"QEventDispatcherBlackberry: bps_add_fd error");
302 return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
310 bps_event_t *held_event = 0;
311 (void)bps_get_event(&held_event, 0);
324 d->ioData->count = 0;
325 d->ioData->readfds = readfds;
326 d->ioData->writefds = writefds;
327 d->ioData->exceptfds = exceptfds;
339 bps_event_t *
event = 0;
340 unsigned int eventCount = 0;
360 int holding_channel =
d->holding_channel;
361 if ((
d->loop_level > 1) &&
362 Q_UNLIKELY(bps_channel_create(&holding_channel, 0) != BPS_SUCCESS)) {
363 qWarning(
"QEventDispatcherBlackberry: bps_channel_create failed");
364 holding_channel = -1;
368 int timeoutTotal = -1;
371 int timeoutLeft = timeoutTotal;
386 if (eventCount > 0) {
392 if (
Q_LIKELY(holding_channel != -1)) {
400 if (timeoutTotal != -1) {
402 timeoutLeft = timeoutTotal
409 if (
d->timerList.timerWait(tnext)) {
411 if (timeoutNext < timeoutLeft || timeoutTotal == -1) {
412 timeoutTotal = timeoutLeft = timeoutNext;
424 const int result = bps_get_event(&
event, timeoutLeft);
426 qWarning(
"QEventDispatcherBlackberry: bps_get_event failed");
437 if (
Q_LIKELY(holding_channel != 1) &&
438 Q_UNLIKELY(bps_channel_push_event(holding_channel,
event) != BPS_SUCCESS)) {
439 qWarning(
"QEventDispatcherBlackberry: bps_channel_push_event failed");
447 const unsigned int maximumEventCount = 12;
448 if (
Q_UNLIKELY((eventCount > maximumEventCount && timeoutLeft == 0)
453 if (
Q_LIKELY(holding_channel != -1)) {
464 if ((holding_channel !=
d->holding_channel) &&
466 Q_UNLIKELY(bps_channel_destroy(holding_channel) != BPS_SUCCESS)) {
467 qWarning(
"QEventDispatcherBlackberry: bps_channel_destroy failed");
471 return d->ioData->count;
477 if (
d->wakeUps.testAndSetAcquire(0, 1)) {
480 if (
Q_LIKELY(bps_channel_push_event(
d->bps_channel, event) == BPS_SUCCESS))
483 bps_event_destroy(event);
485 qWarning(
"QEventDispatcherBlackberry: wakeUp failed");
495 if (FD_ISSET(fd, &
d->sn_vec[0].enabled_fds))
496 io_events |= BPS_IO_INPUT;
498 if (FD_ISSET(fd, &
d->sn_vec[1].enabled_fds))
499 io_events |= BPS_IO_OUTPUT;
501 if (FD_ISSET(fd, &
d->sn_vec[2].enabled_fds))
502 io_events |= BPS_IO_EXCEPT;
~QEventDispatcherBlackberryPrivate()
bool filterEvent(void *message)
Sends message through the event filter that was set by setEventFilter().
#define QT_END_NAMESPACE
This macro expands to.
QEventDispatcherBlackberryPrivate * d
void wakeUp()
Wakes up the event loop.
void registerSocketNotifier(QSocketNotifier *notifier)
Registers notifier with the event loop.
~QEventDispatcherBlackberry()
QEventDispatcherBlackberry(QObject *parent=0)
BpsChannelScopeSwitcher(int scopeChannel)
void unregisterSocketNotifier(QSocketNotifier *notifier)
Unregisters notifier from the event dispatcher.
The QObject class is the base class of all Qt objects.
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
static bool isMonotonic()
Returns true if this is a monotonic clock, false otherwise.
Type type() const
Returns the socket event type specified to the constructor.
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
void registerSocketNotifier(QSocketNotifier *notifier)
Registers notifier with the event loop.
~BBScopedLoopLevelCounter()
BBScopedLoopLevelCounter(QEventDispatcherBlackberryPrivate *p)
void awake()
This signal is emitted after the event loop returns from a function that could block.
static int bpsUnblockDomain
int processThreadWakeUp(int nsel)
static int timevalToMillisecs(const timeval &tv)
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
static void destroyHeldBpsEvent(int holding_channel)
~BpsChannelScopeSwitcher()
#define qEventDispatcherDebug
Q_CORE_EXPORT void qFatal(const char *,...)
void aboutToBlock()
This signal is emitted before the event loop calls a function that could block.
QObject * parent() const
Returns a pointer to the parent object.
#define Q_UNLIKELY(x)
Hints to the compiler that the enclosed condition, expr, is likely to evaluate to false...
#define Q_LIKELY(x)
Hints to the compiler that the enclosed condition, expr, is likely to evaluate to true...
QEventDispatcherBlackberryPrivate()
static int bpsIOHandler(int fd, int io_events, void *data)
int fetchAndStoreRelaxed(int newValue)
Atomic fetch-and-store.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, timeval *timeout)
void unregisterSocketNotifier(QSocketNotifier *notifier)
Unregisters notifier from the event dispatcher.
int socket() const
Returns the socket identifier specified to the constructor.
#define forever
This macro is provided for convenience for writing infinite loops.