Christopher Piro | 8ba8157 | 2008-01-15 12:04:15 +0000 | [diff] [blame] | 1 | -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 Piro | 3f1d8c7 | 2008-01-15 12:52:51 +0000 | [diff] [blame] | 9 | -export([go/0]). |
| 10 | |
| 11 | p(X) -> |
| 12 | io:format("~p~n", [X]), |
| 13 | ok. |
Christopher Piro | 8ba8157 | 2008-01-15 12:04:15 +0000 | [diff] [blame] | 14 | |
| 15 | t() -> |
Christopher Piro | 3f1d8c7 | 2008-01-15 12:52:51 +0000 | [diff] [blame] | 16 | thrift:start(), |
Christopher Piro | 8ba8157 | 2008-01-15 12:04:15 +0000 | [diff] [blame] | 17 | Host = "dev020", |
| 18 | Port = 9999, |
| 19 | |
Christopher Piro | 3f1d8c7 | 2008-01-15 12:52:51 +0000 | [diff] [blame] | 20 | try |
| 21 | _Sock = oop:start_new(tSocket, [Host, Port]), |
| 22 | Trans = oop:start_new(tBufferedTransport, [_Sock]), |
| 23 | Prot = oop:start_new(tBinaryProtocol, [Trans]), |
Christopher Piro | 8ba8157 | 2008-01-15 12:04:15 +0000 | [diff] [blame] | 24 | |
Christopher Piro | 3f1d8c7 | 2008-01-15 12:52:51 +0000 | [diff] [blame] | 25 | ?R0(Trans, effectful_open), |
Christopher Piro | 8ba8157 | 2008-01-15 12:04:15 +0000 | [diff] [blame] | 26 | |
Christopher Piro | 3f1d8c7 | 2008-01-15 12:52:51 +0000 | [diff] [blame] | 27 | Client = calculator_thrift:new(Prot), |
Christopher Piro | 8ba8157 | 2008-01-15 12:04:15 +0000 | [diff] [blame] | 28 | |
Christopher Piro | 3f1d8c7 | 2008-01-15 12:52:51 +0000 | [diff] [blame] | 29 | calculator_thrift:ping(Client), |
| 30 | io:format("ping~n", []), |
Christopher Piro | 8ba8157 | 2008-01-15 12:04:15 +0000 | [diff] [blame] | 31 | |
Christopher Piro | 3f1d8c7 | 2008-01-15 12:52:51 +0000 | [diff] [blame] | 32 | Sum = calculator_thrift:add(Client, 1, 1), |
| 33 | io:format("1+1=~p~n", [Sum]), |
Christopher Piro | 8ba8157 | 2008-01-15 12:04:15 +0000 | [diff] [blame] | 34 | |
Christopher Piro | 3f1d8c7 | 2008-01-15 12:52:51 +0000 | [diff] [blame] | 35 | 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 Piro | 8ba8157 | 2008-01-15 12:04:15 +0000 | [diff] [blame] | 73 | ok. |