-
Notifications
You must be signed in to change notification settings - Fork 955
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Following the same logic as in the diff D63095017 and adding multiplugin on the java side. The logic of the methods are the same as in the C++ functions Reviewed By: mkareta Differential Revision: D63325568 fbshipit-source-id: 855708e6fc378715403ef3f398dc2c5c72cb1af3
- Loading branch information
1 parent
937e1da
commit f160979
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
android/src/main/java/com/facebook/flipper/core/FlipperMultiPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.flipper.core; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* A FlipperMultiPlugin is an object containing several plugins with the same identifiers exposeing | ||
* an API to the Desktop Flipper application. | ||
*/ | ||
public class FlipperMultiPlugin implements FlipperPlugin { | ||
private List<FlipperPlugin> plugins; | ||
|
||
public FlipperMultiPlugin(List<FlipperPlugin> plugins) { | ||
this.plugins = plugins; | ||
// Assert that all plugins have the same identifier. | ||
String expectedIdentifier = plugins.get(0).getId(); | ||
boolean expectedRunInBackground = plugins.get(0).runInBackground(); | ||
for (FlipperPlugin plugin : plugins) { | ||
assert plugin.getId().equals(expectedIdentifier); | ||
assert plugin.runInBackground() == expectedRunInBackground; | ||
} | ||
} | ||
|
||
public void addPlugin(FlipperPlugin plugin) { | ||
// Assert that the new plugin has the same identifier as the existing plugins. | ||
assert plugin.getId().equals(plugins.get(0).getId()); | ||
assert plugin.runInBackground() == plugins.get(0).runInBackground(); | ||
plugins.add(plugin); | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return plugins.get(0).getId(); | ||
} | ||
|
||
@Override | ||
public void onConnect(FlipperConnection conn) throws Exception { | ||
// Forward the connection to each plugin. | ||
for (FlipperPlugin plugin : plugins) { | ||
plugin.onConnect(conn); | ||
} | ||
} | ||
|
||
@Override | ||
public void onDisconnect() throws Exception { | ||
// Forward the disconnection to each plugin. | ||
for (FlipperPlugin plugin : plugins) { | ||
plugin.onDisconnect(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean runInBackground() { | ||
// Check if any of the plugins need to run in the background. | ||
for (FlipperPlugin plugin : plugins) { | ||
if (plugin.runInBackground()) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |