summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSascha Volkenandt <sascha (at) akv-soft (dot) de>2007-01-03 21:43:21 +0000
committerSascha Volkenandt <sascha (at) akv-soft (dot) de>2007-01-03 21:43:21 +0000
commitc5a0ac492575efb83ecc76524ff3c13fe1a9799b (patch)
tree7b4af9bb32c58e5d3aed9ac039180ac7533db052
parent95739a127dc2b85fe831ac13553578490fea34b0 (diff)
downloadvdr-plugin-live-c5a0ac492575efb83ecc76524ff3c13fe1a9799b.tar.gz
vdr-plugin-live-c5a0ac492575efb83ecc76524ff3c13fe1a9799b.tar.bz2
- renamed Setup::Get() to LiveSetup()
- added method that fetches plugin class from vdr and gets its setup object - demo code in channels.ecpp
-rw-r--r--Makefile4
-rw-r--r--live.cpp38
-rw-r--r--live.h43
-rw-r--r--pages/channels.ecpp7
-rw-r--r--setup.cpp22
-rw-r--r--setup.h27
-rw-r--r--thread.cpp2
-rw-r--r--tntconfig.cpp6
-rw-r--r--tools.cpp2
9 files changed, 104 insertions, 47 deletions
diff --git a/Makefile b/Makefile
index 799b89f..5615c59 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
#
# Makefile for a Video Disk Recorder plugin
#
-# $Id: Makefile,v 1.17 2007/01/03 20:48:13 tadi Exp $
+# $Id: Makefile,v 1.18 2007/01/03 21:43:21 lordjaxom Exp $
# The official name of this plugin.
# This name will be used in the '-P...' option of VDR to load the plugin.
@@ -13,7 +13,7 @@ PLUGIN = live
### The version number of this plugin (taken from the main source file):
-VERSION = $(shell grep 'static const char \*VERSION *=' $(PLUGIN).cpp | awk '{ print $$6 }' | sed -e 's/[";]//g')
+VERSION = $(shell grep 'const char \*Plugin::VERSION *=' $(PLUGIN).h | awk '{ print $$5 }' | sed -e 's/[";]//g')
### The C++ compiler and options:
diff --git a/live.cpp b/live.cpp
index cf219d8..0000186 100644
--- a/live.cpp
+++ b/live.cpp
@@ -3,12 +3,12 @@
*
* See the README file for copyright information and how to reach the author.
*
- * $Id: live.cpp,v 1.4 2007/01/03 15:54:31 lordjaxom Exp $
+ * $Id: live.cpp,v 1.5 2007/01/03 21:43:21 lordjaxom Exp $
*/
-#include <memory>
#include <vdr/plugin.h>
#include "i18n.h"
+#include "live.h"
#include "setup.h"
#include "thread.h"
@@ -16,26 +16,8 @@ namespace vdrlive {
using namespace std;
-static const char *VERSION = "0.0.1";
-static const char *DESCRIPTION = "Live Integrated VDR Environment";
-
-class Plugin : public cPlugin {
-public:
- Plugin(void);
- virtual const char *Version(void) { return VERSION; }
- virtual const char *Description(void) { return DESCRIPTION; }
- virtual const char *CommandLineHelp(void);
- virtual bool ProcessArgs(int argc, char *argv[]);
- virtual bool Start(void);
- virtual void Stop(void);
- virtual void MainThreadHook(void);
- virtual cString Active(void);
- virtual cMenuSetupPage *SetupMenu(void);
- virtual bool SetupParse(const char *Name, const char *Value);
-
-private:
- auto_ptr< ServerThread > m_thread;
-};
+const char *Plugin::VERSION = "0.0.1";
+const char *Plugin::DESCRIPTION = "Live Integrated VDR Environment";
Plugin::Plugin(void)
{
@@ -43,12 +25,12 @@ Plugin::Plugin(void)
const char *Plugin::CommandLineHelp(void)
{
- return Setup::Get().Help();
+ return LiveSetup().CommandLineHelp();
}
bool Plugin::ProcessArgs(int argc, char *argv[])
{
- return Setup::Get().Parse( argc, argv );
+ return LiveSetup().ParseCommandLine( argc, argv );
}
bool Plugin::Start(void)
@@ -80,7 +62,13 @@ cMenuSetupPage *Plugin::SetupMenu(void)
bool Plugin::SetupParse(const char *Name, const char *Value)
{
- return true;
+ return LiveSetup().ParseSetupEntry( Name, Value );
+}
+
+Setup& Plugin::GetLiveSetup()
+{
+ static Setup instance;
+ return instance;
}
} // namespace vdrlive
diff --git a/live.h b/live.h
new file mode 100644
index 0000000..f5d9e18
--- /dev/null
+++ b/live.h
@@ -0,0 +1,43 @@
+#ifndef VDR_LIVE_LIVE_H
+#define VDR_LIVE_LIVE_H
+
+#include <memory>
+#include <vdr/plugin.h>
+#include "thread.h"
+
+namespace vdrlive {
+
+class Setup;
+
+class PluginBase : public cPlugin
+{
+public:
+ virtual Setup& GetLiveSetup() = 0;
+};
+
+class Plugin : public PluginBase {
+public:
+ Plugin(void);
+ virtual const char *Version(void) { return VERSION; }
+ virtual const char *Description(void) { return DESCRIPTION; }
+ virtual const char *CommandLineHelp(void);
+ virtual bool ProcessArgs(int argc, char *argv[]);
+ virtual bool Start(void);
+ virtual void Stop(void);
+ virtual void MainThreadHook(void);
+ virtual cString Active(void);
+ virtual cMenuSetupPage *SetupMenu(void);
+ virtual bool SetupParse(const char *Name, const char *Value);
+
+ virtual Setup& GetLiveSetup();
+
+private:
+ static const char *VERSION;
+ static const char *DESCRIPTION;
+
+ std::auto_ptr< ServerThread > m_thread;
+};
+
+} // namespace vdrlive
+
+#endif // VDR_LIVE_LIVE_H
diff --git a/pages/channels.ecpp b/pages/channels.ecpp
index aa48f03..5f64d1d 100644
--- a/pages/channels.ecpp
+++ b/pages/channels.ecpp
@@ -2,17 +2,20 @@
#include <boost/lexical_cast.hpp>
#include <vdr/plugin.h>
#include <vdr/channels.h>
+#include "setup.h"
+
+using namespace vdrlive;
+
</%pre>
<html>
<head>
<title><$ tr("channels") $></title>
</head>
<body>
-
<div id="inhalt">
<{
- for (cChannel *channel = Channels.First(); channel; channel = Channels.Next(channel)) {
+ for (cChannel *channel = Channels.First(); channel && channel->Number() <= LiveSetup().GetLastChannel(); channel = Channels.Next(channel)) {
if (!channel->GroupSep() && *channel->Name()) {
}>
<div class="channel">
diff --git a/setup.cpp b/setup.cpp
index bb11f60..7ee2f82 100644
--- a/setup.cpp
+++ b/setup.cpp
@@ -19,11 +19,12 @@ using namespace std;
Setup::Setup():
m_libraryPath( "/usr/local/lib" ),
- m_serverPort( 8001 )
+ m_serverPort( 8001 ),
+ m_lastChannel( 0 )
{
}
-bool Setup::Parse( int argc, char* argv[] )
+bool Setup::ParseCommandLine( int argc, char* argv[] )
{
static struct option opts[] = {
{ "lib", required_argument, NULL, 'L' },
@@ -47,7 +48,7 @@ bool Setup::Parse( int argc, char* argv[] )
CheckServerIps();
}
-char const* Setup::Help() const
+char const* Setup::CommandLineHelp() const
{
if ( m_helpString.empty() ) {
ostringstream builder;
@@ -63,6 +64,15 @@ char const* Setup::Help() const
return m_helpString.c_str();
}
+bool Setup::ParseSetupEntry( char const* name, char const* value )
+{
+ cout << "Parsing " << name << " = " << value << endl;
+ if ( strcmp( name, "LastChannel" ) == 0 ) m_lastChannel = atoi( value );
+ else return false;
+ return true;
+}
+
+
bool Setup::CheckLibraryPath()
{
ostringstream builder;
@@ -102,10 +112,4 @@ bool Setup::CheckServerIps()
return true;
}
-Setup& Setup::Get()
-{
- static Setup instance;
- return instance;
-}
-
} // namespace vdrlive
diff --git a/setup.h b/setup.h
index 6d08ccf..ef1cba3 100644
--- a/setup.h
+++ b/setup.h
@@ -3,37 +3,54 @@
#include <string>
#include <list>
+#include "live.h"
namespace vdrlive {
+class Plugin;
+
class Setup
{
+ friend Setup& Plugin::GetLiveSetup();
+
public:
typedef std::list< std::string > IpList;
- static Setup& Get();
-
+ // commandline
std::string const& GetLibraryPath() const { return m_libraryPath; }
int GetServerPort() const { return m_serverPort; }
IpList const& GetServerIps() const { return m_serverIps; }
+ // vdr-setup
+ int GetLastChannel() const { return m_lastChannel; }
- bool Parse( int argc, char* argv[] );
- char const* Help() const;
+ bool ParseCommandLine( int argc, char* argv[] );
+ char const* CommandLineHelp() const;
+
+ bool ParseSetupEntry( char const* name, char const* value );
private:
Setup();
Setup( Setup const& );
mutable std::string m_helpString;
+ // commandline
std::string m_libraryPath;
int m_serverPort;
- std::list< std::string > m_serverIps;
+ IpList m_serverIps;
+ // vdr-setup
+ int m_lastChannel;
bool CheckLibraryPath();
bool CheckServerPort();
bool CheckServerIps();
};
+inline Setup& LiveSetup()
+{
+ static PluginBase& plugin = *static_cast< Plugin* >( cPluginManager::GetPlugin( PLUGIN_NAME_I18N ) );
+ return plugin.GetLiveSetup();
+}
+
} // namespace vdrlive
#endif // VDR_LIVE_SETUP_H
diff --git a/thread.cpp b/thread.cpp
index df6580c..cb2954a 100644
--- a/thread.cpp
+++ b/thread.cpp
@@ -1,8 +1,8 @@
#include <cstdlib>
#include <iostream>
#include <stdexcept>
+#include <vdr/tools.h>
#include <tnt/tntnet.h>
-#include <vdr/plugin.h>
#include "thread.h"
#include "tntconfig.h"
diff --git a/tntconfig.cpp b/tntconfig.cpp
index ea6f9d0..60bfad2 100644
--- a/tntconfig.cpp
+++ b/tntconfig.cpp
@@ -35,10 +35,10 @@ void TntConfig::WriteConfig()
file << "MapUrl ^/$ whats_on_now@libtnt-live" << endl;
file << "MapUrl /([^.]+)(\\..+)? $1@libtnt-live" << endl;
file << "PropertyFile " << m_propertiesPath << endl;
- file << "CompPath " << Setup::Get().GetLibraryPath() << endl;
+ file << "CompPath " << LiveSetup().GetLibraryPath() << endl;
- Setup::IpList const& ips = Setup::Get().GetServerIps();
- int port = Setup::Get().GetServerPort();
+ Setup::IpList const& ips = LiveSetup().GetServerIps();
+ int port = LiveSetup().GetServerPort();
for ( Setup::IpList::const_iterator ip = ips.begin(); ip != ips.end(); ++ip ) {
file << "Listen " << *ip << " " << port << endl;
}
diff --git a/tools.cpp b/tools.cpp
index 3eda4b8..aeaba36 100644
--- a/tools.cpp
+++ b/tools.cpp
@@ -1,5 +1,7 @@
#include <sstream>
#include <stdexcept>
+#include "live.h"
+#include "setup.h"
#include "tools.h"
namespace vdrlive {