/* $Header: https://svn.mpia.de/gulli/TwiceAsNice/branch/unstable/ln/ltcs/test/LbtoIIFSimulator/LbtoIIFSimulatorService.cc 14502 2017-07-17 08:46:15Z mathar $
*/

#include <LbtoIIFInterfaceFactoryI.h>
#include <Ltcs/Iif/PropertyName.h>
#include "LbtoIIFSimulatorService.h"

#undef LOG_NAME
#define LOG_NAME Ltcs::IIFSimulatorService::s_name

std::string Ltcs::IIFSimulatorService::s_name ( "IIFSimulatorService" );

int Ltcs::IIFSimulatorService::run(int /*argc*/, char** /*argv[]*/)
{
//    D_LOG(config())
//    D_LOG(adapter()->getEndpoints()[0]->toString())

	Ice::ObjectPtr object = new lbto::FactoryI();
	adapter()->add(object, communicator()->stringToIdentity("Factory"));
	adapter()->activate();

	N_LOG("Service started");
	Nice::Application::wait();

	//Exit.
	return EXIT_SUCCESS;
}

void Ltcs::IIFSimulatorService::interruptCallback ( int /*_sig*/ )
{
	I_LOG ( "Shutdown IIF Simulator Worker" );
	// m_basdard->changeState( Basda::SHUTDOWN );
}


/*!****************
* @brief Substitute of the LBTO IIF server for test purposes.
* Usage:
* -  cd ~/lnsw/config
*    rm alias.cfg
*    ln -s alias-localhost.cfg alias.cfg
* -  LbtoIIFSimulator --LOGGER.LEVEL=INFO --CONFIG=lbcs/lbcs.iifDummyLocalhost-svr.cfg &
*/
int main(int argc, char* argv[])
{
	//read the server configuration file.
	Ltcs::IIFSimulatorService app;
	Nice::JointPtr preconfig = Nice::AppConfig::preinitialize()->get();
	preconfig->setAtNode("HEARTBEAT.REMOTE", true);
	return app.start ( argc, argv );
}
