1 /*
2  * Copyright (c) Facebook, Inc. and its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <thrift/lib/py3lite/server/server.h>
18 #include <thrift/lib/py3lite/server/server_api.h> // @manual
19 
20 namespace thrift {
21 namespace py3lite {
22 
23 namespace {
24 
do_import()25 void do_import() {
26   if (0 != import_thrift__py3lite__server()) {
27     throw std::runtime_error("import_thrift__py3lite__server failed");
28   }
29 }
30 
31 } // namespace
32 
handlePythonServerCallback(apache::thrift::ProtocolType protocol,apache::thrift::Cpp2RequestContext * context,folly::Promise<std::unique_ptr<folly::IOBuf>> promise,apache::thrift::SerializedRequest serializedRequest)33 void Py3LiteAsyncProcessor::handlePythonServerCallback(
34     apache::thrift::ProtocolType protocol,
35     apache::thrift::Cpp2RequestContext* context,
36     folly::Promise<std::unique_ptr<folly::IOBuf>> promise,
37     apache::thrift::SerializedRequest serializedRequest) {
38   FOLLY_MAYBE_UNUSED static bool done = (do_import(), false);
39   handleServerCallback(
40       functions_.at(context->getMethodName()),
41       serviceName_ + "." + context->getMethodName(),
42       context,
43       std::move(promise),
44       std::move(serializedRequest),
45       protocol);
46 }
47 
handlePythonServerCallbackOneway(apache::thrift::ProtocolType protocol,apache::thrift::Cpp2RequestContext * context,folly::Promise<folly::Unit> promise,apache::thrift::SerializedRequest serializedRequest)48 void Py3LiteAsyncProcessor::handlePythonServerCallbackOneway(
49     apache::thrift::ProtocolType protocol,
50     apache::thrift::Cpp2RequestContext* context,
51     folly::Promise<folly::Unit> promise,
52     apache::thrift::SerializedRequest serializedRequest) {
53   FOLLY_MAYBE_UNUSED static bool done = (do_import(), false);
54   handleServerCallbackOneway(
55       functions_.at(context->getMethodName()),
56       serviceName_ + "." + context->getMethodName(),
57       context,
58       std::move(promise),
59       std::move(serializedRequest),
60       protocol);
61 }
62 
63 } // namespace py3lite
64 } // namespace thrift
65