summaryrefslogtreecommitdiff
path: root/p2pvr/carddaemon/carddaemon.cpp
blob: 1ea7e438d7e5329a3115a76dabdd4ad4966dc01b (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
#include <daemon.h>
#include <options.h>
#include <logger.h>
#include <Ice/Ice.h>
#include "localDevices.h"

class P2PvrCardDaemon : public Daemon {
	public:
		P2PvrCardDaemon(int argc, char ** argv) :
			ic(Ice::initialize(argc, argv))
		{
		}

		~P2PvrCardDaemon()
		{
			ic->destroy();
		}

		void run() const
		{
			IceUtil::TimerPtr timer = new IceUtil::Timer();
			Logger()->messagebf(LOG_INFO, "Creating adapter (%s, %s)", Adapter, Endpoint);
			auto adapter = ic->createObjectAdapterWithEndpoints(Adapter, Endpoint);
			P2PVR::LocalDevicesPrx::checkedCast(adapter->add(new LocalDevices(adapter, timer), ic->stringToIdentity(Identity)));
			adapter->activate();
			ic->waitForShutdown();
			timer->destroy();
		}

		void shutdown() const
		{
			ic->shutdown();
		}
		INITOPTIONS;

	private:
		Ice::CommunicatorPtr ic;

		static std::string Adapter;
		static std::string Endpoint;
		static std::string Identity;
};

std::string P2PvrCardDaemon::Adapter;
std::string P2PvrCardDaemon::Endpoint;
std::string P2PvrCardDaemon::Identity;

DECLARE_GENERIC_LOADER("p2pvrcarddaemon", DaemonLoader, P2PvrCardDaemon);

DECLARE_OPTIONS(P2PvrCardDaemon, "P2PVR Card Daemon")
("p2pvr.carddaemon.iceadapter", Options::value(&Adapter, "DefaultAdapter"), "ICE Adapter name")
("p2pvr.carddaemon.iceendpoint", Options::value(&Endpoint, "default -p 10001"), "ICE Endpoint address")
("p2pvr.carddaemon.iceidentity", Options::value(&Identity, "Devices"), "ICE Interface identity")
END_OPTIONS(P2PvrCardDaemon);