Files
flipper/xplat/Flipper/FlipperConnection.h
Lorenzo Blasa d1c06c9c46 Do not overload send as this causes issues with folly::dynamic
Summary:
folly::dynamic, std::string, implicit constructors and method overloading is not a good combination.

This renames the send method to sendRaw as to avoid issues with existing plugins currently sending string params.

Reviewed By: mweststrate

Differential Revision: D38827539

fbshipit-source-id: 653f62e41ebfbe93d1af25f39c81f6b05bf84cb4
2022-08-18 09:39:42 -07:00

63 lines
1.5 KiB
C++

/*
* 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.
*/
#pragma once
#include <folly/json.h>
#include <functional>
#include <string>
#include "FlipperResponder.h"
namespace facebook {
namespace flipper {
/**
Represents a connection between the Desktop and mobile plugins
with corresponding identifiers.
*/
class FlipperConnection {
public:
using FlipperReceiver = std::function<
void(const folly::dynamic&, std::shared_ptr<FlipperResponder>)>;
virtual ~FlipperConnection() {}
/**
Invoke a method on the Flipper desktop plugin with a matching identifier.
*/
virtual void send(
const std::string& method,
const folly::dynamic& params) = 0;
/**
Invoke a method on the Flipper desktop plugin with a matching
identifier.
Note: The `message` argument is expected to contain a valid JSON.
*/
virtual void sendRaw(
const std::string& method,
const std::string& params) = 0;
/**
Report an error to the Flipper desktop app
*/
virtual void error(
const std::string& message,
const std::string& stacktrace) = 0;
/**
Register a receiver to be notified of incoming calls of the given
method from the Flipper desktop plugin with a matching identifier.
*/
virtual void receive(
const std::string& method,
const FlipperReceiver& receiver) = 0;
};
} // namespace flipper
} // namespace facebook