Files
flipper/xplat/Flipper/FlipperSocketProvider.h
Lorenzo Blasa ef831f346d Socket provider
Summary:
Abstract the socket creation from FlipperConnectionManagerImpl. Instead, use FlipperSocketProvider.

There's a default provider which will always return RSocket sockets. This provider can be changed and thus can return other implementations.

Reviewed By: fabiomassimo

Differential Revision: D30396322

fbshipit-source-id: 0583865376809260b0240e5bd653d73f2fa514b1
2021-08-23 03:17:47 -07:00

75 lines
2.4 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <folly/io/async/EventBase.h>
#include <memory>
namespace facebook {
namespace flipper {
class FlipperSocket;
class FlipperConnectionManager;
class ConnectionContextStore;
struct FlipperConnectionEndpoint;
struct FlipperSocketBasePayload;
/**
A socket provider is responsible of the creation of FlipperSocket instances.
It also defines static factory methods that can be used to construct such
instances.
*/
class FlipperSocketProvider {
public:
virtual ~FlipperSocketProvider() {}
/**
Create an instance of FlipperSocket.
@param endpoint Endpoint to connect to.
@param payload Any configuration payload to establish a connection with
the specified endpoint.
@param eventBase A folly event base used to execute connection operations.
*/
virtual std::unique_ptr<FlipperSocket> create(
FlipperConnectionEndpoint endpoint,
std::unique_ptr<FlipperSocketBasePayload> payload,
folly::EventBase* eventBase) = 0;
/**
Create an instance of FlipperSocket.
@param endpoint Endpoint to connect to.
@param payload Any configuration payload to establish a connection with
the specified endpoint.
@param eventBase A folly event base used to execute connection operations.
@param connectionContextStore A connection context store used for obtaining
the certificate used for secure connections.
*/
virtual std::unique_ptr<FlipperSocket> create(
FlipperConnectionEndpoint endpoint,
std::unique_ptr<FlipperSocketBasePayload> payload,
folly::EventBase* eventBase,
ConnectionContextStore* connectionContextStore) = 0;
static std::unique_ptr<FlipperSocket> socketCreate(
FlipperConnectionEndpoint endpoint,
std::unique_ptr<FlipperSocketBasePayload> payload,
folly::EventBase* eventBase);
static std::unique_ptr<FlipperSocket> socketCreate(
FlipperConnectionEndpoint endpoint,
std::unique_ptr<FlipperSocketBasePayload> payload,
folly::EventBase* eventBase,
ConnectionContextStore* connectionContextStore);
static void setDefaultProvider(
std::unique_ptr<FlipperSocketProvider> provider);
private:
static std::unique_ptr<FlipperSocketProvider> provider_;
};
} // namespace flipper
} // namespace facebook