#include "MAXProxyHeaders.hpp"

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
MAXSplitByStateProcess::MAXSplitByStateProcess(Stuff::NotationFile *data_file, 
											   Interface *i, 
											   int p, 
											   bool bSuppress,
											   LPVOID fcn
											   ):	
	SplitByStateProcess(data_file,bSuppress,fcn),
	iPointer(i),
	progress(p)
{
	Check_Object(data_file);

	Page *page = data_file->FindPage("SplitByState");
	if (page) {
		page->GetEntry("Verbose", &suppress);
		suppress = !suppress;
	}
}

typedef int (*LPERROR_CALLBACKFN)(char *,bool);

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
void
	MAXSplitByStateProcess::SplitCallback(Proxies::GenericProxy *proxy, int type)
{
	Check_Object(this);
	Check_Object(proxy);

	//
	//----------------------------
	// Print the name of the proxy
	//----------------------------
	//
	MString name;
	char buffer[200];
	if (!proxy->GetName(&name)) {
		char tempName[200];
		strcpy(tempName, proxy->GetClassString());
		name = tempName;
	}

	switch (type)
	{
	case StatusCheck:
		//
		//----------------------------
		// Print the name of the proxy
		//----------------------------
		//
		
		if (!suppress)
		{
			sprintf(buffer, "Splitting %s...", static_cast<char*>(name));
			iPointer->ProgressUpdate(++progress,false,_T(buffer));
		}
		return;

	case WARNING_MultipleStates:
		sprintf(buffer, "Proxy %s has more than one unique state!", (char*)name);
		break;
	}

	if (errorfn)
	{
		LPERROR_CALLBACKFN fcn = (LPERROR_CALLBACKFN)errorfn;
		fcn(buffer,true);
	}
}
