unit PlugServ;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  Windows, ActiveX, Classes, ComObj, CM2CMLXInterface, Filter, SysUtils;

type
  TCMLXLogic = class(TComObject, ICM2CMLXPlug)
  private
   LastErrMsg: String;
   XMLHandle: THandle;
   Foo: String;
  protected
   // Declare Basics
   Function Name(OUT Name: Pchar): HResult; stdcall;
   Function Version(OUT Version: word): HResult; stdcall; // Uses MMRB Notation
   Function RequiredCoreVersion(OUT RCV: Word): HResult; stdcall; // Uses MMRB Notation - Please refer to CM2Plugtypes for details
   Function SetParentHandle(Handle: THandle): HResult; stdcall;
   // Declare Error commands
   Function GetLastErrorMsg(OUT Msg: PChar): HResult; stdcall;
   // Declare Info system
   Function GetInfoCount(OUT InfoCount: Integer): HResult; stdcall;
   Function GetInfo(Index: Integer; OUT InfoName: PChar; OUT InfoVar: PChar): HResult; stdcall;
  // Declare "Event" types
   Function Init: HResult; stdcall;
   Function Terminating: HResult; stdcall;
   Function Setup: HResult; stdcall;
   // Plugin Speficic
   Function TagName(OUT Tag: PChar): HResult; stdcall;
   Function Perform(Attribute: PChar; Parameters: PChar; OUT ResultString: PChar; OUT ResultType: Byte): HResult; stdcall;
  end;

const
  Class_CMLXLogic: TGUID = '{C36C2258-28F2-4C20-A10A-81D2F79B742C}';

implementation

uses ComServ;


{ TCMLXLogic }

function TCMLXLogic.GetInfo(Index: Integer; out InfoName,
  InfoVar: PChar): HResult;
begin
 Result := S_OK;
 Case Index of
  0: Begin InfoName := 'Programmed By'; InfoVar := 'M. Israelsen & C. Aaangel'; end;
  1: Begin InfoName := 'Created'; InfoVar := 'August 15th 2004'; end;
  2: Begin InfoName := 'Updated'; InfoVar := 'August 15th 2004'; end;
  else begin
   LastErrMsg := 'Index out of bounds';
   Result := E_FAIL;
  end;
 end;
end;

function TCMLXLogic.GetInfoCount(out InfoCount: Integer): HResult;
begin
 InfoCount := 3;
 Result := S_OK;
end;

function TCMLXLogic.GetLastErrorMsg(out Msg: PChar): HResult;
begin
 If LastErrMsg <> '' then Msg := Pchar(LastErrMsg)
  else Msg := 'No Error';
 Result := S_OK;
end;

function TCMLXLogic.Init: HResult;
begin
 // Do nothing for now
 Result := S_OK;
end;

function TCMLXLogic.Name(out Name: Pchar): HResult;
begin
 Name := 'Logic';
 Result := S_OK;
end;

function TCMLXLogic.Perform(Attribute, Parameters: PChar;
  out ResultString: PChar; out ResultType: Byte): HResult;
begin
 // Insert Standard handling for Attribute
 // Insert XML Handling for Parameters
 // Do Logic Operations
 // Return ResultString and ResultType (Refer to Interface file)
 ResultType := rtSensor;
 Randomize;
 Foo := IntToStr(Random(1000));
 ResultString := PChar(Foo);
 Result := S_OK;
end;

function TCMLXLogic.RequiredCoreVersion(out RCV: Word): HResult;
begin
 RCV := 0500;
 Result := S_OK;
end;

function TCMLXLogic.SetParentHandle(Handle: THandle): HResult;
begin
 XMLHandle := Handle;
 Result := S_OK;
end;

function TCMLXLogic.Setup: HResult;
begin
 (* YOU CAN DO THIS *)
 // Form.Create
 // Load Settings onto form
 // Form.Showmodal
 // Save Settings
 // Freeandnil(form);

 (* BUT FOR NOW *)
 Result := E_NOTIMPL;
end;

function TCMLXLogic.TagName(out Tag: PChar): HResult;
begin
 Tag := 'Logic';
 Result := S_OK;
end;

function TCMLXLogic.Terminating: HResult;
begin
 // Do nothing
 Result := S_OK;
end;

function TCMLXLogic.Version(out Version: word): HResult;
begin
 Version := 0005;
 Result := S_OK;
end;

initialization
  TComObjectFactory.Create(ComServer, TCMLXLogic, Class_CMLXLogic,
    'CMLXLogic', '', ciMultiInstance, tmApartment);
end.
