Files
flipper/docs/send-data.md
Pascal Hartig b22f02510c Fix docs inconsistencies (#214)
Summary:
When referring to the project, we usually capitalize Flipper, but don't
do this super consistently. This fixes a few cases and some other
grammar issues.
Pull Request resolved: https://github.com/facebook/flipper/pull/214

Reviewed By: jknoxville

Differential Revision: D9219587

Pulled By: passy

fbshipit-source-id: 4c2a30730b8719ea4c058ad3c6cc262cbbdf6266
2018-08-08 13:43:17 -07:00

1.6 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 SonarClient and each SonarClient 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, "MySonarPlugin":

Android

final SonarClient client = AndroidSonarClient.getInstance(context);
// Client may be null if AndroidSonarClient.createInstance() was never called
// which is the case in production builds.
if (client != null) {
  final MySonarPlugin plugin = client.getPlugin("MySonarPlugin");
  plugin.sendData(myData);
}

iOS

SonarClient *client = [SonarClient sharedClient];
MySonarPlugin *myPlugin = [client pluginWithIdentifier:@"MySonarPlugin"];
[myPlugin sendData:myData];

C++

auto &client = SonarClient::instance();

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

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

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

myPlugin->sendData(myData);

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