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: D36626483

fbshipit-source-id: add0241caf4af0aa5c3b5c2e7efc2e725f5400ab
This commit is contained in:
Lorenzo Blasa
2022-05-25 15:58:05 -07:00
committed by Facebook GitHub Bot
parent 9c7850604c
commit e44cad5e99
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,