blob: 9e1874673625c503559a38ef86192c416a328fa7 [file] [log] [blame]
Christopher Piro8ba81572008-01-15 12:04:15 +00001-module(client).
2
3-include("thrift.hrl").
4-include("transport/tSocket.hrl").
5-include("protocol/tBinaryProtocol.hrl").
6
7-include("calculator_thrift.hrl").
8
Christopher Piro3f1d8c72008-01-15 12:52:51 +00009-export([go/0]).
10
11p(X) ->
12 io:format("~p~n", [X]),
13 ok.
Christopher Piro8ba81572008-01-15 12:04:15 +000014
15t() ->
Christopher Piro3f1d8c72008-01-15 12:52:51 +000016 thrift:start(),
Christopher Piro8ba81572008-01-15 12:04:15 +000017 Host = "dev020",
18 Port = 9999,
19
Christopher Piro3f1d8c72008-01-15 12:52:51 +000020 try
21 _Sock = oop:start_new(tSocket, [Host, Port]),
22 Trans = oop:start_new(tBufferedTransport, [_Sock]),
23 Prot = oop:start_new(tBinaryProtocol, [Trans]),
Christopher Piro8ba81572008-01-15 12:04:15 +000024
Christopher Piro3f1d8c72008-01-15 12:52:51 +000025 ?R0(Trans, effectful_open),
Christopher Piro8ba81572008-01-15 12:04:15 +000026
Christopher Piro3f1d8c72008-01-15 12:52:51 +000027 Client = calculator_thrift:new(Prot),
Christopher Piro8ba81572008-01-15 12:04:15 +000028
Christopher Piro3f1d8c72008-01-15 12:52:51 +000029 calculator_thrift:ping(Client),
30 io:format("ping~n", []),
Christopher Piro8ba81572008-01-15 12:04:15 +000031
Christopher Piro3f1d8c72008-01-15 12:52:51 +000032 Sum = calculator_thrift:add(Client, 1, 1),
33 io:format("1+1=~p~n", [Sum]),
Christopher Piro8ba81572008-01-15 12:04:15 +000034
Christopher Piro3f1d8c72008-01-15 12:52:51 +000035 Sum1 = calculator_thrift:add(Client, 1, 4),
36 io:format("1+4=~p~n", [Sum1]),
37
38 Work = #work{op=?tutorial_SUBTRACT,
39 num1=15,
40 num2=10},
41 Diff = calculator_thrift:calculate(Client, 1, Work),
42 io:format("15-10=~p~n", [Diff]),
43
44 %% xxx inheritance doesn't work
45 %% Log = sharedService_thrift:getStruct(Client, 1),
46 %% io:format("Log: ~p~n", [Log]),
47
48 %% xxx neither do exceptions :(
49 try
50 Work1 = #work{op=?tutorial_DIVIDE,
51 num1=1,
52 num2=0},
53 _Quot = (calculator_thrift:calculate(Client, 1, Work1)),
54
55 io:format("LAME: exception handling is broken~n", [])
56 catch
57 Z ->
58 p(Z)
59 %% rescue InvalidOperation => io
60 %% print "InvalidOperation: ", io.why, "\n"
61 %% end
62 end,
63
64 calculator_thrift:zip(Client),
65 io:format("zip~n", []),
66
67 ?R0(Trans, effectful_close)
68
69 catch
70 Y ->
71 p(Y)
72 end,
Christopher Piro8ba81572008-01-15 12:04:15 +000073 ok.