void InputThread::deviceReport( void* inContext, IOReturn inResult, void* inSender, IOHIDValueRef inIOHIDValueRef ) { IOHIDDeviceRef deviceRef = ( IOHIDDeviceRef ) inSender; InputThread* currentThread = ( InputThread* ) inContext; if( inResult == kIOReturnSuccess && CFGetTypeID( deviceRef ) == IOHIDDeviceGetTypeID() ) { IOHIDElementRef elementRef = IOHIDValueGetElement( inIOHIDValueRef ); int usagePage = IOHIDElementGetUsagePage( elementRef ); int usage = IOHIDElementGetUsage( elementRef ); int value = IOHIDValueGetIntegerValue( inIOHIDValueRef ); if( usagePage == kHIDPage_GenericDesktop || usagePage == kHIDPage_KeyboardOrKeypad || usagePage == kHIDPage_Button ) { if( usagePage == kHIDPage_GenericDesktop && usage == 60 ) return; else if( usagePage == kHIDPage_KeyboardOrKeypad && ( usage <= 3 || usage > 231 ) ) return; switch( currentThread->deviceType() ) { case GluonInput::MouseDevice: if( usagePage == kHIDPage_GenericDesktop ) { if( value == 0 ) return; emit currentThread->relAxisMoved( usage, value ); } break; case GluonInput::JoystickDevice: if( usagePage == kHIDPage_GenericDesktop ) { if( value == 0 ) return; currentThread->absAxisMoved( usage, value ); } break; default: currentThread->buttonStateChanged( usage, value ); break; } } } }
int main(int argc, char *argv[]) { QApplication app(argc, argv); app.setQuitOnLastWindowClosed(false); GnuplotConnection gnuplot; { QStringList arguments; for(int i=1;i<argc;i++) { arguments << argv[i]; } gnuplot.start("gnuplot", arguments); gnuplot.waitForStarted(); if(gnuplot.state()==QProcess::NotRunning) { fprintf(stderr, "Error %d starting gnuplot\n",gnuplot.error()); return 1; } else { //printf("Gnuplot Running\n"); } gnuplot.write("set term svg\n"); } MainWindow mainwindow; mainwindow.gnuplot= &gnuplot; MainWindow::connect(&gnuplot, SIGNAL(plot(QByteArray)), &mainwindow, SLOT(plot(QByteArray)) ); mainwindow.show(); InputThread input; input.setGnuplotConnection(&gnuplot); MainWindow::connect(&input, SIGNAL(x11WindowTitle(QString)), &mainwindow, SLOT(x11WindowTitle(QString))); input.start(); app.exec(); }
int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; InputThread keyThread; // //Set key modifiers // keyThread.addModifierKey(HOTKEY_MOD1); //Win // keyThread.addModifierKey(HOTKEY_MOD2); //Alt // keyThread.addModifierKey(HOTKEY_MOD3); //Ctrl //Associate fullscreen show with hotkey QObject::connect(&keyThread, SIGNAL(sigOnKeyPressed(int,bool)), &w, SLOT(onRecieveKeyInput(int,bool)), Qt::QueuedConnection); //Start listening for hotkey presses (This occurs on a separate thread) keyThread.start(); return a.exec(); //Make sure the keyboard input thread finishes keyThread.quit(); keyThread.wait(); }
int main ( int argc, char **argv ) { char optChar; int xCnt, yCnt, xInt, yInt; xCnt = 3; yCnt = 10; xInt = 1000; yInt = 3000; while ( (optChar = ::getopt(argc, argv, "hi:o:x:y:")) != EOF ) { switch ( optChar ) { case 'h': usage(); return 0; break; case 'i': xInt = atoi(optarg); break; case 'o': yInt = atoi(optarg); break; case 'x': xCnt = atoi(optarg); break; case 'y': yCnt = atoi(optarg); break; default: break; } } ::signal(SIGINT, &sigHandler); ::signal(SIGTERM, &sigHandler); LogFacility::InitThreaded(); LogFacility::AddLogStream("stdout", "thtest", &std::cout); StringQueue * queue = new StringQueue(); ThreadSet ithreads, othreads; InputThread * ith = NULL; std::string iname = "InputThread"; for ( int i = 0; i < xCnt; i++ ) { std::string thname = iname; thname.append("_").append(StringUtils::ToString(i)); ith = new InputThread(queue, xInt); ith->threadName(thname); ith->init(); ith->start(); ithreads.insert(ith); } OutputThread * oth = NULL; std::string oname = "OutputThread"; for ( int i = 0; i < yCnt; i++ ) { std::string thname = oname; thname.append("_").append(StringUtils::ToString(i)); oth = new OutputThread(queue, yInt); oth->threadName(thname); oth->init(); oth->start(); othreads.insert(oth); } size_t qsz; while ( ! Alarm ) { sleep(2); qsz = queue->size(); LogFacility::LogMessage("Queue size is " + StringUtils::ToString(qsz)); } LogFacility::LogMessage("Alarm received, stopping threads"); ThreadSet::iterator tIter; uint64_t ss = 100000000; for ( tIter = ithreads.begin(); tIter != ithreads.end(); ++tIter ) { InputThread * ith = (InputThread*) *tIter; ith->setAlarm(); LogFacility::LogMessage("Killing " + ith->threadName()); EventManager::NanoSleep(ss); delete ith; } ithreads.clear(); for ( tIter = othreads.begin(); tIter != othreads.end(); ++tIter ) { OutputThread * oth = (OutputThread*) *tIter; oth->setAlarm(); LogFacility::LogMessage("Killing " + oth->threadName()); EventManager::NanoSleep(ss); delete oth; } othreads.clear(); while ( ! queue->empty() ) { char * s; if ( queue->pop(s) ) free(s); } delete queue; return 0; }