Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
Modifying addPlugin() based on the isDuplicationAllowed flag
Browse files Browse the repository at this point in the history
Summary:
Adding the flag if the FlipperPlugin is allowed for duplication. This will be set as False by default.

Since there is already existing Multi Plugin and it is possible to find if the current plugin allowed for duplication, modifying the addPlugin() function. The behaviour will stay the same for all plugins that has the newly added flag by default.

If the plugin with the same identifier is already present and allowed for duplication, then instead of skipping - will create an instance of the multi plugin. Also cleaning the already existing one by disconnecting and erasing it.

The newly changed logic can still cause the tree-shape structure, however this might be possible only for the users that will modify the flag and call the addPlugin() few times with the same identifier. As for now, I presume this might be not a problem

Differential Revision: D63325554

fbshipit-source-id: affbc9f4bac1f71c37c5f284e707a324298031f5
  • Loading branch information
Shamil Yessenkulov authored and facebook-github-bot committed Sep 30, 2024
1 parent 6689ca3 commit 937e1da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions xplat/Flipper/FlipperClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "FireAndForgetBasedFlipperResponder.h"
#include "FlipperConnectionImpl.h"
#include "FlipperConnectionManagerImpl.h"
#include "FlipperMultiPlugin.h"
#include "FlipperState.h"
#include "FlipperStep.h"
#include "Log.h"
Expand Down Expand Up @@ -64,6 +65,22 @@ void FlipperClient::addPlugin(std::shared_ptr<FlipperPlugin> plugin) {
std::lock_guard<std::mutex> lock(mutex_);
if (plugins_.find(plugin->identifier()) != plugins_.end()) {
log("[client] Plugin " + plugin->identifier() + " already added");
// If the plugin is allowed to create a multi plugin, then instead of
// skipping, create a multi plugin and replace the existing plugin.
if (plugin->isDuplicationAllowed) {
log("[client] Plugin is allowed for duplication. Creating multiplugin");
auto existingPlugin = plugins_[plugin->identifier()];
std::vector<std::shared_ptr<FlipperPlugin>> plugins = {
existingPlugin, plugin};
auto newPlugin =
std::static_pointer_cast<facebook::flipper::FlipperPlugin>(
std::make_shared<facebook::flipper::FlipperMultiPlugin>(
std::move(plugins)));
disconnect(std::move(existingPlugin));
plugins_.erase(plugin->identifier());
plugins_[plugin->identifier()] = std::move(newPlugin);
needs_refresh = true;
}
} else {
plugins_[plugin->identifier()] = plugin;
needs_refresh = true;
Expand Down
2 changes: 2 additions & 0 deletions xplat/Flipper/FlipperPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class FlipperPlugin {
virtual bool runInBackground() {
return false;
}

bool isDuplicationAllowed = false;
};

} // namespace flipper
Expand Down

0 comments on commit 937e1da

Please sign in to comment.