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

import "doc_Plugin.jnc"

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

class $(layerClass): doc.Layer
{
protected:
	jnc.Recognizer m_rxScanner;

public:
	construct (doc.PluginHost* pluginHost);

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

	jnc.AutomatonResult automaton scanRx (jnc.Recognizer* recognizer);

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

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

$(layerClass).construct (doc.PluginHost* pluginHost)
{
	basetype.construct (pluginHost);
	m_rxScanner.construct (scanRx);
	pluginHost.m_log.attachListener (onLogRecord @ pluginHost.m_mainThreadScheduler);
}

jnc.AutomatonResult automaton $(layerClass).scanRx (jnc.Recognizer* recognizer)
{
	%% "about" [\r\n]
		try transmitString ("IO Ninja - $(pluginName)\r\n");

	%% "version" [\r\n]
		try transmitString ("Version 1.0.0\r\n");

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

	%% .
		// ignore everything else
}

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