// Processor.h : Declaration of the CProcessor

#pragma once
#include "resource.h"       // main symbols

extern "C" { 
#include "../../c/lkf5defs.h"
}


// IProcessor
[
	object,
	uuid("5F0A9455-6D61-4E0C-8081-693A0C235264"),
	dual,	helpstring("IProcessor Interface"),
	pointer_default(unique)
]
__interface IProcessor : IDispatch
{
	[id(1), helpstring("method SetData")] HRESULT SetData(BSTR data, [out, retval] LONG* success);
	[id(2), helpstring("method Compute")] HRESULT Compute(LONG Model, LONG Flags, LONG MaxAuf);
	[id(3), helpstring("method PrepareOutput")] HRESULT PrepareOutput(LONG type, LONG flags, [out,retval] LONG* buflen);
	[id(4), helpstring("method GetOutput")] HRESULT GetOutput(LONG offset, LONG maxlen, [out,retval] BSTR* buffer);
	[propget, id(5), helpstring("property ImportSeparator")] HRESULT ImportSeparator([out, retval] BSTR* pVal);
	[propput, id(5), helpstring("property ImportSeparator")] HRESULT ImportSeparator([in] BSTR newVal);
	[propget, id(6), helpstring("property ExportSeparator")] HRESULT ExportSeparator([out, retval] BSTR* pVal);
	[propput, id(6), helpstring("property ExportSeparator")] HRESULT ExportSeparator([in] BSTR newVal);
	[id(8), helpstring("method GetBufferLineCount")] HRESULT GetBufferLineCount([out,retval] LONG* linecount);
	[id(11), helpstring("method GetBufferLen")] HRESULT GetBufferLen([out,retval] LONG* BufLen);
	[id(12), helpstring("method GetDefaultFilename")] HRESULT GetDefaultFilename([out,retval] BSTR* filename);
	[id(13), helpstring("method GetOutputLines")] HRESULT GetOutputLines(LONG startline, LONG linecount, [out,retval] BSTR * linebuf);
	[propget, id(14), helpstring("property FixedModel")] HRESULT FixedModel([out, retval] LONG* pVal);
	[propput, id(14), helpstring("property FixedModel")] HRESULT FixedModel([in] LONG newVal);
	[id(15), helpstring("method PrepareOutputEx")] HRESULT PrepareOutputEx(LONG type, LONG flags, VARIANT parameters, [out,retval] LONG* buflen);
	[propget, id(16), helpstring("property InputFileName")] HRESULT InputFileName([out, retval] BSTR* pVal);
	[propput, id(16), helpstring("property InputFileName")] HRESULT InputFileName([in] BSTR newVal);
	[propget, id(17), helpstring("property OutputFileName")] HRESULT OutputFileName([out, retval] BSTR* pVal);
	[propput, id(17), helpstring("property OutputFileName")] HRESULT OutputFileName([in] BSTR newVal);
	[id(18), helpstring("method CreateFilter")] HRESULT CreateFilter(BSTR FilterText, [out,retval] LONG* Filter);
	[id(19), helpstring("method DropFilter")] HRESULT DropFilter(LONG Filter, [out,retval] LONG* RetVal);
	[id(20), helpstring("method ApplyFilter")] HRESULT ApplyFilter(LONG Filter, LONG Flags, [out,retval] LONG* Count);
	[id(21), helpstring("method GetFilterText")] HRESULT GetFilterText(LONG Filter, [out,retval] BSTR* FilterText);
	[id(22), helpstring("method GetMarkCount")] HRESULT GetMarkCount([out,retval] LONG* MarkCount);
	[id(23), helpstring("method GetAufenthaltCount")] HRESULT GetAufenthaltCount([out,retval] LONG* AufenthaltCount);
	[id(24), helpstring("method MarkAufenthalte")] HRESULT MarkAufenthalte(VARIANT Ids, LONG Flags, [out,retval] LONG* Count);
	[id(25), helpstring("method DoIntScoring")] HRESULT DoIntScoring(LONG flags, VARIANT Settings, [out,retval] LONG* Result);
	[id(26), helpstring("method BatchExecute")] HRESULT BatchExecute(BSTR commands, [out,retval] LONG* returncode);
	[id(27), helpstring("method CheckInput")] HRESULT CheckInput(LONG abrechnungsjahr, LONG modus, [out,retval] ULONG* returncode);
	[id(28), helpstring("method SetErrorFormat")] HRESULT SetErrorFormat(LONG Facility, VARIANT ErrorFields, [out,retval] LONG* ReturnCode);
	[id(29), helpstring("method SetErrorFilter")] HRESULT SetErrorFilter(LONG ErrorFilter, [out,retval] LONG* ErrorCount);
	[id(30), helpstring("method SetCompatibilityMode")] HRESULT SetCompatibilityMode(LONG Compatibility, [out,retval] LONG* ReturnCode);
	[id(31), helpstring("method SetIntAbtData")] HRESULT SetIntAbtData(BSTR ABTFC, LONG Betten, [out,retval] LONG* Returncode);
	[id(32), helpstring("method GetLastError")] HRESULT GetLastError([out,retval] BSTR* Error);
	[id(33), helpstring("method DoScoring")] HRESULT DoScoring(LONG Flags, [out,retval] LONG* Result);
	[id(34), helpstring("method SetFlags")] HRESULT SetFlags(LONG Flags);
	[id(35), helpstring("method SetContextParameters")] HRESULT SetContextParameters(LONG Abrechnungsjahr, LONG PeriodVal, LONG PeriodNr, LONG PeriodType, LONG Flags);
	[id(36), helpstring("method SetAbrechnungsjahr")] HRESULT SetAbrechnungsjahr(LONG Abrechnungsjahr);
	[id(37), helpstring("method SetModelljahr")] HRESULT SetModelljahr(LONG Modelljahr, [out,retval] LONG* Result);
	[id(38), helpstring("method SetIntContextParameters")] HRESULT SetIntContextParameters([in] BSTR VonDatum, [in] BSTR BisDatum, [in] LONG Flags, [in] LONG MindestStd, LONG* Result);
	[id(39), helpstring("method DoStat")] HRESULT DoStat(LONG Flags, [out,retval] LONG* Result);
	[id(40), helpstring("method SendBuffer")] HRESULT SendBuffer(VARIANT Buffer, [out,retval] LONG* ReturnCode);
	[id(41), helpstring("method TraceSetAufenthalt")] HRESULT TraceSetAufenthalt(BSTR AufNr);
	[id(42), helpstring("method TraceSetMode")] HRESULT TraceSetMode(LONG Facility, LONG Level);
	[id(43), helpstring("method TraceGetAufenthalt")] HRESULT TraceGetAufenthalt([out,retval] BSTR* AufNr);
	[id(44), helpstring("method TraceGetMode")] HRESULT TraceGetMode(LONG Facility, [out,retval] LONG* Level);
};


