]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/tutorial/delphi/DelphiClient/DelphiClient.dpr
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / tutorial / delphi / DelphiClient / DelphiClient.dpr
1 (*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 *)
19 program DelphiClient;
20
21 {$APPTYPE CONSOLE}
22 {$D 'Copyright (c) 2012 The Apache Software Foundation'}
23
24 uses
25 SysUtils,
26 Generics.Collections,
27 Thrift in '..\..\..\lib\delphi\src\Thrift.pas',
28 Thrift.Collections in '..\..\..\lib\delphi\src\Thrift.Collections.pas',
29 Thrift.Exception in '..\..\..\lib\delphi\src\Thrift.Exception.pas',
30 Thrift.Utils in '..\..\..\lib\delphi\src\Thrift.Utils.pas',
31 Thrift.Stream in '..\..\..\lib\delphi\src\Thrift.Stream.pas',
32 Thrift.Protocol in '..\..\..\lib\delphi\src\Thrift.Protocol.pas',
33 Thrift.Server in '..\..\..\lib\delphi\src\Thrift.Server.pas',
34 Thrift.Transport in '..\..\..\lib\delphi\src\Thrift.Transport.pas',
35 Thrift.Transport.WinHTTP in '..\..\..\lib\delphi\src\Thrift.Transport.WinHTTP.pas',
36 Thrift.Transport.MsxmlHTTP in '..\..\..\lib\delphi\src\Thrift.Transport.MsxmlHTTP.pas',
37 Thrift.WinHTTP in '..\..\..\lib\delphi\src\Thrift.WinHTTP.pas',
38 Shared in '..\..\gen-delphi\Shared.pas',
39 Tutorial in '..\..\gen-delphi\Tutorial.pas';
40
41
42 type
43 DelphiTutorialClient = class
44 public
45 class procedure Main;
46 end;
47
48
49 //--- DelphiTutorialClient ---------------------------------------
50
51
52 class procedure DelphiTutorialClient.Main;
53 var transport : ITransport;
54 protocol : IProtocol;
55 client : TCalculator.Iface;
56 work : IWork;
57 sum, quotient, diff : Integer;
58 log : ISharedStruct;
59 begin
60 try
61 transport := TSocketImpl.Create( 'localhost', 9090);
62 protocol := TBinaryProtocolImpl.Create( transport);
63 client := TCalculator.TClient.Create( protocol);
64
65 transport.Open;
66
67 client.ping;
68 WriteLn('ping()');
69
70 sum := client.add( 1, 1);
71 WriteLn( Format( '1+1=%d', [sum]));
72
73 work := TWorkImpl.Create;
74
75 work.Op := TOperation.DIVIDE;
76 work.Num1 := 1;
77 work.Num2 := 0;
78 try
79 quotient := client.calculate(1, work);
80 WriteLn( 'Whoa we can divide by 0');
81 WriteLn( Format('1/0=%d',[quotient]));
82 except
83 on io: TInvalidOperation
84 do WriteLn( 'Invalid operation: ' + io.Why);
85 end;
86
87 work.Op := TOperation.SUBTRACT;
88 work.Num1 := 15;
89 work.Num2 := 10;
90 try
91 diff := client.calculate( 1, work);
92 WriteLn( Format('15-10=%d', [diff]));
93 except
94 on io: TInvalidOperation
95 do WriteLn( 'Invalid operation: ' + io.Why);
96 end;
97
98 log := client.getStruct(1);
99 WriteLn( Format( 'Check log: %s', [log.Value]));
100
101 transport.Close();
102
103 except
104 on e : Exception
105 do WriteLn( e.ClassName+': '+e.Message);
106 end;
107 end;
108
109
110 begin
111 try
112 DelphiTutorialClient.Main;
113 except
114 on E: Exception do
115 Writeln(E.ClassName, ': ', E.Message);
116 end;
117 end.