/* $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/iif/Service/LbtoIIFSimulatorService.cc 375 2018-01-11 11:46:56Z depa $
*/

#include <LbtoIIFInterfaceFactoryI.h>
#include <Lbcs/IIF/PropertyName.h>
#include <Ice/Application.h>
#include <Nice/Application.h>
#include <Nice/Log.h>

//Server class.
namespace Lbcs
{
	class IIFSimulatorService : public Nice::Application
	{
	protected:
		static std::string s_name;

	public:

		virtual int run(int, char*[]);
		virtual void interruptCallback ( int _sig );
	};
}

#undef LOG_NAME
#define LOG_NAME Lbcs::IIFSimulatorService::s_name

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

int Lbcs::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 Lbcs::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.
	Lbcs::IIFSimulatorService app;
	Nice::JointPtr preconfig = Nice::AppConfig::preinitialize()->get();
	preconfig->setAtNode("HEARTBEAT.REMOTE", true);
	return app.start ( argc, argv );
}
