add several atb-units to structure the code
This commit is contained in:
		
							
								
								
									
										21
									
								
								atbgit.pas
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								atbgit.pas
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
unit ATBGit;
 | 
			
		||||
 | 
			
		||||
{$mode ObjFPC}{$H+}
 | 
			
		||||
 | 
			
		||||
interface
 | 
			
		||||
 | 
			
		||||
uses
 | 
			
		||||
  Classes, SysUtils, CTypes, fpjson, jsonparser;
 | 
			
		||||
 | 
			
		||||
type
 | 
			
		||||
    function SetFile(const localRepository: String; const fileId: String; const json: TJSONData): Boolean;
 | 
			
		||||
    function SetFileInternal(const localRepository: PChar;
 | 
			
		||||
                             const fileId: PChar;
 | 
			
		||||
                             const json: PChar;
 | 
			
		||||
                             size: cint32): cbool; stdcall;
 | 
			
		||||
 | 
			
		||||
implementation
 | 
			
		||||
    const DLLName = 'CalculatorCInterface.dll';
 | 
			
		||||
 | 
			
		||||
end.
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								atbutils.pas
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								atbutils.pas
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
unit ATBUtils;
 | 
			
		||||
 | 
			
		||||
{$mode ObjFPC}{$H+}
 | 
			
		||||
 | 
			
		||||
interface
 | 
			
		||||
 | 
			
		||||
uses Classes, SysUtils, CTypes;
 | 
			
		||||
 | 
			
		||||
procedure DeleteMem(P: PChar); stdcall;
 | 
			
		||||
 | 
			
		||||
implementation
 | 
			
		||||
    const DLLName = 'CalculatorCInterface.dll';
 | 
			
		||||
 | 
			
		||||
procedure DeleteMem(P: PChar); stdcall; external DLLName;
 | 
			
		||||
 | 
			
		||||
end.
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										136
									
								
								atbwebinterface.pas
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										136
									
								
								atbwebinterface.pas
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,136 @@
 | 
			
		||||
unit ATBWebInterface;
 | 
			
		||||
 | 
			
		||||
{$mode ObjFPC}{$H+}
 | 
			
		||||
 | 
			
		||||
interface
 | 
			
		||||
 | 
			
		||||
uses SysUtils, CTypes, fpjson, jsonparser, ATBUtils;
 | 
			
		||||
 | 
			
		||||
type
 | 
			
		||||
  PTJSONObject = ^TJSONObject;
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// public interface
 | 
			
		||||
//
 | 
			
		||||
function GetFileMenu(const localRepository: UTF8String;
 | 
			
		||||
                     jObj: PTJSONObject): Boolean;
 | 
			
		||||
 | 
			
		||||
function GetFile(const localRepository: UTF8String;
 | 
			
		||||
                 const fileId: UTF8String;
 | 
			
		||||
                 jObj: PTJSONObject): Boolean;
 | 
			
		||||
 | 
			
		||||
function SetFile(const localRepository: UTF8String;
 | 
			
		||||
                 const fileId: UTF8String;
 | 
			
		||||
                 const jsonData: TJSONData): Boolean;
 | 
			
		||||
 | 
			
		||||
function GetFileName(const localRepository: UTF8String;
 | 
			
		||||
                     const fileId: UTF8String): UTF8String;
 | 
			
		||||
 | 
			
		||||
// private c-interface
 | 
			
		||||
function GetFileMenuInternal(const localRepository: PChar): PChar; stdcall;
 | 
			
		||||
function GetFileInternal(const localRepository: PChar; const fileId: PChar): PChar; stdcall;
 | 
			
		||||
function SetFileInternal(const localRepository: PChar; const fileId: PChar;
 | 
			
		||||
                         const json: PChar; size: cint32): cbool; stdcall;
 | 
			
		||||
function GetFileNameInternal(const localRepository: PChar;
 | 
			
		||||
                             const fileId: PChar): PChar; stdcall;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
