Skip to content

Commit

Permalink
[fidl][cpp] Fix hlcpp conversion w/ unknown interactions
Browse files Browse the repository at this point in the history
We were missing Natural/HLCPP conversion rules for transport errors so
it wasn't possible to even build the hlcpp_conversion.h for FIDL
libraries with two-way flexible methods.

The type is the same between Natural and HLCPP bindings so the fix is
just to have a no-op conversion.

Change-Id: Ib4150db3bee55f98ba0f862e6072afed647ca767
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/934374
Fuchsia-Auto-Submit: Ian McKellar <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
API-Review: Adam Barth <[email protected]>
Reviewed-by: Mitchell Kember <[email protected]>
  • Loading branch information
ianloic authored and Rebase bot committed Oct 19, 2023
1 parent 71e1e93 commit 1ad1d43
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/fidl/cpp/fidl_cpp_hlcpp_conversion.api
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"pkg/fidl_cpp_hlcpp_conversion/include/lib/fidl/cpp/hlcpp_conversion.h": "a1a95b2ba032918a786ac281627b834f"
"pkg/fidl_cpp_hlcpp_conversion/include/lib/fidl/cpp/hlcpp_conversion.h": "d1bff0d7426fea5c89da263382bf5354"
}
11 changes: 11 additions & 0 deletions src/lib/fidl/cpp/include/lib/fidl/cpp/hlcpp_conversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <lib/fidl/cpp/box.h>
#include <lib/fidl/cpp/enum.h>
#include <lib/fidl/cpp/string.h>
#include <lib/fidl/cpp/transport_err.h>
#include <lib/fidl/cpp/wire/wire_types.h>

#include <optional>
Expand Down Expand Up @@ -79,6 +80,16 @@ struct HLCPPToNaturalTraits<HLCPP, std::enable_if_t<std::is_base_of_v<zx::object
final : public HLCPPToNaturalTraitsIdentical<HLCPP> {};
#endif

/* Natural to HLCPP types for transport errors */
template <>
struct NaturalToHLCPPTraits<::fidl::internal::TransportErr> final
: public NaturalToHLCPPTraitsIdentical<::fidl::internal::TransportErr> {};

/* HLCPP to Natural types for transport errors */
template <>
struct HLCPPToNaturalTraits<::fidl::internal::TransportErr> final
: public HLCPPToNaturalTraitsIdentical<::fidl::internal::TransportErr> {};

/* Natural to HLCPP traits for strings. */
template <>
struct NaturalToHLCPPTraits<std::string> final : public NaturalToHLCPPTraitsIdentical<std::string> {
Expand Down
1 change: 1 addition & 0 deletions src/lib/fidl/cpp/tests/hlcpp_conversion/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ test("fidl_hlcpp_conversion_tests_bin") {
deps = [
"fidl:test.enums.abc_cpp_hlcpp_conversion",
"fidl:test.enums.xyz_cpp_hlcpp_conversion",
"fidl:test.protocols_cpp_hlcpp_conversion",
"//sdk/testing/fidl/protocols_tests:test.protocol.connector_cpp",
"//sdk/testing/fidl/protocols_tests:test.protocol.connector_cpp_hlcpp_conversion",
"//sdk/testing/fidl/types_tests:test.types_cpp_hlcpp_conversion",
Expand Down
6 changes: 6 additions & 0 deletions src/lib/fidl/cpp/tests/hlcpp_conversion/fidl/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ fidl("test.enums.xyz") {
sources = [ "enums.xyz.test.fidl" ]
enable_hlcpp = true
}

fidl("test.protocols") {
testonly = true
sources = [ "protocols.test.fidl" ]
enable_hlcpp = true
}
100 changes: 100 additions & 0 deletions src/lib/fidl/cpp/tests/hlcpp_conversion/fidl/protocols.test.fidl
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright 2023 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

library test.protocols;

closed protocol ClosedProtocol {
strict StrictOneWay(struct {
arg int32;
});

strict StrictTwoWay(struct {
arg int32;
}) -> (struct {
res int32;
});

strict StrictTwoWayError(struct {
arg int32;
}) -> (struct {
res int32;
}) error int32;

strict -> OnStrictEvent(struct {
arg int32;
});
};

ajar protocol AjarProtocol {
strict StrictOneWay(struct {
arg int32;
});

strict StrictTwoWay(struct {
arg int32;
}) -> (struct {
res int32;
});

strict StrictTwoWayError(struct {
arg int32;
}) -> (struct {
res int32;
}) error int32;

strict -> OnStrictEvent(struct {
arg int32;
});

flexible FlexibleOneWay(struct {
arg int32;
});

flexible -> OnFlexibleEvent(struct {
arg int32;
});
};


open protocol OpenProtocol {
strict StrictOneWay(struct {
arg int32;
});

strict StrictTwoWay(struct {
arg int32;
}) -> (struct {
res int32;
});

strict StrictTwoWayError(struct {
arg int32;
}) -> (struct {
res int32;
}) error int32;

strict -> OnStrictEvent(struct {
arg int32;
});

flexible FlexibleOneWay(struct {
arg int32;
});

flexible -> OnFlexibleEvent(struct {
arg int32;
});

flexible FlexibleTwoWay(struct {
arg int32;
}) -> (struct {
res int32;
});

flexible FlexibleTwoWayError(struct {
arg int32;
}) -> (struct {
res int32;
}) error int32;
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <fidl/test.protocols/cpp/hlcpp_conversion.h>
#include <fidl/test.types/cpp/hlcpp_conversion.h>
#include <lib/fidl/cpp/wire/channel.h>

Expand Down

0 comments on commit 1ad1d43

Please sign in to comment.