#include "testadd.h"

string TestAddLoader::name="add";

Ptr<VarDef> TestAddLoader::variables[]=
{
	new VarDef("a","Defines first  number",VarDef::VAR_INT,"0"),
	new VarDef("b","Defines second number",VarDef::VAR_INT,"0"),

	0
};

Ptr<Command> TestAddLoader::commands[]=
{
	new Command("get","Returns result"),

	0
};

void TestAdd::afterInstantiate()
{
	wasCounted=false;
	c=0;
}

void TestAdd::receiveMessage(TObject* mesg)
{
	if (mesg->typeOf(MesgCommand::type))
	{
		MesgCommand* command=(MesgCommand*)mesg;
		
		if (wasCounted)
		{
			cout<<c<<endl;
		}
		else
		{
			cout<<"UNDEFINED"<<endl;
		}
	}
	
	if (mesg->typeOf(MesgVarChange::type))
	{
		wasCounted=false;
	}
}

void TestAdd::run()
{
	int a=toInt(getVariable("a"));
	int b=toInt(getVariable("b"));

	c=a+b;
	wasCounted=true;
}
