#pragma once

#include "SAXContentHandlerImpl.h"
#include <string>

#include "WindowData.h"
#include "TestResults.h"

class LogParser : public SAXContentHandlerImpl
{
private:
	static const int defaultMsgDelay = 2000;
	WindowData * currentWindow;
	WindowData * currentParent;

	int msgType;
	LPARAM lParam;
	WPARAM wParam;

	boolean useDefaultDelay;
	int delay;

	void sendMessage(HWND hwnd);

	_TCHAR * runCommand;
	unsigned int startupTime;
	HANDLE hProcess;

	std::wstring sessionId;
	RESULT result;
	unsigned int currentMessage;

	TestResults * results;

public:
	LogParser(_TCHAR * runCommand, unsigned int startupChar, TestResults * results, bool useDefaultDelay = false);
	~LogParser(void);

	virtual HRESULT STDMETHODCALLTYPE startElement( 
			wchar_t __RPC_FAR *pwchNamespaceUri,
			int cchNamespaceUri,
			wchar_t __RPC_FAR *pwchLocalName,
			int cchLocalName,
			wchar_t __RPC_FAR *pwchRawName,
			int cchRawName,
			MSXML2::ISAXAttributes __RPC_FAR *pAttributes);

	virtual HRESULT STDMETHODCALLTYPE endElement( 
			wchar_t __RPC_FAR *pwchNamespaceUri,
			int cchNamespaceUri,
			wchar_t __RPC_FAR *pwchLocalName,
			int cchLocalName,
			wchar_t __RPC_FAR *pwchRawName,
			int cchRawName);

	std::wstring GetAttributeValue(MSXML2::ISAXAttributes __RPC_FAR *pAttributes,
							   std::wstring name, std::wstring defvalue);


	int getDefaultMsgDelay();
};
