/*************************************************************************
* For Customer Support contact Analytical Graphics, Inc. at www.agi.com *
*************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string>		
#include <iostream>				
#include "AgConnect.h"

extern "C" {
const char *AgEAppName  = _T("ConnectExample");
}

int
main()
{

char        *connection1      = NULL;
char        *initFileName     = NULL;
static const char  connectName[256] = _T("localhost:5001");

AgTConReturnInfo returnInfo;

#ifdef AGI_Linux_
std::string cmdString1("Load / VDF \"");
if (getenv("STK_INSTALL_DIR") != nullptr)
{
	cmdString1.append(getenv("STK_INSTALL_DIR"));
	cmdString1.append("/Data/ExampleScenarios/Intro_STK_Aircraft_Systems.vdf\"");
}
else
{
	std::cout << "STK_INSTALL_DIR environment variable must be set to run this example.";
	return 0;
}
#else
std::string cmdString1(_T("Load / VDF \"C:\\Program Files\\AGI\\STK 12\\Data\\ExampleScenarios\\Intro_STK_Aircraft_Systems.vdf\""));
#endif
std::string cmdString2(_T("AllAccess / ElimDups"));
int   i;


/* Initialize Connect */

AgConInit(initFileName);

/* Open a connection to STK */

AgConOpenSTK(&connection1, 0, connectName);

/* Set verbose and ack on */

AgConSetProperties(connection1, (AgCConVerboseOn | AgCConAckOn));

/* Begin sending IPC Commands */

AgConProcessSTKCmd(connection1, cmdString1.c_str(), &returnInfo);

/*
* The first command, Load, returns no data, so no need 
* to free memory allocated to returnInfo.
*/

AgConProcessSTKCmd(connection1, cmdString2.c_str(), &returnInfo);

/* Finished sending commands, close the connection */

AgConCloseSTK(&connection1);

/*  Print out the results of the AllAccess command */

for (i=0; i < returnInfo.numEntries; i++)
{
AgUtMsg( AgCMsgForceInfo, AgCMsgNoWait, AgCMsgDispDefault, AgCMsgNoErrorCode,	
	AgCMSourceLine, _T("Return entry %d:\n%s\n"), i+1, returnInfo.returnList[i]);
}

/*  Clean up the Return Information, freeing any unneeded memory */

AgConCleanupReturnInfo ( &returnInfo );

/*  Free remaining allocated memory in the Connect module in
*  preparation for exit
*/

AgConShutdownConnect();

std::cout << "Press enter to exit...\n";
std::cin.get();

return (0);
}