-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mobile: Switch to absl::AnyInvocable for engine_types.h (#33523)
This PR switches from std::function to absl::AnyInvocable since absl::AnyInvocable is more flexible, such that it does not have a copyability requirement. The change should mostly be backward compatible. This change also undeprecates setOnEngineRunning and introduces setOnEngineExit since it makes adding engine callbacks much nicer. This PR also removes the comment about Swift/C++ interop since that support has been removed in #33484. Signed-off-by: Fredy Wijaya <fredyw@google.com>
- Loading branch information
Showing
5 changed files
with
22 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,35 @@ | ||
#pragma once | ||
|
||
//================================================================================================== | ||
// READ THIS BEFORE UPDATING THIS FILE | ||
//================================================================================================== | ||
// Keep the code here (including the includes) as simple as possible given that this file will be | ||
// directly included by Swift and the Swift/C++ interop is far from complete. Including headers or | ||
// having code that is not supported by Swift may lead into weird compilation errors that can be | ||
// difficult to debug. | ||
// For more information, see | ||
// https://github.com/apple/swift/blob/swift-5.7.3-RELEASE/docs/CppInteroperability/CppInteroperabilityStatus.md | ||
|
||
#include <functional> | ||
#include <string> | ||
|
||
#include "source/common/common/base_logger.h" | ||
|
||
#include "absl/container/flat_hash_map.h" | ||
#include "absl/functional/any_invocable.h" | ||
#include "absl/strings/string_view.h" | ||
|
||
namespace Envoy { | ||
|
||
/** The callbacks for the Envoy Engine. */ | ||
struct EngineCallbacks { | ||
std::function<void()> on_engine_running_ = [] {}; | ||
std::function<void()> on_exit_ = [] {}; | ||
absl::AnyInvocable<void()> on_engine_running_ = [] {}; | ||
absl::AnyInvocable<void()> on_exit_ = [] {}; | ||
}; | ||
|
||
/** The callbacks for Envoy Logger. */ | ||
struct EnvoyLogger { | ||
std::function<void(Logger::Logger::Levels, const std::string&)> on_log_ = | ||
absl::AnyInvocable<void(Logger::Logger::Levels, const std::string&)> on_log_ = | ||
[](Logger::Logger::Levels, const std::string&) {}; | ||
std::function<void()> on_exit_ = [] {}; | ||
absl::AnyInvocable<void()> on_exit_ = [] {}; | ||
}; | ||
|
||
inline constexpr absl::string_view ENVOY_EVENT_TRACKER_API_NAME = "event_tracker_api"; | ||
|
||
/** The callbacks for Envoy Event Tracker. */ | ||
struct EnvoyEventTracker { | ||
std::function<void(const absl::flat_hash_map<std::string, std::string>&)> on_track_ = | ||
absl::AnyInvocable<void(const absl::flat_hash_map<std::string, std::string>&)> on_track_ = | ||
[](const absl::flat_hash_map<std::string, std::string>&) {}; | ||
std::function<void()> on_exit_ = [] {}; | ||
absl::AnyInvocable<void()> on_exit_ = [] {}; | ||
}; | ||
|
||
} // namespace Envoy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters