#include <windows.h>
#include <stdio.h>
#include <bncs_string.h>
#include <bncs_config.h>
#include "csiCapabilities.h"
#include <ccClient.h>

#define PNL_MAIN	1

#define TIMER_SETUP	1

// this nasty little macro to make our class visible to the outside world
EXPORT_BNCS_SCRIPT( csiCapabilities )

// constructor - equivalent to ApplCore STARTUP
csiCapabilities::csiCapabilities( bncs_client_callback * parent, const char * path ) : bncs_script_helper( parent, path )
{
	// show a panel from file csiCapabilities.bncs_ui and we'll know it as our panel PNL_MAIN
	panelShow( PNL_MAIN, "csiCapabilities.bncs_ui" );

	setSize(PNL_MAIN);

	// no callback required
	ccClient c(0);

	// c will immediately go out-of-scope and disconnected after we've called
	if (!c.connect())
	{
		textPut("text", bncs_string("%1").arg(c.maxDevices()), PNL_MAIN, "maxDevices");
		textPut("text", bncs_string("%1").arg(c.maxIndexes()), PNL_MAIN, "maxIndexes");
		textPut("text", bncs_string("%1").arg(c.maxSources()), PNL_MAIN, "maxSources");
		textPut("text", bncs_string("%1").arg(c.maxDatabases()), PNL_MAIN, "maxDatabases");
		textPut("text", bncs_string("%1").arg(c.maxString()), PNL_MAIN, "maxString");
	}
	else
	{
		textPut("text", "No", PNL_MAIN, "maxDevices");
		textPut("text", "CSI", PNL_MAIN, "maxIndexes");
		textPut("text", "Connection", PNL_MAIN, "maxSources");
		textPut("text", "", PNL_MAIN, "maxDatabases");
		textPut("text", "", PNL_MAIN, "maxString");
	}

}

// destructor - equivalent to ApplCore CLOSEDOWN
csiCapabilities::~csiCapabilities()
{
}

// all button pushes and notifications come here
void csiCapabilities::buttonCallback( buttonNotify *b )
{
	if( b->panel() == PNL_MAIN )
	{
		switch( b->id() )
		{
			case 1:			textPut( "text", "you pressed|control 1", PNL_MAIN, 4 );		break;
			case 2:			textPut( "text", "you pressed|control 2", PNL_MAIN, 4 );		break;
			case 3:			textPut( "text", "you pressed|control 3", PNL_MAIN, 4 );		break;
		}
	}
}

// all revertives come here
int csiCapabilities::revertiveCallback( revertiveNotify * r )
{
/*	switch( r->device() )
	{
		case 123:
 			textPut( "text", r->sInfo(), PNL_MAIN, 3 );
			break;
	}
*/	return 0;
}

// all database name changes come back here
void csiCapabilities::databaseCallback( revertiveNotify * r )
{
}

// all parent notifications come here i.e. when this script is just one 
//  component of another dialog then our host might want to tell us things
bncs_string csiCapabilities::parentCallback( parentNotify *p )
{
	if( p->command() == "return" )
	{
		if( p->value() == "all" )
		{	// Persisting values for bncs_vis_ed
			bncs_stringlist sl;
			
			sl << bncs_string( "myParam=%1" ).arg( m_myParam );
			
			return sl.toString( '\n' );
		}

		else if( p->value() == "myParam" )
		{	// Specific value being asked for by a textGet
			return( bncs_string( "%1=%2" ).arg( p->value() ).arg( m_myParam ) );
		}

	}
	else if( p->command() == "instance" && p->value() != m_instance )
	{	// Our instance is being set/changed
		m_instance = p->value();
		//Do something instance-change related here
	}

	else if( p->command() == "myParam" )
	{	// Persisted value or 'Command' being set here
		m_myParam = p->value();
	}

	// ***** CONNECTIONS EVENTS HELPER LIST *****
	else if( p->command() == "_events" )
	{	// Helper-list of everything in this component generated by hostNotify's
		bncs_stringlist sl;

		sl << "notify=*";		
		
		return sl.toString( '\n' );
	}

	// ***** CONNECTIONS COMMANDS HELPER LIST *****
	else if( p->command() == "_commands" )
	{	// Helper-list of any commands/parameters you might want to set at run-time
		bncs_stringlist sl;
		
		sl << "myParam=[value]";
		
		return sl.toString( '\n' );
	}

	return "";
}

// timer events come here
void csiCapabilities::timerCallback( int id )
{
	switch( id )
	{
	case TIMER_SETUP:
		timerStop(id);
		break;

	default:	// Unhandled timer event
		timerStop(id);
		break;
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////// Callbacks above - Methods below ///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////


