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
10 http://www.apache.org/licenses/LICENSE-2.0
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
32 inherit Calculator.iface
33 val log = Hashtbl.create 23
34 method ping = Printf.printf "ping()\n" ; flush stdout
36 Printf.printf"add(%ld,%ld)\n" (sod a) (sod b); flush stdout ;
37 Int32.add (sod a) (sod b)
38 method calculate logid w =
40 Printf.printf "calculate(%ld,{%ld,%ld,%ld})\n" (sod logid) (Operation.to_i w#grab_op) w#grab_num1 w#grab_num2; flush stdout ;
44 Int32.add w#grab_num1 w#grab_num2
45 | Operation.SUBTRACT ->
46 Int32.sub w#grab_num1 w#grab_num2
47 | Operation.MULTIPLY ->
48 Int32.mul w#grab_num1 w#grab_num2
50 if w#grab_num2 = Int32.zero then
51 let io = new invalidOperation in
52 io#set_whatOp (Operation.to_i w#grab_op) ;
53 io#set_why "Cannot divide by 0" ;
54 raise (InvalidOperation io)
56 Int32.div w#grab_num1 w#grab_num2 in
58 let ss = new sharedStruct in
59 ss#set_key (sod logid) ;
60 let buffer = Int32.to_string rv in
62 Hashtbl.add log (sod logid) ss ;
66 Printf.printf "zip()\n"; flush stdout
68 method getStruct logid =
69 Printf.printf "getStruct(%ld)\n" (sod logid) ; flush stdout ;
70 Hashtbl.find log (sod logid)
75 let h = new calc_handler in
76 let proc = new Calculator.processor h in
78 let pf = new TBinaryProtocol.factory in
79 let server = new TThreadedServer.t
81 (new TServerSocket.t port)
82 (new Transport.factory)