interface Ilkf5;
class LKFStatic;
class BufferChar;
class Output;
class ProtocolObject;

// CProcessor

[
	coclass,
	threading("apartment"),
	vi_progid("LKFServer.Processor"),
	progid("LKFServer.Processor.1"),
	version(1.0),
	uuid("E8AB8F91-384E-463F-B373-40BF78AEF62A"),
	helpstring("Processor Class")
]
class ATL_NO_VTABLE CProcessor : 
	public IProcessor
{
protected:
	LKFStatic *pLKFStatic;
	LKF_CONTEXT *ctx;
	BufferChar *pOutputBuffer;
	LKF_FILTER **ppFilter;
	unsigned int nFilterCount;
	ProtocolObject *pProtocolObject;

	char sLastError[512];
	int  stammdaten_ok;
	int  modelljahr_gesetzt;

	const char *m_OutputFile;
	const char *m_InputFile;

	char	  LineSepImport[MAX_LINESEP];
	char	  LineSepExport[MAX_LINESEP];
	unsigned int LineSepExportLen;
	unsigned int LineSepImportLen;

	long FixedModelYear;
	long m_LastUsedModelYear;

	int ComputeLine (const char *line);
	int FinishPrepareOutput (Output *pOutput, LONG *buflen);

	unsigned int CreateUIntArray (VARIANT v, unsigned int *&array);
	void FreeUIntArray (unsigned int *&array);

	unsigned int GetFreeFilterIndex (void);

public:
	CProcessor();
	virtual ~CProcessor();

	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}
	
	void FinalRelease() 
	{
	}

