Rename SonarConnection to FlipperConnection
Summary: Part of Sonar -> Flipper rename Reviewed By: passy Differential Revision: D9907353 fbshipit-source-id: 01f7bb84da1c27fd68d608151f437a18b6eaaa4e
This commit is contained in:
committed by
Facebook Github Bot
parent
3c656de7fa
commit
9889df3f3c
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
#include <Flipper/FlipperClient.h>
|
#include <Flipper/FlipperClient.h>
|
||||||
#include <Flipper/SonarWebSocket.h>
|
#include <Flipper/SonarWebSocket.h>
|
||||||
#include <Flipper/SonarConnection.h>
|
#include <Flipper/FlipperConnection.h>
|
||||||
#include <Flipper/FlipperResponder.h>
|
#include <Flipper/FlipperResponder.h>
|
||||||
#include <Flipper/SonarStateUpdateListener.h>
|
#include <Flipper/SonarStateUpdateListener.h>
|
||||||
#include <Flipper/SonarState.h>
|
#include <Flipper/SonarState.h>
|
||||||
@@ -175,9 +175,9 @@ class JFlipperConnectionImpl : public jni::HybridClass<JFlipperConnectionImpl, J
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
friend HybridBase;
|
friend HybridBase;
|
||||||
std::shared_ptr<SonarConnection> _connection;
|
std::shared_ptr<FlipperConnection> _connection;
|
||||||
|
|
||||||
JFlipperConnectionImpl(std::shared_ptr<SonarConnection> connection): _connection(std::move(connection)) {}
|
JFlipperConnectionImpl(std::shared_ptr<FlipperConnection> connection): _connection(std::move(connection)) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class JFlipperPlugin : public jni::JavaClass<JFlipperPlugin> {
|
class JFlipperPlugin : public jni::JavaClass<JFlipperPlugin> {
|
||||||
@@ -189,7 +189,7 @@ class JFlipperPlugin : public jni::JavaClass<JFlipperPlugin> {
|
|||||||
return method(self())->toStdString();
|
return method(self())->toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void didConnect(std::shared_ptr<SonarConnection> conn) {
|
void didConnect(std::shared_ptr<FlipperConnection> conn) {
|
||||||
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFlipperConnection::javaobject>)>("onConnect");
|
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFlipperConnection::javaobject>)>("onConnect");
|
||||||
method(self(), JFlipperConnectionImpl::newObjectCxxArgs(conn));
|
method(self(), JFlipperConnectionImpl::newObjectCxxArgs(conn));
|
||||||
}
|
}
|
||||||
@@ -239,7 +239,7 @@ class JFlipperPluginWrapper : public SonarPlugin {
|
|||||||
return jplugin->identifier();
|
return jplugin->identifier();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void didConnect(std::shared_ptr<SonarConnection> conn) override {
|
virtual void didConnect(std::shared_ptr<FlipperConnection> conn) override {
|
||||||
jplugin->didConnect(conn);
|
jplugin->didConnect(conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class MySonarPlugin implements SonarPlugin {
|
|||||||
class MySonarPlugin : public SonarPlugin {
|
class MySonarPlugin : public SonarPlugin {
|
||||||
public:
|
public:
|
||||||
std::string identifier() const override { return "MySonarPlugin"; }
|
std::string identifier() const override { return "MySonarPlugin"; }
|
||||||
void didConnect(std::shared_ptr<SonarConnection> conn) override;
|
void didConnect(std::shared_ptr<FlipperConnection> conn) override;
|
||||||
void didDisconnect() override;
|
void didDisconnect() override;
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
@@ -102,7 +102,7 @@ connection.receive("getData", new SonarReceiver() {
|
|||||||
### C++
|
### C++
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
void MySonarPlugin::didConnect(std::shared_ptr<SonarConnection> conn) {
|
void MySonarPlugin::didConnect(std::shared_ptr<FlipperConnection> conn) {
|
||||||
conn->receive("getData", [](const folly::dynamic ¶ms,
|
conn->receive("getData", [](const folly::dynamic ¶ms,
|
||||||
std::unique_ptr<FlipperResponder> responder) {
|
std::unique_ptr<FlipperResponder> responder) {
|
||||||
dynamic response = folly::dynamic::object("data", getMyData());
|
dynamic response = folly::dynamic::object("data", getMyData());
|
||||||
@@ -133,7 +133,7 @@ connection.send("MyMessage",
|
|||||||
### C++
|
### C++
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
void MySonarPlugin::didConnect(std::shared_ptr<SonarConnection> conn) {
|
void MySonarPlugin::didConnect(std::shared_ptr<FlipperConnection> conn) {
|
||||||
dynamic message = folly::dynamic::object("message", "hello");
|
dynamic message = folly::dynamic::object("message", "hello");
|
||||||
conn->send("getData", message);
|
conn->send("getData", message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ Always use `ErrorReportingRunnable` for error handling instead of `try`/`catch`
|
|||||||
|
|
||||||
## C++
|
## C++
|
||||||
|
|
||||||
To gracefully handle errors in Flipper we perform all transactions inside of a try block which catches all exceptions, stopping them from crashing the application and reporting them to the plugin developer. This includes your own customs implementations of `SonarPlugin::didConnect()` and `SonarConnection::send()` and `::receive()`!
|
To gracefully handle errors in Flipper we perform all transactions inside of a try block which catches all exceptions, stopping them from crashing the application and reporting them to the plugin developer. This includes your own customs implementations of `SonarPlugin::didConnect()` and `FlipperConnection::send()` and `::receive()`!
|
||||||
|
|
||||||
That means you can safely throw exceptions in your plugin code. The exception messages will be sent to the Flipper desktop app. During plugin development the exception messages are surfaced in the Chrome dev console.
|
That means you can safely throw exceptions in your plugin code. The exception messages will be sent to the Flipper desktop app. During plugin development the exception messages are surfaced in the Chrome dev console.
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ Start by creating your first test file in this directory `MySonarPluginTests.cpp
|
|||||||
|
|
||||||
```
|
```
|
||||||
#include <MySonarPlugin/MySonarPlugin.h>
|
#include <MySonarPlugin/MySonarPlugin.h>
|
||||||
#include <FlipperTestLib/SonarConnectionMock.h>
|
#include <FlipperTestLib/FlipperConnectionMock.h>
|
||||||
#include <FlipperTestLib/SonarResponderMock.h>
|
#include <FlipperTestLib/SonarResponderMock.h>
|
||||||
|
|
||||||
#include <folly/json.h>
|
#include <folly/json.h>
|
||||||
@@ -79,7 +79,7 @@ Here is a simple test using these mock utilities to create a plugin, send some d
|
|||||||
TEST(MySonarPluginTests, testDummy) {
|
TEST(MySonarPluginTests, testDummy) {
|
||||||
std::vector<folly::dynamic> successfulResponses;
|
std::vector<folly::dynamic> successfulResponses;
|
||||||
auto responder = std::make_unique<SonarResponderMock>(&successfulResponses);
|
auto responder = std::make_unique<SonarResponderMock>(&successfulResponses);
|
||||||
auto conn = std::make_shared<SonarConnectionMock>();
|
auto conn = std::make_shared<FlipperConnectionMock>();
|
||||||
|
|
||||||
MySonarPlugin plugin;
|
MySonarPlugin plugin;
|
||||||
plugin.didConnect(conn);
|
plugin.didConnect(conn);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* file in the root directory of this source tree.
|
* file in the root directory of this source tree.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#import <Flipper/SonarConnection.h>
|
#import <Flipper/FlipperConnection.h>
|
||||||
#import <FlipperKit/FlipperConnection.h>
|
#import <FlipperKit/FlipperConnection.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,5 +14,5 @@ that forwards messages to the underlying C++ connection. This class allows
|
|||||||
pure Objective-C plugins to send messages to the underlying connection.
|
pure Objective-C plugins to send messages to the underlying connection.
|
||||||
*/
|
*/
|
||||||
@interface FlipperCppBridgingConnection : NSObject <FlipperConnection>
|
@interface FlipperCppBridgingConnection : NSObject <FlipperConnection>
|
||||||
- (instancetype)initWithCppConnection:(std::shared_ptr<facebook::flipper::SonarConnection>)conn;
|
- (instancetype)initWithCppConnection:(std::shared_ptr<facebook::flipper::FlipperConnection>)conn;
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -13,10 +13,10 @@
|
|||||||
|
|
||||||
@implementation FlipperCppBridgingConnection
|
@implementation FlipperCppBridgingConnection
|
||||||
{
|
{
|
||||||
std::shared_ptr<facebook::flipper::SonarConnection> conn_;
|
std::shared_ptr<facebook::flipper::FlipperConnection> conn_;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithCppConnection:(std::shared_ptr<facebook::flipper::SonarConnection>)conn
|
- (instancetype)initWithCppConnection:(std::shared_ptr<facebook::flipper::FlipperConnection>)conn
|
||||||
{
|
{
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
conn_ = conn;
|
conn_ = conn;
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public:
|
|||||||
|
|
||||||
std::string identifier() const override { return [[_objCPlugin identifier] UTF8String]; }
|
std::string identifier() const override { return [[_objCPlugin identifier] UTF8String]; }
|
||||||
|
|
||||||
void didConnect(std::shared_ptr<facebook::flipper::SonarConnection> conn) override
|
void didConnect(std::shared_ptr<facebook::flipper::FlipperConnection> conn) override
|
||||||
{
|
{
|
||||||
FlipperCppBridgingConnection *const bridgingConn = [[FlipperCppBridgingConnection alloc] initWithCppConnection:conn];
|
FlipperCppBridgingConnection *const bridgingConn = [[FlipperCppBridgingConnection alloc] initWithCppConnection:conn];
|
||||||
[_objCPlugin didConnect:bridgingConn];
|
[_objCPlugin didConnect:bridgingConn];
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "FlipperClient.h"
|
#include "FlipperClient.h"
|
||||||
#include "SonarConnectionImpl.h"
|
#include "FlipperConnectionImpl.h"
|
||||||
#include "SonarResponderImpl.h"
|
#include "SonarResponderImpl.h"
|
||||||
#include "SonarState.h"
|
#include "SonarState.h"
|
||||||
#include "SonarStep.h"
|
#include "SonarStep.h"
|
||||||
@@ -159,7 +159,7 @@ void FlipperClient::onMessageReceived(const dynamic& message) {
|
|||||||
}
|
}
|
||||||
const auto plugin = plugins_.at(identifier);
|
const auto plugin = plugins_.at(identifier);
|
||||||
auto& conn = connections_[plugin->identifier()];
|
auto& conn = connections_[plugin->identifier()];
|
||||||
conn = std::make_shared<SonarConnectionImpl>(
|
conn = std::make_shared<FlipperConnectionImpl>(
|
||||||
socket_.get(), plugin->identifier());
|
socket_.get(), plugin->identifier());
|
||||||
plugin->didConnect(conn);
|
plugin->didConnect(conn);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "SonarConnectionImpl.h"
|
#include "FlipperConnectionImpl.h"
|
||||||
#include "SonarInitConfig.h"
|
#include "SonarInitConfig.h"
|
||||||
#include "SonarPlugin.h"
|
#include "SonarPlugin.h"
|
||||||
#include "SonarState.h"
|
#include "SonarState.h"
|
||||||
@@ -92,7 +92,7 @@ class FlipperClient : public SonarWebSocket::Callbacks {
|
|||||||
bool connected_ = false;
|
bool connected_ = false;
|
||||||
std::unique_ptr<SonarWebSocket> socket_;
|
std::unique_ptr<SonarWebSocket> socket_;
|
||||||
std::map<std::string, std::shared_ptr<SonarPlugin>> plugins_;
|
std::map<std::string, std::shared_ptr<SonarPlugin>> plugins_;
|
||||||
std::map<std::string, std::shared_ptr<SonarConnectionImpl>> connections_;
|
std::map<std::string, std::shared_ptr<FlipperConnectionImpl>> connections_;
|
||||||
std::mutex mutex_;
|
std::mutex mutex_;
|
||||||
std::shared_ptr<SonarState> sonarState_;
|
std::shared_ptr<SonarState> sonarState_;
|
||||||
|
|
||||||
|
|||||||
@@ -20,12 +20,12 @@ namespace flipper {
|
|||||||
Represents a connection between the Desktop and mobile plugins
|
Represents a connection between the Desktop and mobile plugins
|
||||||
with corresponding identifiers.
|
with corresponding identifiers.
|
||||||
*/
|
*/
|
||||||
class SonarConnection {
|
class FlipperConnection {
|
||||||
public:
|
public:
|
||||||
using SonarReceiver = std::function<
|
using SonarReceiver = std::function<
|
||||||
void(const folly::dynamic&, std::unique_ptr<FlipperResponder>)>;
|
void(const folly::dynamic&, std::unique_ptr<FlipperResponder>)>;
|
||||||
|
|
||||||
virtual ~SonarConnection() {}
|
virtual ~FlipperConnection() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Invoke a method on the Sonar desktop plugin with with a matching identifier.
|
Invoke a method on the Sonar desktop plugin with with a matching identifier.
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "SonarConnection.h"
|
#include "FlipperConnection.h"
|
||||||
#include "SonarWebSocket.h"
|
#include "SonarWebSocket.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -16,9 +16,9 @@
|
|||||||
namespace facebook {
|
namespace facebook {
|
||||||
namespace flipper {
|
namespace flipper {
|
||||||
|
|
||||||
class SonarConnectionImpl : public SonarConnection {
|
class FlipperConnectionImpl : public FlipperConnection {
|
||||||
public:
|
public:
|
||||||
SonarConnectionImpl(SonarWebSocket* socket, const std::string& name)
|
FlipperConnectionImpl(SonarWebSocket* socket, const std::string& name)
|
||||||
: socket_(socket), name_(name) {}
|
: socket_(socket), name_(name) {}
|
||||||
|
|
||||||
void call(
|
void call(
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "SonarConnection.h"
|
#include "FlipperConnection.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace facebook {
|
namespace facebook {
|
||||||
@@ -29,10 +29,10 @@ class SonarPlugin {
|
|||||||
connection can be used to register method receivers as well as send
|
connection can be used to register method receivers as well as send
|
||||||
messages back to the desktop app.
|
messages back to the desktop app.
|
||||||
*/
|
*/
|
||||||
virtual void didConnect(std::shared_ptr<SonarConnection> conn) = 0;
|
virtual void didConnect(std::shared_ptr<FlipperConnection> conn) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Called when a plugin has been disconnected and the SonarConnection
|
Called when a plugin has been disconnected and the FlipperConnection
|
||||||
provided in didConnect is no longer valid to use.
|
provided in didConnect is no longer valid to use.
|
||||||
*/
|
*/
|
||||||
virtual void didDisconnect() = 0;
|
virtual void didDisconnect() = 0;
|
||||||
|
|||||||
@@ -8,14 +8,14 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <Flipper/SonarConnection.h>
|
#include <Flipper/FlipperConnection.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace facebook {
|
namespace facebook {
|
||||||
namespace flipper {
|
namespace flipper {
|
||||||
|
|
||||||
class SonarConnectionMock : public SonarConnection {
|
class FlipperConnectionMock : public FlipperConnection {
|
||||||
public:
|
public:
|
||||||
void send(const std::string& method, const folly::dynamic& params) override {
|
void send(const std::string& method, const folly::dynamic& params) override {
|
||||||
sent_[method] = params;
|
sent_[method] = params;
|
||||||
@@ -16,7 +16,7 @@ namespace test {
|
|||||||
|
|
||||||
class SonarPluginMock : public SonarPlugin {
|
class SonarPluginMock : public SonarPlugin {
|
||||||
using ConnectionCallback =
|
using ConnectionCallback =
|
||||||
std::function<void(std::shared_ptr<SonarConnection>)>;
|
std::function<void(std::shared_ptr<FlipperConnection>)>;
|
||||||
using DisconnectionCallback = std::function<void()>;
|
using DisconnectionCallback = std::function<void()>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -39,7 +39,7 @@ class SonarPluginMock : public SonarPlugin {
|
|||||||
return identifier_;
|
return identifier_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void didConnect(std::shared_ptr<SonarConnection> conn) override {
|
void didConnect(std::shared_ptr<FlipperConnection> conn) override {
|
||||||
if (connectionCallback_) {
|
if (connectionCallback_) {
|
||||||
connectionCallback_(conn);
|
connectionCallback_(conn);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ TEST(SonarClientTests, testConnectDisconnect) {
|
|||||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||||
|
|
||||||
bool pluginConnected = false;
|
bool pluginConnected = false;
|
||||||
const auto connectionCallback = [&](std::shared_ptr<SonarConnection> conn) {
|
const auto connectionCallback = [&](std::shared_ptr<FlipperConnection> conn) {
|
||||||
pluginConnected = true;
|
pluginConnected = true;
|
||||||
};
|
};
|
||||||
const auto disconnectionCallback = [&]() { pluginConnected = false; };
|
const auto disconnectionCallback = [&]() { pluginConnected = false; };
|
||||||
@@ -126,7 +126,7 @@ TEST(SonarClientTests, testInitDeinit) {
|
|||||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||||
|
|
||||||
bool pluginConnected = false;
|
bool pluginConnected = false;
|
||||||
const auto connectionCallback = [&](std::shared_ptr<SonarConnection> conn) {
|
const auto connectionCallback = [&](std::shared_ptr<FlipperConnection> conn) {
|
||||||
pluginConnected = true;
|
pluginConnected = true;
|
||||||
};
|
};
|
||||||
const auto disconnectionCallback = [&]() { pluginConnected = false; };
|
const auto disconnectionCallback = [&]() { pluginConnected = false; };
|
||||||
@@ -164,7 +164,7 @@ TEST(SonarClientTests, testRemovePluginWhenConnected) {
|
|||||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||||
|
|
||||||
bool pluginConnected = false;
|
bool pluginConnected = false;
|
||||||
const auto connectionCallback = [&](std::shared_ptr<SonarConnection> conn) {
|
const auto connectionCallback = [&](std::shared_ptr<FlipperConnection> conn) {
|
||||||
pluginConnected = true;
|
pluginConnected = true;
|
||||||
};
|
};
|
||||||
const auto disconnectionCallback = [&]() { pluginConnected = false; };
|
const auto disconnectionCallback = [&]() { pluginConnected = false; };
|
||||||
@@ -205,7 +205,7 @@ TEST(SonarClientTests, testExecute) {
|
|||||||
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
FlipperClient client(std::unique_ptr<SonarWebSocketMock>{socket}, state);
|
||||||
client.start();
|
client.start();
|
||||||
|
|
||||||
const auto connectionCallback = [](std::shared_ptr<SonarConnection> conn) {
|
const auto connectionCallback = [](std::shared_ptr<FlipperConnection> conn) {
|
||||||
const auto receiver = [](const dynamic ¶ms,
|
const auto receiver = [](const dynamic ¶ms,
|
||||||
std::unique_ptr<FlipperResponder> responder) {
|
std::unique_ptr<FlipperResponder> responder) {
|
||||||
dynamic payload = dynamic::object("message", "yes_i_hear_u");
|
dynamic payload = dynamic::object("message", "yes_i_hear_u");
|
||||||
@@ -234,7 +234,7 @@ TEST(SonarClientTests, testExecuteWithParams) {
|
|||||||
auto socket = new SonarWebSocketMock;
|
auto socket = new SonarWebSocketMock;
|
||||||
FlipperClient 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 connectionCallback = [&](std::shared_ptr<FlipperConnection> conn) {
|
||||||
const auto receiver = [](const dynamic ¶ms,
|
const auto receiver = [](const dynamic ¶ms,
|
||||||
std::unique_ptr<FlipperResponder> responder) {
|
std::unique_ptr<FlipperResponder> responder) {
|
||||||
const auto &first = params["first"].asString();
|
const auto &first = params["first"].asString();
|
||||||
|
|||||||
Reference in New Issue
Block a user