]> git.vomp.tv Git - vompclient-marten.git/commitdiff
Portability
authorChris Tallon <chris@vomp.tv>
Sun, 26 Mar 2006 21:29:06 +0000 (21:29 +0000)
committerChris Tallon <chris@vomp.tv>
Sun, 26 Mar 2006 21:29:06 +0000 (21:29 +0000)
14 files changed:
Makefile
afeed.h
afeedr.h
defines.h
player.h
thread.cc
thread.h
threadp.cc [new file with mode: 0644]
threadp.h [new file with mode: 0644]
threadwin.cc [new file with mode: 0644]
threadwin.h [new file with mode: 0644]
timers.h
vconnect.h
vfeed.h

index eef915820f38586b30045e102d3762126ca8e0f5..3a47e85ade2f266def85770f9a2eb9754f9f4a36 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -21,18 +21,13 @@ OBJECTS1 = main.o command.o log.o tcp.o dsock.o thread.o timers.o i18n.o
            vchannellist.o vwelcome.o vvideolive.o vvideorec.o vepgsettimer.o           \
            vchannelselect.o vserverselect.o vconnect.o voptions.o vepg.o               \
            widget.o wselectlist.o wjpeg.o wsymbol.o wbutton.o woptionbox.o wtextbox.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                                                     \
-           ledmvp.o ledwin.o                                                           \
-           mtdmvp.o mtdwin.o                                                           \
-           videomvp.o videowin.o                                                       \
-           audiomvp.o audiowin.o                                                       \
-           osdmvp.o osdwin.o                                                           \
-           surfacemvp.o surfacewin.o
-
-OBJECTS = $(OBJECTS1) $(OBJECTS2)
+           fonts/helvB24.o fonts/helvB18.o                                             \
+           remote.o led.o mtd.o video.o audio.o osd.o surface.o
+
+OBJECTSMVP = threadp.o   remotemvp.o ledmvp.o mtdmvp.o videomvp.o audiomvp.o osdmvp.o surfacemvp.o
+OBJECTSWIN = threadwin.o remotewin.o ledwin.o mtdwin.o videowin.o audiowin.o osdwin.o surfacewin.o
+
+OBJECTS = $(OBJECTS1) $(OBJECTSMVP)
 
 .PHONY: clean fresh all install strip
 
diff --git a/afeed.h b/afeed.h
index dfd4c61ec4e79f3550e6f0edd9d756e1b79299f9..d5739fb7efabb743046fea577954adada6f94b6f 100644 (file)
--- a/afeed.h
+++ b/afeed.h
 #include <time.h>
 
 #include "log.h"
-#include "thread.h"
 #include "demuxer.h"
 #include "callback.h"
 
