1 /** 2 * Autogenerated by Thrift for src/module.thrift 3 * 4 * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 * @generated @nocommit 6 */ 7 #pragma once 8 9 #include <thrift/lib/cpp2/gen/client_h.h> 10 11 #include "thrift/compiler/test/fixtures/basic-structured-annotations/gen-cpp2/module_types.h" 12 #include "thrift/compiler/test/fixtures/basic-structured-annotations/gen-cpp2/included_types.h" 13 #include "thrift/compiler/test/fixtures/basic-structured-annotations/gen-cpp2/namespaced_types.h" 14 15 namespace apache { namespace thrift { 16 class Cpp2RequestContext; 17 namespace detail { namespace ac { struct ClientRequestContext; }} 18 namespace transport { class THeader; } 19 }} 20 21 namespace cpp2 { 22 23 class MyServiceAsyncClient : public apache::thrift::GeneratedAsyncClient { 24 public: 25 using apache::thrift::GeneratedAsyncClient::GeneratedAsyncClient; 26 getServiceName()27 char const* getServiceName() const noexcept override { 28 return "MyService"; 29 } 30 31 32 virtual void first(std::unique_ptr<apache::thrift::RequestCallback> callback); 33 virtual void first(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr<apache::thrift::RequestCallback> callback); 34 protected: 35 void firstImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::RequestClientCallback::Ptr callback, bool stealRpcOptions = false); 36 public: 37 38 virtual void sync_first(::cpp2::annotated_inline_string& _return); 39 virtual void sync_first(apache::thrift::RpcOptions& rpcOptions, ::cpp2::annotated_inline_string& _return); 40 41 virtual folly::Future<::cpp2::annotated_inline_string> future_first(); 42 virtual folly::SemiFuture<::cpp2::annotated_inline_string> semifuture_first(); 43 virtual folly::Future<::cpp2::annotated_inline_string> future_first(apache::thrift::RpcOptions& rpcOptions); 44 virtual folly::SemiFuture<::cpp2::annotated_inline_string> semifuture_first(apache::thrift::RpcOptions& rpcOptions); 45 virtual folly::Future<std::pair<::cpp2::annotated_inline_string, std::unique_ptr<apache::thrift::transport::THeader>>> header_future_first(apache::thrift::RpcOptions& rpcOptions); 46 virtual folly::SemiFuture<std::pair<::cpp2::annotated_inline_string, std::unique_ptr<apache::thrift::transport::THeader>>> header_semifuture_first(apache::thrift::RpcOptions& rpcOptions); 47 48 #if FOLLY_HAS_COROUTINES 49 template <int = 0> co_first()50 folly::coro::Task<::cpp2::annotated_inline_string> co_first() { 51 return co_first<false>(nullptr); 52 } 53 template <int = 0> co_first(apache::thrift::RpcOptions & rpcOptions)54 folly::coro::Task<::cpp2::annotated_inline_string> co_first(apache::thrift::RpcOptions& rpcOptions) { 55 return co_first<true>(&rpcOptions); 56 } 57 private: 58 template <bool hasRpcOptions> co_first(apache::thrift::RpcOptions * rpcOptions)59 folly::coro::Task<::cpp2::annotated_inline_string> co_first(apache::thrift::RpcOptions* rpcOptions) { 60 const folly::CancellationToken& cancelToken = 61 co_await folly::coro::co_current_cancellation_token; 62 const bool cancellable = cancelToken.canBeCancelled(); 63 apache::thrift::ClientReceiveState returnState; 64 apache::thrift::ClientSyncCallback<false> callback(&returnState); 65 auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId(); 66 auto [ctx, header] = firstCtx(rpcOptions); 67 using CancellableCallback = apache::thrift::CancellableRequestClientCallback<false>; 68 auto cancellableCallback = cancellable ? CancellableCallback::create(&callback, channel_) : nullptr; 69 static apache::thrift::RpcOptions defaultRpcOptions; 70 auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback); 71 if constexpr (hasRpcOptions) { 72 firstImpl(*rpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback)); 73 } else { 74 firstImpl(defaultRpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback)); 75 } 76 if (cancellable) { 77 folly::CancellationCallback cb(cancelToken, [&] { CancellableCallback::cancel(std::move(cancellableCallback)); }); 78 co_await callback.co_waitUntilDone(); 79 } else { 80 co_await callback.co_waitUntilDone(); 81 } 82 if (returnState.isException()) { 83 co_yield folly::coro::co_error(std::move(returnState.exception())); 84 } 85 returnState.resetProtocolId(protocolId); 86 returnState.resetCtx(std::move(ctx)); 87 SCOPE_EXIT { 88 if (hasRpcOptions && returnState.header()) { 89 auto* rheader = returnState.header(); 90 if (!rheader->getHeaders().empty()) { 91 rpcOptions->setReadHeaders(rheader->releaseHeaders()); 92 } 93 rpcOptions->setRoutingData(rheader->releaseRoutingData()); 94 } 95 }; 96 ::cpp2::annotated_inline_string _return; 97 if (auto ew = recv_wrapped_first(_return, returnState)) { 98 co_yield folly::coro::co_error(std::move(ew)); 99 } 100 co_return _return; 101 } 102 public: 103 #endif // FOLLY_HAS_COROUTINES 104 105 virtual void first(folly::Function<void (::apache::thrift::ClientReceiveState&&)> callback); 106 107 108 static folly::exception_wrapper recv_wrapped_first(::cpp2::annotated_inline_string& _return, ::apache::thrift::ClientReceiveState& state); 109 static void recv_first(::cpp2::annotated_inline_string& _return, ::apache::thrift::ClientReceiveState& state); 110 // Mock friendly virtual instance method 111 virtual void recv_instance_first(::cpp2::annotated_inline_string& _return, ::apache::thrift::ClientReceiveState& state); 112 virtual folly::exception_wrapper recv_instance_wrapped_first(::cpp2::annotated_inline_string& _return, ::apache::thrift::ClientReceiveState& state); 113 private: 114 template <typename Protocol_, typename RpcOptions> 115 void firstT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::RequestClientCallback::Ptr callback); 116 std::pair<std::unique_ptr<::apache::thrift::ContextStack>, std::shared_ptr<::apache::thrift::transport::THeader>> firstCtx(apache::thrift::RpcOptions* rpcOptions); 117 public: 118 virtual void second(std::unique_ptr<apache::thrift::RequestCallback> callback, ::std::int64_t p_count); 119 virtual void second(apache::thrift::RpcOptions& rpcOptions, std::unique_ptr<apache::thrift::RequestCallback> callback, ::std::int64_t p_count); 120 protected: 121 void secondImpl(apache::thrift::RpcOptions& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::RequestClientCallback::Ptr callback, ::std::int64_t p_count, bool stealRpcOptions = false); 122 public: 123 124 virtual bool sync_second(::std::int64_t p_count); 125 virtual bool sync_second(apache::thrift::RpcOptions& rpcOptions, ::std::int64_t p_count); 126 127 virtual folly::Future<bool> future_second(::std::int64_t p_count); 128 virtual folly::SemiFuture<bool> semifuture_second(::std::int64_t p_count); 129 virtual folly::Future<bool> future_second(apache::thrift::RpcOptions& rpcOptions, ::std::int64_t p_count); 130 virtual folly::SemiFuture<bool> semifuture_second(apache::thrift::RpcOptions& rpcOptions, ::std::int64_t p_count); 131 virtual folly::Future<std::pair<bool, std::unique_ptr<apache::thrift::transport::THeader>>> header_future_second(apache::thrift::RpcOptions& rpcOptions, ::std::int64_t p_count); 132 virtual folly::SemiFuture<std::pair<bool, std::unique_ptr<apache::thrift::transport::THeader>>> header_semifuture_second(apache::thrift::RpcOptions& rpcOptions, ::std::int64_t p_count); 133 134 #if FOLLY_HAS_COROUTINES 135 template <int = 0> co_second(::std::int64_t p_count)136 folly::coro::Task<bool> co_second(::std::int64_t p_count) { 137 return co_second<false>(nullptr, p_count); 138 } 139 template <int = 0> co_second(apache::thrift::RpcOptions & rpcOptions,::std::int64_t p_count)140 folly::coro::Task<bool> co_second(apache::thrift::RpcOptions& rpcOptions, ::std::int64_t p_count) { 141 return co_second<true>(&rpcOptions, p_count); 142 } 143 private: 144 template <bool hasRpcOptions> co_second(apache::thrift::RpcOptions * rpcOptions,::std::int64_t p_count)145 folly::coro::Task<bool> co_second(apache::thrift::RpcOptions* rpcOptions, ::std::int64_t p_count) { 146 const folly::CancellationToken& cancelToken = 147 co_await folly::coro::co_current_cancellation_token; 148 const bool cancellable = cancelToken.canBeCancelled(); 149 apache::thrift::ClientReceiveState returnState; 150 apache::thrift::ClientSyncCallback<false> callback(&returnState); 151 auto protocolId = apache::thrift::GeneratedAsyncClient::getChannel()->getProtocolId(); 152 auto [ctx, header] = secondCtx(rpcOptions); 153 using CancellableCallback = apache::thrift::CancellableRequestClientCallback<false>; 154 auto cancellableCallback = cancellable ? CancellableCallback::create(&callback, channel_) : nullptr; 155 static apache::thrift::RpcOptions defaultRpcOptions; 156 auto wrappedCallback = apache::thrift::RequestClientCallback::Ptr(cancellableCallback ? (apache::thrift::RequestClientCallback*)cancellableCallback.get() : &callback); 157 if constexpr (hasRpcOptions) { 158 secondImpl(*rpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback), p_count); 159 } else { 160 secondImpl(defaultRpcOptions, std::move(header), ctx.get(), std::move(wrappedCallback), p_count); 161 } 162 if (cancellable) { 163 folly::CancellationCallback cb(cancelToken, [&] { CancellableCallback::cancel(std::move(cancellableCallback)); }); 164 co_await callback.co_waitUntilDone(); 165 } else { 166 co_await callback.co_waitUntilDone(); 167 } 168 if (returnState.isException()) { 169 co_yield folly::coro::co_error(std::move(returnState.exception())); 170 } 171 returnState.resetProtocolId(protocolId); 172 returnState.resetCtx(std::move(ctx)); 173 SCOPE_EXIT { 174 if (hasRpcOptions && returnState.header()) { 175 auto* rheader = returnState.header(); 176 if (!rheader->getHeaders().empty()) { 177 rpcOptions->setReadHeaders(rheader->releaseHeaders()); 178 } 179 rpcOptions->setRoutingData(rheader->releaseRoutingData()); 180 } 181 }; 182 bool _return; 183 if (auto ew = recv_wrapped_second(_return, returnState)) { 184 co_yield folly::coro::co_error(std::move(ew)); 185 } 186 co_return _return; 187 } 188 public: 189 #endif // FOLLY_HAS_COROUTINES 190 191 virtual void second(folly::Function<void (::apache::thrift::ClientReceiveState&&)> callback, ::std::int64_t p_count); 192 193 194 static folly::exception_wrapper recv_wrapped_second(bool& _return, ::apache::thrift::ClientReceiveState& state); 195 static bool recv_second(::apache::thrift::ClientReceiveState& state); 196 // Mock friendly virtual instance method 197 virtual bool recv_instance_second(::apache::thrift::ClientReceiveState& state); 198 virtual folly::exception_wrapper recv_instance_wrapped_second(bool& _return, ::apache::thrift::ClientReceiveState& state); 199 private: 200 template <typename Protocol_, typename RpcOptions> 201 void secondT(Protocol_* prot, RpcOptions&& rpcOptions, std::shared_ptr<apache::thrift::transport::THeader> header, apache::thrift::ContextStack* contextStack, apache::thrift::RequestClientCallback::Ptr callback, ::std::int64_t p_count); 202 std::pair<std::unique_ptr<::apache::thrift::ContextStack>, std::shared_ptr<::apache::thrift::transport::THeader>> secondCtx(apache::thrift::RpcOptions* rpcOptions); 203 public: 204 }; 205 206 } // cpp2 207