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 |
|
|
Classes, SysUtils, IB, FBParamBlock, FBActivityMonitor; |
44 |
|
|
|
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 |
143 |
constructor Create(ServerName: AnsiString; Protocol: TProtocol; SPB: ISPB; Port: AnsiString = ''); |
61 |
tony |
45 |
destructor Destroy; override; |
62 |
|
|
public |
63 |
|
|
{IServiceManager} |
64 |
|
|
function getSPB: ISPB; |
65 |
tony |
56 |
function getServerName: AnsiString; |
66 |
tony |
45 |
procedure Attach; |
67 |
|
|
procedure Detach(Force: boolean=false); virtual; abstract; |
68 |
|
|
function AllocateSRB: ISRB; |
69 |
|
|
function AllocateSQPB: ISQPB; |
70 |
tony |
56 |
function Query(SQPB: ISQPB; Request: ISRB): IServiceQueryResults; overload; virtual; abstract; |
71 |
tony |
45 |
function Query(Request: ISRB): IServiceQueryResults; overload; |
72 |
|
|
end; |
73 |
|
|
|
74 |
|
|
implementation |
75 |
|
|
|
76 |
tony |
143 |
uses FBMessages, FBClientAPI, IBUtils; |
77 |
tony |
45 |
|
78 |
|
|
{ TFBServiceManager } |
79 |
|
|
|
80 |
|
|
procedure TFBServiceManager.CheckServerName; |
81 |
|
|
begin |
82 |
|
|
if (FServerName = '') and (FProtocol <> Local) then |
83 |
|
|
IBError(ibxeServerNameMissing, [nil]); |
84 |
|
|
end; |
85 |
|
|
|
86 |
tony |
143 |
constructor TFBServiceManager.Create(ServerName: AnsiString; |
87 |
|
|
Protocol: TProtocol; SPB: ISPB; Port: AnsiString); |
88 |
tony |
45 |
begin |
89 |
|
|
inherited Create; |
90 |
|
|
FFirebirdAPI := FirebirdAPI; {Keep reference to interface} |
91 |
|
|
FProtocol := Protocol; |
92 |
|
|
FSPB := SPB; |
93 |
|
|
FServerName := ServerName; |
94 |
tony |
143 |
FPort := Port; |
95 |
tony |
45 |
Attach; |
96 |
|
|
end; |
97 |
|
|
|
98 |
|
|
destructor TFBServiceManager.Destroy; |
99 |
|
|
begin |
100 |
|
|
Detach(true); |
101 |
|
|
inherited Destroy; |
102 |
|
|
end; |
103 |
|
|
|
104 |
|
|
function TFBServiceManager.getSPB: ISPB; |
105 |
|
|
begin |
106 |
|
|
Result := FSPB; |
107 |
|
|
end; |
108 |
|
|
|
109 |
tony |
56 |
function TFBServiceManager.getServerName: AnsiString; |
110 |
tony |
45 |
begin |
111 |
|
|
Result := FServerName; |
112 |
|
|
end; |
113 |
|
|
|
114 |
|
|
procedure TFBServiceManager.Attach; |
115 |
tony |
56 |
var ConnectString: AnsiString; |
116 |
tony |
45 |
begin |
117 |
tony |
143 |
ConnectString := MakeConnectString(FServerName,'service_mgr',FProtocol,FPort); |
118 |
tony |
45 |
InternalAttach(ConnectString); |
119 |
|
|
end; |
120 |
|
|
|
121 |
|
|
function TFBServiceManager.AllocateSRB: ISRB; |
122 |
|
|
begin |
123 |
|
|
Result := TSRB.Create; |
124 |
|
|
end; |
125 |
|
|
|
126 |
|
|
function TFBServiceManager.AllocateSQPB: ISQPB; |
127 |
|
|
begin |
128 |
|
|
Result := TSQPB.Create; |
129 |
|
|
end; |
130 |
|
|
|
131 |
|
|
function TFBServiceManager.Query(Request: ISRB): IServiceQueryResults; |
132 |
|
|
begin |
133 |
|
|
Result := Query(nil,Request); |
134 |
|
|
end; |
135 |
|
|
|
136 |
|
|
end. |
137 |
|
|
|