implementation
 | 
			
		||||
    const DLLName = 'CalculatorCInterface.dll';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    ///
 | 
			
		||||
    function GetFileMenu(const localRepository: UTF8String; jObj: PTJSONObject): Boolean;
 | 
			
		||||
    var
 | 
			
		||||
        p: PChar;
 | 
			
		||||
        fileMenuContent: UTF8String;
 | 
			
		||||
    begin
 | 
			
		||||
        Result := false;
 | 
			
		||||
        try
 | 
			
		||||
            p := GetFileMenuInternal(PChar(Utf8ToAnsi(localRepository)));
 | 
			
		||||
            if p <> nil then begin
 | 
			
		||||
                fileMenuContent := UTF8String(p);
 | 
			
		||||
                jObj^ := GetJSON(fileMenuContent) as TJSONObject;
 | 
			
		||||
                Result := true;
 | 
			
		||||
            end;
 | 
			
		||||
        finally
 | 
			
		||||
            DeleteMem(p);
 | 
			
		||||
        end;
 | 
			
		||||
    end;
 | 
			
		||||
 | 
			
		||||
    function GetFileName(const localRepository: UTF8String;
 | 
			
		||||
                     const fileId: UTF8String): UTF8String;
 | 
			
		||||
    var
 | 
			
		||||
        p: PChar;
 | 
			
		||||
    begin
 | 
			
		||||
        Result := '';
 | 
			
		||||
        try
 | 
			
		||||
            p := GetFileNameInternal(PChar(Utf8ToAnsi(localRepository)),
 | 
			
		||||
                                     PChar(Utf8ToAnsi(fileId)));
 | 
			
		||||
            if p <> nil then begin
 | 
			
		||||
                Result := UTF8String(p);
 | 
			
		||||
            end;
 | 
			
		||||
        finally
 | 
			
		||||
            DeleteMem(p);
 | 
			
		||||
        end;
 | 
			
		||||
    end;
 | 
			
		||||
 | 
			
		||||
    function GetFile(const localRepository: UTF8String; const fileId: UTF8String;
 | 
			
		||||
                     jObj: PTJSONObject): Boolean;
 | 
			
		||||
    var
 | 
			
		||||
        p: PChar;
 | 
			
		||||
        fileContent: UTF8String;
 | 
			
		||||
    begin
 | 
			
		||||
        Result := false;
 | 
			
		||||
                try
 | 
			
		||||
            p := GetFileInternal(PChar(Utf8ToAnsi(localRepository)),
 | 
			
		||||
                                 PChar(Utf8ToAnsi(fileId)));
 | 
			
		||||
            if p <> nil then begin
 | 
			
		||||
                fileContent := UTF8String(p);
 | 
			
		||||
                jObj^ := GetJSON(fileContent) as TJSONObject;
 | 
			
		||||
                Result := true;
 | 
			
		||||
            end;
 | 
			
		||||
        finally
 | 
			
		||||
            DeleteMem(p);
 | 
			
		||||
        end;
 | 
			
		||||
    end;
 | 
			
		||||
 | 
			
		||||
    ///
 | 
			
		||||
    function SetFile(const localRepository: UTF8String; const fileId: UTF8String;
 | 
			
		||||
                     const jsonData: TJSONData): Boolean;
 | 
			
		||||
    var
 | 
			
		||||
        P: PChar;
 | 
			
		||||
        Len: Integer;
 | 
			
		||||
        S: UTF8String;
 | 
			
		||||
    begin
 | 
			
		||||
        try
 | 
			
		||||
            writeLn(jsonData.FormatJSON);
 | 
			
		||||
            S := jsonData.AsJSON;
 | 
			
		||||
            P := PChar(S);
 | 
			
		||||
            Len := System.Length(Utf8ToAnsi(P));
 | 
			
		||||
            Result := SetFileInternal(PChar(Utf8ToAnsi(localRepository)),
 | 
			
		||||
                                      PChar(Utf8ToAnsi(fileId)), P, Len);
 | 
			
		||||
        finally
 | 
			
		||||
        end;
 | 
			
		||||
    end;
 | 
			
		||||
 | 
			
		||||
    // external c-interface
 | 
			
		||||
    function GetFileInternal(const localRepository: PChar;
 | 
			
		||||
                             const fileId: PChar): PChar; stdcall;
 | 
			
		||||
        external DLLName;
 | 
			
		||||
 | 
			
		||||
    function GetFileNameInternal(const localRepository: PChar;
 | 
			
		||||
                                 const fileId: PChar): PChar; stdcall;
 | 
			
		||||
        external DLLName;
 | 
			
		||||
 | 
			
		||||
    function GetFileMenuInternal(const localRepository: PChar): PChar; stdcall;
 | 
			
		||||
        external DLLName;
 | 
			
		||||
 | 
			
		||||
    function SetFileInternal(const localRepository: PChar;
 | 
			
		||||
                             const fileId: PChar;
 | 
			
		||||
                             const json: PChar;
 | 
			
		||||
                             size: cint32): cbool; stdcall;
 | 
			
		||||
        external DLLName;
 | 
			
		||||
 | 
			
		||||
