blob: fcb06d1962c63261908a651a99289c56ec8913f2 [file] [log] [blame]
Jens Geyerbd52f1a2014-07-28 01:25:30 +02001/*
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
20package;
21
22import haxe.ds.IntMap;
23
24import org.apache.thrift.*;
25import org.apache.thrift.protocol.*;
26import org.apache.thrift.transport.*;
27import org.apache.thrift.server.*;
28import org.apache.thrift.meta_data.*;
29
30import tutorial.*;
31import shared.*;
32
33
Jens Geyer2dcefad2021-02-25 09:42:52 +010034class CalculatorHandler implements Calculator_service {
Jens Geyerbd52f1a2014-07-28 01:25:30 +020035
Jens Geyerb5028322014-11-09 02:38:11 +010036 private var log = new IntMap<SharedStruct>();
Jens Geyerbd52f1a2014-07-28 01:25:30 +020037
Jens Geyerb5028322014-11-09 02:38:11 +010038 public function new() {
39 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020040
Jens Geyerb5028322014-11-09 02:38:11 +010041 public function ping() : Void {
42 trace("ping()");
43 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020044
Jens Geyerbd52f1a2014-07-28 01:25:30 +020045
Jens Geyerb5028322014-11-09 02:38:11 +010046 public function add( num1 : haxe.Int32, num2 : haxe.Int32) : haxe.Int32 {
47 trace('add( $num1, $num2)');
48 return num1 + num2;
49 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +020050
Jens Geyerb5028322014-11-09 02:38:11 +010051 public function calculate( logid : haxe.Int32, work : Work) : haxe.Int32 {
52 trace('calculate( $logid, '+work.op+","+work.num1+","+work.num2+")");
Jens Geyerbd52f1a2014-07-28 01:25:30 +020053
Jens Geyerb5028322014-11-09 02:38:11 +010054 var val : haxe.Int32 = 0;
55 switch (work.op)
56 {
57 case Operation.ADD:
58 val = work.num1 + work.num2;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020059
Jens Geyerb5028322014-11-09 02:38:11 +010060 case Operation.SUBTRACT:
61 val = work.num1 - work.num2;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020062
Jens Geyerb5028322014-11-09 02:38:11 +010063 case Operation.MULTIPLY:
64 val = work.num1 * work.num2;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020065
Jens Geyerb5028322014-11-09 02:38:11 +010066 case Operation.DIVIDE:
67 if (work.num2 == 0)
68 {
69 var io = new InvalidOperation();
Konrad Grochowski3b115df2015-05-18 17:58:36 +020070 io.whatOp = work.op;
Jens Geyerb5028322014-11-09 02:38:11 +010071 io.why = "Cannot divide by 0";
72 throw io;
73 }
74 val = Std.int( work.num1 / work.num2);
Jens Geyerbd52f1a2014-07-28 01:25:30 +020075
Jens Geyerb5028322014-11-09 02:38:11 +010076 default:
77 var io = new InvalidOperation();
Konrad Grochowski3b115df2015-05-18 17:58:36 +020078 io.whatOp = work.op;
Jens Geyerb5028322014-11-09 02:38:11 +010079 io.why = "Unknown operation";
80 throw io;
81 }
82
83 var entry = new SharedStruct();
84 entry.key = logid;
85 entry.value = '$val';
86 log.set(logid, entry);
87
88 return val;
89 }
90
91 public function getStruct( key : haxe.Int32) : SharedStruct {
92 trace('getStruct($key)');
93 return log.get(key);
94 }
95
96 // oneway method, no args
97 public function zip() : Void {
98 trace("zip()");
99 }
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200100
101}