Skip to content

Commit 6f55a3e

Browse files
authored
format: use type alias (envoyproxy#12125)
Commit Message: format: use type alias Additional Description: N/A Risk Level: N/A Testing: N/A Docs Changes: N/A Release Notes: N/A Part of envoyproxy#11634 Signed-off-by: tomocy <[email protected]>
1 parent e6c57fa commit 6f55a3e

35 files changed

+126
-57
lines changed

include/envoy/config/grpc_mux.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <memory>
4+
35
#include "envoy/common/exception.h"
46
#include "envoy/common/pure.h"
57
#include "envoy/config/subscription.h"
@@ -119,6 +121,7 @@ class GrpcMux {
119121
using GrpcMuxPtr = std::unique_ptr<GrpcMux>;
120122
using GrpcMuxSharedPtr = std::shared_ptr<GrpcMux>;
121123

124+
template <class ResponseProto> using ResponseProtoPtr = std::unique_ptr<ResponseProto>;
122125
/**
123126
* A grouping of callbacks that a GrpcMux should provide to its GrpcStream.
124127
*/
@@ -141,7 +144,7 @@ template <class ResponseProto> class GrpcStreamCallbacks {
141144
/**
142145
* For the GrpcStream to pass received protos to the context.
143146
*/
144-
virtual void onDiscoveryResponse(std::unique_ptr<ResponseProto>&& message,
147+
virtual void onDiscoveryResponse(ResponseProtoPtr<ResponseProto>&& message,
145148
ControlPlaneStats& control_plane_stats) PURE;
146149

147150
/**

source/common/config/grpc_mux_impl.h

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <memory>
34
#include <queue>
45
#include <unordered_map>
56

@@ -141,6 +142,9 @@ class GrpcMuxImpl : public GrpcMux,
141142
const envoy::config::core::v3::ApiVersion transport_api_version_;
142143
};
143144

145+
using GrpcMuxImplPtr = std::unique_ptr<GrpcMuxImpl>;
146+
using GrpcMuxImplSharedPtr = std::shared_ptr<GrpcMuxImpl>;
147+
144148
class NullGrpcMuxImpl : public GrpcMux,
145149
GrpcStreamCallbacks<envoy::service::discovery::v3::DiscoveryResponse> {
146150
public:

source/common/config/grpc_stream.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <functional>
4+
#include <memory>
45

56
#include "envoy/common/random_generator.h"
67
#include "envoy/config/grpc_mux.h"
@@ -14,6 +15,8 @@
1415
namespace Envoy {
1516
namespace Config {
1617

18+
template <class ResponseProto> using ResponseProtoPtr = std::unique_ptr<ResponseProto>;
19+
1720
// Oversees communication for gRPC xDS implementations (parent to both regular xDS and delta
1821
// xDS variants). Reestablishes the gRPC channel when necessary, and provides rate limiting of
1922
// requests.
@@ -75,7 +78,7 @@ class GrpcStream : public Grpc::AsyncStreamCallbacks<ResponseProto>,
7578
UNREFERENCED_PARAMETER(metadata);
7679
}
7780

78-
void onReceiveMessage(std::unique_ptr<ResponseProto>&& message) override {
81+
void onReceiveMessage(ResponseProtoPtr<ResponseProto>&& message) override {
7982
// Reset here so that it starts with fresh backoff interval on next disconnect.
8083
backoff_strategy_->reset();
8184
// Sometimes during hot restarts this stat's value becomes inconsistent and will continue to

source/common/config/grpc_subscription_impl.h

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <memory>
4+
35
#include "envoy/config/grpc_mux.h"
46
#include "envoy/config/subscription.h"
57
#include "envoy/event/dispatcher.h"
@@ -54,5 +56,8 @@ class GrpcSubscriptionImpl : public Subscription,
5456
const bool is_aggregated_;
5557
};
5658

59+
using GrpcSubscriptionImplPtr = std::unique_ptr<GrpcSubscriptionImpl>;
60+
using GrpcSubscriptionImplSharedPtr = std::shared_ptr<GrpcSubscriptionImpl>;
61+
5762
} // namespace Config
5863
} // namespace Envoy

source/common/config/new_grpc_mux_impl.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <memory>
4+
35
#include "envoy/api/v2/discovery.pb.h"
46
#include "envoy/common/random_generator.h"
57
#include "envoy/common/token_bucket.h"
@@ -70,8 +72,10 @@ class NewGrpcMuxImpl
7072
SubscriptionStuff& operator=(const SubscriptionStuff&) = delete;
7173
};
7274

75+
using SubscriptionStuffPtr = std::unique_ptr<SubscriptionStuff>;
76+
7377
// for use in tests only
74-
const absl::flat_hash_map<std::string, std::unique_ptr<SubscriptionStuff>>& subscriptions() {
78+
const absl::flat_hash_map<std::string, SubscriptionStuffPtr>& subscriptions() {
7579
return subscriptions_;
7680
}
7781

@@ -130,7 +134,7 @@ class NewGrpcMuxImpl
130134
PausableAckQueue pausable_ack_queue_;
131135

132136
// Map key is type_url.
133-
absl::flat_hash_map<std::string, std::unique_ptr<SubscriptionStuff>> subscriptions_;
137+
absl::flat_hash_map<std::string, SubscriptionStuffPtr> subscriptions_;
134138

135139
// Determines the order of initial discovery requests. (Assumes that subscriptions are added in
136140
// the order of Envoy's dependency ordering).
@@ -145,6 +149,7 @@ class NewGrpcMuxImpl
145149
const envoy::config::core::v3::ApiVersion transport_api_version_;
146150
};
147151

152+
using NewGrpcMuxImplPtr = std::unique_ptr<NewGrpcMuxImpl>;
148153
using NewGrpcMuxImplSharedPtr = std::shared_ptr<NewGrpcMuxImpl>;
149154

150155
} // namespace Config

source/common/grpc/async_client_impl.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ AsyncRequest* AsyncClientImpl::sendRaw(absl::string_view service_full_name,
3131
const Http::AsyncClient::RequestOptions& options) {
3232
auto* const async_request = new AsyncRequestImpl(
3333
*this, service_full_name, method_name, std::move(request), callbacks, parent_span, options);
34-
std::unique_ptr<AsyncStreamImpl> grpc_stream{async_request};
34+
AsyncStreamImplPtr grpc_stream{async_request};
3535

3636
grpc_stream->initialize(true);
3737
if (grpc_stream->hasResetStream()) {

source/common/grpc/async_client_impl.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <memory>
4+
35
#include "envoy/config/core/v3/base.pb.h"
46
#include "envoy/config/core/v3/grpc_service.pb.h"
57
#include "envoy/grpc/async_client.h"
@@ -13,7 +15,9 @@ namespace Envoy {
1315
namespace Grpc {
1416

1517
class AsyncRequestImpl;
18+
1619
class AsyncStreamImpl;
20+
using AsyncStreamImplPtr = std::unique_ptr<AsyncStreamImpl>;
1721

1822
class AsyncClientImpl final : public RawAsyncClient {
1923
public:
@@ -34,7 +38,7 @@ class AsyncClientImpl final : public RawAsyncClient {
3438
Upstream::ClusterManager& cm_;
3539
const std::string remote_cluster_name_;
3640
const Protobuf::RepeatedPtrField<envoy::config::core::v3::HeaderValue> initial_metadata_;
37-
std::list<std::unique_ptr<AsyncStreamImpl>> active_streams_;
41+
std::list<AsyncStreamImplPtr> active_streams_;
3842
TimeSource& time_source_;
3943

4044
friend class AsyncRequestImpl;

source/common/grpc/google_async_client_impl.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ AsyncRequest* GoogleAsyncClientImpl::sendRaw(absl::string_view service_full_name
112112
const Http::AsyncClient::RequestOptions& options) {
113113
auto* const async_request = new GoogleAsyncRequestImpl(
114114
*this, service_full_name, method_name, std::move(request), callbacks, parent_span, options);
115-
std::unique_ptr<GoogleAsyncStreamImpl> grpc_stream{async_request};
115+
GoogleAsyncStreamImplPtr grpc_stream{async_request};
116116

117117
grpc_stream->initialize(true);
118118
if (grpc_stream->callFailed()) {
@@ -378,7 +378,7 @@ void GoogleAsyncStreamImpl::deferredDelete() {
378378
// Hence, it is safe here to create a unique_ptr to this and transfer
379379
// ownership to dispatcher_.deferredDelete(). After this call, no further
380380
// methods may be invoked on this object.
381-
dispatcher_.deferredDelete(std::unique_ptr<GoogleAsyncStreamImpl>(this));
381+
dispatcher_.deferredDelete(GoogleAsyncStreamImplPtr(this));
382382
}
383383

384384
void GoogleAsyncStreamImpl::cleanup() {

source/common/grpc/google_async_client_impl.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ namespace Envoy {
2929
namespace Grpc {
3030

3131
class GoogleAsyncStreamImpl;
32+
33+
using GoogleAsyncStreamImplPtr = std::unique_ptr<GoogleAsyncStreamImpl>;
34+
3235
class GoogleAsyncRequestImpl;
3336

3437
struct GoogleAsyncTag {
@@ -109,6 +112,8 @@ class GoogleAsyncClientThreadLocal : public ThreadLocal::ThreadLocalObject,
109112
std::unordered_set<GoogleAsyncStreamImpl*> streams_;
110113
};
111114

115+
using GoogleAsyncClientThreadLocalPtr = std::unique_ptr<GoogleAsyncClientThreadLocal>;
116+
112117
// Google gRPC client stats. TODO(htuch): consider how a wider set of stats collected by the
113118
// library, such as the census related ones, can be externalized as needed.
114119
struct GoogleAsyncClientStats {
@@ -189,7 +194,7 @@ class GoogleAsyncClientImpl final : public RawAsyncClient, Logger::Loggable<Logg
189194
// the client if it gets destructed. The streams need to wait for their tags
190195
// to drain from the CQ.
191196
GoogleStubSharedPtr stub_;
192-
std::list<std::unique_ptr<GoogleAsyncStreamImpl>> active_streams_;
197+
std::list<GoogleAsyncStreamImplPtr> active_streams_;
193198
const std::string stat_prefix_;
194199
const Protobuf::RepeatedPtrField<envoy::config::core::v3::HeaderValue> initial_metadata_;
195200
Stats::ScopeSharedPtr scope_;

source/common/grpc/typed_async_client.h

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <chrono>
4+
#include <memory>
45

56
#include "envoy/grpc/async_client.h"
67

@@ -62,17 +63,19 @@ template <typename Request> class AsyncStream /* : public RawAsyncStream */ {
6263
RawAsyncStream* stream_{};
6364
};
6465

66+
template <typename Response> using ResponsePtr = std::unique_ptr<Response>;
67+
6568
/**
6669
* Convenience subclasses for AsyncRequestCallbacks.
6770
*/
6871
template <typename Response> class AsyncRequestCallbacks : public RawAsyncRequestCallbacks {
6972
public:
7073
~AsyncRequestCallbacks() override = default;
71-
virtual void onSuccess(std::unique_ptr<Response>&& response, Tracing::Span& span) PURE;
74+
virtual void onSuccess(ResponsePtr<Response>&& response, Tracing::Span& span) PURE;
7275

7376
private:
7477
void onSuccessRaw(Buffer::InstancePtr&& response, Tracing::Span& span) override {
75-
auto message = std::unique_ptr<Response>(dynamic_cast<Response*>(
78+
auto message = ResponsePtr<Response>(dynamic_cast<Response*>(
7679
Internal::parseMessageUntyped(std::make_unique<Response>(), std::move(response))
7780
.release()));
7881
if (!message) {
@@ -138,11 +141,11 @@ class VersionedMethods {
138141
template <typename Response> class AsyncStreamCallbacks : public RawAsyncStreamCallbacks {
139142
public:
140143
~AsyncStreamCallbacks() override = default;
141-
virtual void onReceiveMessage(std::unique_ptr<Response>&& message) PURE;
144+
virtual void onReceiveMessage(ResponsePtr<Response>&& message) PURE;
142145

143146
private:
144147
bool onReceiveMessageRaw(Buffer::InstancePtr&& response) override {
145-
auto message = std::unique_ptr<Response>(dynamic_cast<Response*>(
148+
auto message = ResponsePtr<Response>(dynamic_cast<Response*>(
146149
Internal::parseMessageUntyped(std::make_unique<Response>(), std::move(response))
147150
.release()));
148151
if (!message) {

source/extensions/access_loggers/grpc/config_utils.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace GrpcCommon {
1010
// Singleton registration via macro defined in envoy/singleton/manager.h
1111
SINGLETON_MANAGER_REGISTRATION(grpc_access_logger_cache);
1212

13-
std::shared_ptr<GrpcCommon::GrpcAccessLoggerCache>
13+
GrpcCommon::GrpcAccessLoggerCacheSharedPtr
1414
getGrpcAccessLoggerCacheSingleton(Server::Configuration::FactoryContext& context) {
1515
return context.singletonManager().getTyped<GrpcCommon::GrpcAccessLoggerCache>(
1616
SINGLETON_MANAGER_REGISTERED_NAME(grpc_access_logger_cache), [&context] {

source/extensions/access_loggers/grpc/grpc_access_log_impl.h

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <memory>
34
#include <unordered_map>
45
#include <vector>
56

@@ -129,6 +130,8 @@ class GrpcAccessLoggerImpl : public GrpcAccessLogger {
129130
const envoy::config::core::v3::ApiVersion transport_api_version_;
130131
};
131132

133+
using GrpcAccessLoggerImplPtr = std::unique_ptr<GrpcAccessLoggerImpl>;
134+
132135
class GrpcAccessLoggerCacheImpl : public Singleton::Instance, public GrpcAccessLoggerCache {
133136
public:
134137
GrpcAccessLoggerCacheImpl(Grpc::AsyncClientManager& async_client_manager, Stats::Scope& scope,
@@ -158,6 +161,8 @@ class GrpcAccessLoggerCacheImpl : public Singleton::Instance, public GrpcAccessL
158161
const LocalInfo::LocalInfo& local_info_;
159162
};
160163

164+
using GrpcAccessLoggerCacheImplPtr = std::unique_ptr<GrpcAccessLoggerCacheImpl>;
165+
161166
} // namespace GrpcCommon
162167
} // namespace AccessLoggers
163168
} // namespace Extensions

source/extensions/access_loggers/grpc/http_grpc_access_log_impl.h

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <memory>
34
#include <unordered_map>
45
#include <vector>
56

@@ -59,6 +60,8 @@ class HttpGrpcAccessLog : public Common::ImplBase {
5960
std::vector<std::string> filter_states_to_log_;
6061
};
6162

63+
using HttpGrpcAccessLogPtr = std::unique_ptr<HttpGrpcAccessLog>;
64+
6265
} // namespace HttpGrpc
6366
} // namespace AccessLoggers
6467
} // namespace Extensions

source/extensions/common/aws/region_provider.h

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#pragma once
22

3+
#include <memory>
4+
35
#include "envoy/common/pure.h"
46

57
#include "absl/types/optional.h"
@@ -23,6 +25,7 @@ class RegionProvider {
2325
virtual absl::optional<std::string> getRegion() PURE;
2426
};
2527

28+
using RegionProviderPtr = std::unique_ptr<RegionProvider>;
2629
using RegionProviderSharedPtr = std::shared_ptr<RegionProvider>;
2730

2831
} // namespace Aws

source/extensions/filters/common/ext_authz/ext_authz_grpc_impl.h

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <chrono>
44
#include <cstdint>
5+
#include <memory>
56
#include <string>
67
#include <vector>
78

@@ -73,6 +74,8 @@ class GrpcClientImpl : public Client,
7374
const envoy::config::core::v3::ApiVersion transport_api_version_;
7475
};
7576

77+
using GrpcClientImplPtr = std::unique_ptr<GrpcClientImpl>;
78+
7679
} // namespace ExtAuthz
7780
} // namespace Common
7881
} // namespace Filters

source/extensions/filters/http/grpc_http1_reverse_bridge/filter.h

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <memory>
34
#include <string>
45

56
#include "envoy/extensions/filters/http/grpc_http1_reverse_bridge/v3/config.pb.h"
@@ -48,6 +49,8 @@ class Filter : public Envoy::Http::PassThroughFilter {
4849
Buffer::OwnedImpl buffer_{};
4950
};
5051

52+
using FilterPtr = std::unique_ptr<Filter>;
53+
5154
class FilterConfigPerRoute : public Router::RouteSpecificFilterConfig {
5255
public:
5356
FilterConfigPerRoute(

0 commit comments

Comments
 (0)