end.
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										21
									
								
								deploy/atbgit.pas
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								deploy/atbgit.pas
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,21 @@
 | 
			
		||||
unit ATBGit;
 | 
			
		||||
 | 
			
		||||
{$mode ObjFPC}{$H+}
 | 
			
		||||
 | 
			
		||||
interface
 | 
			
		||||
 | 
			
		||||
uses
 | 
			
		||||
  Classes, SysUtils, CTypes, fpjson, jsonparser;
 | 
			
		||||
 | 
			
		||||
type
 | 
			
		||||
    function SetFile(const localRepository: String; const fileId: String; const json: TJSONData): Boolean;
 | 
			
		||||
    function SetFileInternal(const localRepository: PChar;
 | 
			
		||||
                             const fileId: PChar;
 | 
			
		||||
                             const json: PChar;
 | 
			
		||||
                             size: cint32): cbool; stdcall;
 | 
			
		||||
 | 
			
		||||
implementation
 | 
			
		||||
    const DLLName = 'CalculatorCInterface.dll';
 | 
			
		||||
 | 
			
		||||
end.
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								deploy/atbutils.pas
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								deploy/atbutils.pas
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,17 @@
 | 
			
		||||
unit ATBUtils;
 | 
			
		||||
 | 
			
		||||
{$mode ObjFPC}{$H+}
 | 
			
		||||
 | 
			
		||||
interface
 | 
			
		||||
 | 
			
		||||
uses Classes, SysUtils, CTypes;
 | 
			
		||||
 | 
			
		||||
procedure DeleteMem(P: PChar); stdcall;
 | 
			
		||||
 | 
			
		||||
implementation
 | 
			
		||||
    const DLLName = 'CalculatorCInterface.dll';
 | 
			
		||||
 | 
			
		||||
procedure DeleteMem(P: PChar); stdcall; external DLLName;
 | 
			
		||||
 | 
			
		||||
end.
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										136
									
								
								deploy/atbwebinterface.pas
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										136
									
								
								deploy/atbwebinterface.pas
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,136 @@
 | 
			
		||||
unit ATBWebInterface;
 | 
			
		||||
 | 
			
		||||
{$mode ObjFPC}{$H+}
 | 
			
		||||
 | 
			
		||||
interface
 | 
			
		||||
 | 
			
		||||
uses SysUtils, CTypes, fpjson, jsonparser, ATBUtils;
 | 
			
		||||
 | 
			
		||||
type
 | 
			
		||||
  PTJSONObject = ^TJSONObject;
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
// public interface
 | 
			
		||||
//
 | 
			
		||||
function GetFileMenu(const localRepository: UTF8String;
 | 
			
		||||
                     jObj: PTJSONObject): Boolean;
 | 
			
		||||
 | 
			
		||||
function GetFile(const localRepository: UTF8String;
 | 
			
		||||
                 const fileId: UTF8String;
 | 
			
		||||
                 jObj: PTJSONObject): Boolean;
 | 
			
		||||
 | 
			
		||||
function SetFile(const localRepository: UTF8String;
 | 
			
		||||
                 const fileId: UTF8String;
 | 
			
		||||
                 const jsonData: TJSONData): Boolean;
 | 
			
		||||
 | 
			
		||||
function GetFileName(const localRepository: UTF8String;
 | 
			
		||||
                     const fileId: UTF8String): UTF8String;
 | 
			
		||||
 | 
			
		||||
// private c-interface
 | 
			
		||||
function GetFileMenuInternal(const localRepository: PChar): PChar; stdcall;
 | 
			
		||||
function GetFileInternal(const localRepository: PChar; const fileId: PChar): PChar; stdcall;
 | 
			
		||||
function SetFileInternal(const localRepository: PChar; const fileId: PChar;
 | 
			
		||||
                         const json: PChar; size: cint32): cbool; stdcall;
 | 
			
		||||
function GetFileNameInternal(const localRepository: PChar;
 | 
			
		||||
                             const fileId: PChar): PChar; stdcall;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
