]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/thrift/tutorial/hs/HaskellClient.hs
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / thrift / tutorial / hs / HaskellClient.hs
CommitLineData
f67539c2
TL
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
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 Control.Exception
34import Data.Maybe
35import Data.Text.Lazy
36import Text.Printf
37import Network
38
39main = do
40 transport <- hOpen ("localhost", PortNumber 9090)
41 let binProto = BinaryProtocol transport
42 let client = (binProto, binProto)
43
44 Client.ping client
45 print "ping()"
46
47 sum <- Client.add client 1 1
48 printf "1+1=%d\n" sum
49
50
51 let work = Work { work_op = DIVIDE,
52 work_num1 = 1,
53 work_num2 = 0,
54 work_comment = Nothing
55 }
56
57 Control.Exception.catch (printf "1/0=%d\n" =<< Client.calculate client 1 work)
58 (\e -> printf "InvalidOperation %s\n" (show (e :: InvalidOperation)))
59
60
61 let work = Work { work_op = SUBTRACT,
62 work_num1 = 15,
63 work_num2 = 10,
64 work_comment = Nothing
65 }
66
67 diff <- Client.calculate client 1 work
68 printf "15-10=%d\n" diff
69
70 log <- SClient.getStruct client 1
71 printf "Check log: %s\n" $ unpack $ sharedStruct_value log
72
73 -- Close!
74 tClose transport
75
76