summaryrefslogtreecommitdiff
path: root/pagelib
diff options
context:
space:
mode:
authorSascha Volkenandt <sascha (at) akv-soft (dot) de>2007-01-04 15:02:00 +0000
committerSascha Volkenandt <sascha (at) akv-soft (dot) de>2007-01-04 15:02:00 +0000
commit64eaee28c243214e654c60b06a27212e8dcb5c02 (patch)
tree21b264c07166720513b65638feeb8fc3344530ec /pagelib
parent4bfb50c7a53074fa7e4673ffdd16502c1bf72fcb (diff)
downloadvdr-plugin-live-64eaee28c243214e654c60b06a27212e8dcb5c02.tar.gz
vdr-plugin-live-64eaee28c243214e654c60b06a27212e8dcb5c02.tar.bz2
- optimized interface to access plugin objects from website
- moved website code to pagelib subdirectory - introduced TimerManager that will help working on timers from a background thread
Diffstat (limited to 'pagelib')
-rw-r--r--pagelib/Makefile33
-rw-r--r--pagelib/sortedtimers.cpp28
-rw-r--r--pagelib/sortedtimers.h26
-rw-r--r--pagelib/tools.cpp29
-rw-r--r--pagelib/tools.h30
5 files changed, 146 insertions, 0 deletions
diff --git a/pagelib/Makefile b/pagelib/Makefile
new file mode 100644
index 0000000..6c91953
--- /dev/null
+++ b/pagelib/Makefile
@@ -0,0 +1,33 @@
+CXX ?= g++
+AR ?= ar
+
+CXXFLAGS ?= -O2 -Woverloaded-virtual -Wall -fPIC
+
+INCLUDES += -I.. -I$(VDRDIR)/include
+
+### The directory environment:
+
+VDRDIR ?= ../../../..
+
+### The object files (add further files here):
+
+OBJS = sortedtimers.o tools.o
+
+### Default rules:
+
+.PHONY: all clean
+
+all: libpagelib.a
+
+### Implicit rules:
+
+%.o: %.cpp
+ $(CXX) $(CXXFLAGS) -c $(DEFINES) $(INCLUDES) $<
+
+### Targets:
+
+libpagelib.a: $(OBJS)
+ $(AR) r $@ $^
+
+clean:
+ @rm -f *~ *.o core* libpagelib.a
diff --git a/pagelib/sortedtimers.cpp b/pagelib/sortedtimers.cpp
new file mode 100644
index 0000000..547c482
--- /dev/null
+++ b/pagelib/sortedtimers.cpp
@@ -0,0 +1,28 @@
+#include "sortedtimers.h"
+
+static bool operator<( cTimer const& left, cTimer const& right )
+{
+ return left.Compare( right ) < 0;
+}
+
+/*
+static bool operator==( cTimer const& left, cTimer const& right )
+{
+ return left.Channel() == right.Channel() &&
+ (left.WeekDays() && left.WeekDays() == right.WeekDays() || !left.WeekDays() && left.Day() == right.Day()) &&
+ left.Start() == right.Start() &&
+ left.Stop() == right.Stop();
+}
+*/
+
+namespace vdrlive {
+
+SortedTimers::SortedTimers()
+{
+ for ( cTimer* timer = Timers.First(); timer != 0; timer = Timers.Next( timer ) ) {
+ m_timers.push_back( *timer );
+ }
+ m_timers.sort();
+}
+
+} // namespace vdrlive
diff --git a/pagelib/sortedtimers.h b/pagelib/sortedtimers.h
new file mode 100644
index 0000000..ffe9150
--- /dev/null
+++ b/pagelib/sortedtimers.h
@@ -0,0 +1,26 @@
+#ifndef VDR_LIVE_SORTEDTIMERS_H
+#define VDR_LIVE_SORTEDTIMERS_H
+
+#include <list>
+#include <vdr/timers.h>
+
+namespace vdrlive {
+
+class SortedTimers
+{
+public:
+ typedef std::list< cTimer > List;
+ typedef List::iterator iterator;
+
+ SortedTimers();
+
+ iterator begin() { return m_timers.begin(); }
+ iterator end() { return m_timers.end(); }
+
+private:
+ List m_timers;
+};
+
+} // namespace vdrlive
+
+#endif // VDR_LIVE_SORTEDTIMERS_H
diff --git a/pagelib/tools.cpp b/pagelib/tools.cpp
new file mode 100644
index 0000000..aeaba36
--- /dev/null
+++ b/pagelib/tools.cpp
@@ -0,0 +1,29 @@
+#include <sstream>
+#include <stdexcept>
+#include "live.h"
+#include "setup.h"
+#include "tools.h"
+
+namespace vdrlive {
+
+using namespace std;
+
+string FormatDateTime( char const* format, time_t time )
+{
+ struct tm tm_r;
+ if ( localtime_r( &time, &tm_r ) == 0 ) {
+ ostringstream builder;
+ builder << "cannot represent timestamp " << time << " as local time";
+ throw runtime_error( builder.str() );
+ }
+
+ char result[ 256 ];
+ if ( strftime( result, sizeof( result ), format, &tm_r ) == 0 ) {
+ ostringstream builder;
+ builder << "representation of timestamp " << time << " exceeds " << sizeof( result ) << " bytes";
+ throw runtime_error( builder.str() );
+ }
+ return result;
+}
+
+}
diff --git a/pagelib/tools.h b/pagelib/tools.h
new file mode 100644
index 0000000..f9eb33a
--- /dev/null
+++ b/pagelib/tools.h
@@ -0,0 +1,30 @@
+#ifndef VDR_LIVE_TOOLS_H
+#define VDR_LIVE_TOOLS_H
+
+#include <ctime>
+#include <string>
+#include <vdr/thread.h>
+
+namespace vdrlive {
+
+std::string FormatDateTime( char const* format, time_t time );
+
+class ReadLock
+{
+public:
+ ReadLock( cRwLock& lock, int timeout = 100 ): m_lock( lock ), m_locked( false ) { if ( m_lock.Lock( false, timeout ) ) m_locked = true; }
+ ~ReadLock() { if ( m_locked ) m_lock.Unlock(); }
+
+ operator bool() { return m_locked; }
+ bool operator!() { return !m_locked; }
+
+private:
+ ReadLock( ReadLock const& );
+
+ cRwLock& m_lock;
+ bool m_locked;
+};
+
+} // namespace vdrlive
+
+#endif // VDR_LIVE_TOOLS_H