blob: a56187b6ae175c006cc368be44735e5def94b679 [file] [log] [blame]
David Reiss68f8c382010-01-11 19:13:18 +00001--
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
20import qualified Calculator
21import qualified Calculator_Client as Client
22import qualified SharedService_Client as SClient
23import Tutorial_Types
24import SharedService_Iface
25import Shared_Types
26
27import Thrift
28import Thrift.Protocol.Binary
29import Thrift.Transport
30import Thrift.Transport.Handle
31import Thrift.Server
32
33import Data.Maybe
34import Text.Printf
35import Network
36
37main = do
38 transport <- hOpen ("localhost", PortNumber 9090)
39 let binProto = BinaryProtocol transport
40 let client = (binProto, binProto)
41
42 Client.ping client
43 print "ping()"
44
45 sum <- Client.add client 1 1
46 printf "1+1=%d\n" sum
47
48
49 let work = Work { f_Work_op = Just DIVIDE,
50 f_Work_num1 = Just 1,
51 f_Work_num2 = Just 0,
52 f_Work_comment = Nothing
53 }
54
55 -- TODO - get this one working
56 --catch (Client.calculate client 1 work) (\except ->
57 -- printf "InvalidOp %s" (show except))
58
59
60 let work = Work { f_Work_op = Just SUBTRACT,
61 f_Work_num1 = Just 15,
62 f_Work_num2 = Just 10,
63 f_Work_comment = Nothing
64 }
65
66 diff <- Client.calculate client 1 work
67 printf "15-10=%d\n" diff
68
69 log <- SClient.getStruct client 1
70 printf "Check log: %s\n" $ fromJust $ f_SharedStruct_value log
71
72 -- Close!
73 tClose transport
74
75