Rename C++ fields and internal methods
Summary: From sonar* to flipper*. Reviewed By: priteshrnandgaonkar Differential Revision: D9944461 fbshipit-source-id: 870997e3d1d5aaef73dd445e6d94615f93fe6abc
This commit is contained in:
committed by
Facebook Github Bot
parent
a14bbc0421
commit
1a076f1300
@@ -36,7 +36,7 @@ bool ConnectionContextStore::hasRequiredFiles() {
|
||||
}
|
||||
|
||||
std::string ConnectionContextStore::createCertificateSigningRequest() {
|
||||
ensureSonarDirExists();
|
||||
ensureFlipperDirExists();
|
||||
generateCertSigningRequest(
|
||||
deviceData_.appId.c_str(),
|
||||
absoluteFilePath(CSR_FILE_NAME).c_str(),
|
||||
@@ -90,7 +90,7 @@ std::string ConnectionContextStore::getCertificateDirectoryPath() {
|
||||
return absoluteFilePath("");
|
||||
}
|
||||
|
||||
bool ConnectionContextStore::ensureSonarDirExists() {
|
||||
bool ConnectionContextStore::ensureFlipperDirExists() {
|
||||
std::string dirPath = absoluteFilePath("");
|
||||
struct stat info;
|
||||
if (stat(dirPath.c_str(), &info) != 0) {
|
||||
@@ -99,7 +99,7 @@ bool ConnectionContextStore::ensureSonarDirExists() {
|
||||
} else if (info.st_mode & S_IFDIR) {
|
||||
return true;
|
||||
} else {
|
||||
log("ERROR: Sonar path exists but is not a directory: " + dirPath);
|
||||
log("ERROR: Flipper path exists but is not a directory: " + dirPath);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ private:
|
||||
DeviceData deviceData_;
|
||||
|
||||
std::string absoluteFilePath(const char* filename);
|
||||
bool ensureSonarDirExists();
|
||||
bool ensureFlipperDirExists();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -42,12 +42,12 @@ FlipperClient* FlipperClient::instance() {
|
||||
void FlipperClient::setStateListener(
|
||||
std::shared_ptr<FlipperStateUpdateListener> stateListener) {
|
||||
log("Setting state listener");
|
||||
sonarState_->setUpdateListener(stateListener);
|
||||
flipperState_->setUpdateListener(stateListener);
|
||||
}
|
||||
|
||||
void FlipperClient::addPlugin(std::shared_ptr<FlipperPlugin> plugin) {
|
||||
log("FlipperClient::addPlugin " + plugin->identifier());
|
||||
auto step = sonarState_->start("Add plugin " + plugin->identifier());
|
||||
auto step = flipperState_->start("Add plugin " + plugin->identifier());
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
performAndReportError([this, plugin, step]() {
|
||||
@@ -117,7 +117,7 @@ void FlipperClient::onConnected() {
|
||||
|
||||
void FlipperClient::onDisconnected() {
|
||||
log("FlipperClient::onDisconnected");
|
||||
auto step = sonarState_->start("Trigger onDisconnected callbacks");
|
||||
auto step = flipperState_->start("Trigger onDisconnected callbacks");
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
connected_ = false;
|
||||
performAndReportError([this, step]() {
|
||||
@@ -214,11 +214,11 @@ void FlipperClient::performAndReportError(const std::function<void()>& func) {
|
||||
}
|
||||
|
||||
std::string FlipperClient::getState() {
|
||||
return sonarState_->getState();
|
||||
return flipperState_->getState();
|
||||
}
|
||||
|
||||
std::vector<StateElement> FlipperClient::getStateElements() {
|
||||
return sonarState_->getStateElements();
|
||||
return flipperState_->getStateElements();
|
||||
}
|
||||
|
||||
} // namespace flipper
|
||||
|
||||
@@ -25,7 +25,7 @@ class FlipperClient : public FlipperConnectionManager::Callbacks {
|
||||
public:
|
||||
/**
|
||||
Call before accessing instance with FlipperClient::instance(). This will set up
|
||||
all the state needed to establish a Sonar connection.
|
||||
all the state needed to establish a Flipper connection.
|
||||
*/
|
||||
static void init(FlipperInitConfig config);
|
||||
|
||||
@@ -41,20 +41,20 @@ class FlipperClient : public FlipperConnectionManager::Callbacks {
|
||||
Only public for testing
|
||||
*/
|
||||
FlipperClient(std::unique_ptr<FlipperConnectionManager> socket, std::shared_ptr<FlipperState> state)
|
||||
: socket_(std::move(socket)), sonarState_(state) {
|
||||
auto step = sonarState_->start("Create client");
|
||||
: socket_(std::move(socket)), flipperState_(state) {
|
||||
auto step = flipperState_->start("Create client");
|
||||
socket_->setCallbacks(this);
|
||||
step->complete();
|
||||
}
|
||||
|
||||
void start() {
|
||||
auto step = sonarState_->start("Start client");
|
||||
auto step = flipperState_->start("Start client");
|
||||
socket_->start();
|
||||
step->complete();
|
||||
}
|
||||
|
||||
void stop() {
|
||||
auto step = sonarState_->start("Stop client");
|
||||
auto step = flipperState_->start("Stop client");
|
||||
socket_->stop();
|
||||
step->complete();
|
||||
}
|
||||
@@ -94,7 +94,7 @@ class FlipperClient : public FlipperConnectionManager::Callbacks {
|
||||
std::map<std::string, std::shared_ptr<FlipperPlugin>> plugins_;
|
||||
std::map<std::string, std::shared_ptr<FlipperConnectionImpl>> connections_;
|
||||
std::mutex mutex_;
|
||||
std::shared_ptr<FlipperState> sonarState_;
|
||||
std::shared_ptr<FlipperState> flipperState_;
|
||||
|
||||
void performAndReportError(const std::function<void()>& func);
|
||||
void disconnect(std::shared_ptr<FlipperPlugin> plugin);
|
||||
|
||||
@@ -22,20 +22,20 @@ with corresponding identifiers.
|
||||
*/
|
||||
class FlipperConnection {
|
||||
public:
|
||||
using SonarReceiver = std::function<
|
||||
using FlipperReceiver = std::function<
|
||||
void(const folly::dynamic&, std::unique_ptr<FlipperResponder>)>;
|
||||
|
||||
virtual ~FlipperConnection() {}
|
||||
|
||||
/**
|
||||
Invoke a method on the Sonar desktop plugin with with a matching identifier.
|
||||
Invoke a method on the Flipper desktop plugin with with a matching identifier.
|
||||
*/
|
||||
virtual void send(
|
||||
const std::string& method,
|
||||
const folly::dynamic& params) = 0;
|
||||
|
||||
/**
|
||||
Report an error to the Sonar desktop app
|
||||
Report an error to the Flipper desktop app
|
||||
*/
|
||||
virtual void error(
|
||||
const std::string& message,
|
||||
@@ -43,11 +43,11 @@ class FlipperConnection {
|
||||
|
||||
/**
|
||||
Register a receiver to be notified of incoming calls of the given
|
||||
method from the Sonar desktop plugin with a matching identifier.
|
||||
method from the Flipper desktop plugin with a matching identifier.
|
||||
*/
|
||||
virtual void receive(
|
||||
const std::string& method,
|
||||
const SonarReceiver& receiver) = 0;
|
||||
const FlipperReceiver& receiver) = 0;
|
||||
};
|
||||
|
||||
} // namespace flipper
|
||||
|
||||
@@ -46,7 +46,7 @@ class FlipperConnectionImpl : public FlipperConnection {
|
||||
folly::dynamic::object("message", message)("stacktrace", stacktrace)));
|
||||
}
|
||||
|
||||
void receive(const std::string& method, const SonarReceiver& receiver)
|
||||
void receive(const std::string& method, const FlipperReceiver& receiver)
|
||||
override {
|
||||
receivers_[method] = receiver;
|
||||
}
|
||||
@@ -54,7 +54,7 @@ class FlipperConnectionImpl : public FlipperConnection {
|
||||
private:
|
||||
FlipperConnectionManager* socket_;
|
||||
std::string name_;
|
||||
std::map<std::string, SonarReceiver> receivers_;
|
||||
std::map<std::string, FlipperReceiver> receivers_;
|
||||
};
|
||||
|
||||
} // namespace flipper
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <stdexcept>
|
||||
|
||||
#define WRONG_THREAD_EXIT_MSG \
|
||||
"ERROR: Aborting sonar initialization because it's not running in the sonar thread."
|
||||
"ERROR: Aborting flipper initialization because it's not running in the flipper thread."
|
||||
|
||||
static constexpr int reconnectIntervalSeconds = 2;
|
||||
static constexpr int connectionKeepaliveSeconds = 10;
|
||||
@@ -78,7 +78,7 @@ class Responder : public rsocket::RSocketResponder {
|
||||
};
|
||||
|
||||
FlipperConnectionManagerImpl::FlipperConnectionManagerImpl(FlipperInitConfig config, std::shared_ptr<FlipperState> state, std::shared_ptr<ConnectionContextStore> contextStore)
|
||||
: deviceData_(config.deviceData), sonarState_(state), sonarEventBase_(config.callbackWorker), connectionEventBase_(config.connectionWorker), contextStore_(contextStore) {
|
||||
: deviceData_(config.deviceData), flipperState_(state), flipperEventBase_(config.callbackWorker), connectionEventBase_(config.connectionWorker), contextStore_(contextStore) {
|
||||
CHECK_THROW(config.callbackWorker, std::invalid_argument);
|
||||
CHECK_THROW(config.connectionWorker, std::invalid_argument);
|
||||
}
|
||||
@@ -88,9 +88,9 @@ FlipperConnectionManagerImpl::~FlipperConnectionManagerImpl() {
|
||||
}
|
||||
|
||||
void FlipperConnectionManagerImpl::start() {
|
||||
auto step = sonarState_->start("Start connection thread");
|
||||
auto step = flipperState_->start("Start connection thread");
|
||||
folly::makeFuture()
|
||||
.via(sonarEventBase_->getEventBase())
|
||||
.via(flipperEventBase_->getEventBase())
|
||||
.delayed(std::chrono::milliseconds(0))
|
||||
.thenValue([this, step](auto&&){ step->complete(); startSync(); });
|
||||
}
|
||||
@@ -104,7 +104,7 @@ void FlipperConnectionManagerImpl::startSync() {
|
||||
log("Already connected");
|
||||
return;
|
||||
}
|
||||
auto connect = sonarState_->start("Connect to desktop");
|
||||
auto connect = flipperState_->start("Connect to desktop");
|
||||
try {
|
||||
if (isCertificateExchangeNeeded()) {
|
||||
doCertificateExchange();
|
||||
@@ -142,7 +142,7 @@ void FlipperConnectionManagerImpl::doCertificateExchange() {
|
||||
"device", deviceData_.device)("app", deviceData_.app)));
|
||||
address.setFromHostPort(deviceData_.host, insecurePort);
|
||||
|
||||
auto connectingInsecurely = sonarState_->start("Connect insecurely");
|
||||
auto connectingInsecurely = flipperState_->start("Connect insecurely");
|
||||
connectionIsTrusted_ = false;
|
||||
client_ =
|
||||
rsocket::RSocket::createConnectedClient(
|
||||
@@ -156,14 +156,14 @@ void FlipperConnectionManagerImpl::doCertificateExchange() {
|
||||
.get();
|
||||
connectingInsecurely->complete();
|
||||
|
||||
requestSignedCertFromSonar();
|
||||
requestSignedCertFromFlipper();
|
||||
}
|
||||
|
||||
void FlipperConnectionManagerImpl::connectSecurely() {
|
||||
rsocket::SetupParameters parameters;
|
||||
folly::SocketAddress address;
|
||||
|
||||
auto loadingDeviceId = sonarState_->start("Load Device Id");
|
||||
auto loadingDeviceId = flipperState_->start("Load Device Id");
|
||||
auto deviceId = contextStore_->getDeviceId();
|
||||
if (deviceId.compare("unknown")) {
|
||||
loadingDeviceId->complete();
|
||||
@@ -174,7 +174,7 @@ void FlipperConnectionManagerImpl::connectSecurely() {
|
||||
address.setFromHostPort(deviceData_.host, securePort);
|
||||
|
||||
std::shared_ptr<folly::SSLContext> sslContext = contextStore_->getSSLContext();
|
||||
auto connectingSecurely = sonarState_->start("Connect securely");
|
||||
auto connectingSecurely = flipperState_->start("Connect securely");
|
||||
connectionIsTrusted_ = true;
|
||||
client_ =
|
||||
rsocket::RSocket::createConnectedClient(
|
||||
@@ -194,7 +194,7 @@ void FlipperConnectionManagerImpl::connectSecurely() {
|
||||
|
||||
void FlipperConnectionManagerImpl::reconnect() {
|
||||
folly::makeFuture()
|
||||
.via(sonarEventBase_->getEventBase())
|
||||
.via(flipperEventBase_->getEventBase())
|
||||
.delayed(std::chrono::seconds(reconnectIntervalSeconds))
|
||||
.thenValue([this](auto&&){ startSync(); });
|
||||
}
|
||||
@@ -215,7 +215,7 @@ void FlipperConnectionManagerImpl::setCallbacks(Callbacks* callbacks) {
|
||||
}
|
||||
|
||||
void FlipperConnectionManagerImpl::sendMessage(const folly::dynamic& message) {
|
||||
sonarEventBase_->add([this, message]() {
|
||||
flipperEventBase_->add([this, message]() {
|
||||
if (client_) {
|
||||
client_->getRequester()
|
||||
->fireAndForget(rsocket::Payload(folly::toJson(message)))
|
||||
@@ -230,7 +230,7 @@ bool FlipperConnectionManagerImpl::isCertificateExchangeNeeded() {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto step = sonarState_->start("Check required certificates are present");
|
||||
auto step = flipperState_->start("Check required certificates are present");
|
||||
bool hasRequiredFiles = contextStore_->hasRequiredFiles();
|
||||
if (hasRequiredFiles) {
|
||||
step->complete();
|
||||
@@ -238,16 +238,16 @@ bool FlipperConnectionManagerImpl::isCertificateExchangeNeeded() {
|
||||
return !hasRequiredFiles;
|
||||
}
|
||||
|
||||
void FlipperConnectionManagerImpl::requestSignedCertFromSonar() {
|
||||
auto generatingCSR = sonarState_->start("Generate CSR");
|
||||
void FlipperConnectionManagerImpl::requestSignedCertFromFlipper() {
|
||||
auto generatingCSR = flipperState_->start("Generate CSR");
|
||||
std::string csr = contextStore_->createCertificateSigningRequest();
|
||||
generatingCSR->complete();
|
||||
|
||||
folly::dynamic message = folly::dynamic::object("method", "signCertificate")(
|
||||
"csr", csr.c_str())("destination", contextStore_->getCertificateDirectoryPath().c_str());
|
||||
auto gettingCert = sonarState_->start("Getting cert from desktop");
|
||||
auto gettingCert = flipperState_->start("Getting cert from desktop");
|
||||
|
||||
sonarEventBase_->add([this, message, gettingCert]() {
|
||||
flipperEventBase_->add([this, message, gettingCert]() {
|
||||
client_->getRequester()
|
||||
->requestResponse(rsocket::Payload(folly::toJson(message)))
|
||||
->subscribe([this, gettingCert](rsocket::Payload p) {
|
||||
@@ -269,7 +269,7 @@ void FlipperConnectionManagerImpl::requestSignedCertFromSonar() {
|
||||
std::string errorMessage = errorWithPayload.payload.moveDataToString();
|
||||
|
||||
if (errorMessage.compare("not implemented")) {
|
||||
log("Desktop failed to provide certificates. Error from sonar desktop:\n" + errorMessage);
|
||||
log("Desktop failed to provide certificates. Error from flipper desktop:\n" + errorMessage);
|
||||
} else {
|
||||
sendLegacyCertificateRequest(message);
|
||||
}
|
||||
@@ -286,7 +286,7 @@ void FlipperConnectionManagerImpl::requestSignedCertFromSonar() {
|
||||
void FlipperConnectionManagerImpl::sendLegacyCertificateRequest(folly::dynamic message) {
|
||||
// Desktop is using an old version of Flipper.
|
||||
// Fall back to fireAndForget, instead of requestResponse.
|
||||
auto sendingRequest = sonarState_->start("Sending fallback certificate request");
|
||||
auto sendingRequest = flipperState_->start("Sending fallback certificate request");
|
||||
client_->getRequester()
|
||||
->fireAndForget(rsocket::Payload(folly::toJson(message)))
|
||||
->subscribe([this, sendingRequest]() {
|
||||
@@ -298,7 +298,7 @@ void FlipperConnectionManagerImpl::sendLegacyCertificateRequest(folly::dynamic m
|
||||
}
|
||||
|
||||
bool FlipperConnectionManagerImpl::isRunningInOwnThread() {
|
||||
return sonarEventBase_->isInEventBaseThread();
|
||||
return flipperEventBase_->isInEventBaseThread();
|
||||
}
|
||||
|
||||
} // namespace flipper
|
||||
|
||||
@@ -48,9 +48,9 @@ class FlipperConnectionManagerImpl : public FlipperConnectionManager {
|
||||
bool isOpen_ = false;
|
||||
Callbacks* callbacks_;
|
||||
DeviceData deviceData_;
|
||||
std::shared_ptr<FlipperState> sonarState_;
|
||||
std::shared_ptr<FlipperState> flipperState_;
|
||||
|
||||
folly::EventBase* sonarEventBase_;
|
||||
folly::EventBase* flipperEventBase_;
|
||||
folly::EventBase* connectionEventBase_;
|
||||
std::unique_ptr<rsocket::RSocketClient> client_;
|
||||
bool connectionIsTrusted_;
|
||||
@@ -61,7 +61,7 @@ class FlipperConnectionManagerImpl : public FlipperConnectionManager {
|
||||
void doCertificateExchange();
|
||||
void connectSecurely();
|
||||
bool isCertificateExchangeNeeded();
|
||||
void requestSignedCertFromSonar();
|
||||
void requestSignedCertFromFlipper();
|
||||
bool isRunningInOwnThread();
|
||||
void sendLegacyCertificateRequest(folly::dynamic message);
|
||||
std::string getDeviceId();
|
||||
|
||||
@@ -15,22 +15,22 @@ namespace flipper {
|
||||
|
||||
/**
|
||||
* FlipperResponder is used to asynchronously respond to messages
|
||||
* received from the Sonar desktop app.
|
||||
* received from the Flipper desktop app.
|
||||
*/
|
||||
class FlipperResponder {
|
||||
public:
|
||||
virtual ~FlipperResponder(){};
|
||||
|
||||
/**
|
||||
* Deliver a successful response to the Sonar desktop app.
|
||||
* Deliver a successful response to the Flipper desktop app.
|
||||
*/
|
||||
virtual void success(const folly::dynamic& response) const = 0;
|
||||
|
||||
/**
|
||||
* Inform the Sonar desktop app of an error in handling the request.
|
||||
* Inform the Flipper desktop app of an error in handling the request.
|
||||
*/
|
||||
virtual void error(const folly::dynamic& response) const = 0;
|
||||
};
|
||||
|
||||
} // namespace sonar
|
||||
} // namespace flipper
|
||||
} // namespace facebook
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
using namespace facebook::flipper;
|
||||
|
||||
/* Class responsible for collecting state updates and combining them into a
|
||||
* view of the current state of the sonar client. */
|
||||
* view of the current state of the flipper client. */
|
||||
|
||||
|
||||
FlipperState::FlipperState(): log("") {}
|
||||
|
||||
@@ -9,9 +9,9 @@ namespace flipper {
|
||||
|
||||
void log(const std::string& message) {
|
||||
#ifdef __ANDROID__
|
||||
__android_log_print(ANDROID_LOG_INFO, "sonar", "sonar: %s", message.c_str());
|
||||
__android_log_print(ANDROID_LOG_INFO, "flipper", "flipper: %s", message.c_str());
|
||||
#else
|
||||
printf("sonar: %s\n", message.c_str());
|
||||
printf("flipper: %s\n", message.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ class FlipperConnectionMock : public FlipperConnection {
|
||||
sent_[method] = params;
|
||||
}
|
||||
|
||||
void receive(const std::string& method, const SonarReceiver& receiver)
|
||||
void receive(const std::string& method, const FlipperReceiver& receiver)
|
||||
override {
|
||||
receivers_[method] = receiver;
|
||||
}
|
||||
@@ -30,7 +30,7 @@ class FlipperConnectionMock : public FlipperConnection {
|
||||
override {}
|
||||
|
||||
std::map<std::string, folly::dynamic> sent_;
|
||||
std::map<std::string, SonarReceiver> receivers_;
|
||||
std::map<std::string, FlipperReceiver> receivers_;
|
||||
};
|
||||
|
||||
} // namespace flipper
|
||||
|
||||
@@ -70,27 +70,27 @@ TEST_F(FlipperConnectionManagerImplTerminationTest, testNonStartedEventBaseDoesn
|
||||
}
|
||||
|
||||
TEST_F(FlipperConnectionManagerImplTerminationTest, testStartedEventBaseDoesntHang) {
|
||||
auto sonarEventBase = new EventBase();
|
||||
auto flipperEventBase = new EventBase();
|
||||
auto connectionEventBase = new EventBase();
|
||||
auto sonarThread = std::thread([sonarEventBase](){
|
||||
sonarEventBase->loopForever();
|
||||
auto flipperThread = std::thread([flipperEventBase](){
|
||||
flipperEventBase->loopForever();
|
||||
});
|
||||
auto connectionThread = std::thread([connectionEventBase](){
|
||||
connectionEventBase->loopForever();
|
||||
});
|
||||
auto config = FlipperInitConfig {
|
||||
DeviceData {},
|
||||
sonarEventBase,
|
||||
flipperEventBase,
|
||||
connectionEventBase
|
||||
};
|
||||
auto instance = std::make_shared<FlipperConnectionManagerImpl>(config, state, contextStore);
|
||||
|
||||
instance->start();
|
||||
|
||||
sonarEventBase->terminateLoopSoon();
|
||||
flipperEventBase->terminateLoopSoon();
|
||||
connectionEventBase->terminateLoopSoon();
|
||||
|
||||
sonarThread.join();
|
||||
flipperThread.join();
|
||||
connectionThread.join();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user