//-------------------------------------------------------------------------------------------------
// <copyright file="TestClient.cpp" company="LiquidRobotics">
//  Copyright (c) Liquid Robotics Corporation, confidential and proprietary.  All rights reserved. 
// </copyright>
//
// <summary>
// </summary>
//
// <owner></owner>
//-------------------------------------------------------------------------------------------------

#include "includes.h"
#include <iostream>
#include "TestClientProgram.h"
#include "LqrSMACEvent.h"
#include <boost/any.hpp>

using namespace std;
using namespace boost;
using namespace LiquidRobotics::EventManagerClient;
using namespace LiquidRobotics::SMACFramework;

int main(int argc, char* argv[])
{
	int programExitCode = 0;

	cout << "Starting EventManager test client ..." << endl;

	try
	{
		TestClientProgram program;
		program.Initialize(argc, argv);

		{
			CORBA::Any_var foo = new CORBA::Any();
			foo <<= "Hello, world";
			Event::ValueType vt(foo);
			if (vt.AsAny().type() == typeid(string))
			{
				cout << "yes: " << any_cast<string>(vt.AsAny()) << endl;
			}
		}

		{
			vector<string> strings;
			strings.push_back("One");
			strings.push_back("Two");
			strings.push_back("Three");

			boost::any a = strings;
			Event::ValueType vt(a);

			Event::ValueType::CORBAEntity foo;
			vt.MakeCORBAEntity(foo);

			Event::ValueType vt2(foo);
			vector<string> strings2 = any_cast< vector<string> >(vt2.AsAny());

			cout << endl << strings2.size() << " strings:" << endl << endl;

			for (int i = 0; i < (int) strings2.size(); ++i)
				cout << (i+1) << ". " << strings2[i] << endl;
		}


		programExitCode = program.Run();
	}
	catch(std::exception& ex)
	{
		cerr << "Default exception handler triggered for STL exception " << ex.what() << endl;
		programExitCode = 1;
	}
	catch(CORBA::Exception& ex)
	{
		cerr << " Default exception handler triggered for CORBA exception " << ex._name() << endl;
		programExitCode = 1;
	}
	catch(...)
	{
		cerr << "Default exception handler triggered" << endl;
		programExitCode = 1;
	}

	cout << "Ending EventManager with exit code " << programExitCode << endl;
	return programExitCode;
}

