void wxSocketEventDispatcher::AddEvents(fd_set* readset, fd_set* writeset) { BeginFind(); wxHashTable::compatibility_iterator node = Next(); while (node) { // We have to store the next node here, because the event processing can // destroy the object before we call Next() wxHashTable::compatibility_iterator next_node = Next(); wxSocketEventDispatcherEntry* entry = (wxSocketEventDispatcherEntry*) node->GetData(); wxCHECK_RET(entry->m_socket, wxT("Critical: Processing a NULL socket in wxSocketEventDispatcher")); if (entry->m_fdInput != -1 && wxFD_ISSET(entry->m_fdInput, readset)) entry->m_socket->Detected_Read(); if (entry->m_fdOutput != -1 && wxFD_ISSET(entry->m_fdOutput, writeset)) entry->m_socket->Detected_Write();; node = next_node; } }
bool wxSelectSets::Handle(int fd, wxFDIOHandler& handler) const { #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for ( int n = 0; n < Max; n++ ) { if ( wxFD_ISSET(fd, (fd_set*) &m_fds[n]) ) { wxLogTrace(wxSelectDispatcher_Trace, wxT("Got %s event on fd %d"), ms_names[n], fd); (handler.*ms_handlers[n])(); // callback can modify sets and destroy handler // this forces that one event can be processed at one time return true; } } return false; }
bool wxSelectSets::SetFD(int fd, int flags) { wxCHECK_MSG( fd >= 0, false, wxT("invalid descriptor") ); #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for ( int n = 0; n < Max; n++ ) { if ( flags & ms_flags[n] ) { wxFD_SET(fd, &m_fds[n]); } else if ( wxFD_ISSET(fd, (fd_set*) &m_fds[n]) ) { wxFD_CLR(fd, &m_fds[n]); } } return true; }
bool wxSelectSets::HasFD(int fd) const { for ( int n = 0; n < Max; n++ ) { if ( wxFD_ISSET(fd, (fd_set*) &m_fds[n]) ) return true; } return false; }
bool wxSelectSets::Handle(int fd, wxFDIOHandler& handler) const { for ( int n = 0; n < Max; n++ ) { if ( wxFD_ISSET(fd, (fd_set*) &m_fds[n]) ) { wxLogTrace(wxSelectDispatcher_Trace, wxT("Got %s event on fd %d"), ms_names[n], fd); (handler.*ms_handlers[n])(); // callback can modify sets and destroy handler // this forces that one event can be processed at one time return true; } } return false; }
bool wxSelectSets::SetFD(int fd, int flags) { wxCHECK_MSG( fd >= 0, false, wxT("invalid descriptor") ); for ( int n = 0; n < Max; n++ ) { if ( flags & ms_flags[n] ) { wxFD_SET(fd, &m_fds[n]); } else if ( wxFD_ISSET(fd, (fd_set*) &m_fds[n]) ) { wxFD_CLR(fd, &m_fds[n]); } } return true; }
bool wxSelectSets::HasFD(int fd) const { #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ for ( int n = 0; n < Max; n++ ) { if ( wxFD_ISSET(fd, (fd_set*) &m_fds[n]) ) return true; } return false; }
void* wxJoystickThread::Entry() { struct js_event j_evt; fd_set read_fds; struct timeval time_out = {0, 0}; wxFD_ZERO(&read_fds); while (true) { if (TestDestroy()) break; // We use select when either polling or 'blocking' as even in the // blocking case we need to check TestDestroy periodically if (m_polling) time_out.tv_usec = m_polling * 1000; else time_out.tv_usec = 10 * 1000; // check at least every 10 msec in blocking case wxFD_SET(m_device, &read_fds); select(m_device+1, &read_fds, NULL, NULL, &time_out); if (wxFD_ISSET(m_device, &read_fds)) { memset(&j_evt, 0, sizeof(j_evt)); read(m_device, &j_evt, sizeof(j_evt)); //printf("time: %d\t value: %d\t type: %d\t number: %d\n", // j_evt.time, j_evt.value, j_evt.type, j_evt.number); if ((j_evt.type & JS_EVENT_AXIS) && (j_evt.number < wxJS_MAX_AXES)) { // Ignore invalid axis. if ( j_evt.number >= wxJS_MAX_AXES ) { wxLogDebug(wxS("Invalid axis index %d in joystick message."), j_evt.number); continue; } if ( (m_axe[j_evt.number] + m_threshold < j_evt.value) || (m_axe[j_evt.number] - m_threshold > j_evt.value) ) { m_axe[j_evt.number] = j_evt.value; switch (j_evt.number) { case wxJS_AXIS_X: m_lastposition.x = j_evt.value; SendEvent(wxEVT_JOY_MOVE, j_evt.time); break; case wxJS_AXIS_Y: m_lastposition.y = j_evt.value; SendEvent(wxEVT_JOY_MOVE, j_evt.time); break; case wxJS_AXIS_Z: SendEvent(wxEVT_JOY_ZMOVE, j_evt.time); break; default: SendEvent(wxEVT_JOY_MOVE, j_evt.time); // TODO: There should be a way to indicate that the event // is for some other axes. break; } } } if ( (j_evt.type & JS_EVENT_BUTTON) && (j_evt.number < wxJS_MAX_BUTTONS) ) { if (j_evt.value) { m_buttons |= (1 << j_evt.number); SendEvent(wxEVT_JOY_BUTTON_DOWN, j_evt.time, j_evt.number); } else { m_buttons &= ~(1 << j_evt.number); SendEvent(wxEVT_JOY_BUTTON_UP, j_evt.time, j_evt.number); } } } } close(m_device); return NULL; }
void* wxJoystickThread::Entry() { struct js_event j_evt; fd_set read_fds; struct timeval time_out = {0, 0}; wxFD_ZERO(&read_fds); while (true) { if (TestDestroy()) break; // We use select when either polling or 'blocking' as even in the // blocking case we need to check TestDestroy periodically if (m_polling) time_out.tv_usec = m_polling * 1000; else time_out.tv_usec = 10 * 1000; // check at least every 10 msec in blocking case wxFD_SET(m_device, &read_fds); select(m_device+1, &read_fds, NULL, NULL, &time_out); if (wxFD_ISSET(m_device, &read_fds)) { memset(&j_evt, 0, sizeof(j_evt)); read(m_device, &j_evt, sizeof(j_evt)); //printf("time: %d\t value: %d\t type: %d\t number: %d\n", // j_evt.time, j_evt.value, j_evt.type, j_evt.number); wxJoystickEvent jwx_event; if (j_evt.type & JS_EVENT_AXIS) { m_axe[j_evt.number] = j_evt.value; switch (j_evt.number) { case wxJS_AXIS_X: m_lastposition.x = j_evt.value; jwx_event.SetEventType(wxEVT_JOY_MOVE); break; case wxJS_AXIS_Y: m_lastposition.y = j_evt.value; jwx_event.SetEventType(wxEVT_JOY_MOVE); break; case wxJS_AXIS_Z: jwx_event.SetEventType(wxEVT_JOY_ZMOVE); break; default: jwx_event.SetEventType(wxEVT_JOY_MOVE); // TODO: There should be a way to indicate that the event // is for some other axes. break; } } if (j_evt.type & JS_EVENT_BUTTON) { if (j_evt.value) { m_buttons |= (1 << j_evt.number); jwx_event.SetEventType(wxEVT_JOY_BUTTON_DOWN); } else { m_buttons &= ~(1 << j_evt.number); jwx_event.SetEventType(wxEVT_JOY_BUTTON_UP); } jwx_event.SetButtonChange(j_evt.number); jwx_event.SetTimestamp(j_evt.time); jwx_event.SetJoystick(m_joystick); jwx_event.SetButtonState(m_buttons); jwx_event.SetPosition(m_lastposition); jwx_event.SetZPosition(m_axe[3]); jwx_event.SetEventObject(m_catchwin); if (m_catchwin) m_catchwin->AddPendingEvent(jwx_event); } } } close(m_device); return NULL; }