void Sted::Handle (Event& e) { if (e.eventType == KeyEvent) { if (e.len != 0) { char c = e.keystring[0]; switch (c) { case '\010': case '\177': if (editor->Dot() != editor->Mark()) { editor->DeleteSelection(); } else { editor->DeleteText(-1); } break; case '\015': InsertChar('\n'); break; default: if (!iscntrl(c)) { InsertChar(c); } break; } } } else if (e.eventType == DownEvent) { GetRelative(e.x, e.y, editor); editor->Select(editor->Locate(e.x, e.y)); do { editor->ScrollToView(e.x, e.y); editor->SelectMore(editor->Locate(e.x, e.y)); Poll(e); GetRelative(e.x, e.y, editor); } while (e.leftmouse); } }
/// <summary> /// Is laptop ? /// </summary> /// <returns></returns> BOOL PowerSchemes::IsLaptop() { BOOL bLaptop = FALSE; Poll(); if(isPsValid) { // BatteryFlag // // The battery charge status. This member can contain one or more of the following flags. // 1: High¡ªthe battery capacity is at more than 66 percent // 2: Low¡ªthe battery capacity is at less than 33 percent // 4: Critical¡ªthe battery capacity is at less than five percent // 8: Charging // 128: No system battery // 255: Unknown status¡ªunable to read the battery flag information int BatStat = (int)pwrStat.BatteryFlag; if (BatStat == 128) { bLaptop = FALSE; } else { bLaptop = TRUE; } } return bLaptop; }
bool SocketImpl::Connect(const SocketAddress& address, const std::chrono::seconds& timeout /*= std::chrono::seconds(0)*/) { if (INVALID_SOCKET == m_sockfd) Init(AF_INET); if (timeout.count() > 0) SetBlocking(false); bool bResult = false; do { if (SOCKET_ERROR == connect(m_sockfd, address.GetAddress(), address.GetLength())) { if (timeout.count() == 0) break; int err = WSAGetLastError(); if (WSAEINPROGRESS != err && WSAEWOULDBLOCK != err && WSAEISCONN != err) break; if (!Poll(timeout, SELECT_READ | SELECT_WRITE | SELECT_ERROR)) break; if (GetSocketError() != 0) break; } bResult = true; } while (0); if (timeout.count() > 0) SetBlocking(true); return bResult; }
void LongPollManager::handleGotLPServer() { auto reply = qobject_cast<QNetworkReply*> (sender ()); reply->deleteLater (); if (reply->error () != QNetworkReply::NoError) { qWarning () << Q_FUNC_INFO << "error getting poll server:" << reply->errorString (); QTimer::singleShot (15000, this, SLOT (start ())); return; } const auto& data = QJson::Parser ().parse (reply); const auto& map = data.toMap () ["response"].toMap (); LPKey_ = map ["key"].toString (); LPServer_ = map ["server"].toString (); LPTS_ = map ["ts"].toULongLong (); LPURLTemplate_ = QUrl ("http://" + LPServer_); LPURLTemplate_.addQueryItem ("act", "a_check"); LPURLTemplate_.addQueryItem ("key", LPKey_); LPURLTemplate_.addQueryItem ("mode", "2"); emit listening (); Poll (); }
/* _clean_fd * - Remove any extraneous packets sitting on the fd buffer */ static void _clean_fd(int fd) { int rv; struct pollfd ufds; char buffer[IPMIPOWER_PACKET_BUFLEN]; while (1) { ufds.fd = fd; ufds.events = POLLIN; ufds.revents = 0; /* Must use Poll, we may go outside of the fd numbers * that Select is capable of using */ Poll(&ufds, 1, 0); if (ufds.revents & POLLIN) { rv = Recvfrom(fd, (uint8_t *)buffer, IPMIPOWER_PACKET_BUFLEN, 0, NULL, NULL); if (rv == 0) break; } else break; ierr_dbg("_clean_fd: removed packet: %d", rv); } }
void Thread::addPollFd(int fd, int action, void (*handler)(void*, void*), void* p, void* q) { if (fd == -1) return; for (iPoll i = plist.begin(); i != plist.end(); ++i) { if ((i->fd == fd) && (i->action == action)) return; } plist.push_back(Poll(fd, action, handler, p, q)); if (npfd == maxpfd) { int n = (maxpfd == 0) ? 4 : maxpfd * 2; //TODO: delete old pfd pfd = new struct pollfd[n]; maxpfd = n; } ++npfd; int idx = 0; for (iPoll i = plist.begin(); i != plist.end(); ++i, ++idx) { pfd[idx].fd = i->fd; pfd[idx].events = i->action; } }
bool EventFsm::Update() { UpdateEvents(); Poll(); return true; }
boolean StringBrowser::LeftButtonDown (Event& e) { boolean status = false; if (DoubleClicked(e)) { subject->SetValue(done[0]); status = true; } else if (uniqueSel) { if (Selections() == 0) { Select(Locate(e.x, e.y)); } else { Unselect(Selection()); if (!e.shift) { Select(Locate(e.x, e.y)); } } } else { lastdot = lastmark = Locate(e.x, e.y); if (Selected(lastdot) && e.shift) { Unselect(lastdot); do { ScrollToView(e.x, e.y); UpdateSelection(lastdot, Locate(e.x, e.y), Plain); Poll(e); } while (e.leftmouse); } else { if (!e.shift) { UnselectAll(); } Select(lastdot); do { ScrollToView(e.x, e.y); UpdateSelection(lastdot, Locate(e.x, e.y), highlight); Poll(e); } while (e.leftmouse); } } Note(e); if (singleClick) { subject->SetValue(done[0]); status = true; } return status; }
void EEPROM::SetAddr(int addr) { //Sets EEPROM internal address pointer. Poll(); //Poll until EEPROM acknowledges SendByte(addr >> 8); //Send address high byte SendByte(addr); //Send address low byte }
void LuaHostWindows::WaitForDebuggerConnection() { while (!IsConnected()) { Poll(); OsSleep(50); } }
void LightGun::Poke(const uint data) { if (arcade) { shifter = ~data & 0x1; stream = (Poll() >= LIGHT_SENSOR ? 0x40 : 0x00); stream |= 0x10 | fire; } }
void FamilyTrainer::Poke(const uint data) { if (input) Poll(); if ((data & 0x1) == 0) { output = state >> 8 & 0x1E; }
/*bool RegionFilteredSensor::projectSensorToBody(){ std::vector <position> vertices; sbody->getGeometryVertices(&vertices); } */ void BodySensor::outputSensorReadings(QTextStream & qts){ SensorOutput * so = Poll(); int sNum = SensorOutputTools::getSensorReadingNumber(so); qts << "Body "; for(int sInd = 0; sInd < sNum; sInd ++){ qts << " "; qts << so->sensorReading[sInd]; } qts << endl; }
void FieldStringEditor::do_grab_scroll(Event& e) { Window* w = canvas->window(); Cursor* c = w->cursor(); w->cursor(kit_->hand_cursor()); int origin = display->Left(0, 0); int width = display->Width(); Poll(e); int x = e.x; do { origin += e.x - x; origin = Math::min( 0, Math::max(Math::min(0, xmax - width), origin) ); display->Scroll(0, origin, ymax); x = e.x; Poll(e); } while (e.middlemouse); w->cursor(c); }
Burger::Mouse::Mouse(GameApp *pGameApp) : m_pGameApp(pGameApp), m_MouseLock(), m_pHIDManager(NULL), m_uMiceCount(0), m_uX(0), m_uY(0), m_uBoundsX(640), m_uBoundsY(480), m_iDeltaX(0), m_iDeltaY(0), m_iMouseWheelX(0), m_iMouseWheelY(0), m_uButtons(0), m_uPressedButtons(0), m_bButtonSwap(FALSE), m_uArrayStart(0), m_uArrayEnd(0) { // Back link to the game app CFMutableDictionaryRef pDictionary = Globals::CreateHIDDictionary(kHIDPage_GenericDesktop,kHIDUsage_GD_Mouse); if (pDictionary != NULL) { m_pHIDManager = IOHIDManagerCreate(kCFAllocatorDefault,kIOHIDOptionsTypeNone); if (m_pHIDManager != NULL) { CFRunLoopRef pRunLoop = CFRunLoopGetCurrent(); IOHIDManagerRegisterDeviceMatchingCallback(m_pHIDManager,EnumerationCallback,this); IOHIDManagerScheduleWithRunLoop(m_pHIDManager,pRunLoop,g_BurgerMouse); IOHIDManagerSetDeviceMatching(m_pHIDManager,pDictionary); IOHIDManagerOpen(m_pHIDManager,kIOHIDOptionsTypeNone); // Handle the run loops Poll(this); // All scanned! IOHIDManagerUnscheduleFromRunLoop(m_pHIDManager,pRunLoop,g_BurgerMouse); IOHIDManagerRegisterDeviceMatchingCallback(m_pHIDManager,NULL, NULL); // Open all the located devices Word i; DeviceStruct *pRat = m_Mice; for (i = 0; i < m_uMiceCount; i++) { IOHIDDeviceRef pDevice = pRat->m_pDevice; if (IOHIDDeviceOpen(pDevice,kIOHIDOptionsTypeNone) != kIOReturnSuccess) { pRat->m_pDevice = NULL; // Hmm. Toast it pRat->m_bUnplugged = FALSE; // Don't attempt to reconnect } else { IOHIDDeviceRegisterRemovalCallback(pDevice,DisconnectionCallback,this); IOHIDDeviceRegisterInputValueCallback(pDevice,InputCallback,this); IOHIDDeviceScheduleWithRunLoop(pDevice,pRunLoop,g_BurgerMouse); } ++pRat; } pGameApp->AddRoutine(Poll,NULL,this,RunQueue::PRIORITY_MOUSE); } CFRelease(pDictionary); } }
void RegionFilteredSensor::outputSensorReadings(QTextStream & qts){ SensorOutput * so = Poll(); int sNum = SensorOutputTools::getSensorReadingNumber(so); qts << "Filtered "; qts << pos[0][0] << " " << pos[0][1] << " " << pos[0][2] << " " << pos[1][0] << " " << pos[1][1] << " " << pos[1][2]; for(int sInd = 0; sInd < sNum; sInd ++){ qts << " "; qts << so->sensorReading[sInd]; } qts << endl; }
void Pad::Poke(const uint data) { const uint prev = strobe; strobe = data & 0x1; if (prev > strobe) { Poll(); stream = state ^ 0xFF; } }
// Handle callback from LineTerm when new input/output needs to be displayed NS_IMETHODIMP mozXMLTerminal::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData) { nsCOMPtr<mozILineTermAux> lineTermAux = do_QueryInterface(aSubject); PR_ASSERT(lineTermAux != nsnull); PR_ASSERT(lineTermAux.get() == mLineTermAux.get()); return Poll(); }
void main(void) #endif { USB_STATUS status = USB_OK; /* Initialize the current platform. Call for the _bsp_platform_init which is specific to each processor family */ _bsp_platform_init(); #ifdef MCU_MK70F12 sci2_init(); #else sci1_init(); #endif TimerInit(); /* Init polling global variable */ POLL_init(); DisableInterrupts; status = _usb_host_init(HOST_CONTROLLER_NUMBER, /* Use value in header file */ MAX_FRAME_SIZE, /* Frame size per USB spec */ &host_handle); /* Returned pointer */ if(status != USB_OK) { printf("\nUSB Host Initialization failed! STATUS: 0x%x",(unsigned int) status); fflush(stdout); exit(1); } /* ** Since we are going to act as the host driver, register the driver ** information for wanted class/subclass/protocols */ status = _usb_host_driver_info_register(host_handle, (void *)DriverInfoTable); if(status != USB_OK) { printf("\nUSB Initialization driver info failed! STATUS: 0x%x", status); fflush(stdout); exit(1); } EnableInterrupts; printf("\nUSB Printer Host Demo\nWaiting for USB printer to be attached...\n"); fflush(stdout); for(;;) { Poll(); Printer_Task(NULL); __RESET_WATCHDOG(); /* feeds the dog */ } /* Loop forever */ /* Please make sure that you never leave main */ #ifdef __GNUC__ return 0; #endif }
void poll_do(int sockfd, int family) { struct pollfd clients[OPEN_MAX]; char buf[MAXLINE]; int clientfd, client_len = (family == AF_INET) ? 16 : 28; struct sockaddr client_addr; int i, max_index, nready; clients[0].fd = sockfd; clients[0].events = POLLRDNORM; for ( i = 1; i < OPEN_MAX; ++i) clients[i].fd = -1; for ( ; ;) { nready = Poll(clients, max_index+1, INFTIM); if (clients[0].revents & POLLRDNORM) { clientfd = Accept(sockfd, &client_addr, client_len); for (i = 1; i < OPEN_MAX; ++i) { if (clients[i].fd < 0) { clients[i].fd == clientfd; break; } } if (i == OPEN_MAX) err_quit("too many clients"); if (i > max_index) max_index = i; if (--nready <= 0) continue; } for (i = 1; i <= max_index; ++i) { if ( (clientfd = clients[i].fd) < 0) continue; if (clients[i].revents & (POLLRDNORM | POLLERR)) { if ( (n = read(clientfd, buf, MAXLINE)) < 0) { if (errno == ECONNRESET) { Close(clientfd); clients[i].fd = -1; } else err_sys("read error"); } else if (n == 0) { Close(clientfd); clients[i].fd = -1; } else Write(clientfd, buf, n); if (--nready <= 0) continue; } } } }
void PassiveLogSource::Loop() { for (;;) { Poll(); Signal(); if (LogSource::AtEnd()) break; // sub 16ms sleep, depends on available hardware for accuracy boost::this_thread::sleep_for(m_microsecondInterval); } }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { int wmId, wmEvent; switch (message) { case WM_TIMER: Poll(); return 0; case WM_SYSCOMMAND: wmId = LOWORD(wParam); // Remember, these are... wmEvent = HIWORD(wParam); // ...different for Win32! switch (wmId) { case SC_MINIMIZE: if (MinimizetoTray) return ShowWindow(hWnd, SW_HIDE); else return (DefWindowProc(hWnd, message, wParam, lParam)); break; default: return (DefWindowProc(hWnd, message, wParam, lParam)); } case WM_CLOSE: PostQuitMessage(0); break; default: return (DefWindowProc(hWnd, message, wParam, lParam)); } return (0); }
/// <summary> /// This functions returns percent battery life indicating how much /// battery life is left. Common usage of this function is that it should /// be called when running on battery only. This can be called when running /// on AC power as well. /// </summary> /// <returns>Returns -1 if function fails</returns> INT PowerSchemes::GetPercentBatteryLife() { Poll(); if (!isPsValid) { return -1; } INT BatLife = (INT)pwrStat.BatteryLifePercent; // 0-100% return BatLife; }
void StringBrowser::GrabScroll (Event& e) { int y = e.y; Cursor* origCursor = GetCursor(); SetCursor(handCursor); do { ScrollBy(0, y - e.y); y = e.y; Poll(e); } while (e.middlemouse); SetCursor(origCursor); }
uint LightGun::Peek(uint) { if (!arcade) { uint data = (Poll() >= LIGHT_SENSOR ? 0x0 : 0x8); return data | fire; } else { const uint data = stream; stream >>= shifter; return data & 0x1; } }
void FieldStringEditor::do_select(Event& e) { int origin = display->Left(0, 0); int width = display->Width(); Poll(e); start_ = display->LineIndex(0, e.x); do { if (e.x < 0) { origin = Math::min(0, origin - e.x); } else if (e.x > xmax) { origin = Math::max( xmax - width, origin - (e.x - xmax) ); } display->Scroll(0, origin, ymax); index_ = display->LineIndex(0, e.x); DoSelect(start_, index_); Poll(e); } while (e.leftmouse); SelectionManager* s = e.display()->primary_selection(); s->own( new SelectionCallback(FieldStringEditor)(this, &FieldStringEditor::cut) ); }
void Menu::Popup (register Event& e, Interactor*& item) { register Interactor* i; World* w; Coord wx, wy; e.GetAbsolute(w, wx, wy); /* force computation of (xoff, yoff) */ Config(w); w->InsertPopup(this, wx - xoff, wy - yoff); i = nil; for (;;) { Read(e); if (e.eventType == UpEvent) { break; } if (e.target->Parent() == layout) { i = e.target; i->Handle(e); if (e.eventType == UpEvent) { break; } if (!persistent) { Poll(e); if (e.x < 0 || e.x > xmax || e.y < 0 || e.y > ymax) { i = nil; break; } } } else if (e.target == this && e.eventType == OffEvent) { i = nil; if (!persistent) { break; } } } if (i != nil) { xoff = e.x; yoff = e.y; e.target->GetRelative(xoff, yoff, this); } cur = i; item = i; e.GetAbsolute(wx, wy); e.target = w; e.x = wx; e.y = wy; w->Remove(this); Flush(); }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : usb_class_cdc_os_event_wait * Returned Value : OS_EVENT_OK if get event * Comments : * This serves particularly for event waiting on BM when timeout equals 0, which means infinite wait. * *END*--------------------------------------------------------------------*/ uint32_t usb_class_cdc_os_event_wait(os_event_handle handle, uint32_t bitmask, uint32_t flag, uint32_t timeout) { uint32_t ret; #if (OS_ADAPTER_ACTIVE_OS == OS_ADAPTER_MQX) /* USB stack running on MQX */ ret = OS_Event_wait(handle, bitmask, flag, timeout); #else while(OS_EVENT_OK != (ret = OS_Event_wait(handle, bitmask, flag, timeout))) { /* Actually we want to run _usb_khci_task() */ Poll(); } #endif return ret; }
bool emSvgServerModel::Cycle() { bool busy; busy=emModel::Cycle(); Poll(IsTimeSliceAtEnd()?0:10); if ( FirstRunningJob || FirstWaitingJob || !WriteBuf.IsEmpty() || (Process.IsRunning() && !ProcSvgInstCount) ) busy=true; return busy; }
void TextEditor::GrabScroll (Event& e) { e.target->GetRelative(e.x, e.y, this); int y = e.y; int x = e.x; Cursor* origCursor = GetCursor(); SetCursor(handCursor); do { ScrollBy(0, y - e.y); y = e.y; x = e.x; Poll(e); } while (e.middlemouse); SetCursor(origCursor); }