| Anthony F. Molinaro | 71a58a8 | 2010-09-27 19:27:40 +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 | module DebugProtoTest_TestServer where | 
|  | 21 |  | 
|  | 22 |  | 
|  | 23 | import Control.Exception | 
|  | 24 | import qualified Data.ByteString.Lazy as DBL | 
|  | 25 | import Maybe | 
|  | 26 |  | 
|  | 27 | import Thrift | 
|  | 28 | import Thrift.Server | 
|  | 29 |  | 
|  | 30 | import DebugProtoTest_Types | 
|  | 31 | import Inherited | 
|  | 32 | import Inherited_Iface | 
|  | 33 | import Srv_Iface | 
|  | 34 |  | 
|  | 35 |  | 
|  | 36 | data InheritedHandler = InheritedHandler | 
|  | 37 | instance Srv_Iface InheritedHandler where | 
|  | 38 | janky _ arg = do | 
|  | 39 | print $ "Got janky method call: " ++ show arg | 
|  | 40 | return $ 31 | 
|  | 41 |  | 
|  | 42 | voidMethod _ = do | 
|  | 43 | print "Got voidMethod method call" | 
|  | 44 | return () | 
|  | 45 |  | 
|  | 46 | primitiveMethod _ = do | 
|  | 47 | print "Got primitiveMethod call" | 
|  | 48 | return $ 42 | 
|  | 49 |  | 
|  | 50 | structMethod _ = do | 
|  | 51 | print "Got structMethod call" | 
|  | 52 | return $ CompactProtoTestStruct { | 
|  | 53 | f_CompactProtoTestStruct_a_byte = Just 0x01, | 
|  | 54 | f_CompactProtoTestStruct_a_i16 = Just 0x02, | 
|  | 55 | f_CompactProtoTestStruct_a_i32 = Just 0x03, | 
|  | 56 | f_CompactProtoTestStruct_a_i64 = Just 0x04, | 
|  | 57 | f_CompactProtoTestStruct_a_double = Just 0.1, | 
|  | 58 | f_CompactProtoTestStruct_a_string = Just "abcdef", | 
|  | 59 | f_CompactProtoTestStruct_a_binary = Just DBL.empty, | 
|  | 60 | f_CompactProtoTestStruct_true_field = Just True, | 
|  | 61 | f_CompactProtoTestStruct_false_field = Just False, | 
|  | 62 | f_CompactProtoTestStruct_empty_struct_field = Just Empty, | 
|  | 63 |  | 
|  | 64 | f_CompactProtoTestStruct_byte_list = Nothing, | 
|  | 65 | f_CompactProtoTestStruct_i16_list = Nothing, | 
|  | 66 | f_CompactProtoTestStruct_i32_list = Nothing, | 
|  | 67 | f_CompactProtoTestStruct_i64_list = Nothing, | 
|  | 68 | f_CompactProtoTestStruct_double_list = Nothing, | 
|  | 69 | f_CompactProtoTestStruct_string_list = Nothing, | 
|  | 70 | f_CompactProtoTestStruct_binary_list = Nothing, | 
|  | 71 | f_CompactProtoTestStruct_boolean_list = Nothing, | 
|  | 72 | f_CompactProtoTestStruct_struct_list = Just [Empty], | 
|  | 73 |  | 
|  | 74 | f_CompactProtoTestStruct_byte_set = Nothing, | 
|  | 75 | f_CompactProtoTestStruct_i16_set = Nothing, | 
|  | 76 | f_CompactProtoTestStruct_i32_set = Nothing, | 
|  | 77 | f_CompactProtoTestStruct_i64_set = Nothing, | 
|  | 78 | f_CompactProtoTestStruct_double_set = Nothing, | 
|  | 79 | f_CompactProtoTestStruct_string_set = Nothing, | 
|  | 80 | f_CompactProtoTestStruct_binary_set = Nothing, | 
|  | 81 | f_CompactProtoTestStruct_boolean_set = Nothing, | 
|  | 82 | f_CompactProtoTestStruct_struct_set = Nothing, | 
|  | 83 |  | 
|  | 84 | f_CompactProtoTestStruct_byte_byte_map = Nothing, | 
|  | 85 | f_CompactProtoTestStruct_i16_byte_map = Nothing, | 
|  | 86 | f_CompactProtoTestStruct_i32_byte_map = Nothing, | 
|  | 87 | f_CompactProtoTestStruct_i64_byte_map = Nothing, | 
|  | 88 | f_CompactProtoTestStruct_double_byte_map = Nothing, | 
|  | 89 | f_CompactProtoTestStruct_string_byte_map = Nothing, | 
|  | 90 | f_CompactProtoTestStruct_binary_byte_map = Nothing, | 
|  | 91 | f_CompactProtoTestStruct_boolean_byte_map = Nothing, | 
|  | 92 |  | 
|  | 93 | f_CompactProtoTestStruct_byte_i16_map = Nothing, | 
|  | 94 | f_CompactProtoTestStruct_byte_i32_map = Nothing, | 
|  | 95 | f_CompactProtoTestStruct_byte_i64_map = Nothing, | 
|  | 96 | f_CompactProtoTestStruct_byte_double_map = Nothing, | 
|  | 97 | f_CompactProtoTestStruct_byte_string_map = Nothing, | 
|  | 98 | f_CompactProtoTestStruct_byte_binary_map = Nothing, | 
|  | 99 | f_CompactProtoTestStruct_byte_boolean_map = Nothing, | 
|  | 100 |  | 
|  | 101 | f_CompactProtoTestStruct_list_byte_map = Nothing, | 
|  | 102 | f_CompactProtoTestStruct_set_byte_map = Nothing, | 
|  | 103 | f_CompactProtoTestStruct_map_byte_map = Nothing, | 
|  | 104 |  | 
|  | 105 | f_CompactProtoTestStruct_byte_map_map = Nothing, | 
|  | 106 | f_CompactProtoTestStruct_byte_set_map = Nothing, | 
|  | 107 | f_CompactProtoTestStruct_byte_list_map = Nothing } | 
|  | 108 |  | 
|  | 109 | methodWithDefaultArgs _ arg = do | 
|  | 110 | print $ "Got methodWithDefaultArgs: " ++ show arg | 
|  | 111 | return () | 
|  | 112 |  | 
|  | 113 | onewayMethod _ = do | 
|  | 114 | print "Got onewayMethod" | 
|  | 115 |  | 
|  | 116 | instance Inherited_Iface InheritedHandler where | 
|  | 117 | identity _ arg = do | 
|  | 118 | print $ "Got identity method: " ++ show arg | 
|  | 119 | return $ fromJust arg | 
|  | 120 |  | 
|  | 121 | main :: IO () | 
|  | 122 | main = do putStrLn "Server ready..." | 
|  | 123 | (runBasicServer InheritedHandler process 9090) | 
|  | 124 | `Control.Exception.catch` | 
|  | 125 | (\(TransportExn s _) -> print s) |