-class AFeed : public Thread
+#ifdef WIN32
+#include "threadwin.h"
+#else
+#include "threadp.h"
+#endif
+
+class AFeed : public Thread_TYPE
 {
   public:
     AFeed(Callback* tcb);
index 0d9d29e78543ac7e67cc53c003f419e1d06d3ca2..8f12e206afc22624c102103d647105fe95abc44b 100644 (file)
--- a/afeedr.h
+++ b/afeedr.h
 #include <time.h>
 
 #include "log.h"
-#include "thread.h"
 #include "callback.h"
 #include "stream.h"
 
-class AFeedR : public Thread
+#ifdef WIN32
+#include "threadwin.h"
+#else
+#include "threadp.h"
+#endif
+
+class AFeedR : public Thread_TYPE
 {
   public:
     AFeedR(Callback* tcb, Stream* tstream);
index f95d2862200f33e6904b839f5cbc90da0134cb80..d4c13bc5aea221540bed46591dd4af401fe11a06 100644 (file)
--- a/defines.h
+++ b/defines.h
@@ -37,6 +37,7 @@ void MILLISLEEP(ULONG a);
 #ifdef WIN32
 
   #define Surface_TYPE SurfaceWin
+  #define Thread_TYPE ThreadWin
 
   #define SNPRINTF _snprintf
   #define VSNPRINTF _vsnprintf
@@ -48,6 +49,7 @@ void MILLISLEEP(ULONG a);
 #else
 
   #define Surface_TYPE SurfaceMVP
+  #define Thread_TYPE ThreadP
 
   #define SNPRINTF snprintf
   #define VSNPRINTF vsnprintf
index 24f5e180588354874502ca11ccf8f10fa277b00f..d7a5ec7ef786acfdf7a74a8e6329c09c5f97b67e 100644 (file)
--- a/player.h
+++ b/player.h
 #include "vfeed.h"
 #include "afeed.h"
 #include "remote.h"
-#include "thread.h"
 #include "vdr.h"
 #include "callback.h"
 #include "message.h"
 #include "messagequeue.h"
 
-class Player : public Thread, public Callback
+#ifdef WIN32
+#include "threadwin.h"
+#else
+#include "threadp.h"
+#endif
+
+class Player : public Thread_TYPE, public Callback
 {
   public:
     Player(MessageQueue* messageQueue, UCHAR isRecording, UCHAR isRadio);
index 6e210a547dc48e51ad90c91743ea132db7aba6c6..7644075cab531533a45522439e1c3ca54062c60f 100644 (file)
--- a/thread.cc
+++ b/thread.cc
 
 #include "thread.h"
 
-// Undeclared functions, only for use in this file to start the thread
-void threadInternalStart(void *arg)
-{
-  // I don't want signals
-  sigset_t sigs;
-  sigfillset(&sigs);
-  pthread_sigmask(SIG_BLOCK, &sigs, NULL);
-
-  Thread *t = (Thread *)arg;
-  t->threadInternalStart2();
-}
-
-void Thread::threadInternalStart2()
-{
-  threadMethod();
-}
-
-int Thread::threadStart()
-{
-  pthread_cond_init(&threadCond, NULL);
-  pthread_mutex_init(&threadCondMutex, NULL);
-
-  threadActive = 1;
-  if (pthread_create(&pthread, NULL, (void*(*)(void*))threadInternalStart, (void *)this) == -1) return 0;
-  return 1;
-}
-
-void Thread::threadStop()
-{
-  threadActive = 0;
-  // Signal thread here in case it's waiting
-  threadSignal();
-  pthread_join(pthread, NULL);
-  this->threadPostStopCleanup();
-}
-
-void Thread::threadCancel()
-{
-  threadActive = 0;
-  pthread_cancel(pthread);
-  pthread_join(pthread, NULL);
-  this->threadPostStopCleanup();
-}
-
-void Thread::threadCheckExit()
-{
-  if (!threadActive) pthread_exit(NULL);
-}
-
 char Thread::threadIsActive()
 {
   return threadActive;
 }
 
-void Thread::threadLock()
-{
-  pthread_mutex_lock(&threadCondMutex);
-}
-
-void Thread::threadUnlock()
-{
-  pthread_mutex_unlock(&threadCondMutex);
-}
-
-void Thread::threadSignal()
-{
-  pthread_mutex_lock(&threadCondMutex);
-  pthread_cond_signal(&threadCond);
-  pthread_mutex_unlock(&threadCondMutex);
-}
-
-void Thread::threadSignalNoLock()
-{
-  pthread_cond_signal(&threadCond);
-}
-
-void Thread::threadWaitForSignal()
-{
-  pthread_cond_wait(&threadCond, &threadCondMutex);
-}
-
-void Thread::threadWaitForSignalTimed(struct timespec* ts)
-{
-  pthread_cond_timedwait(&threadCond, &threadCondMutex, ts);
-}
-
-void Thread::threadSetKillable()
+void Thread::threadInternalStart2()
 {
-  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
-  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+  threadMethod();
 }
index 544d3455d8685f8e7e297438354d53450aae500a..12da488090841693f32709805c0fbdd71cdcee39 100644 (file)
--- a/thread.h
+++ b/thread.h
 #ifndef THREAD_H
 #define THREAD_H
 
-#include <pthread.h>
-#include <signal.h>
-
 class Thread
 {
   protected:
-    // Override this method in derived classes
+    // Override this method in classes derived from ThreadP or ThreadWin
     virtual void threadMethod()=0;
     virtual void threadPostStopCleanup()=0;
 
     // Methods to use from outside the thread
-    int threadStart();    // start the thread. threadMethod() will be called in derived class
-    void threadStop();    // stop the thread nicely. thread will be stopped when it next calls threadCheckExit()
-    void threadCancel();  // stop thread immediately. thread will be stopped at the next cancellation point
-    void threadSignal();  // releases a thread that has called threadWaitForSignal
-    void threadSignalNoLock();  // same as above but without locking guarantees. probably not a good idea.
+    virtual int threadStart()=0;    // start the thread. threadMethod() will be called in derived class
+    virtual void threadStop()=0;    // stop the thread nicely. thread will be stopped when it next calls threadCheckExit()
+    virtual void threadCancel()=0;  // stop thread immediately. thread will be stopped at the next cancellation point
+    virtual void threadSignal()=0;  // releases a thread that has called threadWaitForSignal
+    virtual void threadSignalNoLock()=0;  // same as above but without locking guarantees. probably not a good idea.
     char threadIsActive(); // returns 1 if thread has been started but not stop() or cancel() 'd
 
     // Methods to use from inside the thread
-    void threadSetKillable();    // allows threadCancel() to work
-    void threadCheckExit();      // terminates thread if threadStop() has been called
-    void threadWaitForSignal();  // pauses thread until threadSignal() is called
-    void threadWaitForSignalTimed(struct timespec*);  // pauses thread until threadSignal() is called or timer expires
-    void threadLock();           // locks the mutex used for internal cond/signal stuff
-    void threadUnlock();         // unlocks.
+    virtual void threadSetKillable()=0;    // allows threadCancel() to work
+    virtual void threadCheckExit()=0;      // terminates thread if threadStop() has been called
+    virtual void threadWaitForSignal()=0;  // pauses thread until threadSignal() is called
+    virtual void threadWaitForSignalTimed(struct timespec*)=0;  // pauses thread until threadSignal() is called or timer expires
+    virtual void threadLock()=0;           // locks the mutex used for internal cond/signal stuff
+    virtual void threadUnlock()=0;         // unlocks.
 
     // Internal bits and pieces
 
-  private:
+  protected:
     char threadActive;
-    pthread_t pthread;
-    pthread_cond_t threadCond;
-    pthread_mutex_t threadCondMutex;
 
   public:
     void threadInternalStart2();
diff --git a/threadp.cc b/threadp.cc
new file mode 100644 (file)
index 0000000..019c54d
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+    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 "threadp.h"
+
+// Undeclared functions, only for use in this file to start the thread
+void threadPInternalStart(void *arg)
+{
+  // I don't want signals
+  sigset_t sigs;
+  sigfillset(&sigs);
+  pthread_sigmask(SIG_BLOCK, &sigs, NULL);
+
+  Thread *t = (Thread *)arg;
+  t->threadInternalStart2();
+}
+
+int ThreadP::threadStart()
+{
+  pthread_cond_init(&threadCond, NULL);
+  pthread_mutex_init(&threadCondMutex, NULL);
+
+  threadActive = 1;
+  if (pthread_create(&pthread, NULL, (void*(*)(void*))threadPInternalStart, (void *)this) == -1) return 0;
+  return 1;
+}
+
+void ThreadP::threadStop()
+{
+  threadActive = 0;
+  // Signal thread here in case it's waiting
+  threadSignal();
+  pthread_join(pthread, NULL);
+  this->threadPostStopCleanup();
+}
+
+void ThreadP::threadCancel()
+{
+  threadActive = 0;
+  pthread_cancel(pthread);
+  pthread_join(pthread, NULL);
+  this->threadPostStopCleanup();
+}
+
+void ThreadP::threadCheckExit()
+{
+  if (!threadActive) pthread_exit(NULL);
+}
+
+void ThreadP::threadLock()
+{
+  pthread_mutex_lock(&threadCondMutex);
+}
+
+void ThreadP::threadUnlock()
+{
+  pthread_mutex_unlock(&threadCondMutex);
+}
+
+void ThreadP::threadSignal()
+{
+  pthread_mutex_lock(&threadCondMutex);
+  pthread_cond_signal(&threadCond);
+  pthread_mutex_unlock(&threadCondMutex);
+}
+
+void ThreadP::threadSignalNoLock()
+{
+  pthread_cond_signal(&threadCond);
+}
+
+void ThreadP::threadWaitForSignal()
+{
+  pthread_cond_wait(&threadCond, &threadCondMutex);
+}
+
+void ThreadP::threadWaitForSignalTimed(struct timespec* ts)
+{
+  pthread_cond_timedwait(&threadCond, &threadCondMutex, ts);
+}
+
+void ThreadP::threadSetKillable()
+{
+  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
+  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
+}
diff --git a/threadp.h b/threadp.h
new file mode 100644 (file)
index 0000000..5461f86
--- /dev/null
+++ b/threadp.h
@@ -0,0 +1,59 @@
+/*
+    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 THREADP_H
+#define THREADP_H
+
+#include <pthread.h>
+#include <signal.h>
+
+#include "thread.h"
+
+class ThreadP : public Thread
+{
+  protected:
+    // Override this method in derived classes
+    virtual void threadMethod()=0;
+    virtual void threadPostStopCleanup()=0;
+
+    // Methods to use from outside the thread
+    int threadStart();    // start the thread. threadMethod() will be called in derived class
+    void threadStop();    // stop the thread nicely. thread will be stopped when it next calls threadCheckExit()
+    void threadCancel();  // stop thread immediately. thread will be stopped at the next cancellation point
+    void threadSignal();  // releases a thread that has called threadWaitForSignal
+    void threadSignalNoLock();  // same as above but without locking guarantees. probably not a good idea.
+
+    // Methods to use from inside the thread
+    void threadSetKillable();    // allows threadCancel() to work
+    void threadCheckExit();      // terminates thread if threadStop() has been called
+    void threadWaitForSignal();  // pauses thread until threadSignal() is called
+    void threadWaitForSignalTimed(struct timespec*);  // pauses thread until threadSignal() is called or timer expires
+    void threadLock();           // locks the mutex used for internal cond/signal stuff
+    void threadUnlock();         // unlocks.
+
+    // Internal bits and pieces
+
+  private:
+    pthread_t pthread;
+    pthread_cond_t threadCond;
+    pthread_mutex_t threadCondMutex;
+};
+
+#endif
diff --git a/threadwin.cc b/threadwin.cc
new file mode 100644 (file)
index 0000000..e42b989
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+    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 "threadwin.h"
+
+// Undeclared functions, only for use in this file to start the thread
+DWORD WINAPI threadInternalStart(void *arg)
+{
+  Thread *t = (Thread *)arg;
+  t->threadInternalStart2();
+  return 0;
+}
+
+int ThreadP::threadStart()
+{
+  threadCond = CreateEvent(NULL,FALSE,FALSE,NULL);
+  if (threadCond == NULL) return 0;
+  threadCondMutex = CreateMutex(NULL,TRUE,NULL);
+  if (threadCondMutex == NULL)
+  {
+    CloseHandle(threadCond);
+    return 0;
+  }
+
+  threadActive = 1;
+  DWORD threadId;
+  pthread = CreateThread(NULL, 0, threadInternalStart, (void*)this,0, &threadId);
+  if (pthread == NULL)
+  {
+    CloseHandle(threadCond);
+    CloseHandle(threadCondMutex);
+    return 0;
+  }
+  return 1;
+}
+
+void ThreadP::threadStop()
+{
+  threadActive = 0;
+  // Signal thread here in case it's waiting
+  threadSignal();
+  WaitForSingleObject(pthread, INFINITE);
+  this->threadPostStopCleanup();
+}
+
+void ThreadP::threadCancel()
+{
+  threadActive = 0;
+  TerminateThread(pthread, 0);
+  WaitForSingleObject(pthread, INFINITE);
+  this->threadPostStopCleanup();
+}
+
+void ThreadP::threadCheckExit()
+{
+  if (!threadActive) ExitThread(NULL);
+}
+
+void ThreadP::threadLock()
+{
+  WaitForSingleObject(threadCondMutex, INFINITE);
+}
+
+void ThreadP::threadUnlock()
+{
+  ReleaseMutex(threadCondMutex);
+}
+
+void ThreadP::threadSignal()
+{
+  WaitForSingleObject(threadCondMutex, INFINITE);
+  SetEvent(threadCond);
+  ReleaseMutex(threadCondMutex);
+}
+
+void ThreadP::threadSignalNoLock()
+{
+  SetEvent(threadCond);
+}
+
+void ThreadP::threadWaitForSignal()
+{
+  WaitForSingleObject(threadCond,INFINITE);
+}
+
+void ThreadP::threadWaitForSignalTimed(struct timespec* ts)
+{
+  HANDLE handles[2] ={threadCond, NULL};
+  LARGE_INTEGER duration;
+  duration.QuadPart=ts->tv_sec*1000*1000*10+ts->tv_nsec/100;
+
+  handles[1]=CreateWaitableTimer(NULL,TRUE,NULL);
+  /* SetWaitableTimer(handles[1], &duration, 0, NULL, NULL, 0);
+  WaitForMultipleObject(2,handles,INFINITE);*/
+  CloseHandle(handles[1]);
+}
+
+void ThreadP::threadSetKillable()
+{
+  //WIN32:Ignore or use a separate Event Object to simulate this
+}
diff --git a/threadwin.h b/threadwin.h
new file mode 100644 (file)
index 0000000..1e55507
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+    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 THREADWIN_H
+#define THREADWIN_H
+
+#define _WIN32_WINNT 0x400
+#include <winsock2.h>
+#include <windows.h>
+typedef struct timespec
+{
+  long tv_sec; /* seconds */
+  long tv_nsec; /* nanoseconds */
+} timespec;
+
+#include "thread.h"
+
+class ThreadWin : public Thread
+{
+  protected:
+    // Override this method in derived classes
+    virtual void threadMethod()=0;
+    virtual void threadPostStopCleanup()=0;
+
+    // Methods to use from outside the thread
+    int threadStart();    // start the thread. threadMethod() will be called in derived class
+    void threadStop();    // stop the thread nicely. thread will be stopped when it next calls threadCheckExit()
+    void threadCancel();  // stop thread immediately. thread will be stopped at the next cancellation point
+    void threadSignal();  // releases a thread that has called threadWaitForSignal
+    void threadSignalNoLock();  // same as above but without locking guarantees. probably not a good idea.
+
+    // Methods to use from inside the thread
+    void threadSetKillable();    // allows threadCancel() to work
+    void threadCheckExit();      // terminates thread if threadStop() has been called
+    void threadWaitForSignal();  // pauses thread until threadSignal() is called
+    void threadWaitForSignalTimed(struct timespec*);  // pauses thread until threadSignal() is called or timer expires
+    void threadLock();           // locks the mutex used for internal cond/signal stuff
+    void threadUnlock();         // unlocks.
+
+    // Internal bits and pieces
+
+  private:
+    HANDLE pthread;
+    HANDLE threadCondMutex;
+    HANDLE threadCond;
+};
+
+#endif
index 0aac2e7f54323b94ea6f68efa6dec362a026183e..7878b984a09dc6c3d342eb70baf885d62b09dded 100755 (executable)
--- a/timers.h
+++ b/timers.h
 
 #include "defines.h"
 #include "log.h"
-#include "thread.h"
 #include "command.h"
 #include "timerreceiver.h"
 
+#ifdef WIN32
+#include "threadwin.h"
+#else
+#include "threadp.h"
+#endif
+
 /*
 
 Timers documentation
@@ -64,7 +69,7 @@ using namespace std;
 //using namespace __gnu_cxx;
 typedef list<Timer*> TimerList;
 
-class Timers : public Thread
+class Timers : public Thread_TYPE
 {
   public:
     Timers();
index 139550e3ad62c098324fdc7a0961a3dc57c08e4d..bc4cdf495354e6f263f1b489e60230c818bd7f22 100644 (file)
 #include "message.h"
 #include "colour.h"
 #include "video.h"
-#include "thread.h"
 #include "i18n.h"
 
-class VConnect : public VInfo, public Thread
+#ifdef WIN32
+#include "threadwin.h"
+#else
+#include "threadp.h"
+#endif
+
+class VConnect : public VInfo, public Thread_TYPE
 {
   public:
     VConnect();
diff --git a/vfeed.h b/vfeed.h
index 93117ce3b1274f37b1a6f5c6755cc64da0ec55ff..c8e6b0ca40bd65e2a097c7965df55199e9eb5ba4 100644 (file)
--- a/vfeed.h
+++ b/vfeed.h
 #include <time.h>
 
 #include "log.h"
-#include "thread.h"
 #include "demuxer.h"
 #include "callback.h"
 
-class VFeed : public Thread
+#ifdef WIN32
+#include "threadwin.h"
+#else
+#include "threadp.h"
+#endif
+
+class VFeed : public Thread_TYPE
 {
   public:
     VFeed(Callback* tcb);