implementation
 | 
			
		||||
    const DLLName = 'CalculatorCInterface.dll';
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    ///
 | 
			
		||||
    function GetFileMenu(const localRepository: UTF8String; jObj: PTJSONObject): Boolean;
 | 
			
		||||
    var
 | 
			
		||||
        p: PChar;
 | 
			
		||||
        fileMenuContent: UTF8String;
 | 
			
		||||
    begin
 | 
			
		||||
        Result := false;
 | 
			
		||||
        try
 | 
			
		||||
            p := GetFileMenuInternal(PChar(Utf8ToAnsi(localRepository)));
 | 
			
		||||
            if p <> nil then begin
 | 
			
		||||
                fileMenuContent := UTF8String(p);
 | 
			
		||||
                jObj^ := GetJSON(fileMenuContent) as TJSONObject;
 | 
			
		||||
                Result := true;
 | 
			
		||||
            end;
 | 
			
		||||
        finally
 | 
			
		||||
            DeleteMem(p);
 | 
			
		||||
        end;
 | 
			
		||||
    end;
 | 
			
		||||
 | 
			
		||||
    function GetFileName(const localRepository: UTF8String;
 | 
			
		||||
                     const fileId: UTF8String): UTF8String;
 | 
			
		||||
    var
 | 
			
		||||
        p: PChar;
 | 
			
		||||
    begin
 | 
			
		||||
        Result := '';
 | 
			
		||||
        try
 | 
			
		||||
            p := GetFileNameInternal(PChar(Utf8ToAnsi(localRepository)),
 | 
			
		||||
                                     PChar(Utf8ToAnsi(fileId)));
 | 
			
		||||
            if p <> nil then begin
 | 
			
		||||
                Result := UTF8String(p);
 | 
			
		||||
            end;
 | 
			
		||||
        finally
 | 
			
		||||
            DeleteMem(p);
 | 
			
		||||
        end;
 | 
			
		||||
    end;
 | 
			
		||||
 | 
			
		||||
    function GetFile(const localRepository: UTF8String; const fileId: UTF8String;
 | 
			
		||||
                     jObj: PTJSONObject): Boolean;
 | 
			
		||||
    var
 | 
			
		||||
        p: PChar;
 | 
			
		||||
        fileContent: UTF8String;
 | 
			
		||||
    begin
 | 
			
		||||
        Result := false;
 | 
			
		||||
                try
 | 
			
		||||
            p := GetFileInternal(PChar(Utf8ToAnsi(localRepository)),
 | 
			
		||||
                                 PChar(Utf8ToAnsi(fileId)));
 | 
			
		||||
            if p <> nil then begin
 | 
			
		||||
                fileContent := UTF8String(p);
 | 
			
		||||
                jObj^ := GetJSON(fileContent) as TJSONObject;
 | 
			
		||||
                Result := true;
 | 
			
		||||
            end;
 | 
			
		||||
        finally
 | 
			
		||||
            DeleteMem(p);
 | 
			
		||||
        end;
 | 
			
		||||
    end;
 | 
			
		||||
 | 
			
		||||
    ///
 | 
			
		||||
    function SetFile(const localRepository: UTF8String; const fileId: UTF8String;
 | 
			
		||||
                     const jsonData: TJSONData): Boolean;
 | 
			
		||||
    var
 | 
			
		||||
        P: PChar;
 | 
			
		||||
        Len: Integer;
 | 
			
		||||
        S: UTF8String;
 | 
			
		||||
    begin
 | 
			
		||||
        try
 | 
			
		||||
            writeLn(jsonData.FormatJSON);
 | 
			
		||||
            S := jsonData.AsJSON;
 | 
			
		||||
            P := PChar(S);
 | 
			
		||||
            Len := System.Length(Utf8ToAnsi(P));
 | 
			
		||||
            Result := SetFileInternal(PChar(Utf8ToAnsi(localRepository)),
 | 
			
		||||
                                      PChar(Utf8ToAnsi(fileId)), P, Len);
 | 
			
		||||
        finally
 | 
			
		||||
        end;
 | 
			
		||||
    end;
 | 
			
		||||
 | 
			
		||||
    // external c-interface
 | 
			
		||||
    function GetFileInternal(const localRepository: PChar;
 | 
			
		||||
                             const fileId: PChar): PChar; stdcall;
 | 
			
		||||
        external DLLName;
 | 
			
		||||
 | 
			
		||||
    function GetFileNameInternal(const localRepository: PChar;
 | 
			
		||||
                                 const fileId: PChar): PChar; stdcall;
 | 
			
		||||
        external DLLName;
 | 
			
		||||
 | 
			
		||||
    function GetFileMenuInternal(const localRepository: PChar): PChar; stdcall;
 | 
			
		||||
        external DLLName;
 | 
			
		||||
 | 
			
		||||
    function SetFileInternal(const localRepository: PChar;
 | 
			
		||||
                             const fileId: PChar;
 | 
			
		||||
                             const json: PChar;
 | 
			
		||||
                             size: cint32): cbool; stdcall;
 | 
			
		||||
        external DLLName;
 | 
			
		||||
 | 
			
		||||
end.
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user