mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-18 23:49:07 +02:00
* Allow selectively adding handlers to reported API
git-svn-id: trunk@28193 -
This commit is contained in:
parent
7db9fbc234
commit
ad574ca377
@ -24,6 +24,10 @@ Type
|
|||||||
Protected
|
Protected
|
||||||
function FormatResult(const AClassName, AMethodName: TJSONStringType;
|
function FormatResult(const AClassName, AMethodName: TJSONStringType;
|
||||||
const Params, ID, Return: TJSONData): TJSONData; override;
|
const Params, ID, Return: TJSONData): TJSONData; override;
|
||||||
|
// Called during API creation. Can be used to restrict list of reported handlers.
|
||||||
|
Function PublishHandler(H: TCustomJSONRPCHandler): Boolean; virtual;
|
||||||
|
// Called during API creation. Can be used to restrict list of reported handlers.
|
||||||
|
Function PublishHandlerDef(HD: TJSONRPCHandlerDef): Boolean; virtual;
|
||||||
// 'tid'
|
// 'tid'
|
||||||
Class Function TransactionProperty : String; override;
|
Class Function TransactionProperty : String; override;
|
||||||
// 'method'
|
// 'method'
|
||||||
@ -224,6 +228,18 @@ begin
|
|||||||
Result:=TJSONObject.Create(['name',H.HandlerMethodName,'len',H.ArgumentCount])
|
Result:=TJSONObject.Create(['name',H.HandlerMethodName,'len',H.ArgumentCount])
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Function TCustomExtDirectDispatcher.PublishHandler(H : TCustomJSONRPCHandler) : Boolean;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Result:=(H<>Nil); // Avoid warning
|
||||||
|
end;
|
||||||
|
|
||||||
|
Function TCustomExtDirectDispatcher.PublishHandlerDef(HD : TJSONRPCHandlerDef) : Boolean;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Result:=(HD<>Nil); // Avoid warning
|
||||||
|
end;
|
||||||
|
|
||||||
Function TCustomExtDirectDispatcher.DoAPI: TJSONData;
|
Function TCustomExtDirectDispatcher.DoAPI: TJSONData;
|
||||||
|
|
||||||
Var
|
Var
|
||||||
@ -249,6 +265,9 @@ begin
|
|||||||
begin
|
begin
|
||||||
for I:=Owner.ComponentCount-1 downto 0 do
|
for I:=Owner.ComponentCount-1 downto 0 do
|
||||||
If Owner.Components[i] is TCustomJSONRPCHandler then
|
If Owner.Components[i] is TCustomJSONRPCHandler then
|
||||||
|
begin
|
||||||
|
H:=Owner.Components[i] as TCustomJSONRPCHandler;
|
||||||
|
if PublishHandler(H) then
|
||||||
begin
|
begin
|
||||||
If (R=Nil) then
|
If (R=Nil) then
|
||||||
begin
|
begin
|
||||||
@ -256,25 +275,24 @@ begin
|
|||||||
R:=TJSONArray.Create;
|
R:=TJSONArray.Create;
|
||||||
A.Add(N,R);
|
A.Add(N,R);
|
||||||
end;
|
end;
|
||||||
H:=Owner.Components[i] as TCustomJSONRPCHandler;
|
|
||||||
R.Add(HandlerToAPIMethod(H));
|
R.Add(HandlerToAPIMethod(H));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
If (jdoSearchRegistry in Options) then
|
If (jdoSearchRegistry in Options) then
|
||||||
begin
|
begin
|
||||||
M:=JSONRPCHandlerManager;
|
M:=JSONRPCHandlerManager;
|
||||||
For I:=M.HandlerCount-1 downto 0 do
|
For I:=M.HandlerCount-1 downto 0 do
|
||||||
begin
|
begin
|
||||||
HD:=M.HandlerDefs[i];
|
HD:=M.HandlerDefs[i];
|
||||||
{$ifdef extdebug}SendDebugFmt('Creating API entry for %s.%s',[HD.HandlerClassName,HD.HandlerMethodName]);{$endif}
|
if PublishHandlerDef(HD) then
|
||||||
|
begin
|
||||||
If (R=Nil) or (CompareText(N,HD.HandlerClassName)<>0) then
|
If (R=Nil) or (CompareText(N,HD.HandlerClassName)<>0) then
|
||||||
begin
|
begin
|
||||||
{$ifdef extdebug}SendDebugFmt('Seems like new action entry : %s<> %s',[HD.HandlerClassName,N]);{$endif}
|
|
||||||
N:=HD.HandlerClassName;
|
N:=HD.HandlerClassName;
|
||||||
J:=A.IndexOfName(N);
|
J:=A.IndexOfName(N);
|
||||||
If (J=-1) then
|
If (J=-1) then
|
||||||
begin
|
begin
|
||||||
{$ifdef extdebug}SendDebugFmt('Creating new action entry : %s ',[N]);{$endif}
|
|
||||||
R:=TJSONArray.Create;
|
R:=TJSONArray.Create;
|
||||||
A.Add(N,R);
|
A.Add(N,R);
|
||||||
end
|
end
|
||||||
@ -284,6 +302,7 @@ begin
|
|||||||
R.Add(HandlerDefToAPIMethod(HD));
|
R.Add(HandlerDefToAPIMethod(HD));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
Result:=D;
|
Result:=D;
|
||||||
except
|
except
|
||||||
FreeAndNil(D);
|
FreeAndNil(D);
|
||||||
|
Loading…
Reference in New Issue
Block a user