diff --git a/atbgit.pas b/atbgit.pas new file mode 100644 index 0000000..81c5a41 --- /dev/null +++ b/atbgit.pas @@ -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. + diff --git a/atbutils.pas b/atbutils.pas new file mode 100644 index 0000000..fe0aa6c --- /dev/null +++ b/atbutils.pas @@ -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. + diff --git a/atbwebinterface.pas b/atbwebinterface.pas new file mode 100644 index 0000000..b6b534f --- /dev/null +++ b/atbwebinterface.pas @@ -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. + diff --git a/deploy/atbgit.pas b/deploy/atbgit.pas new file mode 100644 index 0000000..81c5a41 --- /dev/null +++ b/deploy/atbgit.pas @@ -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. + diff --git a/deploy/atbutils.pas b/deploy/atbutils.pas new file mode 100644 index 0000000..fe0aa6c --- /dev/null +++ b/deploy/atbutils.pas @@ -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. + diff --git a/deploy/atbwebinterface.pas b/deploy/atbwebinterface.pas new file mode 100644 index 0000000..b6b534f --- /dev/null +++ b/deploy/atbwebinterface.pas @@ -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. +