Files
flipper/docs/extending/send-data.md
John Knox f72e4b5122 Tidy up "Sending data to Plugins" page
Summary:
* Made the code snippets uniform across languages.
* Renamed to "Providing data to plugins" because sending hints at sending across the desktop-client connection which is misleading.

Reviewed By: danielbuechele

Differential Revision: D15198081

fbshipit-source-id: e2c318cdc6055c191f47e846b518c26dd21e4a68
2019-05-03 07:10:57 -07:00

1.4 KiB

id, title
id title
send-data Providing data to plugins

It is often useful to get an instance of a Flipper plugin to send data to it. Flipper makes this simple with built-in support.

Plugins should be treated as singleton instances as there can only be one FlipperClient and each FlipperClient can only have one instance of a certain plugin. The Flipper API makes this simple by offering a way to get the current client and query it for plugins.

Plugins are identified by the string that their identifier method returns, in this example, "MyFlipperPlugin". Note that null checks may be required as plugins may not be initialized, for example in production builds.

final FlipperClient client = AndroidFlipperClient.getInstance(context);
if (client != null) {
  final MyFlipperPlugin plugin = client.getPluginByClass(MyFlipperPlugin.class);
  plugin.sendData(myData);
}
FlipperClient *client = [FlipperClient sharedClient];
MyFlipperPlugin *myPlugin = [client pluginWithIdentifier:@"MyFlipperPlugin"];
[myPlugin sendData:myData];
auto& client = FlipperClient::instance();
auto myPlugin = client.getPlugin<MyFlipperPlugin>("MyFlipperPlugin");
if (myPlugin) {
  myPlugin->sendData(myData);
}

Here, sendData is an example of a method that might be implemented by the Flipper plugin.