//-------------------------------------------------------------------------------------------------
// <copyright file="LWProgram.h" company="LiquidRobotics">
//  Copyright (c) Liquid Robotics Corporation, confidential and proprietary.  All rights reserved. 
// </copyright>
//
// <summary>
//	Declarations for LWProgram, the lua wrapper's module representing the sensor
//	pattern's program class. "Program" classes implement CORBA interface methods and
//	interact with the EventManager; they provide any required connections between the
//	controller and the CORBA world.
// </summary>
//
// <owner>Mike Cookson</owner>
//-------------------------------------------------------------------------------------------------

#ifndef __LWProgram_h__
#define __LWProgram_h__

#include "EventTransceiver.h"
#include "LqrSMACIdl.h"
#include "LqrSMACSharedLib.h"
#include "LWController.h"
#include "LWProgramSettings.h"
#include "SensorProgram.h"
#include "PayloadManagerClient.h"

namespace LiquidRobotics {
namespace LuaWrapper {

class SHARED_LIB_PUBLIC LWProgram
: public LiquidRobotics::EventLib::SensorProgram
{
public:

	typedef LiquidRobotics::EventLib::PayloadManagerClient PayloadManagerClient;
	typedef LiquidRobotics::EventLib::SensorProgram Base;
	typedef LiquidRobotics::SMACFramework::PayloadDescription Desc;

	LWProgram(IObjectBroker& _broker, const LWProgramSettings& _settings, Logger& _logger);
	virtual ~LWProgram();

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

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

protected:

	typedef LiquidRobotics::EventLib::IEventBase IEventBase;

	virtual void OnAnyEventReceived(EventTransceiver& sender, const IEventBase& receivedEvent);
	virtual void OnCommandCompleted(const EventLib::SensorControllerBaseCommandID& cmdID, const string& result, bool success);
	virtual void OnPublishDataSetEvent(LWController& sender, const string& instanceName, const string& eventName,
			const string& eventType, const string& eventDomain, const string& dataSetName, const string& content);
	virtual void OnPublishEvent(LWController& sender, LWController::IEventBase& evt);

	IObjectBroker& broker;
	const LWProgramSettings& settings;
	Logger& logger;
	LWControllerPtr ctrl;
	LWController::ScopedConnectionPtr commandCompletedConnection;
	LWController::ScopedConnectionPtr publishDataSetConnection;
	LWController::ScopedConnectionPtr publishEventConnection;
	LWController::ScopedConnectionPtr allEventsConnection;
};

}
}

#endif
