Subversion Repositories SmartDukaan

Rev

Rev 30 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 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
 
20
-module(client).
21
 
22
-include("calculator_thrift.hrl").
23
 
24
-export([t/0]).
25
 
26
p(X) ->
27
    io:format("~p~n", [X]),
28
    ok.
29
 
30
t() ->
31
    Port = 9999,
32
 
33
    {ok, Client} = thrift_client:start_link("127.0.0.1",
34
                                            Port,
35
                                            calculator_thrift),
36
 
37
    thrift_client:call(Client, ping, []),
38
    io:format("ping~n", []),
39
 
40
    {ok, Sum} = thrift_client:call(Client, add,  [1, 1]),
41
    io:format("1+1=~p~n", [Sum]),
42
 
43
    {ok, Sum1} = thrift_client:call(Client, add, [1, 4]),
44
    io:format("1+4=~p~n", [Sum1]),
45
 
46
    Work = #work{op=?tutorial_SUBTRACT,
47
                 num1=15,
48
                 num2=10},
49
    {ok, Diff} = thrift_client:call(Client, calculate, [1, Work]),
50
    io:format("15-10=~p~n", [Diff]),
51
 
52
    {ok, Log} = thrift_client:call(Client, getStruct, [1]),
53
    io:format("Log: ~p~n", [Log]),
54
 
55
    try
56
        Work1 = #work{op=?tutorial_DIVIDE,
57
                      num1=1,
58
                      num2=0},
59
        {ok, _Quot} = thrift_client:call(Client, calculate, [2, Work1]),
60
 
61
        io:format("LAME: exception handling is broken~n", [])
62
    catch
63
        Z ->
64
            io:format("Got exception where expecting - the " ++
65
                      "following is NOT a problem!!!~n"),
66
            p(Z)
67
    end,
68
 
69
 
70
    {ok, ok} = thrift_client:call(Client, zip, []),
71
    io:format("zip~n", []),
72
 
73
    ok = thrift_client:close(Client),
74
    ok.