David Reiss | 68f8c38 | 2010-01-11 19:13:18 +0000 | [diff] [blame] | 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 Data.Maybe |
| 34 | import Text.Printf |
| 35 | import Network |
| 36 | |
| 37 | main = 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 | |