From d45a900ae7c9072d1492892fbcf0414a9700f585 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 26 Mar 2006 16:53:05 +0000 Subject: [PATCH] Portability --- Makefile | 1 + main.cc | 12 +++-- remote.cc | 106 --------------------------------------- remote.h | 19 +++---- remotemvp.cc | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++ remotemvp.h | 50 +++++++++++++++++++ remotewin.cc | 62 +++++++++++++++++++++++ remotewin.h | 46 +++++++++++++++++ 8 files changed, 311 insertions(+), 121 deletions(-) create mode 100644 remotemvp.cc create mode 100644 remotemvp.h create mode 100644 remotewin.cc create mode 100644 remotewin.h diff --git a/Makefile b/Makefile index 6ddb8ed..a731f69 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,7 @@ OBJECTS1 = main.o command.o log.o tcp.o dsock.o thread.o timers.o i18n.o fonts/helvB24.o fonts/helvB18.o OBJECTS2 = remote.o led.o mtd.o video.o audio.o osd.o surface.o \ + remotemvp.o remotewin.o \ audiomvp.o audiowin.o \ videomvp.o videowin.o \ osdmvp.o osdwin.o \ diff --git a/main.cc b/main.cc index 01943fd..e9024a6 100644 --- a/main.cc +++ b/main.cc @@ -27,7 +27,6 @@ #include "defines.h" #include "log.h" -#include "remote.h" #include "mtd.h" #include "timers.h" #include "vdr.h" @@ -35,11 +34,13 @@ #include "command.h" #ifdef WIN32 + #include "remotewin.h" #include "ledwin.h" #include "osdwin.h" #include "audiowin.h" #include "videowin.h" #else + #include "remotemvp.h" #include "ledmvp.h" #include "osdmvp.h" #include "audiomvp.h" @@ -71,16 +72,17 @@ int main(int argc, char** argv) // Init global vars ------------------------------------------------------------------------------------------------ logger = new Log(); - remote = new Remote(); mtd = new Mtd(); timers = new Timers(); vdr = new VDR(); #ifdef WIN32 + remote = new RemoteWin(); led = new LedWin(); osd = new OsdWin(); audio = new AudioWin(); video = new VideoWin(); #else + remote = new RemoteMVP(); led = new LedMVP(); osd = new OsdMVP(); audio = new AudioMVP(); @@ -186,7 +188,11 @@ int main(int argc, char** argv) shutdown(1); } - success = led->init(remote->getDevice()); +#ifdef WIN32 + success = led->init(); +#else + success = led->init(((RemoteMVP*)remote)->getDevice()); +#endif if (success) { logger->log("Core", Log::INFO, "LED module initialised"); diff --git a/remote.cc b/remote.cc index ce04e10..aaa6d6f 100644 --- a/remote.cc +++ b/remote.cc @@ -26,10 +26,6 @@ Remote::Remote() { if (instance) return; instance = this; - initted = 0; - device = 0; - tv.tv_sec = 0; - tv.tv_usec = 0; remoteType = OLDREMOTE; } @@ -43,110 +39,8 @@ Remote* Remote::getInstance() return instance; } -int Remote::init(char* devName) -{ - if (initted) return 0; - initted = 1; - - device = open(devName, O_RDONLY); - if (device < 0) - { - initted = 0; - return 0; - } - - return 1; -} - -int Remote::shutdown() -{ - if (!initted) return 0; - initted = 0; - close(device); - device = 0; - return 1; -} - -int Remote::getDevice() -{ - if (!initted) return 0; - return device; -} - void Remote::setRemoteType(UCHAR newType) { if ((newType != OLDREMOTE) && (newType != NEWREMOTE)) return; remoteType = newType; } - -UCHAR Remote::getButtonPress(int waitType) -{ - /* how = 0 - block - how = 1 - start new wait - how = 2 - continue wait - how = 3 - no wait - */ - - unsigned long input; - struct timeval* passToSelect = NULL; - int retval; - fd_set readfds; - - if (waitType == 0) - { - passToSelect = NULL; - } - else if (waitType == 1) - { - tv.tv_sec = 1; - tv.tv_usec = 000000; - passToSelect = &tv; - } - else if (waitType == 2) - { - if ((tv.tv_sec == 0) && (tv.tv_usec == 0)) // protection in case timer = 0 - { - tv.tv_sec = 1; - tv.tv_usec = 000000; - } - passToSelect = &tv; - } - else if (waitType == 3) - { - tv.tv_sec = 0; - tv.tv_usec = 0; - passToSelect = &tv; - } - FD_ZERO(&readfds); - FD_SET(device, &readfds); - - retval = select(device + 1, &readfds, NULL, NULL, &tv); - // 0 = nothing happened - // 1 = data arrived (actually num of descriptors that changed) - // other value = signal or error - if (retval == 0) return NA_NONE; - if (retval == -1) return NA_SIGNAL; - - int count = read(device, &input, 4); - if (count == 4) - { - input = (0X00FF0000 & input) >> 16; - Log::getInstance()->log("Remote", Log::DEBUG, "Button %i", input); - - if (remoteType == OLDREMOTE) - { - if (input == VOLUMEDOWN) return DF_LEFT; - if (input == VOLUMEUP) return DF_RIGHT; - if (input == CHANNELUP) return DF_UP; - if (input == CHANNELDOWN) return DF_DOWN; - } - - return (UCHAR) input; - } - return NA_UNKNOWN; -} - -void Remote::clearBuffer() -{ - while(getButtonPress(3) != NA_NONE); -} diff --git a/remote.h b/remote.h index edba87a..806dece 100644 --- a/remote.h +++ b/remote.h @@ -22,8 +22,6 @@ #define REMOTE_H #include -#include -#include #include "defines.h" #include "log.h" @@ -32,15 +30,15 @@ class Remote { public: Remote(); - ~Remote(); + virtual ~Remote(); static Remote* getInstance(); - int init(char *devName); - int shutdown(); - int getDevice(); void setRemoteType(UCHAR type); - UCHAR getButtonPress(int how); - void clearBuffer(); + + virtual int init(char *devName)=0; + virtual int shutdown()=0; + virtual UCHAR getButtonPress(int how)=0; + virtual void clearBuffer()=0; // Not buttons const static UCHAR NA_NONE = 98; @@ -109,11 +107,8 @@ class Remote const static UCHAR OLDREMOTE = 1; const static UCHAR NEWREMOTE = 2; - private: + protected: static Remote* instance; - int initted; - int device; - struct timeval tv; UCHAR remoteType; }; diff --git a/remotemvp.cc b/remotemvp.cc new file mode 100644 index 0000000..634ee1e --- /dev/null +++ b/remotemvp.cc @@ -0,0 +1,136 @@ +/* + Copyright 2004-2005 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "remotemvp.h" + +RemoteMVP::RemoteMVP() +{ + if (instance) return; + initted = 0; + device = 0; + tv.tv_sec = 0; + tv.tv_usec = 0; +} + +RemoteMVP::~RemoteMVP() +{ +} + +int RemoteMVP::init(char* devName) +{ + if (initted) return 0; + initted = 1; + + device = open(devName, O_RDONLY); + if (device < 0) + { + initted = 0; + return 0; + } + + return 1; +} + +int RemoteMVP::shutdown() +{ + if (!initted) return 0; + initted = 0; + close(device); + device = 0; + return 1; +} + +int RemoteMVP::getDevice() +{ + if (!initted) return 0; + return device; +} + +UCHAR RemoteMVP::getButtonPress(int waitType) +{ + /* how = 0 - block + how = 1 - start new wait + how = 2 - continue wait + how = 3 - no wait + */ + + unsigned long input; + struct timeval* passToSelect = NULL; + int retval; + fd_set readfds; + + if (waitType == 0) + { + passToSelect = NULL; + } + else if (waitType == 1) + { + tv.tv_sec = 1; + tv.tv_usec = 000000; + passToSelect = &tv; + } + else if (waitType == 2) + { + if ((tv.tv_sec == 0) && (tv.tv_usec == 0)) // protection in case timer = 0 + { + tv.tv_sec = 1; + tv.tv_usec = 000000; + } + passToSelect = &tv; + } + else if (waitType == 3) + { + tv.tv_sec = 0; + tv.tv_usec = 0; + passToSelect = &tv; + } + FD_ZERO(&readfds); + FD_SET(device, &readfds); + + retval = select(device + 1, &readfds, NULL, NULL, &tv); + // 0 = nothing happened + // 1 = data arrived (actually num of descriptors that changed) + // other value = signal or error + if (retval == 0) return NA_NONE; + if (retval == -1) return NA_SIGNAL; + + int count = read(device, &input, 4); + if (count == 4) + { + input = (0X00FF0000 & input) >> 16; + Log::getInstance()->log("Remote", Log::DEBUG, "Button %i", input); + + if (remoteType == OLDREMOTE) + { + if (input == VOLUMEDOWN) return DF_LEFT; + if (input == VOLUMEUP) return DF_RIGHT; + if (input == CHANNELUP) return DF_UP; + if (input == CHANNELDOWN) return DF_DOWN; + } + + return (UCHAR) input; + } + return NA_UNKNOWN; +} + +void RemoteMVP::clearBuffer() +{ + while(getButtonPress(3) != NA_NONE); +} diff --git a/remotemvp.h b/remotemvp.h new file mode 100644 index 0000000..25c3844 --- /dev/null +++ b/remotemvp.h @@ -0,0 +1,50 @@ +/* + Copyright 2004-2005 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef REMOTEMVP_H +#define REMOTEMVP_H + +#include +#include +#include + +#include "defines.h" +#include "log.h" +#include "remote.h" + +class RemoteMVP : public Remote +{ + public: + RemoteMVP(); + ~RemoteMVP(); + + int init(char *devName); + int shutdown(); + int getDevice(); + UCHAR getButtonPress(int how); + void clearBuffer(); + + private: + int initted; + int device; + struct timeval tv; +}; + +#endif diff --git a/remotewin.cc b/remotewin.cc new file mode 100644 index 0000000..04e5475 --- /dev/null +++ b/remotewin.cc @@ -0,0 +1,62 @@ +/* + Copyright 2004-2005 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "remotewin.h" + +RemoteWin::RemoteWin() +{ + if (instance) return; + initted = 0; +} + +RemoteWin::~RemoteWin() +{ +} + +int RemoteWin::init(char* devName) +{ + if (initted) return 0; + initted = 1; + + return 1; +} + +int RemoteWin::shutdown() +{ + if (!initted) return 0; + initted = 0; + return 1; +} + +UCHAR RemoteWin::getButtonPress(int waitType) +{ + /* how = 0 - block + how = 1 - start new wait + how = 2 - continue wait + how = 3 - no wait + */ + + + return NA_UNKNOWN; +} + +void RemoteWin::clearBuffer() +{ +} diff --git a/remotewin.h b/remotewin.h new file mode 100644 index 0000000..1ec0047 --- /dev/null +++ b/remotewin.h @@ -0,0 +1,46 @@ +/* + Copyright 2004-2005 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef REMOTEWIN_H +#define REMOTEWIN_H + +#include + +#include "defines.h" +#include "log.h" +#include "remote.h" + +class RemoteWin : public Remote +{ + public: + RemoteWin(); + ~RemoteWin(); + + int init(char *devName); + int shutdown(); + int getDevice(); + UCHAR getButtonPress(int how); + void clearBuffer(); + + private: + int initted; +}; + +#endif -- 2.39.5