[453] | 1 | unit ORNet;
|
---|
| 2 |
|
---|
| 3 | {$DEFINE CCOWBROKER}
|
---|
| 4 |
|
---|
| 5 | interface
|
---|
| 6 |
|
---|
[654] | 7 | uses SysUtils, Windows, Classes, Forms, Controls, ORFn, TRPCB, RPCConf1, Dialogs
|
---|
[453] | 8 | {$IFDEF CCOWBROKER}, CCOWRPCBroker {$ENDIF} ; //, SharedRPCBroker;
|
---|
| 9 |
|
---|
| 10 |
|
---|
| 11 | procedure SetBrokerServer(const AName: string; APort: Integer; WantDebug: Boolean);
|
---|
| 12 | function AuthorizedOption(const OptionName: string): Boolean;
|
---|
| 13 | function ConnectToServer(const OptionName: string): Boolean;
|
---|
| 14 | function MRef(glvn: string): string;
|
---|
| 15 | procedure CallV(const RPCName: string; const AParam: array of const);
|
---|
| 16 | function sCallV(const RPCName: string; const AParam: array of const): string;
|
---|
| 17 | procedure tCallV(ReturnData: TStrings; const RPCName: string; const AParam: array of const);
|
---|
| 18 | function UpdateContext(NewContext: string): boolean;
|
---|
| 19 | function IsBaseContext: boolean;
|
---|
| 20 | procedure CallBrokerInContext;
|
---|
| 21 | procedure CallBroker;
|
---|
| 22 | function RetainedRPCCount: Integer;
|
---|
| 23 | procedure SetRetainedRPCMax(Value: Integer);
|
---|
| 24 | function GetRPCMax: integer;
|
---|
| 25 | procedure LoadRPCData(Dest: TStrings; ID: Integer);
|
---|
| 26 | function DottedIPStr: string;
|
---|
| 27 | procedure CallRPCWhenIdle(CallProc: TORIdleCallProc; Msg: String);
|
---|
| 28 | procedure EnsureBroker;
|
---|
[612] | 29 | procedure RPCCallsClear; //kt added
|
---|
[453] | 30 |
|
---|
| 31 | (*
|
---|
| 32 | function pCallV(const RPCName: string; const AParam: array of const): PChar;
|
---|
| 33 | procedure wCallV(AControl: TControl; const RPCName: string; const AParam: array of const);
|
---|
| 34 | procedure WrapWP(Buf: pChar);
|
---|
| 35 | *)
|
---|
| 36 |
|
---|
| 37 | var
|
---|
| 38 | {$IFDEF CCOWBROKER}
|
---|
| 39 | RPCBrokerV: TCCOWRPCBroker;
|
---|
| 40 | {$ELSE}
|
---|
| 41 | RPCBrokerV: TRPCBroker;
|
---|
| 42 | //RPCBrokerV: TSharedRPCBroker;
|
---|
| 43 | {$ENDIF}
|
---|
| 44 | RPCLastCall: string;
|
---|
| 45 |
|
---|
| 46 | implementation
|
---|
| 47 |
|
---|
[612] | 48 | uses
|
---|
| 49 | DateUtils, //kt
|
---|
| 50 | Winsock;
|
---|
[453] | 51 |
|
---|
| 52 | const
|
---|
| 53 | // *** these are constants from RPCBErr.pas, will broker document them????
|
---|
| 54 | XWB_M_REJECT = 20000 + 2; // M error
|
---|
| 55 | XWB_BadSignOn = 20000 + 4; // SignOn 'Error' (happens when cancel pressed)
|
---|
| 56 |
|
---|
| 57 | var
|
---|
| 58 | uCallList: TList;
|
---|
| 59 | uMaxCalls: Integer;
|
---|
| 60 | uShowRPCs: Boolean;
|
---|
| 61 | uBaseContext: string = '';
|
---|
| 62 | uCurrentContext: string = '';
|
---|
| 63 |
|
---|
| 64 | { private procedures and functions ---------------------------------------------------------- }
|
---|
| 65 |
|
---|
| 66 | procedure EnsureBroker;
|
---|
| 67 | { ensures that a broker object has been created - creates & initializes it if necessary }
|
---|
| 68 | begin
|
---|
| 69 | if RPCBrokerV = nil then
|
---|
| 70 | begin
|
---|
| 71 | {$IFDEF CCOWBROKER}
|
---|
| 72 | RPCBrokerV := TCCOWRPCBroker.Create(Application);
|
---|
| 73 | {$ELSE}
|
---|
| 74 | RPCBrokerV := TRPCBroker.Create(Application);
|
---|
| 75 | //RPCBrokerV := TSharedRPCBroker.Create(Application);
|
---|
| 76 | {$ENDIF}
|
---|
| 77 | with RPCBrokerV do
|
---|
| 78 | begin
|
---|
| 79 | KernelLogIn := True;
|
---|
| 80 | Login.Mode := lmAppHandle;
|
---|
| 81 | ClearParameters := True;
|
---|
| 82 | ClearResults := True;
|
---|
| 83 | DebugMode := False;
|
---|
| 84 | end;
|
---|
| 85 | end;
|
---|
| 86 | end;
|
---|
| 87 |
|
---|
| 88 | procedure SetList(AStringList: TStrings; ParamIndex: Integer);
|
---|
| 89 | { places TStrings into RPCBrokerV.Mult[n], where n is a 1-based (not 0-based) index }
|
---|
| 90 | var
|
---|
| 91 | i: Integer;
|
---|
| 92 | begin
|
---|
| 93 | with RPCBrokerV.Param[ParamIndex] do
|
---|
| 94 | begin
|
---|
| 95 | PType := list;
|
---|
| 96 | with AStringList do for i := 0 to Count - 1 do Mult[IntToStr(i+1)] := Strings[i];
|
---|
| 97 | end;
|
---|
| 98 | end;
|
---|
| 99 |
|
---|
| 100 | procedure SetParams(const RPCName: string; const AParam: array of const);
|
---|
| 101 | { takes the params (array of const) passed to xCallV and sets them into RPCBrokerV.Param[i] }
|
---|
| 102 | const
|
---|
| 103 | BoolChar: array[boolean] of char = ('0', '1');
|
---|
| 104 | var
|
---|
| 105 | i: integer;
|
---|
| 106 | TmpExt: Extended;
|
---|
| 107 | begin
|
---|
| 108 | RPCLastCall := RPCName + ' (SetParam begin)';
|
---|
| 109 | if Length(RPCName) = 0 then raise Exception.Create('No RPC Name');
|
---|
| 110 | EnsureBroker;
|
---|
| 111 | with RPCBrokerV do
|
---|
| 112 | begin
|
---|
| 113 | ClearParameters := True;
|
---|
| 114 | RemoteProcedure := RPCName;
|
---|
| 115 | for i := 0 to High(AParam) do with AParam[i] do
|
---|
| 116 | begin
|
---|
| 117 | Param[i].PType := literal;
|
---|
| 118 | case VType of
|
---|
| 119 | vtInteger: Param[i].Value := IntToStr(VInteger);
|
---|
| 120 | vtBoolean: Param[i].Value := BoolChar[VBoolean];
|
---|
| 121 | vtChar: if VChar = #0 then
|
---|
| 122 | Param[i].Value := ''
|
---|
| 123 | else
|
---|
| 124 | Param[i].Value := VChar;
|
---|
| 125 | //vtExtended: Param[i].Value := FloatToStr(VExtended^);
|
---|
| 126 | vtExtended: begin
|
---|
| 127 | TmpExt := VExtended^;
|
---|
| 128 | if(abs(TmpExt) < 0.0000000000001) then TmpExt := 0;
|
---|
| 129 | Param[i].Value := FloatToStr(TmpExt);
|
---|
| 130 | end;
|
---|
| 131 | vtString: with Param[i] do
|
---|
| 132 | begin
|
---|
| 133 | Value := VString^;
|
---|
| 134 | if (Length(Value) > 0) and (Value[1] = #1) then
|
---|
| 135 | begin
|
---|
| 136 | Value := Copy(Value, 2, Length(Value));
|
---|
| 137 | PType := reference;
|
---|
| 138 | end;
|
---|
| 139 | end;
|
---|
| 140 | vtPChar: Param[i].Value := StrPas(VPChar);
|
---|
| 141 | vtPointer: if VPointer = nil
|
---|
| 142 | then ClearParameters := True {Param[i].PType := null}
|
---|
| 143 | else raise Exception.Create('Pointer type must be nil.');
|
---|
| 144 | vtObject: if VObject is TStrings then SetList(TStrings(VObject), i);
|
---|
| 145 | vtAnsiString: with Param[i] do
|
---|
| 146 | begin
|
---|
| 147 | Value := string(VAnsiString);
|
---|
| 148 | if (Length(Value) > 0) and (Value[1] = #1) then
|
---|
| 149 | begin
|
---|
| 150 | Value := Copy(Value, 2, Length(Value));
|
---|
| 151 | PType := reference;
|
---|
| 152 | end;
|
---|
| 153 | end;
|
---|
| 154 | vtInt64: Param[i].Value := IntToStr(VInt64^);
|
---|
| 155 | else raise Exception.Create('Unable to pass parameter type to Broker.');
|
---|
| 156 | end; {case}
|
---|
| 157 | end; {for}
|
---|
| 158 | end; {with}
|
---|
| 159 | RPCLastCall := RPCName + ' (SetParam end)';
|
---|
| 160 | end;
|
---|
| 161 |
|
---|
| 162 | { public procedures and functions ----------------------------------------------------------- }
|
---|
| 163 |
|
---|
| 164 | function UpdateContext(NewContext: string): boolean;
|
---|
| 165 | begin
|
---|
| 166 | if NewContext = uCurrentContext then
|
---|
| 167 | Result := TRUE
|
---|
| 168 | else
|
---|
| 169 | begin
|
---|
| 170 | Result := RPCBrokerV.CreateContext(NewContext);
|
---|
| 171 | if Result then
|
---|
| 172 | uCurrentContext := NewContext
|
---|
| 173 | else
|
---|
| 174 | if (NewContext <> uBaseContext) and RPCBrokerV.CreateContext(uBaseContext) then
|
---|
| 175 | uCurrentContext := uBaseContext
|
---|
| 176 | else
|
---|
| 177 | uCurrentContext := '';
|
---|
| 178 | end;
|
---|
| 179 | end;
|
---|
| 180 |
|
---|
| 181 | function IsBaseContext: boolean;
|
---|
| 182 | begin
|
---|
| 183 | Result := ((uCurrentContext = uBaseContext) or (uCurrentContext = ''));
|
---|
| 184 | end;
|
---|
| 185 |
|
---|
| 186 | procedure CallBrokerInContext;
|
---|
| 187 | var
|
---|
| 188 | AStringList: TStringList;
|
---|
| 189 | i, j: Integer;
|
---|
| 190 | x, y: string;
|
---|
[612] | 191 | Time1,Time2 : TDateTime; //kt
|
---|
[453] | 192 | begin
|
---|
| 193 | RPCLastCall := RPCBrokerV.RemoteProcedure + ' (CallBroker begin)';
|
---|
| 194 | if uShowRPCs then StatusText(RPCBrokerV.RemoteProcedure);
|
---|
| 195 | with RPCBrokerV do if not Connected then // happens if broker connection is lost
|
---|
| 196 | begin
|
---|
| 197 | ClearResults := True;
|
---|
| 198 | Exit;
|
---|
| 199 | end;
|
---|
| 200 | if uCallList.Count = uMaxCalls then
|
---|
| 201 | begin
|
---|
| 202 | AStringList := uCallList.Items[0];
|
---|
| 203 | AStringList.Free;
|
---|
| 204 | uCallList.Delete(0);
|
---|
| 205 | end;
|
---|
| 206 | AStringList := TStringList.Create;
|
---|
| 207 | AStringList.Add(RPCBrokerV.RemoteProcedure);
|
---|
| 208 | if uCurrentContext <> uBaseContext then
|
---|
| 209 | AStringList.Add('Context: ' + uCurrentContext);
|
---|
[612] | 210 | Time1 := GetTime; //kt
|
---|
| 211 | AStringList.Add('Called at: '+ TimeToStr(Time1)); //kt
|
---|
[453] | 212 | AStringList.Add(' ');
|
---|
| 213 | AStringList.Add('Params ------------------------------------------------------------------');
|
---|
| 214 | with RPCBrokerV do for i := 0 to Param.Count - 1 do
|
---|
| 215 | begin
|
---|
| 216 | case Param[i].PType of
|
---|
| 217 | //global: x := 'global';
|
---|
| 218 | list: x := 'list';
|
---|
| 219 | literal: x := 'literal';
|
---|
| 220 | //null: x := 'null';
|
---|
| 221 | reference: x := 'reference';
|
---|
| 222 | undefined: x := 'undefined';
|
---|
| 223 | //wordproc: x := 'wordproc';
|
---|
| 224 | end;
|
---|
| 225 | AStringList.Add(x + #9 + Param[i].Value);
|
---|
| 226 | if Param[i].PType = list then
|
---|
| 227 | begin
|
---|
| 228 | for j := 0 to Param[i].Mult.Count - 1 do
|
---|
| 229 | begin
|
---|
| 230 | x := Param[i].Mult.Subscript(j);
|
---|
| 231 | y := Param[i].Mult[x];
|
---|
| 232 | AStringList.Add(#9 + '(' + x + ')=' + y);
|
---|
| 233 | end;
|
---|
| 234 | end;
|
---|
| 235 | end; {with...for}
|
---|
| 236 | //RPCBrokerV.Call;
|
---|
| 237 | try
|
---|
| 238 | RPCBrokerV.Call;
|
---|
| 239 | except
|
---|
| 240 | // The broker erroneously sets connected to false if there is any error (including an
|
---|
| 241 | // error on the M side). It should only set connection to false if there is no connection.
|
---|
| 242 | on E:EBrokerError do
|
---|
| 243 | begin
|
---|
| 244 | if E.Code = XWB_M_REJECT then
|
---|
| 245 | begin
|
---|
| 246 | x := 'An error occurred on the server.' + CRLF + CRLF + E.Action;
|
---|
| 247 | Application.MessageBox(PChar(x), 'Server Error', MB_OK);
|
---|
| 248 | end
|
---|
| 249 | else raise;
|
---|
| 250 | (*
|
---|
| 251 | case E.Code of
|
---|
| 252 | XWB_M_REJECT: begin
|
---|
| 253 | x := 'An error occurred on the server.' + CRLF + CRLF + E.Action;
|
---|
| 254 | Application.MessageBox(PChar(x), 'Server Error', MB_OK);
|
---|
| 255 | end;
|
---|
| 256 | else begin
|
---|
| 257 | x := 'An error occurred with the network connection.' + CRLF +
|
---|
| 258 | 'Action was: ' + E.Action + CRLF + 'Code was: ' + E.Mnemonic +
|
---|
| 259 | CRLF + CRLF + 'Application cannot continue.';
|
---|
| 260 | Application.MessageBox(PChar(x), 'Network Error', MB_OK);
|
---|
| 261 | end;
|
---|
| 262 | end;
|
---|
| 263 | *)
|
---|
| 264 | // make optional later...
|
---|
| 265 | if not RPCBrokerV.Connected then Application.Terminate;
|
---|
| 266 | end;
|
---|
| 267 | end;
|
---|
| 268 | AStringList.Add(' ');
|
---|
| 269 | AStringList.Add('Results -----------------------------------------------------------------');
|
---|
| 270 | AStringList.AddStrings(RPCBrokerV.Results);
|
---|
[612] | 271 | AStringList.Add(' '); //kt
|
---|
| 272 | Time2 := GetTime; //kt
|
---|
| 273 | AStringList.Add('Elapsed Time: ' + IntToStr(Round(MilliSecondSpan(Time2,Time1))) + ' ms'); //kt
|
---|
[453] | 274 | uCallList.Add(AStringList);
|
---|
| 275 | if uShowRPCs then StatusText('');
|
---|
| 276 | RPCLastCall := RPCBrokerV.RemoteProcedure + ' (completed)';
|
---|
| 277 | end;
|
---|
| 278 |
|
---|
| 279 | procedure CallBroker;
|
---|
| 280 | begin
|
---|
| 281 | UpdateContext(uBaseContext);
|
---|
| 282 | CallBrokerInContext;
|
---|
| 283 | end;
|
---|
| 284 |
|
---|
| 285 | procedure SetBrokerServer(const AName: string; APort: Integer; WantDebug: Boolean);
|
---|
| 286 | { makes the initial connection to a server }
|
---|
| 287 | begin
|
---|
| 288 | EnsureBroker;
|
---|
| 289 | with RPCBrokerV do
|
---|
| 290 | begin
|
---|
| 291 | Server := AName;
|
---|
| 292 | if APort > 0 then ListenerPort := APort;
|
---|
| 293 | DebugMode := WantDebug;
|
---|
| 294 | Connected := True;
|
---|
| 295 | end;
|
---|
| 296 | end;
|
---|
| 297 |
|
---|
| 298 | function AuthorizedOption(const OptionName: string): Boolean;
|
---|
| 299 | { checks to see if the user is authorized to use this application }
|
---|
| 300 | begin
|
---|
| 301 | EnsureBroker;
|
---|
| 302 | Result := RPCBrokerV.CreateContext(OptionName);
|
---|
| 303 | if Result then
|
---|
| 304 | begin
|
---|
| 305 | if (uBaseContext = '') then
|
---|
| 306 | uBaseContext := OptionName;
|
---|
| 307 | uCurrentContext := OptionName;
|
---|
| 308 | end;
|
---|
| 309 | end;
|
---|
| 310 |
|
---|
| 311 | function ConnectToServer(const OptionName: string): Boolean;
|
---|
| 312 | { establish initial connection to server using optional command line parameters and check that
|
---|
| 313 | this application (option) is allowed for this user }
|
---|
| 314 | var
|
---|
| 315 | WantDebug: Boolean;
|
---|
| 316 | AServer, APort, x: string;
|
---|
| 317 | i, ModalResult: Integer;
|
---|
| 318 | begin
|
---|
| 319 | Result := False;
|
---|
| 320 | WantDebug := False;
|
---|
| 321 | AServer := '';
|
---|
| 322 | APort := '';
|
---|
| 323 | for i := 1 to ParamCount do // params may be: S[ERVER]=hostname P[ORT]=port DEBUG
|
---|
| 324 | begin
|
---|
| 325 | if UpperCase(ParamStr(i)) = 'DEBUG' then WantDebug := True;
|
---|
| 326 | if UpperCase(ParamStr(i)) = 'SHOWRPCS' then uShowRPCs := True;
|
---|
| 327 | x := UpperCase(Piece(ParamStr(i), '=', 1));
|
---|
| 328 | if (x = 'S') or (x = 'SERVER') then AServer := Piece(ParamStr(i), '=', 2);
|
---|
| 329 | if (x = 'P') or (x = 'PORT') then APort := Piece(ParamStr(i), '=', 2);
|
---|
| 330 | end;
|
---|
| 331 | if (AServer = '') or (APort = '') then
|
---|
| 332 | begin
|
---|
| 333 | ModalResult := GetServerInfo(AServer, APort);
|
---|
| 334 | if ModalResult = mrCancel then Exit;
|
---|
| 335 | end;
|
---|
| 336 | // use try..except to work around errors in the Broker SignOn screen
|
---|
| 337 | try
|
---|
| 338 | SetBrokerServer(AServer, StrToIntDef(APort, 9200), WantDebug);
|
---|
| 339 | Result := AuthorizedOption(OptionName);
|
---|
| 340 | if Result then Result := RPCBrokerV.Connected;
|
---|
| 341 | RPCBrokerV.RPCTimeLimit := 300;
|
---|
| 342 | except
|
---|
| 343 | on E:EBrokerError do
|
---|
| 344 | begin
|
---|
| 345 | if E.Code <> XWB_BadSignOn then InfoBox(E.Message, 'Error', MB_OK or MB_ICONERROR);
|
---|
| 346 | Result := False;
|
---|
| 347 | end;
|
---|
| 348 | end;
|
---|
| 349 | end;
|
---|
| 350 |
|
---|
| 351 | function MRef(glvn: string): string;
|
---|
| 352 | { prepends ASCII 1 to string, allows SetParams to interpret as an M reference }
|
---|
| 353 | begin
|
---|
| 354 | Result := #1 + glvn;
|
---|
| 355 | end;
|
---|
| 356 |
|
---|
| 357 | procedure CallV(const RPCName: string; const AParam: array of const);
|
---|
| 358 | { calls the broker leaving results in results property which must be read by caller }
|
---|
| 359 | var
|
---|
| 360 | SavedCursor: TCursor;
|
---|
| 361 | begin
|
---|
| 362 | SavedCursor := Screen.Cursor;
|
---|
| 363 | Screen.Cursor := crHourGlass;
|
---|
| 364 | SetParams(RPCName, AParam);
|
---|
| 365 | CallBroker; //RPCBrokerV.Call;
|
---|
| 366 | Screen.Cursor := SavedCursor;
|
---|
| 367 | end;
|
---|
| 368 |
|
---|
| 369 | function sCallV(const RPCName: string; const AParam: array of const): string;
|
---|
| 370 | { calls the broker and returns a scalar value. }
|
---|
| 371 | var
|
---|
| 372 | SavedCursor: TCursor;
|
---|
| 373 | begin
|
---|
| 374 | SavedCursor := Screen.Cursor;
|
---|
| 375 | Screen.Cursor := crHourGlass;
|
---|
| 376 | SetParams(RPCName, AParam);
|
---|
| 377 | CallBroker; //RPCBrokerV.Call;
|
---|
| 378 | if RPCBrokerV.Results.Count > 0 then Result := RPCBrokerV.Results[0] else Result := '';
|
---|
| 379 | Screen.Cursor := SavedCursor;
|
---|
| 380 | end;
|
---|
| 381 |
|
---|
| 382 | procedure tCallV(ReturnData: TStrings; const RPCName: string; const AParam: array of const);
|
---|
| 383 | { calls the broker and returns TStrings data }
|
---|
| 384 | var
|
---|
| 385 | SavedCursor: TCursor;
|
---|
| 386 | begin
|
---|
| 387 | if ReturnData = nil then raise Exception.Create('TString not created');
|
---|
| 388 | SavedCursor := Screen.Cursor;
|
---|
| 389 | Screen.Cursor := crHourGlass;
|
---|
| 390 | SetParams(RPCName, AParam);
|
---|
| 391 | CallBroker; //RPCBrokerV.Call;
|
---|
| 392 | ReturnData.Assign(RPCBrokerV.Results);
|
---|
| 393 | Screen.Cursor := SavedCursor;
|
---|
| 394 | end;
|
---|
| 395 |
|
---|
| 396 | (* uncomment if these are needed -
|
---|
| 397 |
|
---|
| 398 | function pCallV(const RPCName: string; const AParam: array of const): PChar;
|
---|
| 399 | { Calls the Broker. Result is a PChar containing raw Broker data. }
|
---|
| 400 | { -- Caller must dispose the string that is returned -- }
|
---|
| 401 | var
|
---|
| 402 | SavedCursor: TCursor;
|
---|
| 403 | begin
|
---|
| 404 | SavedCursor := Screen.Cursor;
|
---|
| 405 | Screen.Cursor := crHourGlass;
|
---|
| 406 | SetParams(RPCName, AParam);
|
---|
| 407 | RPCBrokerV.Call;
|
---|
| 408 | pCallV := StrNew(RPCBrokerV.Results.GetText);
|
---|
| 409 | Screen.Cursor := SavedCursor;
|
---|
| 410 | end;
|
---|
| 411 |
|
---|
| 412 | procedure wCallV(AControl: TControl; const RPCName: string; const AParam: array of const);
|
---|
| 413 | { Calls the Broker. Places data into control (wrapped). }
|
---|
| 414 | var
|
---|
| 415 | BufPtr: PChar;
|
---|
| 416 | begin
|
---|
| 417 | BufPtr := pCallV(RPCName, AParam);
|
---|
| 418 | WrapWP(BufPtr);
|
---|
| 419 | AControl.SetTextBuf(BufPtr);
|
---|
| 420 | StrDispose(BufPtr);
|
---|
| 421 | end;
|
---|
| 422 |
|
---|
| 423 | procedure WrapWP(Buf: pChar);
|
---|
| 424 | { Iterates through Buf and wraps text in the same way that FM wraps text. }
|
---|
| 425 | var
|
---|
| 426 | PSub: PChar;
|
---|
| 427 | begin
|
---|
| 428 | PSub := StrScan(Buf, #13);
|
---|
| 429 | while PSub <> nil do
|
---|
| 430 | begin
|
---|
| 431 | if Ord(PSub[2]) > 32 then
|
---|
| 432 | begin
|
---|
| 433 | StrMove(PSub, PSub + SizeOf(Char), StrLen(PSub));
|
---|
| 434 | PSub[0] := #32;
|
---|
| 435 | end
|
---|
| 436 | else repeat Inc(PSub, SizeOf(Char)) until (Ord(PSub[0]) > 32) or (PSub = StrEnd(PSub));
|
---|
| 437 | PSub := StrScan(PSub, #13);
|
---|
| 438 | end;
|
---|
| 439 | end;
|
---|
| 440 |
|
---|
| 441 | *)
|
---|
| 442 |
|
---|
| 443 | function RetainedRPCCount: Integer;
|
---|
| 444 | begin
|
---|
| 445 | Result := uCallList.Count;
|
---|
| 446 | end;
|
---|
| 447 |
|
---|
| 448 | procedure SetRetainedRPCMax(Value: Integer);
|
---|
| 449 | begin
|
---|
| 450 | if Value > 0 then uMaxCalls := Value;
|
---|
| 451 | end;
|
---|
| 452 |
|
---|
| 453 | function GetRPCMax: integer;
|
---|
| 454 | begin
|
---|
| 455 | Result := uMaxCalls;
|
---|
| 456 | end;
|
---|
| 457 |
|
---|
| 458 | procedure LoadRPCData(Dest: TStrings; ID: Integer);
|
---|
| 459 | begin
|
---|
| 460 | if (ID > -1) and (ID < uCallList.Count) then Dest.Assign(TStringList(uCallList.Items[ID]));
|
---|
| 461 | end;
|
---|
| 462 |
|
---|
| 463 | function DottedIPStr: string;
|
---|
| 464 | { return the IP address of the local machine as a string in dotted form: nnn.nnn.nnn.nnn }
|
---|
| 465 | const
|
---|
| 466 | WINSOCK1_1 = $0101; // minimum required version of WinSock
|
---|
| 467 | SUCCESS = 0; // value returned by WinSock functions if no error
|
---|
| 468 | var
|
---|
| 469 | //WSAData: TWSAData; // structure to hold startup information
|
---|
| 470 | HostEnt: PHostEnt; // pointer to Host Info structure (see WinSock 1.1, page 60)
|
---|
| 471 | IPAddr: PInAddr; // pointer to IP address in network order (4 bytes)
|
---|
| 472 | LocalName: array[0..255] of Char; // buffer for the name of the client machine
|
---|
| 473 | begin
|
---|
| 474 | Result := 'No IP Address';
|
---|
| 475 | // ensure the Winsock DLL has been loaded (should be if there is a broker connection)
|
---|
| 476 | //if WSAStartup(WINSOCK1_1, WSAData) <> SUCCESS then Exit;
|
---|
| 477 | //try
|
---|
| 478 | // get the name of the client machine
|
---|
| 479 | if gethostname(LocalName, SizeOf(LocalName) - 1) <> SUCCESS then Exit;
|
---|
| 480 | // get information about the client machine (contained in a record of type THostEnt)
|
---|
| 481 | HostEnt := gethostbyname(LocalName);
|
---|
| 482 | if HostEnt = nil then Exit;
|
---|
| 483 | // get a pointer to the four bytes that contain the IP address
|
---|
| 484 | // Dereference HostEnt to get the THostEnt record. In turn, dereference the h_addr_list
|
---|
| 485 | // field to get a pointer to the IP address. The pointer to the IP address is type PChar,
|
---|
| 486 | // so it needs to be typecast as PInAddr in order to make the call to inet_ntoa.
|
---|
| 487 | IPAddr := PInAddr(HostEnt^.h_addr_list^);
|
---|
| 488 | // Dereference IPAddr (which is a PChar typecast as PInAddr) to get the 4 bytes that need
|
---|
| 489 | // to be passed to inet_ntoa. A string with the IP address in dotted format is returned.
|
---|
| 490 | Result := inet_ntoa(IPAddr^);
|
---|
| 491 | //finally
|
---|
| 492 | // causes the reference counter in Winsock (set by WSAStartup, above) to be decremented
|
---|
| 493 | //WSACleanup;
|
---|
| 494 | //end;
|
---|
| 495 | end;
|
---|
| 496 |
|
---|
| 497 | procedure RPCIdleCallDone(Msg: string);
|
---|
| 498 | begin
|
---|
| 499 | RPCBrokerV.ClearResults := True;
|
---|
| 500 | end;
|
---|
| 501 |
|
---|
| 502 | procedure CallRPCWhenIdle(CallProc: TORIdleCallProc; Msg: String);
|
---|
| 503 | begin
|
---|
| 504 | CallWhenIdleNotifyWhenDone(CallProc, RPCIdleCallDone, Msg);
|
---|
| 505 | end;
|
---|
| 506 |
|
---|
[612] | 507 | procedure RPCCallsClear;
|
---|
| 508 | //kt Added entire fuction.
|
---|
| 509 | begin
|
---|
| 510 | while uCallList.Count > 0 do
|
---|
| 511 | begin
|
---|
| 512 | TStringList(uCallList.Items[0]).Free;
|
---|
| 513 | uCallList.Delete(0);
|
---|
| 514 | end;
|
---|
| 515 | end;
|
---|
| 516 |
|
---|
[453] | 517 | initialization
|
---|
| 518 | RPCBrokerV := nil;
|
---|
| 519 | RPCLastCall := 'No RPCs called';
|
---|
| 520 | uCallList := TList.Create;
|
---|
[612] | 521 | uMaxCalls := 150; //kt 10
|
---|
[453] | 522 | uShowRPCs := False;
|
---|
| 523 |
|
---|
| 524 | finalization
|
---|
[612] | 525 | { //kt commented out
|
---|
[453] | 526 | while uCallList.Count > 0 do
|
---|
| 527 | begin
|
---|
| 528 | TStringList(uCallList.Items[0]).Free;
|
---|
| 529 | uCallList.Delete(0);
|
---|
| 530 | end;
|
---|
[612] | 531 | }
|
---|
| 532 | RPCCallsClear; //kt added
|
---|
[453] | 533 | uCallList.Free;
|
---|
| 534 |
|
---|
| 535 | end.
|
---|