#include "config.h" #include #include std::string Config::DaemonAddress; std::string Config::CommunicatorArgs; Ice::CommunicatorPtr Config::ic; Ice::ObjectAdapterPtr Config::adapter; DECLARE_OPTIONS(Config, "P2PVR Client options") ("p2pvr.client.daemonaddress", Options::value(&DaemonAddress), "The ICE address of the P2PVR daemon") ("p2pvr.client.communicatorargs", Options::value(&CommunicatorArgs), "Arguments to pass to the client's ICE Communicator") END_OPTIONS(Config); DECLARE_COMPONENT("P2PVR Client Config", Config); void Config::onConfigLoad() { if (ic) { Logger()->messagef(LOG_DEBUG, "%s: Destroying existing ICE Communicator", __PRETTY_FUNCTION__); ic->shutdown(); } Logger()->messagef(LOG_DEBUG, "%s: Creating new ICE Communicator", __PRETTY_FUNCTION__); int argc = 0; char ** argv = {}; ic = Ice::initialize(argc, argv); try { if (!ic) { Logger()->message(LOG_ERR, "Failed to initialize ICE Communicator"); throw std::runtime_error("Failed to initialize ICE Communicator"); } Logger()->messagebf(LOG_DEBUG, "%s: Creating new default adapter for Communicator", __PRETTY_FUNCTION__); adapter = ic->createObjectAdapterWithEndpoints("DefaultAdapter", "default -p 10002"); if (!adapter) { Logger()->message(LOG_ERR, "Failed to create new adapter"); throw std::runtime_error("Failed to create new adapter"); } Logger()->messagef(LOG_DEBUG, "%s: Activating", __PRETTY_FUNCTION__); adapter->activate(); Logger()->messagef(LOG_DEBUG, "%s: Done", __PRETTY_FUNCTION__); } catch (const Ice::Exception & ie) { Logger()->messagebf(LOG_DEBUG, "%s: ICE initialization failed (%s)", __PRETTY_FUNCTION__, ie); } }