Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmsinputthread.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2012 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
00031  **************************************************************************/
00032 
00033 #include "mmsinput/mmsinputthread.h"
00034 #include "mmsinput/mmsinputdfbhandler.h"
00035 #include "mmsinput/mmsinputx11handler.h"
00036 #include "mmsinput/mmsinputlishandler.h"
00037 #include "mmsgui/fb/mmsfb.h"
00038 
00039 extern MMSFB *mmsfb;
00040 
00041 
00042 MMSInputThread::MMSInputThread(class MMSInputManager *manager, MMS_INPUT_DEVICE device, int inputinterval) {
00043     this->manager = manager;
00044     this->handler = NULL;
00045     this->device = device;
00046     this->inputinterval = inputinterval;
00047 }
00048 
00049 MMSInputThread::~MMSInputThread() {
00050     delete handler;
00051 }
00052 
00053 void MMSInputThread::threadMain() {
00054     MMSInputEvent           event, lastevent;
00055     time_t                  aclock;
00056     struct timeval          tv;
00057     double                  currtime, lasttime = 0;
00058     int                     lkcnt = 0, skip = 0;
00059 
00060     lastevent.type = MMSINPUTEVENTTYPE_NONE;
00061 
00062     if (this->handler == NULL) {
00063         if (mmsfb->getBackend()==MMSFB_BE_DFB) {
00064             this->handler = new MMSInputDFBHandler(this->device);
00065         }
00066         else
00067         if (mmsfb->getBackend()==MMSFB_BE_FBDEV) {
00068             this->handler = new MMSInputLISHandler(this->device);
00069         }
00070         else
00071         if (mmsfb->getBackend()==MMSFB_BE_X11) {
00072             this->handler = new MMSInputX11Handler(this->device);
00073         }
00074 
00075 
00076 /*      if(config->getOutputType()!= MMS_OT_X11FB) {
00077             //create dfb input backend
00078             this->handler = new MMSInputDFBHandler(this->device);
00079         } else {
00080             #ifdef __HAVE_XLIB__
00081                 if(mmsfb->getBackend()==MMSFB_BACKEND_X11) {
00082                     this->handler = new MMSInputX11Handler(this->device);
00083                 } else {
00084                     //allthough we have xlib directfb is used;
00085                     this->handler = new MMSInputDFBHandler(this->device);
00086                 }
00087             #else
00088                 //we have no xlib so its dfb x11
00089                 this->handler = new MMSInputDFBHandler(this->device);
00090             #endif
00091         }
00092 */
00093     }
00094 
00095     while (1) {
00096         this->handler->grabEvents(&event);
00097 
00098         if (event.type == MMSINPUTEVENTTYPE_KEYPRESS) {
00099             if (this->inputinterval > 0) {
00100                 /* here we stop to fast input devices */
00101 
00102                 /* get time in milliseconds */
00103                 time(&aclock);
00104                 gettimeofday(&tv, NULL);
00105                 currtime = ((double) aclock) * 1000 + ((double) tv.tv_usec) / 1000;
00106 
00107                 if (event.key == lastevent.key) {
00108                     /* check if input comes slow enough */
00109                     if (currtime < lasttime + ((!skip)?this->inputinterval:(this->inputinterval/2))) {
00110                         /* to fast, ignore the input */
00111                         lkcnt++;
00112                         continue;
00113                     }
00114                 }
00115                 else
00116                     lkcnt = 0;
00117 
00118                 /* save the last event */
00119                 lastevent = event;
00120 
00121                 /* check if the last input is to old */
00122                 skip=0;
00123                 if (lkcnt > 0) {
00124                     if (currtime > lasttime + this->inputinterval*2)
00125                         /* to old */
00126                         lkcnt = 0;
00127                     else
00128                         /* the next loop we want the input faster */
00129                         skip = 1;
00130                 }
00131 
00132                 /* save current time */
00133                 lasttime = currtime;
00134             }
00135         }
00136 
00137         /* to the input manager */
00138         this->manager->handleInput(&event);
00139 
00140         /* call garbage handler */
00141         callGarbageHandler();
00142     }
00143 }
00144 

Generated by doxygen