summaryrefslogtreecommitdiff
path: root/thread.cpp
diff options
context:
space:
mode:
authorSascha Volkenandt <sascha (at) akv-soft (dot) de>2007-01-04 17:42:33 +0000
committerSascha Volkenandt <sascha (at) akv-soft (dot) de>2007-01-04 17:42:33 +0000
commit61e31de98b97f556cfb2a0cafa172bde673e7859 (patch)
treef92c3c42107f89a7de7b3c489527b3b6a2421078 /thread.cpp
parentc5cb6d2e099c9ae44cc3d26e4800c9f9101852e7 (diff)
downloadvdr-plugin-live-61e31de98b97f556cfb2a0cafa172bde673e7859.tar.gz
vdr-plugin-live-61e31de98b97f556cfb2a0cafa172bde673e7859.tar.bz2
- removed thread-unsafe call of cPlugin::ConfigDirectory and replaced it with Plugin::GetConfigDirectory
- implemented proper shutdown of server thread on vdr termination
Diffstat (limited to 'thread.cpp')
-rw-r--r--thread.cpp33
1 files changed, 26 insertions, 7 deletions
diff --git a/thread.cpp b/thread.cpp
index cb2954a..9b0b436 100644
--- a/thread.cpp
+++ b/thread.cpp
@@ -11,25 +11,44 @@ namespace vdrlive {
using namespace std;
using namespace tnt;
-ServerThread::ServerThread():
- m_configPath( 0 )
+class ProtectedCString
+{
+public:
+ ProtectedCString( char const* string ): m_string( strdup( string ) ) {}
+ ~ProtectedCString() { free( m_string ); }
+
+ operator char*() { return m_string; }
+
+private:
+ char* m_string;
+};
+
+ServerThread::ServerThread()
{
}
ServerThread::~ServerThread()
{
- free( m_configPath );
+ Stop();
+}
+
+void ServerThread::Stop()
+{
+ if ( Active() ) {
+ m_server->shutdown();
+ Cancel( 5 );
+ }
}
void ServerThread::Action()
{
try {
- m_configPath = strdup( TntConfig::Get().GetConfigPath().c_str() );
+ ProtectedCString configPath( TntConfig::Get().GetConfigPath().c_str() );
- char* argv[] = { "tntnet", "-c", m_configPath };
+ char* argv[] = { "tntnet", "-c", configPath };
int argc = sizeof( argv ) / sizeof( argv[0] );
- Tntnet app( argc, argv );
- app.run();
+ m_server.reset( new Tntnet( argc, argv ) );
+ m_server->run();
} catch ( exception const& ex ) {
// XXX move initial error handling to live.cpp
esyslog( "ERROR: live httpd server crashed: %s", ex.what() );