Kino Roy | a9da9eb | 2022-10-07 23:13:01 -0700 | [diff] [blame] | 1 | // Licensed to the Apache Software Foundation (ASF) under one |
| 2 | // or more contributor license agreements. See the NOTICE file |
| 3 | // distributed with this work for additional information |
| 4 | // regarding copyright ownership. The ASF licenses this file |
| 5 | // to you under the Apache License, Version 2.0 (the |
| 6 | // "License"); you may not use this file except in compliance |
| 7 | // with the License. You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, |
| 12 | // software distributed under the License is distributed on an |
| 13 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | // KIND, either express or implied. See the License for the |
| 15 | // specific language governing permissions and limitations |
| 16 | // under the License. |
| 17 | |
| 18 | import Foundation |
| 19 | import Thrift |
| 20 | import Common |
| 21 | |
| 22 | class TestServer { |
| 23 | var server: Any? |
| 24 | |
| 25 | func run() throws { |
| 26 | let parameters = try TestServerParameters(arguments: CommandLine.arguments) |
| 27 | |
| 28 | if parameters.showHelp { |
| 29 | parameters.printHelp() |
| 30 | return |
| 31 | } |
| 32 | |
| 33 | let service = ThriftTestImpl() |
| 34 | let processor = ThriftTestProcessor(service: service) |
| 35 | |
| 36 | |
| 37 | switch (parameters.proto, parameters.transport) { |
| 38 | case (.binary, .buffered): |
| 39 | let proto = TBinaryProtocol.self |
| 40 | server = try TSocketServer(port: parameters.port!, inProtocol: proto, outProtocol: proto, processor: processor) |
| 41 | case (.binary, .framed): |
| 42 | let proto = TBinaryProtocol.self |
| 43 | server = try TFramedSocketServer(port: parameters.port!, inProtocol: proto, outProtocol: proto, processor: processor) |
| 44 | case (.compact, .buffered): |
| 45 | let proto = TCompactProtocol.self |
| 46 | server = try TSocketServer(port: parameters.port!, inProtocol: proto, outProtocol: proto, processor: processor) |
| 47 | case (.compact, .framed): |
| 48 | let proto = TCompactProtocol.self |
| 49 | server = try TFramedSocketServer(port: parameters.port!, inProtocol: proto, outProtocol: proto, processor: processor) |
| 50 | default: |
| 51 | throw ParserError.unsupportedOption |
| 52 | } |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | let server = TestServer() |
| 57 | try server.run() |
| 58 | |
| 59 | RunLoop.main.run() |