blob: 34e471b935498ffef265b25295e902e0b1804c2f [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 org.apache.thrift.*;
23import org.apache.thrift.protocol.*;
24import org.apache.thrift.transport.*;
25import org.apache.thrift.server.*;
26import org.apache.thrift.meta_data.*;
27import org.apache.thrift.helper.*;
Jens Geyer18564d22022-06-05 11:36:40 +020028import uuid.Uuid;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020029
30import haxe.Int32;
31import haxe.Int64;
32import haxe.io.Bytes;
33import haxe.ds.IntMap;
34import haxe.ds.StringMap;
35import haxe.ds.ObjectMap;
36
37import thrift.test.*; // generated code
38
39
Jens Geyer2dcefad2021-02-25 09:42:52 +010040class TestServerHandler implements ThriftTest_service {
Jens Geyerbd52f1a2014-07-28 01:25:30 +020041
42 public var server:TServer;
43
44 public function new() {
45 }
46
Jens Geyerb5028322014-11-09 02:38:11 +010047 /**
48 * Prints "testVoid()" and returns nothing.
49 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +020050 public function testVoid():Void
51 {
Jens Geyerb5028322014-11-09 02:38:11 +010052 trace("testVoid()");
Jens Geyerbd52f1a2014-07-28 01:25:30 +020053 }
54
Jens Geyer1d20a372016-03-15 23:04:27 +020055 /**
56 * Prints 'testBool("%s")' where '%s' with thing as 'true' or 'false'
57 * @param bool thing - the bool data to print
58 * @return bool - returns the bool 'thing'
59 *
60 * @param thing
61 */
62 public function testBool(thing : Bool) : Bool
Jens Geyerfa2daef2015-09-22 00:11:01 +020063 {
64 trace('testBool($thing)');
65 return thing;
66 }
67
Jens Geyerb5028322014-11-09 02:38:11 +010068 /**
69 * Prints 'testString("%s")' with thing as '%s'
70 * @param string thing - the string to print
71 * @return string - returns the string 'thing'
72 *
73 * @param thing
74 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +020075 public function testString(thing:String):String
76 {
Jens Geyerb5028322014-11-09 02:38:11 +010077 trace("teststring(\"" + thing + "\")");
78 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020079 }
80
Jens Geyerb5028322014-11-09 02:38:11 +010081 /**
82 * Prints 'testByte("%d")' with thing as '%d'
83 * @param byte thing - the byte to print
84 * @return byte - returns the byte 'thing'
85 *
86 * @param thing
87 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +020088 public function testByte(thing:haxe.Int32):haxe.Int32
89 {
Jens Geyerb5028322014-11-09 02:38:11 +010090 trace("testByte(" + thing + ")");
91 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +020092 }
93
Jens Geyerb5028322014-11-09 02:38:11 +010094 /**
95 * Prints 'testI32("%d")' with thing as '%d'
96 * @param i32 thing - the i32 to print
97 * @return i32 - returns the i32 'thing'
98 *
99 * @param thing
100 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200101 public function testI32(thing:haxe.Int32):haxe.Int32
102 {
Jens Geyerb5028322014-11-09 02:38:11 +0100103 trace("testI32(" + thing + ")");
104 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200105 }
106
Jens Geyerb5028322014-11-09 02:38:11 +0100107 /**
108 * Prints 'testI64("%d")' with thing as '%d'
109 * @param i64 thing - the i64 to print
110 * @return i64 - returns the i64 'thing'
111 *
112 * @param thing
113 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200114 public function testI64(thing:haxe.Int64):haxe.Int64
115 {
Jens Geyerb5028322014-11-09 02:38:11 +0100116 trace("testI64(" + thing + ")");
117 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200118 }
119
Jens Geyerb5028322014-11-09 02:38:11 +0100120 /**
121 * Prints 'testDouble("%f")' with thing as '%f'
122 * @param double thing - the double to print
123 * @return double - returns the double 'thing'
124 *
125 * @param thing
126 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200127 public function testDouble(thing:Float):Float
128 {
Jens Geyerb5028322014-11-09 02:38:11 +0100129 trace("testDouble(" + thing + ")");
130 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200131 }
132
Jens Geyerb5028322014-11-09 02:38:11 +0100133 /**
Jens Geyer43e195a2014-12-14 00:29:17 +0100134 * Prints 'testBinary("%s")' where '%s' is a hex-formatted string of thing's data
135 * @param binary thing - the binary data to print
136 * @return binary - returns the binary 'thing'
Jens Geyer426ab862015-03-02 23:37:15 +0100137 *
Jens Geyer43e195a2014-12-14 00:29:17 +0100138 * @param thing
139 */
140 public function testBinary(thing : haxe.io.Bytes) : haxe.io.Bytes
141 {
Jens Geyer426ab862015-03-02 23:37:15 +0100142 var hex = "";
143 for ( i in 0 ... thing.length) {
144 hex += StringTools.hex( thing.get(i), 2);
145 }
Jens Geyer43e195a2014-12-14 00:29:17 +0100146 trace('testBinary($hex)');
147 return thing;
148 }
Jens Geyer426ab862015-03-02 23:37:15 +0100149
Jens Geyer43e195a2014-12-14 00:29:17 +0100150 /**
Jens Geyer18564d22022-06-05 11:36:40 +0200151 * Prints 'testUuid("%s")'
152 * @param Uuid thing - the uuid to print
153 * @return Uuid - returns the uuid 'thing'
154 *
155 * @param thing
156 */
157 public function testUuid(thing : String) : String
158 {
159 trace('testUuid($thing)');
160 return thing;
161 }
162
163 /**
Jens Geyerb5028322014-11-09 02:38:11 +0100164 * Prints 'testStruct("{%s}")' where thing has been formatted
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100165 * into a string of comma separated values
Jens Geyerb5028322014-11-09 02:38:11 +0100166 * @param Xtruct thing - the Xtruct to print
167 * @return Xtruct - returns the Xtruct 'thing'
168 *
169 * @param thing
170 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200171 public function testStruct(thing:Xtruct):Xtruct
172 {
Jens Geyerb5028322014-11-09 02:38:11 +0100173 trace("testStruct({" +
174 "\"" + thing.string_thing + "\", " +
175 thing.byte_thing + ", " +
176 thing.i32_thing + ", " +
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200177 Int64.toStr(thing.i64_thing) + "})");
Jens Geyerb5028322014-11-09 02:38:11 +0100178 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200179 }
180
Jens Geyerb5028322014-11-09 02:38:11 +0100181 /**
182 * Prints 'testNest("{%s}")' where thing has been formatted
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200183 * into a string of the nested struct
Jens Geyerb5028322014-11-09 02:38:11 +0100184 * @param Xtruct2 thing - the Xtruct2 to print
185 * @return Xtruct2 - returns the Xtruct2 'thing'
186 *
187 * @param thing
188 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200189 public function testNest(nest:Xtruct2):Xtruct2
190 {
Jens Geyerb5028322014-11-09 02:38:11 +0100191 var thing:Xtruct = nest.struct_thing;
192 trace("testNest({" +
193 nest.byte_thing + ", {" +
194 "\"" + thing.string_thing + "\", " +
195 thing.byte_thing + ", " +
196 thing.i32_thing + ", " +
197 Int64.toStr(thing.i64_thing) + "}, " +
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200198 nest.i32_thing + "})");
Jens Geyerb5028322014-11-09 02:38:11 +0100199 return nest;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200200 }
201
Jens Geyerb5028322014-11-09 02:38:11 +0100202 /**
203 * Prints 'testMap("{%s")' where thing has been formatted
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200204 * into a string of 'key => value' pairs
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100205 * separated by commas and new lines
Jens Geyerb5028322014-11-09 02:38:11 +0100206 * @param map<i32,i32> thing - the map<i32,i32> to print
207 * @return map<i32,i32> - returns the map<i32,i32> 'thing'
208 *
209 * @param thing
210 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200211 public function testMap(thing:IntMap<haxe.Int32>):IntMap<haxe.Int32>
212 {
Jens Geyerb5028322014-11-09 02:38:11 +0100213 trace("testMap({");
214 var first:Bool = true;
215 for (key in thing.keys()) {
216 if (first) {
217 first = false;
218 } else {
219 trace(", ");
220 };
221 trace(key + " => " + thing.get(key));
222 };
223 trace("})");
224 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200225 }
226
Jens Geyerb5028322014-11-09 02:38:11 +0100227 /**
228 * Prints 'testStringMap("{%s}")' where thing has been formatted
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200229 * into a string of 'key => value' pairs
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100230 * separated by commas and new lines
Jens Geyerb5028322014-11-09 02:38:11 +0100231 * @param map<string,string> thing - the map<string,string> to print
232 * @return map<string,string> - returns the map<string,string> 'thing'
233 *
234 * @param thing
235 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200236 public function testStringMap(thing:StringMap<String>):StringMap<String>
237 {
Jens Geyerb5028322014-11-09 02:38:11 +0100238 trace("testStringMap({");
239 var first:Bool = true;
240 for (key in thing.keys()) {
241 if (first) {
242 first = false;
243 } else {
244 trace(", ");
245 };
246 trace(key + " => " + thing.get(key));
247 };
248 trace("})");
249 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200250 }
251
Jens Geyerb5028322014-11-09 02:38:11 +0100252 /**
253 * Prints 'testSet("{%s}")' where thing has been formatted
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200254 * into a string of values
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100255 * separated by commas and new lines
Jens Geyerb5028322014-11-09 02:38:11 +0100256 * @param set<i32> thing - the set<i32> to print
257 * @return set<i32> - returns the set<i32> 'thing'
258 *
259 * @param thing
260 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200261 public function testSet(thing:IntSet):IntSet
262 {
Jens Geyerb5028322014-11-09 02:38:11 +0100263 trace("testSet({");
264 var first:Bool = true;
265 for (elem in thing) {
266 if (first) {
267 first = false;
268 } else {
269 trace(", ");
270 };
271 trace(elem);
272 };
273 trace("})");
274 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200275 }
276
Jens Geyerb5028322014-11-09 02:38:11 +0100277 /**
278 * Prints 'testList("{%s}")' where thing has been formatted
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200279 * into a string of values
Konrad Grochowski3b5dacb2014-11-24 10:55:31 +0100280 * separated by commas and new lines
Jens Geyerb5028322014-11-09 02:38:11 +0100281 * @param list<i32> thing - the list<i32> to print
282 * @return list<i32> - returns the list<i32> 'thing'
283 *
284 * @param thing
285 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200286 public function testList(thing:List<haxe.Int32>):List<haxe.Int32>
287 {
Jens Geyerb5028322014-11-09 02:38:11 +0100288 trace("testList({");
289 var first:Bool = true;
290 for (elem in thing) {
291 if (first) {
292 first = false;
293 } else {
294 trace(", ");
295 };
296 trace(elem);
297 };
298 trace("})");
299 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200300 }
301
Jens Geyerb5028322014-11-09 02:38:11 +0100302 /**
303 * Prints 'testEnum("%d")' where thing has been formatted into it's numeric value
304 * @param Numberz thing - the Numberz to print
305 * @return Numberz - returns the Numberz 'thing'
306 *
307 * @param thing
308 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200309 public function testEnum(thing:Int):Int
310 {
Jens Geyerb5028322014-11-09 02:38:11 +0100311 trace("testEnum(" + thing + ")");
312 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200313 }
314
Jens Geyerb5028322014-11-09 02:38:11 +0100315 /**
316 * Prints 'testTypedef("%d")' with thing as '%d'
317 * @param UserId thing - the UserId to print
318 * @return UserId - returns the UserId 'thing'
319 *
320 * @param thing
321 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200322 public function testTypedef(thing:haxe.Int64):haxe.Int64
323 {
Jens Geyerb5028322014-11-09 02:38:11 +0100324 trace("testTypedef(" + thing + ")");
325 return thing;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200326 }
327
Jens Geyerb5028322014-11-09 02:38:11 +0100328 /**
329 * Prints 'testMapMap("%d")' with hello as '%d'
330 * @param i32 hello - the i32 to print
331 * @return map<i32,map<i32,i32>> - returns a dictionary with these values:
332 * {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, },
333 * 4 => {1 => 1, 2 => 2, 3 => 3, 4 => 4, }, }
334 *
335 * @param hello
336 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200337 public function testMapMap(hello:haxe.Int32):IntMap<IntMap<haxe.Int32>>
338 {
Jens Geyerb5028322014-11-09 02:38:11 +0100339 trace("testMapMap(" + hello + ")");
340 var mapmap = new IntMap<IntMap<Int>>();
341 var pos = new IntMap<Int>();
342 var neg = new IntMap<Int>();
343 for (i in 1 ... 5) {
344 pos.set(i, i);
345 neg.set(-i, -i);
346 };
347 mapmap.set(4, pos);
348 mapmap.set(-4, neg);
349 return mapmap;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200350 }
351
Jens Geyerb5028322014-11-09 02:38:11 +0100352 /**
353 * So you think you've got this all worked, out eh?
354 *
355 * Creates a the returned map with these values and prints it out:
356 * { 1 => { 2 => argument,
357 * 3 => argument,
358 * },
359 * 2 => { 6 => <empty Insanity struct>, },
360 * }
361 * @return map<UserId, map<Numberz,Insanity>> - a map with the above values
362 *
363 * @param argument
364 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200365 public function testInsanity(argument : Insanity) : Int64Map< IntMap< Insanity>>
366 {
Jens Geyerb5028322014-11-09 02:38:11 +0100367 trace("testInsanity()");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200368
Jens Geyerb5028322014-11-09 02:38:11 +0100369 var first_map = new IntMap< Insanity>();
Jens Geyer1ca09d02017-01-10 22:48:09 +0100370 first_map.set(Numberz.TWO, argument);
371 first_map.set(Numberz.THREE, argument);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200372
Jens Geyerb5028322014-11-09 02:38:11 +0100373 var second_map = new IntMap< Insanity>();
Jens Geyer1ca09d02017-01-10 22:48:09 +0100374 var looney = new Insanity();
Jens Geyerb5028322014-11-09 02:38:11 +0100375 second_map.set(Numberz.SIX, looney);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200376
Jens Geyerb5028322014-11-09 02:38:11 +0100377 var insane = new Int64Map< IntMap< Insanity>>();
378 insane.set( Int64.make(0,1), first_map);
379 insane.set( Int64.make(0,2), second_map);
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200380
Jens Geyerb5028322014-11-09 02:38:11 +0100381 return insane;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200382 }
383
Jens Geyerb5028322014-11-09 02:38:11 +0100384 /**
385 * Prints 'testMulti()'
386 * @param byte arg0 -
387 * @param i32 arg1 -
388 * @param i64 arg2 -
389 * @param map<i16, string> arg3 -
390 * @param Numberz arg4 -
391 * @param UserId arg5 -
392 * @return Xtruct - returns an Xtruct
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200393 * with string_thing = "Hello2, byte_thing = arg0, i32_thing = arg1
Jens Geyerb5028322014-11-09 02:38:11 +0100394 * and i64_thing = arg2
395 *
396 * @param arg0
397 * @param arg1
398 * @param arg2
399 * @param arg3
400 * @param arg4
401 * @param arg5
402 */
403 public function testMulti(arg0:haxe.Int32, arg1:haxe.Int32, arg2:haxe.Int64,
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200404 arg3:IntMap<String>, arg4:Int, arg5:haxe.Int64):Xtruct
405 {
Jens Geyerb5028322014-11-09 02:38:11 +0100406 trace("testMulti()");
407 var hello = new Xtruct();
408 hello.string_thing = "Hello2";
409 hello.byte_thing = arg0;
410 hello.i32_thing = arg1;
411 hello.i64_thing = arg2;
412 return hello;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200413 }
414
Jens Geyerb5028322014-11-09 02:38:11 +0100415 /**
416 * Print 'testException(%s)' with arg as '%s'
417 * @param string arg - a string indication what type of exception to throw
418 * if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
419 * elsen if arg == "TException" throw TException
420 * else do not throw anything
421 *
422 * @param arg
423 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200424 public function testException(arg:String):Void
425 {
Jens Geyerb5028322014-11-09 02:38:11 +0100426 trace("testException(" + arg + ")");
427 if (arg == "Xception") {
428 var x = new Xception();
429 x.errorCode = 1001;
430 x.message = arg;
431 throw x;
432 };
433 if (arg == "TException") {
434 throw new TException();
435 };
436 return;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200437 }
438
Jens Geyerb5028322014-11-09 02:38:11 +0100439 /**
440 * Print 'testMultiException(%s, %s)' with arg0 as '%s' and arg1 as '%s'
441 * @param string arg - a string indication what type of exception to throw
442 * if arg0 == "Xception"
443 * throw Xception with errorCode = 1001 and message = "This is an Xception"
444 * else if arg0 == "Xception2"
445 * throw Xception2 with errorCode = 2002 and message = "This is an Xception2"
446 * else do not throw anything
447 * @return Xtruct - an Xtruct with string_thing = arg1
448 *
449 * @param arg0
450 * @param arg1
451 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200452 public function testMultiException(arg0:String, arg1:String):Xtruct
453 {
Jens Geyerb5028322014-11-09 02:38:11 +0100454 trace("testMultiException(" + arg0 + ", " + arg1 + ")");
455 if (arg0 == "Xception") {
456 var x = new Xception();
457 x.errorCode = 1001;
458 x.message = "This is an Xception";
459 throw x;
460 } else if (arg0 == "Xception2") {
461 var x = new Xception2();
462 x.errorCode = 2002;
463 x.struct_thing = new Xtruct();
464 x.struct_thing.string_thing = "This is an Xception2";
465 throw x;
466 };
467 var result = new Xtruct();
468 result.string_thing = arg1;
469 return result;
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200470 }
471
Jens Geyerb5028322014-11-09 02:38:11 +0100472 /**
473 * Print 'testOneway(%d): Sleeping...' with secondsToSleep as '%d'
474 * sleep 'secondsToSleep'
475 * Print 'testOneway(%d): done sleeping!' with secondsToSleep as '%d'
476 * @param i32 secondsToSleep - the number of seconds to sleep
477 *
478 * @param secondsToSleep
479 */
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200480 public function testOneway(secondsToSleep:haxe.Int32):Void
481 {
Jens Geyer2dcefad2021-02-25 09:42:52 +0100482 #if sys
Jens Geyerb5028322014-11-09 02:38:11 +0100483 trace("testOneway(" + secondsToSleep + "), sleeping...");
484 Sys.sleep(secondsToSleep);
Jens Geyer2dcefad2021-02-25 09:42:52 +0100485 #end
Jens Geyerb5028322014-11-09 02:38:11 +0100486 trace("testOneway finished");
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200487 }
488
489 public function testStop():Void
490 {
Jens Geyerb5028322014-11-09 02:38:11 +0100491 if (server != null) {
492 server.Stop();
493 };
Jens Geyerbd52f1a2014-07-28 01:25:30 +0200494 }
495}