Rename SonarClient to FlipperClient
Summary: Part of the Sonar -> Flipper rename Reviewed By: passy Differential Revision: D9871902 fbshipit-source-id: 4b64953cb1a64235d47caaf0fabfb560bb85f7a2
This commit is contained in:
committed by
Facebook Github Bot
parent
df8763e697
commit
3c656de7fa
@@ -18,7 +18,7 @@
|
||||
#include <folly/io/async/EventBase.h>
|
||||
#include <folly/io/async/EventBaseManager.h>
|
||||
|
||||
#include <Flipper/SonarClient.h>
|
||||
#include <Flipper/FlipperClient.h>
|
||||
#include <Flipper/SonarWebSocket.h>
|
||||
#include <Flipper/SonarConnection.h>
|
||||
#include <Flipper/FlipperResponder.h>
|
||||
@@ -291,42 +291,42 @@ class JFlipperClient : public jni::HybridClass<JFlipperClient> {
|
||||
}
|
||||
|
||||
void start() {
|
||||
SonarClient::instance()->start();
|
||||
FlipperClient::instance()->start();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
SonarClient::instance()->stop();
|
||||
FlipperClient::instance()->stop();
|
||||
}
|
||||
|
||||
void addPlugin(jni::alias_ref<JFlipperPlugin> plugin) {
|
||||
auto wrapper = std::make_shared<JFlipperPluginWrapper>(make_global(plugin));
|
||||
SonarClient::instance()->addPlugin(wrapper);
|
||||
FlipperClient::instance()->addPlugin(wrapper);
|
||||
}
|
||||
|
||||
void removePlugin(jni::alias_ref<JFlipperPlugin> plugin) {
|
||||
auto client = SonarClient::instance();
|
||||
auto client = FlipperClient::instance();
|
||||
client->removePlugin(client->getPlugin(plugin->identifier()));
|
||||
}
|
||||
|
||||
void subscribeForUpdates(jni::alias_ref<JFlipperStateUpdateListener> stateListener) {
|
||||
auto client = SonarClient::instance();
|
||||
auto client = FlipperClient::instance();
|
||||
mStateListener = std::make_shared<AndroidFlipperStateUpdateListener>(stateListener);
|
||||
client->setStateListener(mStateListener);
|
||||
}
|
||||
|
||||
void unsubscribe() {
|
||||
auto client = SonarClient::instance();
|
||||
auto client = FlipperClient::instance();
|
||||
mStateListener = nullptr;
|
||||
client->setStateListener(nullptr);
|
||||
}
|
||||
|
||||
std::string getState() {
|
||||
return SonarClient::instance()->getState();
|
||||
return FlipperClient::instance()->getState();
|
||||
}
|
||||
|
||||
jni::global_ref<JStateSummary::javaobject> getStateSummary() {
|
||||
auto summary = jni::make_global(JStateSummary::create());
|
||||
auto elements = SonarClient::instance()->getStateElements();
|
||||
auto elements = FlipperClient::instance()->getStateElements();
|
||||
for (auto&& element : elements) {
|
||||
std::string status;
|
||||
switch (element.state_) {
|
||||
@@ -340,7 +340,7 @@ class JFlipperClient : public jni::HybridClass<JFlipperClient> {
|
||||
}
|
||||
|
||||
jni::alias_ref<JFlipperPlugin> getPlugin(const std::string& identifier) {
|
||||
auto plugin = SonarClient::instance()->getPlugin(identifier);
|
||||
auto plugin = FlipperClient::instance()->getPlugin(identifier);
|
||||
if (plugin) {
|
||||
auto wrapper = std::static_pointer_cast<JFlipperPluginWrapper>(plugin);
|
||||
return wrapper->jplugin;
|
||||
@@ -361,7 +361,7 @@ class JFlipperClient : public jni::HybridClass<JFlipperClient> {
|
||||
const std::string appId,
|
||||
const std::string privateAppDirectory) {
|
||||
|
||||
SonarClient::init({
|
||||
FlipperClient::init({
|
||||
{
|
||||
std::move(host),
|
||||
std::move(os),
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
#import "FlipperClient.h"
|
||||
#import "SonarCppWrapperPlugin.h"
|
||||
#import <Flipper/SonarClient.h>
|
||||
#import <Flipper/FlipperClient.h>
|
||||
#include <folly/io/async/EventBase.h>
|
||||
#include <folly/io/async/ScopedEventBaseThread.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
@@ -23,7 +23,7 @@
|
||||
using WrapperPlugin = facebook::flipper::SonarCppWrapperPlugin;
|
||||
|
||||
@implementation FlipperClient {
|
||||
facebook::flipper::SonarClient *_cppClient;
|
||||
facebook::flipper::FlipperClient *_cppClient;
|
||||
folly::ScopedEventBaseThread sonarThread;
|
||||
folly::ScopedEventBaseThread connectionThread;
|
||||
#if !TARGET_OS_SIMULATOR
|
||||
@@ -61,7 +61,7 @@ using WrapperPlugin = facebook::flipper::SonarCppWrapperPlugin;
|
||||
deviceName = [NSString stringWithFormat:@"%@ %@", [[UIDevice currentDevice] model], @"Simulator"];
|
||||
#endif
|
||||
|
||||
facebook::flipper::SonarClient::init({
|
||||
facebook::flipper::FlipperClient::init({
|
||||
{
|
||||
"localhost",
|
||||
"iOS",
|
||||
@@ -74,7 +74,7 @@ using WrapperPlugin = facebook::flipper::SonarCppWrapperPlugin;
|
||||
sonarThread.getEventBase(),
|
||||
connectionThread.getEventBase()
|
||||
});
|
||||
_cppClient = facebook::flipper::SonarClient::instance();
|
||||
_cppClient = facebook::flipper::FlipperClient::instance();
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -11,11 +11,11 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import <Flipper/SonarClient.h>
|
||||
#import <Flipper/FlipperClient.h>
|
||||
#import <FlipperKit/FlipperClient.h>
|
||||
|
||||
@interface FlipperClient (Testing)
|
||||
|
||||
- (instancetype)initWithCppClient:(facebook::flipper::SonarClient *)cppClient;
|
||||
- (instancetype)initWithCppClient:(facebook::flipper::FlipperClient *)cppClient;
|
||||
|
||||
@end
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "SonarClient.h"
|
||||
#include "FlipperClient.h"
|
||||
#include "SonarConnectionImpl.h"
|
||||
#include "SonarResponderImpl.h"
|
||||
#include "SonarState.h"
|
||||
@@ -24,29 +24,29 @@
|
||||
namespace facebook {
|
||||
namespace flipper {
|
||||
|
||||
static SonarClient* kInstance;
|
||||
static FlipperClient* kInstance;
|
||||
|
||||
using folly::dynamic;
|
||||
|
||||
void SonarClient::init(SonarInitConfig config) {
|
||||
void FlipperClient::init(SonarInitConfig config) {
|
||||
auto state = std::make_shared<SonarState>();
|
||||
auto context = std::make_shared<ConnectionContextStore>(config.deviceData);
|
||||
kInstance =
|
||||
new SonarClient(std::make_unique<SonarWebSocketImpl>(std::move(config), state, context), state);
|
||||
new FlipperClient(std::make_unique<SonarWebSocketImpl>(std::move(config), state, context), state);
|
||||
}
|
||||
|
||||
SonarClient* SonarClient::instance() {
|
||||
FlipperClient* FlipperClient::instance() {
|
||||
return kInstance;
|
||||
}
|
||||
|
||||
void SonarClient::setStateListener(
|
||||
void FlipperClient::setStateListener(
|
||||
std::shared_ptr<SonarStateUpdateListener> stateListener) {
|
||||
log("Setting state listener");
|
||||
sonarState_->setUpdateListener(stateListener);
|
||||
}
|
||||
|
||||
void SonarClient::addPlugin(std::shared_ptr<SonarPlugin> plugin) {
|
||||
log("SonarClient::addPlugin " + plugin->identifier());
|
||||
void FlipperClient::addPlugin(std::shared_ptr<SonarPlugin> plugin) {
|
||||
log("FlipperClient::addPlugin " + plugin->identifier());
|
||||
auto step = sonarState_->start("Add plugin " + plugin->identifier());
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
@@ -63,8 +63,8 @@ void SonarClient::addPlugin(std::shared_ptr<SonarPlugin> plugin) {
|
||||
});
|
||||
}
|
||||
|
||||
void SonarClient::removePlugin(std::shared_ptr<SonarPlugin> plugin) {
|
||||
log("SonarClient::removePlugin " + plugin->identifier());
|
||||
void FlipperClient::removePlugin(std::shared_ptr<SonarPlugin> plugin) {
|
||||
log("FlipperClient::removePlugin " + plugin->identifier());
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
performAndReportError([this, plugin]() {
|
||||
@@ -79,7 +79,7 @@ void SonarClient::removePlugin(std::shared_ptr<SonarPlugin> plugin) {
|
||||
});
|
||||
}
|
||||
|
||||
std::shared_ptr<SonarPlugin> SonarClient::getPlugin(
|
||||
std::shared_ptr<SonarPlugin> FlipperClient::getPlugin(
|
||||
const std::string& identifier) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (plugins_.find(identifier) == plugins_.end()) {
|
||||
@@ -88,12 +88,12 @@ std::shared_ptr<SonarPlugin> SonarClient::getPlugin(
|
||||
return plugins_.at(identifier);
|
||||
}
|
||||
|
||||
bool SonarClient::hasPlugin(const std::string& identifier) {
|
||||
bool FlipperClient::hasPlugin(const std::string& identifier) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
return plugins_.find(identifier) != plugins_.end();
|
||||
}
|
||||
|
||||
void SonarClient::disconnect(std::shared_ptr<SonarPlugin> plugin) {
|
||||
void FlipperClient::disconnect(std::shared_ptr<SonarPlugin> plugin) {
|
||||
const auto& conn = connections_.find(plugin->identifier());
|
||||
if (conn != connections_.end()) {
|
||||
connections_.erase(plugin->identifier());
|
||||
@@ -101,22 +101,22 @@ void SonarClient::disconnect(std::shared_ptr<SonarPlugin> plugin) {
|
||||
}
|
||||
}
|
||||
|
||||
void SonarClient::refreshPlugins() {
|
||||
void FlipperClient::refreshPlugins() {
|
||||
performAndReportError([this]() {
|
||||
dynamic message = dynamic::object("method", "refreshPlugins");
|
||||
socket_->sendMessage(message);
|
||||
});
|
||||
}
|
||||
|
||||
void SonarClient::onConnected() {
|
||||
log("SonarClient::onConnected");
|
||||
void FlipperClient::onConnected() {
|
||||
log("FlipperClient::onConnected");
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
connected_ = true;
|
||||
}
|
||||
|
||||
void SonarClient::onDisconnected() {
|
||||
log("SonarClient::onDisconnected");
|
||||
void FlipperClient::onDisconnected() {
|
||||
log("FlipperClient::onDisconnected");
|
||||
auto step = sonarState_->start("Trigger onDisconnected callbacks");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
connected_ = false;
|
||||
@@ -128,7 +128,7 @@ void SonarClient::onDisconnected() {
|
||||
});
|
||||
}
|
||||
|
||||
void SonarClient::onMessageReceived(const dynamic& message) {
|
||||
void FlipperClient::onMessageReceived(const dynamic& message) {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
performAndReportError([this, &message]() {
|
||||
const auto& method = message["method"];
|
||||
@@ -198,7 +198,7 @@ void SonarClient::onMessageReceived(const dynamic& message) {
|
||||
});
|
||||
}
|
||||
|
||||
void SonarClient::performAndReportError(const std::function<void()>& func) {
|
||||
void FlipperClient::performAndReportError(const std::function<void()>& func) {
|
||||
try {
|
||||
func();
|
||||
} catch (std::exception& e) {
|
||||
@@ -213,11 +213,11 @@ void SonarClient::performAndReportError(const std::function<void()>& func) {
|
||||
}
|
||||
}
|
||||
|
||||
std::string SonarClient::getState() {
|
||||
std::string FlipperClient::getState() {
|
||||
return sonarState_->getState();
|
||||
}
|
||||
|
||||
std::vector<StateElement> SonarClient::getStateElements() {
|
||||
std::vector<StateElement> FlipperClient::getStateElements() {
|
||||
return sonarState_->getStateElements();
|
||||
}
|
||||
|
||||
@@ -21,26 +21,26 @@
|
||||
namespace facebook {
|
||||
namespace flipper {
|
||||
|
||||
class SonarClient : public SonarWebSocket::Callbacks {
|
||||
class FlipperClient : public SonarWebSocket::Callbacks {
|
||||
public:
|
||||
/**
|
||||
Call before accessing instance with SonarClient::instance(). This will set up
|
||||
Call before accessing instance with FlipperClient::instance(). This will set up
|
||||
all the state needed to establish a Sonar connection.
|
||||
*/
|
||||
static void init(SonarInitConfig config);
|
||||
|
||||
/**
|
||||
Standard accessor for the shared SonarClient instance. This returns a
|
||||
singleton instance to a shared SonarClient. First call to this function will
|
||||
create the shared SonarClient. Must call SonarClient::initDeviceData() before
|
||||
first call to SonarClient::instance().
|
||||
Standard accessor for the shared FlipperClient instance. This returns a
|
||||
singleton instance to a shared FlipperClient. First call to this function will
|
||||
create the shared FlipperClient. Must call FlipperClient::initDeviceData() before
|
||||
first call to FlipperClient::instance().
|
||||
*/
|
||||
static SonarClient* instance();
|
||||
static FlipperClient* instance();
|
||||
|
||||
/**
|
||||
Only public for testing
|
||||
*/
|
||||
SonarClient(std::unique_ptr<SonarWebSocket> socket, std::shared_ptr<SonarState> state)
|
||||
FlipperClient(std::unique_ptr<SonarWebSocket> socket, std::shared_ptr<SonarState> state)
|
||||
: socket_(std::move(socket)), sonarState_(state) {
|
||||
auto step = sonarState_->start("Create client");
|
||||
socket_->setCallbacks(this);
|
||||
@@ -88,7 +88,7 @@ class SonarClient : public SonarWebSocket::Callbacks {
|
||||
bool hasPlugin(const std::string& identifier);
|
||||
|
||||
private:
|
||||
static SonarClient* instance_;
|
||||
static FlipperClient* instance_;
|
||||
bool connected_ = false;
|
||||
std::unique_ptr<SonarWebSocket> socket_;
|
||||
std::map<std::string, std::shared_ptr<SonarPlugin>> plugins_;
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Flipper/SonarClient.h>
|
||||
#include <Flipper/FlipperClient.h>
|
||||
#include <FlipperTestLib/SonarPluginMock.h>
|
||||
#include <FlipperTestLib/SonarWebSocketMock.h>
|
||||
|
||||
@@ -34,7 +34,7 @@ TEST(SonarClientTests, testSaneMocks) {
|
||||
|
||||
TEST(SonarClientTests, testGetPlugins) {
|
||||
auto socket = new SonarWebSocketMock;
|
||||
SonarClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
client.start();
|
||||
|
||||
client.addPlugin(std::make_shared<SonarPluginMock>("Cat"));
|
||||
@@ -50,7 +50,7 @@ TEST(SonarClientTests, testGetPlugins) {
|
||||
|
||||
TEST(SonarClientTests, testGetPlugin) {
|
||||
auto socket = new SonarWebSocketMock;
|
||||
SonarClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
|
||||
const auto catPlugin = std::make_shared<SonarPluginMock>("Cat");
|
||||
client.addPlugin(catPlugin);
|
||||
@@ -63,7 +63,7 @@ TEST(SonarClientTests, testGetPlugin) {
|
||||
|
||||
TEST(SonarClientTests, testGetPluginWithDowncast) {
|
||||
auto socket = new SonarWebSocketMock;
|
||||
SonarClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
|
||||
const auto catPlugin = std::make_shared<SonarPluginMock>("Cat");
|
||||
client.addPlugin(catPlugin);
|
||||
@@ -72,7 +72,7 @@ TEST(SonarClientTests, testGetPluginWithDowncast) {
|
||||
|
||||
TEST(SonarClientTests, testRemovePlugin) {
|
||||
auto socket = new SonarWebSocketMock;
|
||||
SonarClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
client.start();
|
||||
|
||||
auto plugin = std::make_shared<SonarPluginMock>("Test");
|
||||
@@ -89,7 +89,7 @@ TEST(SonarClientTests, testRemovePlugin) {
|
||||
|
||||
TEST(SonarClientTests, testStartStop) {
|
||||
auto socket = new SonarWebSocketMock;
|
||||
SonarClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
|
||||
client.start();
|
||||
EXPECT_TRUE(socket->isOpen());
|
||||
@@ -100,7 +100,7 @@ TEST(SonarClientTests, testStartStop) {
|
||||
|
||||
TEST(SonarClientTests, testConnectDisconnect) {
|
||||
auto socket = new SonarWebSocketMock;
|
||||
SonarClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
|
||||
bool pluginConnected = false;
|
||||
const auto connectionCallback = [&](std::shared_ptr<SonarConnection> conn) {
|
||||
@@ -123,7 +123,7 @@ TEST(SonarClientTests, testConnectDisconnect) {
|
||||
|
||||
TEST(SonarClientTests, testInitDeinit) {
|
||||
auto socket = new SonarWebSocketMock;
|
||||
SonarClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
|
||||
bool pluginConnected = false;
|
||||
const auto connectionCallback = [&](std::shared_ptr<SonarConnection> conn) {
|
||||
@@ -161,7 +161,7 @@ TEST(SonarClientTests, testInitDeinit) {
|
||||
|
||||
TEST(SonarClientTests, testRemovePluginWhenConnected) {
|
||||
auto socket = new SonarWebSocketMock;
|
||||
SonarClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
|
||||
bool pluginConnected = false;
|
||||
const auto connectionCallback = [&](std::shared_ptr<SonarConnection> conn) {
|
||||
@@ -182,7 +182,7 @@ TEST(SonarClientTests, testRemovePluginWhenConnected) {
|
||||
|
||||
TEST(SonarClientTests, testUnhandleableMethod) {
|
||||
auto socket = new SonarWebSocketMock;
|
||||
SonarClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
|
||||
auto plugin = std::make_shared<SonarPluginMock>("Test");
|
||||
client.addPlugin(plugin);
|
||||
@@ -202,7 +202,7 @@ TEST(SonarClientTests, testUnhandleableMethod) {
|
||||
|
||||
TEST(SonarClientTests, testExecute) {
|
||||
auto socket = new SonarWebSocketMock;
|
||||
SonarClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
client.start();
|
||||
|
||||
const auto connectionCallback = [](std::shared_ptr<SonarConnection> conn) {
|
||||
@@ -232,7 +232,7 @@ TEST(SonarClientTests, testExecute) {
|
||||
|
||||
TEST(SonarClientTests, testExecuteWithParams) {
|
||||
auto socket = new SonarWebSocketMock;
|
||||
SonarClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
|
||||
const auto connectionCallback = [&](std::shared_ptr<SonarConnection> conn) {
|
||||
const auto receiver = [](const dynamic ¶ms,
|
||||
@@ -265,7 +265,7 @@ TEST(SonarClientTests, testExecuteWithParams) {
|
||||
|
||||
TEST(SonarClientTests, testExceptionUnknownPlugin) {
|
||||
auto socket = new SonarWebSocketMock;
|
||||
SonarClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
client.start();
|
||||
|
||||
dynamic messageInit = dynamic::object("method", "init")(
|
||||
@@ -278,7 +278,7 @@ TEST(SonarClientTests, testExceptionUnknownPlugin) {
|
||||
|
||||
TEST(SonarClientTests, testExceptionUnknownApi) {
|
||||
auto socket = new SonarWebSocketMock;
|
||||
SonarClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||
client.start();
|
||||
|
||||
dynamic messageInit = dynamic::object("method", "execute")(
|
||||
|
||||
Reference in New Issue
Block a user