Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@stuartmorgan-g
Copy link
Contributor

Description

The reponse APIs for method channels and event channels used pointers
for optional parameters; this kept the API surface simple, but meant
that they couldn't take rvalues. As a result, returning success values
or error details often took an extra line, declaring a variable for the
result just to have something to pass the address of.

This converts them to using references, with function overloading to
allow for optional parameters, so that values can be inlined.

For now the pointer versions are still present, so that conversion can
be done before it becomes a breaking change; they will be removed soon.

Related Issues

Part of flutter/flutter#63975

Tests

I added the following tests: Updated existing tests to use reference versions.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the contributor guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the C++, Objective-C, Java style guides for the engine.
  • I read the tree hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation.
  • All existing and new tests are passing.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change.

The reponse APIs for method channels and event channels used pointers
for optional parameters; this kept the API surface simple, but meant
that they couldn't take rvalues. As a result, returning success values
or error details often took an extra line, declaring a variable for the
result just to have something to pass the address of.

This converts them to using references, with function overloading to
allow for optional parameters, so that values can be inlined.

For now the pointer versions are still present, so that conversion can
be done before it becomes a breaking change; they will be removed soon.

Part of flutter/flutter#63975
Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

void Success() { SuccessInternal(nullptr); }

// Consumes an error event.
// DEPRECATED. Use the reference version below. This will be removed in the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we do the C++14 deprecated annotation thing? Probably not, since warnings-are-errors, but it seems useful.

i.e.:

  [[deprecated("Use the reference version instead.")]]
  void Error(const std::string& error_code,
             const std::string& error_message,
             const T* error_details) {
    ErrorInternal(error_code, error_message, error_details);
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not, since warnings-are-errors

Exactly. I tried that the last time I did one of these and realized it would just make it an immediate breaking change, which is unfortunate.

In practice, since Windows is still subject to change without warning, it's not a big deal (I'm doing it in stages so I can not break FDE and google3 without having a chance to pre-fix them), but long term it would be nice if we could use them to do soft breaking changes. It's a potential argument for relaxing the template to not treat warnings as errors.

#include <functional>
#include <string>

#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_result_functions.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that the header corresponding to the cc file always came first... Am I just wrong? Is it supposed to come after the system headers like this? Or is that only in the non-test files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should; the style guide is explicit about this. But for reasons that aren't clear to me, clang-format in the engine repo keeps moving the header down in test files.

I keep meaning to look into it, then forgetting. I'll file a bug. Maybe it only understands _test, and not _unittests? But I swear it used to leave it alone.

@stuartmorgan-g stuartmorgan-g merged commit 60b8d00 into flutter:master Aug 20, 2020
@stuartmorgan-g stuartmorgan-g deleted the cpp-channel-api-references branch August 20, 2020 22:10
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 21, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 21, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 21, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 21, 2020
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants