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 
8 #include "thrift/compiler/test/fixtures/interactions/gen-cpp2/MyService.h"
9 #include "thrift/compiler/test/fixtures/interactions/gen-cpp2/MyService.tcc"
10 #include "thrift/compiler/test/fixtures/interactions/gen-cpp2/module_metadata.h"
11 #include <thrift/lib/cpp2/gen/service_cpp.h>
12 
13 namespace cpp2 {
getProcessor()14 std::unique_ptr<apache::thrift::AsyncProcessor> MyServiceSvIf::getProcessor() {
15   return std::make_unique<MyServiceAsyncProcessor>(this);
16 }
17 
createMethodMetadata()18 MyServiceSvIf::CreateMethodMetadataResult MyServiceSvIf::createMethodMetadata() {
19   return ::apache::thrift::detail::ap::createMethodMetadataMap<MyServiceAsyncProcessor>();
20 }
21 
22 
foo()23 void MyServiceSvIf::foo() {
24   apache::thrift::detail::si::throw_app_exn_unimplemented("foo");
25 }
26 
semifuture_foo()27 folly::SemiFuture<folly::Unit> MyServiceSvIf::semifuture_foo() {
28   auto expected{apache::thrift::detail::si::InvocationType::SemiFuture};
29   __fbthrift_invocation_foo.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::Sync, std::memory_order_relaxed);
30   foo();
31   return folly::makeSemiFuture();
32 }
33 
future_foo()34 folly::Future<folly::Unit> MyServiceSvIf::future_foo() {
35   auto expected{apache::thrift::detail::si::InvocationType::Future};
36   __fbthrift_invocation_foo.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::SemiFuture, std::memory_order_relaxed);
37   return apache::thrift::detail::si::future(semifuture_foo(), getInternalKeepAlive());
38 }
39 
async_tm_foo(std::unique_ptr<apache::thrift::HandlerCallback<void>> callback)40 void MyServiceSvIf::async_tm_foo(std::unique_ptr<apache::thrift::HandlerCallback<void>> callback) {
41   // It's possible the coroutine versions will delegate to a future-based
42   // version. If that happens, we need the RequestParams arguments to be
43   // available to the future through the thread-local backchannel, so we create
44   // a RAII object that sets up RequestParams and clears them on destruction.
45   apache::thrift::detail::si::AsyncTmPrep asyncTmPrep(this, callback.get());
46   auto invocationType = __fbthrift_invocation_foo.load(std::memory_order_relaxed);
47   try {
48     switch (invocationType) {
49       case apache::thrift::detail::si::InvocationType::AsyncTm:
50       {
51         __fbthrift_invocation_foo.compare_exchange_strong(invocationType, apache::thrift::detail::si::InvocationType::Future, std::memory_order_relaxed);
52         FOLLY_FALLTHROUGH;
53       }
54       case apache::thrift::detail::si::InvocationType::Future:
55       {
56         auto fut = future_foo();
57         apache::thrift::detail::si::async_tm_future(std::move(callback), std::move(fut));
58         return;
59       }
60       case apache::thrift::detail::si::InvocationType::SemiFuture:
61       {
62         auto fut = semifuture_foo();
63         apache::thrift::detail::si::async_tm_semifuture(std::move(callback), std::move(fut));
64         return;
65       }
66       case apache::thrift::detail::si::InvocationType::Sync:
67       {
68         foo();
69         callback->done();
70         return;
71       }
72       default:
73       {
74         folly::assume_unreachable();
75       }
76     }
77   } catch (...) {
78     callback->exception(std::current_exception());
79   }
80 }
81 
foo()82 void MyServiceSvNull::foo() {
83   return;
84 }
85 
86 
87 
frobnicate()88 ::std::int32_t MyServiceSvIf::MyInteractionIf::frobnicate() {
89   apache::thrift::detail::si::throw_app_exn_unimplemented("frobnicate");
90 }
91 
semifuture_frobnicate()92 folly::SemiFuture<::std::int32_t> MyServiceSvIf::MyInteractionIf::semifuture_frobnicate() {
93   auto expected{apache::thrift::detail::si::InvocationType::SemiFuture};
94   __fbthrift_invocation_frobnicate.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::Sync, std::memory_order_relaxed);
95   return frobnicate();
96 }
97 
98 #if FOLLY_HAS_COROUTINES
co_frobnicate()99 folly::coro::Task<::std::int32_t> MyServiceSvIf::MyInteractionIf::co_frobnicate() {
100   auto expected{apache::thrift::detail::si::InvocationType::Coro};
101   __fbthrift_invocation_frobnicate.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::SemiFuture, std::memory_order_relaxed);
102   return folly::coro::toTask(semifuture_frobnicate());
103 }
104 
co_frobnicate(apache::thrift::RequestParams)105 folly::coro::Task<::std::int32_t> MyServiceSvIf::MyInteractionIf::co_frobnicate(apache::thrift::RequestParams /* params */) {
106   auto expected{apache::thrift::detail::si::InvocationType::CoroParam};
107   __fbthrift_invocation_frobnicate.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::Coro, std::memory_order_relaxed);
108   return co_frobnicate();
109 }
110 #endif // FOLLY_HAS_COROUTINES
111 
async_tm_frobnicate(std::unique_ptr<apache::thrift::HandlerCallback<::std::int32_t>> callback)112 void MyServiceSvIf::MyInteractionIf::async_tm_frobnicate(std::unique_ptr<apache::thrift::HandlerCallback<::std::int32_t>> callback) {
113   // It's possible the coroutine versions will delegate to a future-based
114   // version. If that happens, we need the RequestParams arguments to be
115   // available to the future through the thread-local backchannel, so we create
116   // a RAII object that sets up RequestParams and clears them on destruction.
117   apache::thrift::detail::si::AsyncTmPrep asyncTmPrep(this, callback.get());
118   auto invocationType = __fbthrift_invocation_frobnicate.load(std::memory_order_relaxed);
119   try {
120     switch (invocationType) {
121       case apache::thrift::detail::si::InvocationType::AsyncTm:
122       {
123 #if FOLLY_HAS_COROUTINES
124         __fbthrift_invocation_frobnicate.compare_exchange_strong(invocationType, apache::thrift::detail::si::InvocationType::CoroParam, std::memory_order_relaxed);
125         apache::thrift::RequestParams params{callback->getRequestContext(),
126           callback->getThreadManager(), callback->getEventBase()};
127         auto task = co_frobnicate(params);
128         apache::thrift::detail::si::async_tm_coro(std::move(callback), std::move(task));
129         return;
130 #else // FOLLY_HAS_COROUTINES
131         __fbthrift_invocation_frobnicate.compare_exchange_strong(invocationType, apache::thrift::detail::si::InvocationType::SemiFuture, std::memory_order_relaxed);
132         FOLLY_FALLTHROUGH;
133 #endif // FOLLY_HAS_COROUTINES
134       }
135       case apache::thrift::detail::si::InvocationType::SemiFuture:
136       {
137         auto fut = semifuture_frobnicate();
138         apache::thrift::detail::si::async_tm_semifuture(std::move(callback), std::move(fut));
139         return;
140       }
141 #if FOLLY_HAS_COROUTINES
142       case apache::thrift::detail::si::InvocationType::CoroParam:
143       {
144         apache::thrift::RequestParams params{callback->getRequestContext(),
145           callback->getThreadManager(), callback->getEventBase()};
146         auto task = co_frobnicate(params);
147         apache::thrift::detail::si::async_tm_coro(std::move(callback), std::move(task));
148         return;
149       }
150       case apache::thrift::detail::si::InvocationType::Coro:
151       {
152         auto task = co_frobnicate();
153         apache::thrift::detail::si::async_tm_coro(std::move(callback), std::move(task));
154         return;
155       }
156 #endif // FOLLY_HAS_COROUTINES
157       case apache::thrift::detail::si::InvocationType::Sync:
158       {
159         callback->result(frobnicate());
160         return;
161       }
162       default:
163       {
164         folly::assume_unreachable();
165       }
166     }
167   } catch (...) {
168     callback->exception(std::current_exception());
169   }
170 }
171 
ping()172 void MyServiceSvIf::MyInteractionIf::ping() {
173   apache::thrift::detail::si::throw_app_exn_unimplemented("ping");
174 }
175 
semifuture_ping()176 folly::SemiFuture<folly::Unit> MyServiceSvIf::MyInteractionIf::semifuture_ping() {
177   auto expected{apache::thrift::detail::si::InvocationType::SemiFuture};
178   __fbthrift_invocation_ping.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::Sync, std::memory_order_relaxed);
179   ping();
180   return folly::makeSemiFuture();
181 }
182 
183 #if FOLLY_HAS_COROUTINES
co_ping()184 folly::coro::Task<void> MyServiceSvIf::MyInteractionIf::co_ping() {
185   auto expected{apache::thrift::detail::si::InvocationType::Coro};
186   __fbthrift_invocation_ping.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::SemiFuture, std::memory_order_relaxed);
187   return folly::coro::toTask(semifuture_ping());
188 }
189 
co_ping(apache::thrift::RequestParams)190 folly::coro::Task<void> MyServiceSvIf::MyInteractionIf::co_ping(apache::thrift::RequestParams /* params */) {
191   auto expected{apache::thrift::detail::si::InvocationType::CoroParam};
192   __fbthrift_invocation_ping.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::Coro, std::memory_order_relaxed);
193   return co_ping();
194 }
195 #endif // FOLLY_HAS_COROUTINES
196 
async_tm_ping(std::unique_ptr<apache::thrift::HandlerCallbackBase> callback)197 void MyServiceSvIf::MyInteractionIf::async_tm_ping(std::unique_ptr<apache::thrift::HandlerCallbackBase> callback) {
198   // It's possible the coroutine versions will delegate to a future-based
199   // version. If that happens, we need the RequestParams arguments to be
200   // available to the future through the thread-local backchannel, so we create
201   // a RAII object that sets up RequestParams and clears them on destruction.
202   apache::thrift::detail::si::AsyncTmPrep asyncTmPrep(this, callback.get());
203   auto invocationType = __fbthrift_invocation_ping.load(std::memory_order_relaxed);
204   try {
205     switch (invocationType) {
206       case apache::thrift::detail::si::InvocationType::AsyncTm:
207       {
208 #if FOLLY_HAS_COROUTINES
209         __fbthrift_invocation_ping.compare_exchange_strong(invocationType, apache::thrift::detail::si::InvocationType::CoroParam, std::memory_order_relaxed);
210         apache::thrift::RequestParams params{callback->getRequestContext(),
211           callback->getThreadManager(), callback->getEventBase()};
212         auto task = co_ping(params);
213         apache::thrift::detail::si::async_tm_coro_oneway(std::move(callback), std::move(task));
214         return;
215 #else // FOLLY_HAS_COROUTINES
216         __fbthrift_invocation_ping.compare_exchange_strong(invocationType, apache::thrift::detail::si::InvocationType::SemiFuture, std::memory_order_relaxed);
217         FOLLY_FALLTHROUGH;
218 #endif // FOLLY_HAS_COROUTINES
219       }
220       case apache::thrift::detail::si::InvocationType::SemiFuture:
221       {
222         auto fut = semifuture_ping();
223         apache::thrift::detail::si::async_tm_semifuture_oneway(std::move(callback), std::move(fut));
224         return;
225       }
226 #if FOLLY_HAS_COROUTINES
227       case apache::thrift::detail::si::InvocationType::CoroParam:
228       {
229         apache::thrift::RequestParams params{callback->getRequestContext(),
230           callback->getThreadManager(), callback->getEventBase()};
231         auto task = co_ping(params);
232         apache::thrift::detail::si::async_tm_coro_oneway(std::move(callback), std::move(task));
233         return;
234       }
235       case apache::thrift::detail::si::InvocationType::Coro:
236       {
237         auto task = co_ping();
238         apache::thrift::detail::si::async_tm_coro_oneway(std::move(callback), std::move(task));
239         return;
240       }
241 #endif // FOLLY_HAS_COROUTINES
242       case apache::thrift::detail::si::InvocationType::Sync:
243       {
244         ping();
245         return;
246       }
247       default:
248       {
249         folly::assume_unreachable();
250       }
251     }
252   } catch (...) {
253     callback->exception(std::current_exception());
254   }
255 }
256 
truthify()257 ::apache::thrift::ServerStream<bool> MyServiceSvIf::MyInteractionIf::truthify() {
258   apache::thrift::detail::si::throw_app_exn_unimplemented("truthify");
259 }
260 
semifuture_truthify()261 folly::SemiFuture<::apache::thrift::ServerStream<bool>> MyServiceSvIf::MyInteractionIf::semifuture_truthify() {
262   auto expected{apache::thrift::detail::si::InvocationType::SemiFuture};
263   __fbthrift_invocation_truthify.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::Sync, std::memory_order_relaxed);
264   return truthify();
265 }
266 
267 #if FOLLY_HAS_COROUTINES
co_truthify()268 folly::coro::Task<::apache::thrift::ServerStream<bool>> MyServiceSvIf::MyInteractionIf::co_truthify() {
269   auto expected{apache::thrift::detail::si::InvocationType::Coro};
270   __fbthrift_invocation_truthify.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::SemiFuture, std::memory_order_relaxed);
271   return folly::coro::toTask(semifuture_truthify());
272 }
273 
co_truthify(apache::thrift::RequestParams)274 folly::coro::Task<::apache::thrift::ServerStream<bool>> MyServiceSvIf::MyInteractionIf::co_truthify(apache::thrift::RequestParams /* params */) {
275   auto expected{apache::thrift::detail::si::InvocationType::CoroParam};
276   __fbthrift_invocation_truthify.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::Coro, std::memory_order_relaxed);
277   return co_truthify();
278 }
279 #endif // FOLLY_HAS_COROUTINES
280 
async_tm_truthify(std::unique_ptr<apache::thrift::HandlerCallback<::apache::thrift::ServerStream<bool>>> callback)281 void MyServiceSvIf::MyInteractionIf::async_tm_truthify(std::unique_ptr<apache::thrift::HandlerCallback<::apache::thrift::ServerStream<bool>>> callback) {
282   // It's possible the coroutine versions will delegate to a future-based
283   // version. If that happens, we need the RequestParams arguments to be
284   // available to the future through the thread-local backchannel, so we create
285   // a RAII object that sets up RequestParams and clears them on destruction.
286   apache::thrift::detail::si::AsyncTmPrep asyncTmPrep(this, callback.get());
287   auto invocationType = __fbthrift_invocation_truthify.load(std::memory_order_relaxed);
288   try {
289     switch (invocationType) {
290       case apache::thrift::detail::si::InvocationType::AsyncTm:
291       {
292 #if FOLLY_HAS_COROUTINES
293         __fbthrift_invocation_truthify.compare_exchange_strong(invocationType, apache::thrift::detail::si::InvocationType::CoroParam, std::memory_order_relaxed);
294         apache::thrift::RequestParams params{callback->getRequestContext(),
295           callback->getThreadManager(), callback->getEventBase()};
296         auto task = co_truthify(params);
297         apache::thrift::detail::si::async_tm_coro(std::move(callback), std::move(task));
298         return;
299 #else // FOLLY_HAS_COROUTINES
300         __fbthrift_invocation_truthify.compare_exchange_strong(invocationType, apache::thrift::detail::si::InvocationType::SemiFuture, std::memory_order_relaxed);
301         FOLLY_FALLTHROUGH;
302 #endif // FOLLY_HAS_COROUTINES
303       }
304       case apache::thrift::detail::si::InvocationType::SemiFuture:
305       {
306         auto fut = semifuture_truthify();
307         apache::thrift::detail::si::async_tm_semifuture(std::move(callback), std::move(fut));
308         return;
309       }
310 #if FOLLY_HAS_COROUTINES
311       case apache::thrift::detail::si::InvocationType::CoroParam:
312       {
313         apache::thrift::RequestParams params{callback->getRequestContext(),
314           callback->getThreadManager(), callback->getEventBase()};
315         auto task = co_truthify(params);
316         apache::thrift::detail::si::async_tm_coro(std::move(callback), std::move(task));
317         return;
318       }
319       case apache::thrift::detail::si::InvocationType::Coro:
320       {
321         auto task = co_truthify();
322         apache::thrift::detail::si::async_tm_coro(std::move(callback), std::move(task));
323         return;
324       }
325 #endif // FOLLY_HAS_COROUTINES
326       case apache::thrift::detail::si::InvocationType::Sync:
327       {
328         callback->result(truthify());
329         return;
330       }
331       default:
332       {
333         folly::assume_unreachable();
334       }
335     }
336   } catch (...) {
337     callback->exception(std::current_exception());
338   }
339 }
340 
encode()341 ::apache::thrift::ResponseAndSinkConsumer<::std::set<::std::int32_t>, ::std::string, ::std::string> MyServiceSvIf::MyInteractionIf::encode() {
342   apache::thrift::detail::si::throw_app_exn_unimplemented("encode");
343 }
344 
semifuture_encode()345 folly::SemiFuture<::apache::thrift::ResponseAndSinkConsumer<::std::set<::std::int32_t>, ::std::string, ::std::string>> MyServiceSvIf::MyInteractionIf::semifuture_encode() {
346   auto expected{apache::thrift::detail::si::InvocationType::SemiFuture};
347   __fbthrift_invocation_encode.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::Sync, std::memory_order_relaxed);
348   return encode();
349 }
350 
351 #if FOLLY_HAS_COROUTINES
co_encode()352 folly::coro::Task<::apache::thrift::ResponseAndSinkConsumer<::std::set<::std::int32_t>, ::std::string, ::std::string>> MyServiceSvIf::MyInteractionIf::co_encode() {
353   auto expected{apache::thrift::detail::si::InvocationType::Coro};
354   __fbthrift_invocation_encode.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::SemiFuture, std::memory_order_relaxed);
355   return folly::coro::toTask(semifuture_encode());
356 }
357 
co_encode(apache::thrift::RequestParams)358 folly::coro::Task<::apache::thrift::ResponseAndSinkConsumer<::std::set<::std::int32_t>, ::std::string, ::std::string>> MyServiceSvIf::MyInteractionIf::co_encode(apache::thrift::RequestParams /* params */) {
359   auto expected{apache::thrift::detail::si::InvocationType::CoroParam};
360   __fbthrift_invocation_encode.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::Coro, std::memory_order_relaxed);
361   return co_encode();
362 }
363 #endif // FOLLY_HAS_COROUTINES
364 
async_tm_encode(std::unique_ptr<apache::thrift::HandlerCallback<::apache::thrift::ResponseAndSinkConsumer<::std::set<::std::int32_t>,::std::string,::std::string>>> callback)365 void MyServiceSvIf::MyInteractionIf::async_tm_encode(std::unique_ptr<apache::thrift::HandlerCallback<::apache::thrift::ResponseAndSinkConsumer<::std::set<::std::int32_t>, ::std::string, ::std::string>>> callback) {
366   // It's possible the coroutine versions will delegate to a future-based
367   // version. If that happens, we need the RequestParams arguments to be
368   // available to the future through the thread-local backchannel, so we create
369   // a RAII object that sets up RequestParams and clears them on destruction.
370   apache::thrift::detail::si::AsyncTmPrep asyncTmPrep(this, callback.get());
371   auto invocationType = __fbthrift_invocation_encode.load(std::memory_order_relaxed);
372   try {
373     switch (invocationType) {
374       case apache::thrift::detail::si::InvocationType::AsyncTm:
375       {
376 #if FOLLY_HAS_COROUTINES
377         __fbthrift_invocation_encode.compare_exchange_strong(invocationType, apache::thrift::detail::si::InvocationType::CoroParam, std::memory_order_relaxed);
378         apache::thrift::RequestParams params{callback->getRequestContext(),
379           callback->getThreadManager(), callback->getEventBase()};
380         auto task = co_encode(params);
381         apache::thrift::detail::si::async_tm_coro(std::move(callback), std::move(task));
382         return;
383 #else // FOLLY_HAS_COROUTINES
384         __fbthrift_invocation_encode.compare_exchange_strong(invocationType, apache::thrift::detail::si::InvocationType::SemiFuture, std::memory_order_relaxed);
385         FOLLY_FALLTHROUGH;
386 #endif // FOLLY_HAS_COROUTINES
387       }
388       case apache::thrift::detail::si::InvocationType::SemiFuture:
389       {
390         auto fut = semifuture_encode();
391         apache::thrift::detail::si::async_tm_semifuture(std::move(callback), std::move(fut));
392         return;
393       }
394 #if FOLLY_HAS_COROUTINES
395       case apache::thrift::detail::si::InvocationType::CoroParam:
396       {
397         apache::thrift::RequestParams params{callback->getRequestContext(),
398           callback->getThreadManager(), callback->getEventBase()};
399         auto task = co_encode(params);
400         apache::thrift::detail::si::async_tm_coro(std::move(callback), std::move(task));
401         return;
402       }
403       case apache::thrift::detail::si::InvocationType::Coro:
404       {
405         auto task = co_encode();
406         apache::thrift::detail::si::async_tm_coro(std::move(callback), std::move(task));
407         return;
408       }
409 #endif // FOLLY_HAS_COROUTINES
410       case apache::thrift::detail::si::InvocationType::Sync:
411       {
412         callback->result(encode());
413         return;
414       }
415       default:
416       {
417         folly::assume_unreachable();
418       }
419     }
420   } catch (...) {
421     callback->exception(std::current_exception());
422   }
423 }
424 
async_eb_frobnicate(std::unique_ptr<apache::thrift::HandlerCallback<::std::int32_t>> callback)425 void MyServiceSvIf::MyInteractionFastIf::async_eb_frobnicate(std::unique_ptr<apache::thrift::HandlerCallback<::std::int32_t>> callback) {
426   callback->exception(apache::thrift::detail::si::create_app_exn_unimplemented("frobnicate"));
427 }
428 
async_eb_ping(std::unique_ptr<apache::thrift::HandlerCallbackBase>)429 void MyServiceSvIf::MyInteractionFastIf::async_eb_ping(std::unique_ptr<apache::thrift::HandlerCallbackBase> /*callback*/) {
430   LOG(DFATAL) << "Function ping is unimplemented";
431 }
432 
async_eb_truthify(std::unique_ptr<apache::thrift::HandlerCallback<::apache::thrift::ServerStream<bool>>> callback)433 void MyServiceSvIf::MyInteractionFastIf::async_eb_truthify(std::unique_ptr<apache::thrift::HandlerCallback<::apache::thrift::ServerStream<bool>>> callback) {
434   callback->exception(apache::thrift::detail::si::create_app_exn_unimplemented("truthify"));
435 }
436 
async_eb_encode(std::unique_ptr<apache::thrift::HandlerCallback<::apache::thrift::ResponseAndSinkConsumer<::std::set<::std::int32_t>,::std::string,::std::string>>> callback)437 void MyServiceSvIf::MyInteractionFastIf::async_eb_encode(std::unique_ptr<apache::thrift::HandlerCallback<::apache::thrift::ResponseAndSinkConsumer<::std::set<::std::int32_t>, ::std::string, ::std::string>>> callback) {
438   callback->exception(apache::thrift::detail::si::create_app_exn_unimplemented("encode"));
439 }
440 
frobnicate()441 void MyServiceSvIf::SerialInteractionIf::frobnicate() {
442   apache::thrift::detail::si::throw_app_exn_unimplemented("frobnicate");
443 }
444 
semifuture_frobnicate()445 folly::SemiFuture<folly::Unit> MyServiceSvIf::SerialInteractionIf::semifuture_frobnicate() {
446   auto expected{apache::thrift::detail::si::InvocationType::SemiFuture};
447   __fbthrift_invocation_frobnicate.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::Sync, std::memory_order_relaxed);
448   frobnicate();
449   return folly::makeSemiFuture();
450 }
451 
452 #if FOLLY_HAS_COROUTINES
co_frobnicate()453 folly::coro::Task<void> MyServiceSvIf::SerialInteractionIf::co_frobnicate() {
454   auto expected{apache::thrift::detail::si::InvocationType::Coro};
455   __fbthrift_invocation_frobnicate.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::SemiFuture, std::memory_order_relaxed);
456   return folly::coro::toTask(semifuture_frobnicate());
457 }
458 
co_frobnicate(apache::thrift::RequestParams)459 folly::coro::Task<void> MyServiceSvIf::SerialInteractionIf::co_frobnicate(apache::thrift::RequestParams /* params */) {
460   auto expected{apache::thrift::detail::si::InvocationType::CoroParam};
461   __fbthrift_invocation_frobnicate.compare_exchange_strong(expected, apache::thrift::detail::si::InvocationType::Coro, std::memory_order_relaxed);
462   return co_frobnicate();
463 }
464 #endif // FOLLY_HAS_COROUTINES
465 
async_tm_frobnicate(std::unique_ptr<apache::thrift::HandlerCallback<void>> callback)466 void MyServiceSvIf::SerialInteractionIf::async_tm_frobnicate(std::unique_ptr<apache::thrift::HandlerCallback<void>> callback) {
467   // It's possible the coroutine versions will delegate to a future-based
468   // version. If that happens, we need the RequestParams arguments to be
469   // available to the future through the thread-local backchannel, so we create
470   // a RAII object that sets up RequestParams and clears them on destruction.
471   apache::thrift::detail::si::AsyncTmPrep asyncTmPrep(this, callback.get());
472   auto invocationType = __fbthrift_invocation_frobnicate.load(std::memory_order_relaxed);
473   try {
474     switch (invocationType) {
475       case apache::thrift::detail::si::InvocationType::AsyncTm:
476       {
477 #if FOLLY_HAS_COROUTINES
478         __fbthrift_invocation_frobnicate.compare_exchange_strong(invocationType, apache::thrift::detail::si::InvocationType::CoroParam, std::memory_order_relaxed);
479         apache::thrift::RequestParams params{callback->getRequestContext(),
480           callback->getThreadManager(), callback->getEventBase()};
481         auto task = co_frobnicate(params);
482         apache::thrift::detail::si::async_tm_coro(std::move(callback), std::move(task));
483         return;
484 #else // FOLLY_HAS_COROUTINES
485         __fbthrift_invocation_frobnicate.compare_exchange_strong(invocationType, apache::thrift::detail::si::InvocationType::SemiFuture, std::memory_order_relaxed);
486         FOLLY_FALLTHROUGH;
487 #endif // FOLLY_HAS_COROUTINES
488       }
489       case apache::thrift::detail::si::InvocationType::SemiFuture:
490       {
491         auto fut = semifuture_frobnicate();
492         apache::thrift::detail::si::async_tm_semifuture(std::move(callback), std::move(fut));
493         return;
494       }
495 #if FOLLY_HAS_COROUTINES
496       case apache::thrift::detail::si::InvocationType::CoroParam:
497       {
498         apache::thrift::RequestParams params{callback->getRequestContext(),
499           callback->getThreadManager(), callback->getEventBase()};
500         auto task = co_frobnicate(params);
501         apache::thrift::detail::si::async_tm_coro(std::move(callback), std::move(task));
502         return;
503       }
504       case apache::thrift::detail::si::InvocationType::Coro:
505       {
506         auto task = co_frobnicate();
507         apache::thrift::detail::si::async_tm_coro(std::move(callback), std::move(task));
508         return;
509       }
510 #endif // FOLLY_HAS_COROUTINES
511       case apache::thrift::detail::si::InvocationType::Sync:
512       {
513         frobnicate();
514         callback->done();
515         return;
516       }
517       default:
518       {
519         folly::assume_unreachable();
520       }
521     }
522   } catch (...) {
523     callback->exception(std::current_exception());
524   }
525 }
526 
getServiceName()527 const char* MyServiceAsyncProcessor::getServiceName() {
528   return "MyService";
529 }
530 
getServiceMetadata(apache::thrift::metadata::ThriftServiceMetadataResponse & response)531 void MyServiceAsyncProcessor::getServiceMetadata(apache::thrift::metadata::ThriftServiceMetadataResponse& response) {
532   ::apache::thrift::detail::md::ServiceMetadata<MyServiceSvIf>::gen(response);
533 }
534 
processSerializedCompressedRequest(apache::thrift::ResponseChannelRequest::UniquePtr req,apache::thrift::SerializedCompressedRequest && serializedRequest,apache::thrift::protocol::PROTOCOL_TYPES protType,apache::thrift::Cpp2RequestContext * context,folly::EventBase * eb,apache::thrift::concurrency::ThreadManager * tm)535 void MyServiceAsyncProcessor::processSerializedCompressedRequest(apache::thrift::ResponseChannelRequest::UniquePtr req, apache::thrift::SerializedCompressedRequest&& serializedRequest, apache::thrift::protocol::PROTOCOL_TYPES protType, apache::thrift::Cpp2RequestContext* context, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) {
536   apache::thrift::detail::ap::process(this, std::move(req), std::move(serializedRequest), protType, context, eb, tm);
537 }
538 
processSerializedCompressedRequestWithMetadata(apache::thrift::ResponseChannelRequest::UniquePtr req,apache::thrift::SerializedCompressedRequest && serializedRequest,const apache::thrift::AsyncProcessorFactory::MethodMetadata & methodMetadata,apache::thrift::protocol::PROTOCOL_TYPES protType,apache::thrift::Cpp2RequestContext * context,folly::EventBase * eb,apache::thrift::concurrency::ThreadManager * tm)539 void MyServiceAsyncProcessor::processSerializedCompressedRequestWithMetadata(apache::thrift::ResponseChannelRequest::UniquePtr req, apache::thrift::SerializedCompressedRequest&& serializedRequest, const apache::thrift::AsyncProcessorFactory::MethodMetadata& methodMetadata, apache::thrift::protocol::PROTOCOL_TYPES protType, apache::thrift::Cpp2RequestContext* context, folly::EventBase* eb, apache::thrift::concurrency::ThreadManager* tm) {
540   apache::thrift::detail::ap::process(this, std::move(req), std::move(serializedRequest), methodMetadata, protType, context, eb, tm);
541 }
542 
getOwnProcessMap()543 const MyServiceAsyncProcessor::ProcessMap& MyServiceAsyncProcessor::getOwnProcessMap() {
544   return kOwnProcessMap_;
545 }
546 
547 const MyServiceAsyncProcessor::ProcessMap MyServiceAsyncProcessor::kOwnProcessMap_ {
548   {"foo", {&MyServiceAsyncProcessor::setUpAndProcess_foo<apache::thrift::CompactProtocolReader, apache::thrift::CompactProtocolWriter>, &MyServiceAsyncProcessor::setUpAndProcess_foo<apache::thrift::BinaryProtocolReader, apache::thrift::BinaryProtocolWriter>}},
549   {"MyInteraction.frobnicate", {&MyServiceAsyncProcessor::setUpAndProcess_MyInteraction_frobnicate<apache::thrift::CompactProtocolReader, apache::thrift::CompactProtocolWriter>, &MyServiceAsyncProcessor::setUpAndProcess_MyInteraction_frobnicate<apache::thrift::BinaryProtocolReader, apache::thrift::BinaryProtocolWriter>}},
550   {"MyInteraction.ping", {&MyServiceAsyncProcessor::setUpAndProcess_MyInteraction_ping<apache::thrift::CompactProtocolReader, apache::thrift::CompactProtocolWriter>, &MyServiceAsyncProcessor::setUpAndProcess_MyInteraction_ping<apache::thrift::BinaryProtocolReader, apache::thrift::BinaryProtocolWriter>}},
551   {"MyInteraction.truthify", {&MyServiceAsyncProcessor::setUpAndProcess_MyInteraction_truthify<apache::thrift::CompactProtocolReader, apache::thrift::CompactProtocolWriter>, &MyServiceAsyncProcessor::setUpAndProcess_MyInteraction_truthify<apache::thrift::BinaryProtocolReader, apache::thrift::BinaryProtocolWriter>}},
552   {"MyInteraction.encode", {&MyServiceAsyncProcessor::setUpAndProcess_MyInteraction_encode<apache::thrift::CompactProtocolReader, apache::thrift::CompactProtocolWriter>, &MyServiceAsyncProcessor::setUpAndProcess_MyInteraction_encode<apache::thrift::BinaryProtocolReader, apache::thrift::BinaryProtocolWriter>}},
553   {"MyInteractionFast.frobnicate", {&MyServiceAsyncProcessor::setUpAndProcess_MyInteractionFast_frobnicate<apache::thrift::CompactProtocolReader, apache::thrift::CompactProtocolWriter>, &MyServiceAsyncProcessor::setUpAndProcess_MyInteractionFast_frobnicate<apache::thrift::BinaryProtocolReader, apache::thrift::BinaryProtocolWriter>}},
554   {"MyInteractionFast.ping", {&MyServiceAsyncProcessor::setUpAndProcess_MyInteractionFast_ping<apache::thrift::CompactProtocolReader, apache::thrift::CompactProtocolWriter>, &MyServiceAsyncProcessor::setUpAndProcess_MyInteractionFast_ping<apache::thrift::BinaryProtocolReader, apache::thrift::BinaryProtocolWriter>}},
555   {"MyInteractionFast.truthify", {&MyServiceAsyncProcessor::setUpAndProcess_MyInteractionFast_truthify<apache::thrift::CompactProtocolReader, apache::thrift::CompactProtocolWriter>, &MyServiceAsyncProcessor::setUpAndProcess_MyInteractionFast_truthify<apache::thrift::BinaryProtocolReader, apache::thrift::BinaryProtocolWriter>}},
556   {"MyInteractionFast.encode", {&MyServiceAsyncProcessor::setUpAndProcess_MyInteractionFast_encode<apache::thrift::CompactProtocolReader, apache::thrift::CompactProtocolWriter>, &MyServiceAsyncProcessor::setUpAndProcess_MyInteractionFast_encode<apache::thrift::BinaryProtocolReader, apache::thrift::BinaryProtocolWriter>}},
557   {"SerialInteraction.frobnicate", {&MyServiceAsyncProcessor::setUpAndProcess_SerialInteraction_frobnicate<apache::thrift::CompactProtocolReader, apache::thrift::CompactProtocolWriter>, &MyServiceAsyncProcessor::setUpAndProcess_SerialInteraction_frobnicate<apache::thrift::BinaryProtocolReader, apache::thrift::BinaryProtocolWriter>}},
558 };
559 
getInteractionConstructorMap()560 const MyServiceAsyncProcessor::InteractionConstructorMap& MyServiceAsyncProcessor::getInteractionConstructorMap() {
561   return interactionConstructorMap_;
562 }
563 
564 const MyServiceAsyncProcessor::InteractionConstructorMap MyServiceAsyncProcessor::interactionConstructorMap_ {
565   {"MyInteraction", &MyServiceAsyncProcessor::createMyInteraction},
566   {"MyInteractionFast", &MyServiceAsyncProcessor::createMyInteractionFast},
567   {"SerialInteraction", &MyServiceAsyncProcessor::createSerialInteraction},
568 };
569 
createInteractionImpl(const std::string & name)570 std::unique_ptr<apache::thrift::Tile> MyServiceAsyncProcessor::createInteractionImpl(const std::string& name) {
571   auto fn = getInteractionConstructorMap().at(name);
572   return (this->*fn)();
573 }} // cpp2
574