]> git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/tutorial/hs/HaskellClient.hs
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / jaegertracing / thrift / tutorial / hs / HaskellClient.hs
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 import qualified Calculator
21 import qualified Calculator_Client as Client
22 import qualified SharedService_Client as SClient
23 import Tutorial_Types
24 import SharedService_Iface
25 import Shared_Types
26
27 import Thrift
28 import Thrift.Protocol.Binary
29 import Thrift.Transport
30 import Thrift.Transport.Handle
31 import Thrift.Server
32
33 import Control.Exception
34 import Data.Maybe
35 import Data.Text.Lazy
36 import Text.Printf
37 import Network
38
39 main = 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