public:

	STDMETHOD(SetData)(BSTR data, LONG* success);
	STDMETHOD(Compute)(LONG Model, LONG Flags, LONG MaxAuf);
	STDMETHOD(PrepareOutput)(LONG type, LONG flags, LONG* buflen);
	STDMETHOD(GetOutput)(LONG offset, LONG maxlen, BSTR* buffer);
	STDMETHOD(get_ImportSeparator)(BSTR* pVal);
	STDMETHOD(put_ImportSeparator)(BSTR newVal);
	STDMETHOD(get_ExportSeparator)(BSTR* pVal);
	STDMETHOD(put_ExportSeparator)(BSTR newVal);
	STDMETHOD(GetBufferLineCount)(LONG* linecount);
	STDMETHOD(GetBufferLen)(LONG* BufLen);
	STDMETHOD(GetDefaultFilename)(BSTR* filename);
	STDMETHOD(GetOutputLines)(LONG startline, LONG linecount, BSTR * linebuf);
	STDMETHOD(get_FixedModel)(LONG* pVal);
	STDMETHOD(put_FixedModel)(LONG newVal);
	STDMETHOD(PrepareOutputEx)(LONG type, LONG flags, VARIANT parameters, LONG* buflen);
	STDMETHOD(get_InputFileName)(BSTR* pVal);
	STDMETHOD(put_InputFileName)(BSTR newVal);
	STDMETHOD(get_OutputFileName)(BSTR* pVal);
	STDMETHOD(put_OutputFileName)(BSTR newVal);
	STDMETHOD(CreateFilter)(BSTR FilterText, LONG* Filter);
	STDMETHOD(DropFilter)(LONG Filter, LONG* RetVal);
	STDMETHOD(ApplyFilter)(LONG Filter, LONG Flags, LONG* Count);
	STDMETHOD(GetFilterText)(LONG Filter, BSTR* FilterText);
	STDMETHOD(GetMarkCount)(LONG* MarkCount);
	STDMETHOD(GetAufenthaltCount)(LONG* AufenthaltCount);
	STDMETHOD(MarkAufenthalte)(VARIANT Ids, LONG Flags, LONG* Count);
	STDMETHOD(DoIntScoring)(LONG flags, VARIANT Settings, LONG* Result);
	STDMETHOD(BatchExecute)(BSTR commands, LONG* returncode);
	STDMETHOD(CheckInput)(LONG abrechnungsjahr, LONG modus, ULONG* returncode);
	STDMETHOD(SetErrorFormat)(LONG Facility, VARIANT ErrorFields, LONG* ReturnCode);
	STDMETHOD(SetErrorFilter)(LONG ErrorFilter, LONG* ErrorCount);
	STDMETHOD(SetCompatibilityMode)(LONG Compatibility, LONG* ReturnCode);
	STDMETHOD(SetIntAbtData)(BSTR ABTFC, LONG Betten, LONG* Returncode);
	STDMETHOD(GetLastError)(BSTR* Error);
	STDMETHOD(DoScoring)(LONG Flags, LONG* Result);
	STDMETHOD(SetFlags)(LONG Flags);
	STDMETHOD(SetContextParameters)(LONG Abrechnungsjahr, LONG PeriodVal, LONG PeriodNr, LONG PeriodType, LONG Flags);
	STDMETHOD(SetAbrechnungsjahr)(LONG Abrechnungsjahr);
	STDMETHOD(SetModelljahr)(LONG Modelljahr, LONG* Result);
	STDMETHOD(SetIntContextParameters)(BSTR VonDatum, BSTR BisDatum, LONG Flags, LONG MindestStd, LONG* Result);
	STDMETHOD(DoStat)(LONG Flags, LONG* Result);
	STDMETHOD(SendBuffer)(VARIANT Buffer, LONG* ReturnCode);
	STDMETHOD(TraceSetAufenthalt)(BSTR AufNr);
	STDMETHOD(TraceSetMode)(LONG Facility, LONG Level);
	STDMETHOD(TraceGetAufenthalt)(BSTR* AufNr);
	STDMETHOD(TraceGetMode)(LONG Facility, LONG* Level);
};

