1 |
tony |
45 |
(*
|
2 |
|
|
* Firebird Interface (fbintf). The fbintf components provide a set of
|
3 |
|
|
* Pascal language bindings for the Firebird API. Although predominantly
|
4 |
|
|
* a new development they include source code taken from IBX and may be
|
5 |
|
|
* considered a derived product. This software thus also includes the copyright
|
6 |
|
|
* notice and license conditions from IBX.
|
7 |
|
|
*
|
8 |
|
|
* Except for those parts dervied from IBX, contents of this file are subject
|
9 |
|
|
* to the Initial Developer's Public License Version 1.0 (the "License"); you
|
10 |
|
|
* may not use this file except in compliance with the License. You may obtain a
|
11 |
|
|
* copy of the License here:
|
12 |
|
|
*
|
13 |
|
|
* http://www.firebirdsql.org/index.php?op=doc&id=idpl
|
14 |
|
|
*
|
15 |
|
|
* Software distributed under the License is distributed on an "AS
|
16 |
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
17 |
|
|
* implied. See the License for the specific language governing rights
|
18 |
|
|
* and limitations under the License.
|
19 |
|
|
*
|
20 |
|
|
* The Initial Developer of the Original Code is Tony Whyman.
|
21 |
|
|
*
|
22 |
|
|
* The Original Code is (C) 2016 Tony Whyman, MWA Software
|
23 |
|
|
* (http://www.mwasoftware.co.uk).
|
24 |
|
|
*
|
25 |
|
|
* All Rights Reserved.
|
26 |
|
|
*
|
27 |
|
|
* Contributor(s): ______________________________________.
|
28 |
|
|
*
|
29 |
|
|
*)
|
30 |
|
|
unit FBServices;
|
31 |
tony |
56 |
{$IFDEF MSWINDOWS}
|
32 |
|
|
{$DEFINE WINDOWS}
|
33 |
|
|
{$ENDIF}
|
34 |
tony |
45 |
|
35 |
|
|
{$IFDEF FPC}
|
36 |
tony |
56 |
{$mode delphi}
|
37 |
tony |
45 |
{$interfaces COM}
|
38 |
|
|
{$ENDIF}
|
39 |
|
|
|
40 |
|
|
interface
|
41 |
|
|
|
42 |
|
|
uses
|
43 |
tony |
263 |
Classes, SysUtils, IB, FBParamBlock, FBActivityMonitor, FBClientAPI;
|
44 |
tony |
45 |
|
45 |
|
|
type
|
46 |
|
|
|
47 |
|
|
{ TFBServiceManager }
|
48 |
|
|
|
49 |
|
|
TFBServiceManager = class(TFBInterfacedObject)
|
50 |
|
|
private
|
51 |
|
|
FFirebirdAPI: IFirebirdAPI;
|
52 |
|
|
FProtocol: TProtocol;
|
53 |
tony |
56 |
FServerName: AnsiString;
|
54 |
tony |
143 |
FPort: AnsiString;
|
55 |
tony |
45 |
procedure CheckServerName;
|
56 |
|
|
protected
|
57 |
|
|
FSPB: ISPB;
|
58 |
tony |
56 |
procedure InternalAttach(ConnectString: AnsiString); virtual; abstract;
|
59 |
tony |
45 |
public
|
60 |
tony |
263 |
constructor Create(api: TFBClientAPI; ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB; Port: AnsiString = '');
|
61 |
tony |
45 |
destructor Destroy; override;
|
62 |
|
|
public
|
63 |
|
|
{IServiceManager}
|
64 |
tony |
263 |
function getFirebirdAPI: IFirebirdAPI;
|
65 |
tony |
45 |
function getSPB: ISPB;
|
66 |
tony |
56 |
function getServerName: AnsiString;
|
67 |
tony |
209 |
function getProtocol: TProtocol;
|
68 |
|
|
function getPortNo: AnsiString;
|
69 |
tony |
45 |
procedure Attach;
|
70 |
|
|
procedure Detach(Force: boolean=false); virtual; abstract;
|
71 |
|
|
function AllocateSRB: ISRB;
|
72 |
|
|
function AllocateSQPB: ISQPB;
|
73 |
tony |
209 |
function Query(SQPB: ISQPB; Request: ISRB; RaiseExceptionOnError: boolean=true): IServiceQueryResults; overload; virtual; abstract;
|
74 |
|
|
function Query(Request: ISRB; RaiseExceptionOnError: boolean=true): IServiceQueryResults; overload;
|
75 |
tony |
45 |
end;
|
76 |
|
|
|
77 |
|
|
implementation
|
78 |
|
|
|
79 |
tony |
263 |
uses FBMessages, IBUtils;
|
80 |
tony |
45 |
|
81 |
|
|
{ TFBServiceManager }
|
82 |
|
|
|
83 |
|
|
procedure TFBServiceManager.CheckServerName;
|
84 |
|
|
begin
|
85 |
|
|
if (FServerName = '') and (FProtocol <> Local) then
|
86 |
|
|
IBError(ibxeServerNameMissing, [nil]);
|
87 |
|
|
end;
|
88 |
|
|
|
89 |
tony |
263 |
constructor TFBServiceManager.Create(api: TFBClientAPI; ServerName: AnsiString;
|
90 |
tony |
143 |
Protocol: TProtocol; SPB: ISPB; Port: AnsiString);
|
91 |
tony |
45 |
begin
|
92 |
|
|
inherited Create;
|
93 |
tony |
263 |
FFirebirdAPI := api.getAPI; {Keep reference to interface}
|
94 |
tony |
45 |
FProtocol := Protocol;
|
95 |
|
|
FSPB := SPB;
|
96 |
|
|
FServerName := ServerName;
|
97 |
tony |
143 |
FPort := Port;
|
98 |
tony |
45 |
Attach;
|
99 |
|
|
end;
|
100 |
|
|
|
101 |
|
|
destructor TFBServiceManager.Destroy;
|
102 |
|
|
begin
|
103 |
|
|
Detach(true);
|
104 |
|
|
inherited Destroy;
|
105 |
|
|
end;
|
106 |
|
|
|
107 |
tony |
263 |
function TFBServiceManager.getFirebirdAPI: IFirebirdAPI;
|
108 |
|
|
begin
|
109 |
|
|
Result := FFirebirdAPI;
|
110 |
|
|
end;
|
111 |
|
|
|
112 |
tony |
45 |
function TFBServiceManager.getSPB: ISPB;
|
113 |
|
|
begin
|
114 |
|
|
Result := FSPB;
|
115 |
|
|
end;
|
116 |
|
|
|
117 |
tony |
56 |
function TFBServiceManager.getServerName: AnsiString;
|
118 |
tony |
45 |
begin
|
119 |
|
|
Result := FServerName;
|
120 |
|
|
end;
|
121 |
|
|
|
122 |
tony |
209 |
function TFBServiceManager.getProtocol: TProtocol;
|
123 |
|
|
begin
|
124 |
|
|
Result := FProtocol;
|
125 |
|
|
end;
|
126 |
|
|
|
127 |
|
|
function TFBServiceManager.getPortNo: AnsiString;
|
128 |
|
|
begin
|
129 |
|
|
Result := FPort;
|
130 |
|
|
end;
|
131 |
|
|
|
132 |
tony |
45 |
procedure TFBServiceManager.Attach;
|
133 |
tony |
56 |
var ConnectString: AnsiString;
|
134 |
tony |
45 |
begin
|
135 |
tony |
143 |
ConnectString := MakeConnectString(FServerName,'service_mgr',FProtocol,FPort);
|
136 |
tony |
45 |
InternalAttach(ConnectString);
|
137 |
|
|
end;
|
138 |
|
|
|
139 |
|
|
function TFBServiceManager.AllocateSRB: ISRB;
|
140 |
|
|
begin
|
141 |
tony |
263 |
Result := TSRB.Create(FFirebirdAPI as TFBClientAPI);
|
142 |
tony |
45 |
end;
|
143 |
|
|
|
144 |
|
|
function TFBServiceManager.AllocateSQPB: ISQPB;
|
145 |
|
|
begin
|
146 |
tony |
263 |
Result := TSQPB.Create(FFirebirdAPI as TFBClientAPI);
|
147 |
tony |
45 |
end;
|
148 |
|
|
|
149 |
tony |
209 |
function TFBServiceManager.Query(Request: ISRB; RaiseExceptionOnError: boolean
|
150 |
|
|
): IServiceQueryResults;
|
151 |
tony |
45 |
begin
|
152 |
tony |
209 |
Result := Query(nil,Request,RaiseExceptionOnError);
|
153 |
tony |
45 |
end;
|
154 |
|
|
|
155 |
|
|
end.
|
156 |
|
|
|