//..............................................................................
//
// $(pluginName) layer
//

import "doc_Plugin.jnc"

//..............................................................................

class $(layerClass): doc.Layer
{
protected:
	jnc.RegexState m_rxScannerState;

public:
	construct (doc.PluginHost* pluginHost);

protected:
	onLogRecord (
		uint64_t timestamp,
		uint_t recordCode,
		void const* p,
		size_t size
		)
	{
		if (recordCode == log.StdRecordCode.Rx)
			scanRx (p, size);
	}

	scanRx (
		char const* p,
		size_t length
		);

	size_t transmitString (char const* s)
	{
		return transmitNext (s, strlen (s));
	}
}

// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

$(layerClass).construct (doc.PluginHost* pluginHost)
{
	basetype.construct (pluginHost);
	pluginHost.m_log.attachListener (onLogRecord @ pluginHost.m_mainThreadScheduler);
	m_rxScannerState.m_isIncremental = true;
}

$(layerClass).scanRx (
	char const* p,
	size_t length
	)
{
	char const* end = p + length;
	while (p < end)
	{
		reswitch (m_rxScannerState, p, length)
		{
		case r"about[\r\n]":
			transmitString ("IO Ninja - $(pluginName)\r\n");
			break;

		case r"version[\r\n]":
			transmitString ("Version 1.0.0\r\n");
			break;

		case r"help[\r\n]":
			transmitString ("This plugin is a starting point for writing your test utility\r\n");
			break;

		case ".":
			// ignore everything else
			break;
		}

		p += m_rxScannerState.m_consumedLength;
	}
}

//..............................................................................
