diff options
author | Sascha Volkenandt <sascha (at) akv-soft (dot) de> | 2007-01-03 21:43:21 +0000 |
---|---|---|
committer | Sascha Volkenandt <sascha (at) akv-soft (dot) de> | 2007-01-03 21:43:21 +0000 |
commit | c5a0ac492575efb83ecc76524ff3c13fe1a9799b (patch) | |
tree | 7b4af9bb32c58e5d3aed9ac039180ac7533db052 | |
parent | 95739a127dc2b85fe831ac13553578490fea34b0 (diff) | |
download | vdr-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-- | Makefile | 4 | ||||
-rw-r--r-- | live.cpp | 38 | ||||
-rw-r--r-- | live.h | 43 | ||||
-rw-r--r-- | pages/channels.ecpp | 7 | ||||
-rw-r--r-- | setup.cpp | 22 | ||||
-rw-r--r-- | setup.h | 27 | ||||
-rw-r--r-- | thread.cpp | 2 | ||||
-rw-r--r-- | tntconfig.cpp | 6 | ||||
-rw-r--r-- | tools.cpp | 2 |
9 files changed, 104 insertions, 47 deletions
@@ -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: @@ -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 @@ -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"> @@ -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 @@ -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 @@ -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; } @@ -1,5 +1,7 @@ #include <sstream> #include <stdexcept> +#include "live.h" +#include "setup.h" #include "tools.h" namespace vdrlive { |