/** * Autogenerated by Thrift for thrift/compiler/test/fixtures/basic-annotations/src/module.thrift * * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING * @generated @nocommit */ #pragma once #include #include "thrift/compiler/test/fixtures/basic-annotations/gen-cpp2/module_types.h" #include #include #include namespace apache { namespace thrift { class Cpp2RequestContext; namespace detail { namespace ac { struct ClientRequestContext; }} namespace transport { class THeader; } }} namespace cpp2 { class GoodService; } // namespace cpp2 namespace apache::thrift { template <> class Client<::cpp2::GoodService> : public apache::thrift::GeneratedAsyncClient { public: using apache::thrift::GeneratedAsyncClient::GeneratedAsyncClient; char const* getServiceName() const noexcept override { return "BadService"; } class BadInteraction final : public apache::thrift::InteractionHandle { using apache::thrift::InteractionHandle::InteractionHandle; friend class ::apache::thrift::Client<::cpp2::GoodService>; public: char const* getServiceName() const noexcept override { return "BadService"; } /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadInteraction", "function": "foo"} */ void foo(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback); protected: void fooImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr header, apache::thrift::ContextStack* contextStack, apache::thrift::RequestClientCallback::Ptr callback, bool stealRpcOptions = false); public: /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadInteraction", "function": "foo"} */ void sync_foo(); /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadInteraction", "function": "foo"} */ void sync_foo(apache::thrift::RpcOptions& rpcOptions); /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadInteraction", "function": "foo"} */ folly::SemiFuture semifuture_foo(); /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadInteraction", "function": "foo"} */ folly::SemiFuture semifuture_foo(apache::thrift::RpcOptions& rpcOptions); #if FOLLY_HAS_COROUTINES #if __clang__ /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadInteraction", "function": "foo"} */ template folly::coro::Task co_foo() { return co_foo(nullptr); } /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadInteraction", "function": "foo"} */ template folly::coro::Task co_foo(apache::thrift::RpcOptions& rpcOptions) { return co_foo(&rpcOptions); } #else /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadInteraction", "function": "foo"} */ folly::coro::Task co_foo() { co_await folly::coro::detachOnCancel(semifuture_foo()); } /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadInteraction", "function": "foo"} */ folly::coro::Task co_foo(apache::thrift::RpcOptions& rpcOptions) { co_await folly::coro::detachOnCancel(semifuture_foo(rpcOptions)); } #endif private: template folly::coro::Task co_foo(apache::thrift::RpcOptions* rpcOptions) { const folly::CancellationToken& cancelToken = co_await folly::coro::co_current_cancellation_token; const bool cancellable = cancelToken.canBeCancelled(); apache::thrift::ClientReceiveState returnState; apache::thrift::ClientCoroCallback callback(&returnState, co_await folly::coro::co_current_executor); auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId(); auto [ctx, header] = fooCtx(rpcOptions); using CancellableCallback = apache::thrift::CancellableRequestClientCallback; auto cancellableCallback = cancellable ? CancellableCallback::create(&callback, channel_) : nullptr; static apache::thrift::RpcOptions* defaultRpcOptions = new apache::thrift::RpcOptions(); auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback); if constexpr (hasRpcOptions) { fooImpl(*rpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback)); } else { fooImpl(*defaultRpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback)); } if (cancellable) { folly::CancellationCallback cb(cancelToken, [&] { CancellableCallback::cancel(std::move(cancellableCallback)); }); co_await callback.co_waitUntilDone(); } else { co_await callback.co_waitUntilDone(); } if (returnState.isException()) { co_yield folly::coro::co_error(std::move(returnState.exception())); } returnState.resetProtocolId(protocolId); returnState.resetCtx(std::move(ctx)); SCOPE_EXIT { if (hasRpcOptions && returnState.header()) { auto* rheader = returnState.header(); if (!rheader->getHeaders().empty()) { rpcOptions->setReadHeaders(rheader->releaseHeaders()); } rpcOptions->setRoutingData(rheader->releaseRoutingData()); } }; if (auto ew = recv_wrapped_foo(returnState)) { co_yield folly::coro::co_error(std::move(ew)); } } public: #endif // FOLLY_HAS_COROUTINES /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadInteraction", "function": "foo"} */ static folly::exception_wrapper recv_wrapped_foo(::apache::thrift::ClientReceiveState& state); /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadInteraction", "function": "foo"} */ static void recv_foo(::apache::thrift::ClientReceiveState& state); private: template void fooT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr header, apache::thrift::ContextStack* contextStack, apache::thrift::RequestClientCallback::Ptr callback); std::pair<::apache::thrift::ContextStack::UniquePtr, std::shared_ptr<::apache::thrift::transport::THeader>> fooCtx(apache::thrift::RpcOptions* rpcOptions); public: }; /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "createBadInteraction"} */ BadInteraction createBadInteraction(); /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ virtual void bar(std::unique_ptr callback); /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ virtual void bar(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr callback); protected: void barImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr header, apache::thrift::ContextStack* contextStack, apache::thrift::RequestClientCallback::Ptr callback, bool stealRpcOptions = false); public: /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ virtual ::std::int32_t sync_bar(); /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ virtual ::std::int32_t sync_bar(apache::thrift::RpcOptions& rpcOptions); /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ virtual folly::Future<::std::int32_t> future_bar(); /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ virtual folly::SemiFuture<::std::int32_t> semifuture_bar(); /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ virtual folly::Future<::std::int32_t> future_bar(apache::thrift::RpcOptions& rpcOptions); /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ virtual folly::SemiFuture<::std::int32_t> semifuture_bar(apache::thrift::RpcOptions& rpcOptions); /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ virtual folly::Future>> header_future_bar(apache::thrift::RpcOptions& rpcOptions); /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ virtual folly::SemiFuture>> header_semifuture_bar(apache::thrift::RpcOptions& rpcOptions); #if FOLLY_HAS_COROUTINES #if __clang__ /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ template folly::coro::Task<::std::int32_t> co_bar() { return co_bar(nullptr); } /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ template folly::coro::Task<::std::int32_t> co_bar(apache::thrift::RpcOptions& rpcOptions) { return co_bar(&rpcOptions); } #else /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ folly::coro::Task<::std::int32_t> co_bar() { co_return co_await folly::coro::detachOnCancel(semifuture_bar()); } /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ folly::coro::Task<::std::int32_t> co_bar(apache::thrift::RpcOptions& rpcOptions) { co_return co_await folly::coro::detachOnCancel(semifuture_bar(rpcOptions)); } #endif private: template folly::coro::Task<::std::int32_t> co_bar(apache::thrift::RpcOptions* rpcOptions) { const folly::CancellationToken& cancelToken = co_await folly::coro::co_current_cancellation_token; const bool cancellable = cancelToken.canBeCancelled(); apache::thrift::ClientReceiveState returnState; apache::thrift::ClientCoroCallback callback(&returnState, co_await folly::coro::co_current_executor); auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId(); auto [ctx, header] = barCtx(rpcOptions); using CancellableCallback = apache::thrift::CancellableRequestClientCallback; auto cancellableCallback = cancellable ? CancellableCallback::create(&callback, channel_) : nullptr; static apache::thrift::RpcOptions* defaultRpcOptions = new apache::thrift::RpcOptions(); auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback); if constexpr (hasRpcOptions) { barImpl(*rpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback)); } else { barImpl(*defaultRpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback)); } if (cancellable) { folly::CancellationCallback cb(cancelToken, [&] { CancellableCallback::cancel(std::move(cancellableCallback)); }); co_await callback.co_waitUntilDone(); } else { co_await callback.co_waitUntilDone(); } if (returnState.isException()) { co_yield folly::coro::co_error(std::move(returnState.exception())); } returnState.resetProtocolId(protocolId); returnState.resetCtx(std::move(ctx)); SCOPE_EXIT { if (hasRpcOptions && returnState.header()) { auto* rheader = returnState.header(); if (!rheader->getHeaders().empty()) { rpcOptions->setReadHeaders(rheader->releaseHeaders()); } rpcOptions->setRoutingData(rheader->releaseRoutingData()); } }; ::std::int32_t _return; if (auto ew = recv_wrapped_bar(_return, returnState)) { co_yield folly::coro::co_error(std::move(ew)); } co_return _return; } public: #endif // FOLLY_HAS_COROUTINES /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ virtual void bar(folly::Function callback); /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ static folly::exception_wrapper recv_wrapped_bar(::std::int32_t& _return, ::apache::thrift::ClientReceiveState& state); /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ static ::std::int32_t recv_bar(::apache::thrift::ClientReceiveState& state); // Mock friendly virtual instance method /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ virtual ::std::int32_t recv_instance_bar(::apache::thrift::ClientReceiveState& state); /** Glean {"file": "thrift/compiler/test/fixtures/basic-annotations/src/module.thrift", "service": "BadService", "function": "bar"} */ virtual folly::exception_wrapper recv_instance_wrapped_bar(::std::int32_t& _return, ::apache::thrift::ClientReceiveState& state); private: template void barT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr header, apache::thrift::ContextStack* contextStack, apache::thrift::RequestClientCallback::Ptr callback); std::pair<::apache::thrift::ContextStack::UniquePtr, std::shared_ptr<::apache::thrift::transport::THeader>> barCtx(apache::thrift::RpcOptions* rpcOptions); public: }; } // namespace apache::thrift namespace cpp2 { using GoodServiceAsyncClient [[deprecated("Use apache::thrift::Client instead")]] = ::apache::thrift::Client; } // namespace cpp2