]> git.vomp.tv Git - vompclient-marten.git/commitdiff
Portability
authorChris Tallon <chris@vomp.tv>
Sun, 26 Mar 2006 16:53:05 +0000 (16:53 +0000)
committerChris Tallon <chris@vomp.tv>
Sun, 26 Mar 2006 16:53:05 +0000 (16:53 +0000)
Makefile
main.cc
remote.cc
remote.h
remotemvp.cc [new file with mode: 0644]
remotemvp.h [new file with mode: 0644]
remotewin.cc [new file with mode: 0644]
remotewin.h [new file with mode: 0644]

index 6ddb8ed00fd4629acf135c44e36cf3c9038b26b6..a731f69320d83d4f8abc2435feb891a0ab5216fa 100644 (file)
--- 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 01943fd90d6e3f2da9131a631910b2e79af2bf7b..e9024a64415236da9f9efd45a754711185e578de 100644 (file)
--- 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"
 #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");
index ce04e10f2ed16e8b571763c81b915542fe830579..aaa6d6f267760747727f3dc3b871ed249e2fdfd6 100644 (file)
--- 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);
-}
index edba87a966e92d5fd8e0695c74f68546398cc10b..806dece7bd06428412417417ca60360e56334f3b 100644 (file)
--- a/remote.h
+++ b/remote.h
@@ -22,8 +22,6 @@
 #define REMOTE_H
 
 #include <stdio.h>
-#include <unistd.h>
-#include <fcntl.h>
 
 #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 (file)
index 0000000..634ee1e
--- /dev/null
@@ -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 (file)
index 0000000..25c3844
--- /dev/null
@@ -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 <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#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 (file)
index 0000000..04e5475
--- /dev/null
@@ -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 (file)
index 0000000..1ec0047
--- /dev/null
@@ -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 <stdio.h>
+
+#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