Files
flipper/docs/send-data.md
Pascal Hartig dfd2e279bc Update getPlugin docs
Summary: Per title.

Reviewed By: jknoxville

Differential Revision: D13304655

fbshipit-source-id: 8f9e78dbee043e749b1fdd2d4a540eeece66734b
2018-12-05 08:03:41 -08:00

1.7 KiB

id, title, sidebar_label
id title sidebar_label
send-data Sending Data to Plugins Send Data

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":

Android

final FlipperClient client = AndroidFlipperClient.getInstance(context);
// Client may be null if AndroidFlipperClient.createInstance() was never called
// which is the case in production builds.
if (client != null) {
  final MyFlipperPlugin plugin = client.getPluginByClass(MyFlipperPlugin.class);
  plugin.sendData(myData);
}

iOS

FlipperClient *client = [FlipperClient sharedClient];
MyFlipperPlugin *myPlugin = [client pluginWithIdentifier:@"MyFlipperPlugin"];
[myPlugin sendData:myData];

C++

auto &client = FlipperClient::instance();

// "MyFlipperPlugin is the return value of MyFlipperPlugin::identifier()
auto aPlugin = client.getPlugin("MyFlipperPlugin");

// aPlugin is a std::shared_ptr<FlipperPlugin>. Downcast to expected type.
auto myPlugin = std::static_pointer_cast<MyFlipperPlugin>(aPlugin);

// Alternatively, use the templated version
myPlugin = client.getPlugin<MyFlipperPlugin>("MyFlipperPlugin");

myPlugin->sendData(myData);

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