Partially remove dependency on folly async

Summary:
This change isolates the usage of folly async from Flipper. Is now self-contained in Flipper Folly schedulers.

Users of Flipper can decide not to use the types defined in that header and implement their own.

NOTE: changes are minimal, we are just replacing direct calls to folly event base with a scheduler which simply relays this on to folly.

Reviewed By: fabiomassimo

Differential Revision: D36052198

fbshipit-source-id: 170d64a324a1f1f100224e2622a59cbac3c8b642
This commit is contained in:
Lorenzo Blasa
2022-05-12 17:56:17 -07:00
committed by Facebook GitHub Bot
parent 216c926ca5
commit ade685c621
18 changed files with 132 additions and 116 deletions

View File

@@ -13,6 +13,7 @@
#include <fb/fbjni.h>
#endif
#include <folly/futures/Future.h>
#include <folly/io/async/AsyncSocketException.h>
#include <folly/io/async/EventBase.h>
#include <folly/io/async/EventBaseManager.h>
@@ -23,6 +24,7 @@
#include <Flipper/FlipperClient.h>
#include <Flipper/FlipperConnection.h>
#include <Flipper/FlipperConnectionManager.h>
#include <Flipper/FlipperFollyScheduler.h>
#include <Flipper/FlipperResponder.h>
#include <Flipper/FlipperSocket.h>
#include <Flipper/FlipperSocketProvider.h>
@@ -42,6 +44,9 @@ void handleException(const std::exception& e) {
__android_log_write(ANDROID_LOG_ERROR, "FLIPPER", message.c_str());
}
std::unique_ptr<facebook::flipper::Scheduler> sonarScheduler;
std::unique_ptr<facebook::flipper::Scheduler> connectionScheduler;
class JEventBase : public jni::HybridClass<JEventBase> {
public:
constexpr static auto kJavaDescriptor =
@@ -412,7 +417,7 @@ class JFlipperSocketProvider : public facebook::flipper::FlipperSocketProvider {
virtual std::unique_ptr<facebook::flipper::FlipperSocket> create(
facebook::flipper::FlipperConnectionEndpoint endpoint,
std::unique_ptr<facebook::flipper::FlipperSocketBasePayload> payload,
folly::EventBase* eventBase) override {
facebook::flipper::Scheduler* scheduler) override {
return std::make_unique<JFlipperWebSocket>(
std::move(endpoint), std::move(payload));
;
@@ -420,7 +425,7 @@ class JFlipperSocketProvider : public facebook::flipper::FlipperSocketProvider {
virtual std::unique_ptr<facebook::flipper::FlipperSocket> create(
FlipperConnectionEndpoint endpoint,
std::unique_ptr<FlipperSocketBasePayload> payload,
folly::EventBase* eventBase,
facebook::flipper::Scheduler* scheduler,
ConnectionContextStore* connectionContextStore) override {
return std::make_unique<JFlipperWebSocket>(
std::move(endpoint), std::move(payload), connectionContextStore);
@@ -939,6 +944,11 @@ class JFlipperClient : public jni::HybridClass<JFlipperClient> {
const std::string app,
const std::string appId,
const std::string privateAppDirectory) {
sonarScheduler =
std::make_unique<FollyScheduler>(callbackWorker->eventBase());
connectionScheduler =
std::make_unique<FollyScheduler>(connectionWorker->eventBase());
FlipperClient::init(
{{std::move(host),
std::move(os),
@@ -947,8 +957,8 @@ class JFlipperClient : public jni::HybridClass<JFlipperClient> {
std::move(app),
std::move(appId),
std::move(privateAppDirectory)},
callbackWorker->eventBase(),
connectionWorker->eventBase(),
sonarScheduler.get(),
connectionScheduler.get(),
insecurePort,
securePort,
altInsecurePort,