summaryrefslogtreecommitdiff
path: root/thread.cpp
blob: bfbc6cb29e8ec5918d4362b897a0c5ab2b22a616 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <vdr/tools.h>
#include <tnt/tntnet.h>
#include "thread.h"
#include "tntconfig.h"

namespace vdrlive {

using namespace std;
using namespace tnt;

#if TNTVERSION < 1606
class ProtectedCString
{
public:
	ProtectedCString( char const* string ): m_string( strdup( string ) ) {}
	~ProtectedCString() { free( m_string ); }

	operator char*() { return m_string; }

private:
	char* m_string;
};
#endif // TNTVERSION < 1606

ServerThread::ServerThread()
{
}

ServerThread::~ServerThread()
{
	Stop();
}

void ServerThread::Stop()
{
	if ( Active() ) {
		m_server->shutdown();
		Cancel( 5 );
	}
}

void ServerThread::Action()
{
	try {
#if TNTVERSION >= 1606
	        // tnt::Tntconfig tntconfig;
		// tntconfig.load(TntConfig::Get().GetConfigPath().c_str());
		m_server.reset(new Tntnet());
		//m_server->init(tntconfig);
		TntConfig::Get().Configure(*m_server);
#else
		ProtectedCString configPath(TntConfig::Get().GetConfigPath().c_str());

		char* argv[] = { const_cast< char* >( "tntnet" ), const_cast< char* >( "-c" ), configPath };
		int argc = sizeof( argv ) / sizeof( argv[0] );

		m_server.reset(new Tntnet( argc, argv ));
#endif // TNTVERSION
		m_server->run();
		m_server.reset(0);
	} catch (exception const& ex) {
		// XXX move initial error handling to live.cpp
		esyslog("ERROR: live httpd server crashed: %s", ex.what());
		cerr << "HTTPD FATAL ERROR: " << ex.what() << endl;
		//cThread::EmergencyExit(true);
	}
}

} // namespace vdrlive