//-------------------------------------------------------------------------------------------------
// <copyright file="LogListenerProgram.h" company="LiquidRobotics">
//  Copyright (c) Liquid Robotics Corporation, confidential and proprietary.  All rights reserved. 
// </copyright>
//
// <summary>
// 	Declaration of LogListenerProgram class, which listens to log messages
//  coming from the Float and saves them to a file
// </summary>
//
// <owner>Arash Ushani</owner>
//-------------------------------------------------------------------------------------------------

#ifndef __LogListenerProgram_H__
#define __LogListenerProgram_H__

#include "EventTransceiver.h"
#include "LqrSMACIdl.h"
#include "LqrSMACSharedLib.h"
#include "LqrSMACTimerCollection.h"
#include "LqrSMACFileSet.h"
#include "PayloadManagerClient.h"
#include <boost/shared_ptr.hpp>
#include <boost/signals2.hpp>

namespace LiquidRobotics {

namespace EventLib {
	class IEventBase;
}

namespace SMACFramework {
	class IObjectBroker;
	class ISerialPort;
	class Logger;
	class PayloadDescription;
}

namespace LogListener {

class LogListenerProgramSettings;

class SHARED_LIB_PUBLIC LogListenerProgram
: public LiquidRobotics::EventLib::EventTransceiver
, public LiquidRobotics::SMACFramework::ICommandableBase
{
public:

	typedef LiquidRobotics::SMACFramework::IObjectBroker IObjectBroker;
	typedef LiquidRobotics::EventLib::IEventBase IEventBase;
	typedef LiquidRobotics::SMACFramework::Logger Logger;
	typedef LiquidRobotics::SMACFramework::PayloadDescription Desc;
	typedef LiquidRobotics::EventLib::PayloadManagerClient PayloadManagerClient;
	typedef boost::signals2::scoped_connection ScopedConnection;
	typedef boost::shared_ptr<ScopedConnection> ScopedConnectionPtr;
	typedef LiquidRobotics::SMACFramework::TimerCollection<void*> TimerCollection;

	LogListenerProgram(IObjectBroker& _broker, const LogListenerProgramSettings& _settings, Logger& _logger, SMACFramework::FileSet& _floatLogFile);
	virtual ~LogListenerProgram();

	virtual void Initialize(Object_ptr _pServer, PayloadManagerClient::Ptr _pmClient);

	// IPingable operations
    virtual ::CORBA::Double Ping();

    // IPayloadDevice
    virtual ::LiquidRobotics::SMAC::EnumerationData* GetEnumerationData();
    virtual void PowerOff(::LiquidRobotics::SMAC::PowerOffTimeType offDelay);
    virtual void PowerOn();
    virtual ::LiquidRobotics::SMAC::BoardIDType boardID();
    virtual ::LiquidRobotics::SMAC::PayloadDescription* description();
    virtual ::LiquidRobotics::SMAC::EPayloadEnableState enableState();
    virtual ::LiquidRobotics::SMAC::PowerOffTimeType requestOffTime();
    virtual ::LiquidRobotics::SMAC::PowerOnTimeType requestOnTime();
    virtual ::LiquidRobotics::SMAC::ComponentVersion* softwareVersion();
    virtual ::LiquidRobotics::SMAC::TaskIDType taskID();

    // ICommandable
    virtual void SendCommand(const ::CORBA::Any& command, const char* requester, const char* transactionID, ::CORBA::Any_OUT_arg result);

private:

	void ShutdownHandler(EventTransceiver& sender, const IEventBase& receivedEvent);

	IObjectBroker& broker;
	const LogListenerProgramSettings& settings;
	Logger& logger;
	TimerCollection timerCollection;
	SMACFramework::FileSet& floatLogFile;
	PayloadManagerClient::Ptr pmClient;
};

}
}

#endif
