int main(int argc, char **argv) { QCoreApplication app(argc, argv); setlinebuf(stdout); setlinebuf(stderr); printf("triambience: starting daemon version %s\n", APPVERSION); switcher *sw; UinputEvPoll *uin; QThread *uinThread; uin = new UinputEvPoll(); sw = new switcher(); uinThread = new QThread(); int fd = uin->openDevice("/dev/input/event0"); if (fd == -1) { printf("triambience: error opening input device\n"); return EXIT_FAILURE; } uin->moveToThread(uinThread); QObject::connect(uin, SIGNAL(tristateChanged(QString)), sw, SLOT(switchTo(QString))); QObject::connect(uin, SIGNAL(pollingRequested()), uinThread, SLOT(start())); QObject::connect(uinThread, SIGNAL(started()), uin, SLOT(doPoll())); QObject::connect(uin, SIGNAL(finished()), uinThread, SLOT(quit()), Qt::DirectConnection); uin->requestPolling(fd); return app.exec(); }
void TokenQueueVEG::pollRequests() { std::list<TokenRequestVEG>::iterator it; double pollPeriod = 1.0; // max poll period. for(it = mRequests.begin(); it != mRequests.end();) { if (checkForRequest(it->mToken)) { /* clean it up and handle */ loadRequest(*it); it = mRequests.erase(it); } else { /* calculate desired poll period */ /* if less then current poll period, adjust */ it++; } } if (mRequests.size() > 0) { doPoll(pollPeriod); } }
void TokenQueue::queueRequest(uint32_t token, uint32_t basictype, uint32_t anstype, uint32_t usertype) { #ifdef ID_DEBUG std::cerr << "TokenQueue::queueRequest() Token: " << token << " Type: " << basictype; std::cerr << " AnsType: " << anstype << " UserType: " << usertype; std::cerr << std::endl; #endif TokenRequest req; req.mToken = token; req.mType = basictype; req.mAnsType = anstype; req.mUserType = usertype; gettimeofday(&req.mRequestTs, NULL); req.mPollTs = req.mRequestTs; mRequests.push_back(req); if (mRequests.size() == 1) { /* start the timer */ doPoll(0.25); } }
void EventProcessor::start() { LOG_TRACE("Starting event processor"); if (mPollThread.joinable()) { throw std::runtime_error("Poll thread already running"); } mPollThread = std::thread([this] () { while (!mShutdown.load()) { doPoll(); } }); }
void CPollingThread::run() { state = CSerialPortPrivate::STATE_REQUESTING; //CSerialPortPrivate::STATE_WRITING; forever { if (checkStop()) { break; } else if (!sp->getStatus()){ msleep(30); } else { doPoll(); } } qDebug() << "stop"; }
void Loop::runLoop ( ) { s_lastTime = 0; m_isDoingLoop = true; // . now loop forever waiting for signals // . but every second check for timer-based events for (;;) { g_errno = 0; if ( m_shutdown ) { // a msg if (m_shutdown == 1) { log(LOG_INIT,"loop: got SIGHUP or SIGTERM."); } else if (m_shutdown == 2) { log(LOG_INIT,"loop: got SIGBAD in thread."); } else { log(LOG_INIT,"loop: got SIGPWR."); } // . turn off interrupts here because it doesn't help to do // it in the thread // . TODO: turn off signals for sigbadhandler() // if thread got the signal, just wait for him to save all // Rdbs and then dump core if ( m_shutdown == 2 ) { //log(0,"Thread is saving & shutting down urgently."); //log("loop: Resuming despite thread crash."); //m_shutdown = 0; //goto BIGLOOP; } // otherwise, thread did not save, so we must do it log ( LOG_INIT ,"loop: Saving and shutting down urgently."); g_process.shutdown ( true ); } // // // THE HEART OF GB. process events/signals on FDs. // // doPoll(); } }
void CANWrap::pollCallback(int status, int events) { if (status == 0) { if (events & UV_WRITABLE) { const int err = doSend() < 0 ? errno : 0; m_pollEvents &= ~UV_WRITABLE; doPoll(); if (!m_sentCallback.IsEmpty()) { Nan::HandleScope scope; Local<Value> argv[1] = {Nan::New(err)}; m_sentCallback.Call(1, argv); } else { callErrorCallback(err); } } else if (events & UV_READABLE) { const int err = doRecv(); if (err < 0) { callErrorCallback(errno); } else if (!m_messageCallback.IsEmpty()) { Nan::HandleScope scope; Local<Value> argv[] = { Nan::New(m_recvBuffer.can_id), Nan::CopyBuffer(reinterpret_cast<char*>(&m_recvBuffer.data), m_recvBuffer.can_dlc) .ToLocalChecked()}; m_messageCallback.Call(2, argv); } } } else { callErrorCallback(status); } }
void TokenQueue::pollRequests() { double pollPeriod = 0.1; // max poll period. if (mRequests.empty()) { return; } TokenRequest req; req = mRequests.front(); mRequests.pop_front(); if (checkForRequest(req.mToken)) { /* clean it up and handle */ loadRequest(req); } else { // checkForRequest returns also true when the request cannot be found (e.g. removed by a timeout) //#define MAX_REQUEST_AGE 30 // /* drop old requests too */ // if (time(NULL) - req.mRequestTs.tv_sec < MAX_REQUEST_AGE) // { mRequests.push_back(req); // } // else // { // std::cerr << "TokenQueue::loadRequest(): "; // std::cerr << "Dropping old Token: " << req.mToken << " Type: " << req.mType; // std::cerr << std::endl; // } } if (mRequests.size() > 0) { doPoll(pollPeriod); } }
/* Main */ Tohkbd::Tohkbd(QObject *parent) : QObject(parent) { dbusRegistered = false; interruptsEnabled = false; vddEnabled = false; vkbLayoutIsTohkbd = false; currentActiveLayout = QString(); currentOrientationLock = QString(); keypadIsPresent = false; gpio_fd = -1; displayIsOn = false; keyIsPressed = false; keyRepeat = false; slideEventEmitted = false; taskSwitcherVisible = false; selfieLedOn = false; gpioInterruptCounter = 0; actualSailfishVersion = QString(); fix_CapsLock = !checkSailfishVersion("1.1.7.0"); capsLock = false; tohkbd2user = new ComKimmoliTohkbd2userInterface("com.kimmoli.tohkbd2user", "/", QDBusConnection::sessionBus(), this); tohkbd2user->setTimeout(2000); thread = new QThread(); worker = new Worker(); worker->moveToThread(thread); connect(worker, SIGNAL(gpioInterruptCaptured()), this, SLOT(handleGpioInterrupt())); connect(worker, SIGNAL(workRequested()), thread, SLOT(start())); connect(thread, SIGNAL(started()), worker, SLOT(doWork())); connect(worker, SIGNAL(finished()), thread, SLOT(quit()), Qt::DirectConnection); backlightTimer = new QTimer(this); backlightTimer->setSingleShot(true); connect(backlightTimer, SIGNAL(timeout()), this, SLOT(backlightTimerTimeout())); presenceTimer = new QTimer(this); presenceTimer->setInterval(2000); presenceTimer->setSingleShot(true); connect(presenceTimer, SIGNAL(timeout()), this, SLOT(presenceTimerTimeout())); repeatTimer = new QTimer(this); repeatTimer->setSingleShot(true); connect(repeatTimer, SIGNAL(timeout()), this, SLOT(repeatTimerTimeout())); /* do this automatically at startup */ setVddState(true); setInterruptEnable(true); uinputif = new UinputIf(); uinputif->openUinputDevice(); uinputevpoll = new UinputEvPoll(); evpollThread = new QThread(); uinputevpoll->moveToThread(evpollThread); connect(uinputevpoll, SIGNAL(capsLockLedChanged(bool)), this, SLOT(capsLockLedState(bool))); connect(uinputevpoll, SIGNAL(pollingRequested()), evpollThread, SLOT(start())); connect(evpollThread, SIGNAL(started()), uinputevpoll, SLOT(doPoll())); connect(uinputevpoll, SIGNAL(finished()), evpollThread, SLOT(quit()), Qt::DirectConnection); uinputevpoll->requestPolling(uinputif->getFd()); printf("uinputevpoll->requestPolling(uinputif->getFd());\n"); tca8424 = new tca8424driver(0x3b); keymap = new keymapping(); FKEYS.clear(); FKEYS.append(KEY_F1); FKEYS.append(KEY_F2); FKEYS.append(KEY_F3); FKEYS.append(KEY_F4); FKEYS.append(KEY_F5); FKEYS.append(KEY_F6); FKEYS.append(KEY_F7); FKEYS.append(KEY_F8); FKEYS.append(KEY_F9); FKEYS.append(KEY_F10); FKEYS.append(KEY_F11); FKEYS.append(KEY_F12); reloadSettings(); keymap->setLayout(masterLayout); if (currentActiveLayout.isEmpty()) changeActiveLayout(true); if (currentOrientationLock.isEmpty()) { changeOrientationLock(true); saveOrientation(); } checkKeypadPresence(); connect(keymap, SIGNAL(shiftChanged()), this, SLOT(handleShiftChanged())); connect(keymap, SIGNAL(ctrlChanged()), this, SLOT(handleCtrlChanged())); connect(keymap, SIGNAL(altChanged()), this, SLOT(handleAltChanged())); connect(keymap, SIGNAL(symChanged()), this, SLOT(handleSymChanged())); connect(keymap, SIGNAL(toggleCapsLock()), this, SLOT(toggleCapsLock())); connect(keymap, SIGNAL(keyPressed(QList< QPair<int, int> >)), this, SLOT(handleKeyPressed(QList< QPair<int, int> >))); connect(keymap, SIGNAL(keyReleased()), this, SLOT(handleKeyReleased())); connect(keymap, SIGNAL(bogusDetected()), tca8424, SLOT(reset())); }
bool poll(double timeout) { return doPoll(timeout); }