Skip to content

Commit

Permalink
format: use type alias (#12125)
Browse files Browse the repository at this point in the history
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 #11634

Signed-off-by: tomocy <[email protected]>
  • Loading branch information
tomocy authored Jul 20, 2020
1 parent e6c57fa commit 6f55a3e
Show file tree
Hide file tree
Showing 35 changed files with 126 additions and 57 deletions.
5 changes: 4 additions & 1 deletion include/envoy/config/grpc_mux.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <memory>

#include "envoy/common/exception.h"
#include "envoy/common/pure.h"
#include "envoy/config/subscription.h"
Expand Down Expand Up @@ -119,6 +121,7 @@ class GrpcMux {
using GrpcMuxPtr = std::unique_ptr<GrpcMux>;
using GrpcMuxSharedPtr = std::shared_ptr<GrpcMux>;

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

/**
Expand Down
4 changes: 4 additions & 0 deletions source/common/config/grpc_mux_impl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <memory>
#include <queue>
#include <unordered_map>

Expand Down Expand Up @@ -141,6 +142,9 @@ class GrpcMuxImpl : public GrpcMux,
const envoy::config::core::v3::ApiVersion transport_api_version_;
};

using GrpcMuxImplPtr = std::unique_ptr<GrpcMuxImpl>;
using GrpcMuxImplSharedPtr = std::shared_ptr<GrpcMuxImpl>;

class NullGrpcMuxImpl : public GrpcMux,
GrpcStreamCallbacks<envoy::service::discovery::v3::DiscoveryResponse> {
public:
Expand Down
5 changes: 4 additions & 1 deletion source/common/config/grpc_stream.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <functional>
#include <memory>

#include "envoy/common/random_generator.h"
#include "envoy/config/grpc_mux.h"
Expand All @@ -14,6 +15,8 @@
namespace Envoy {
namespace Config {

template <class ResponseProto> using ResponseProtoPtr = std::unique_ptr<ResponseProto>;

// Oversees communication for gRPC xDS implementations (parent to both regular xDS and delta
// xDS variants). Reestablishes the gRPC channel when necessary, and provides rate limiting of
// requests.
Expand Down Expand Up @@ -75,7 +78,7 @@ class GrpcStream : public Grpc::AsyncStreamCallbacks<ResponseProto>,
UNREFERENCED_PARAMETER(metadata);
}

void onReceiveMessage(std::unique_ptr<ResponseProto>&& message) override {
void onReceiveMessage(ResponseProtoPtr<ResponseProto>&& message) override {
// Reset here so that it starts with fresh backoff interval on next disconnect.
backoff_strategy_->reset();
// Sometimes during hot restarts this stat's value becomes inconsistent and will continue to
Expand Down
5 changes: 5 additions & 0 deletions source/common/config/grpc_subscription_impl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <memory>

#include "envoy/config/grpc_mux.h"
#include "envoy/config/subscription.h"
#include "envoy/event/dispatcher.h"
Expand Down Expand Up @@ -54,5 +56,8 @@ class GrpcSubscriptionImpl : public Subscription,
const bool is_aggregated_;
};

using GrpcSubscriptionImplPtr = std::unique_ptr<GrpcSubscriptionImpl>;
using GrpcSubscriptionImplSharedPtr = std::shared_ptr<GrpcSubscriptionImpl>;

} // namespace Config
} // namespace Envoy
9 changes: 7 additions & 2 deletions source/common/config/new_grpc_mux_impl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <memory>

#include "envoy/api/v2/discovery.pb.h"
#include "envoy/common/random_generator.h"
#include "envoy/common/token_bucket.h"
Expand Down Expand Up @@ -70,8 +72,10 @@ class NewGrpcMuxImpl
SubscriptionStuff& operator=(const SubscriptionStuff&) = delete;
};

using SubscriptionStuffPtr = std::unique_ptr<SubscriptionStuff>;

// for use in tests only
const absl::flat_hash_map<std::string, std::unique_ptr<SubscriptionStuff>>& subscriptions() {
const absl::flat_hash_map<std::string, SubscriptionStuffPtr>& subscriptions() {
return subscriptions_;
}

Expand Down Expand Up @@ -130,7 +134,7 @@ class NewGrpcMuxImpl
PausableAckQueue pausable_ack_queue_;

// Map key is type_url.
absl::flat_hash_map<std::string, std::unique_ptr<SubscriptionStuff>> subscriptions_;
absl::flat_hash_map<std::string, SubscriptionStuffPtr> subscriptions_;

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

using NewGrpcMuxImplPtr = std::unique_ptr<NewGrpcMuxImpl>;
using NewGrpcMuxImplSharedPtr = std::shared_ptr<NewGrpcMuxImpl>;

} // namespace Config
Expand Down
2 changes: 1 addition & 1 deletion source/common/grpc/async_client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ AsyncRequest* AsyncClientImpl::sendRaw(absl::string_view service_full_name,
const Http::AsyncClient::RequestOptions& options) {
auto* const async_request = new AsyncRequestImpl(
*this, service_full_name, method_name, std::move(request), callbacks, parent_span, options);
std::unique_ptr<AsyncStreamImpl> grpc_stream{async_request};
AsyncStreamImplPtr grpc_stream{async_request};

grpc_stream->initialize(true);
if (grpc_stream->hasResetStream()) {
Expand Down
6 changes: 5 additions & 1 deletion source/common/grpc/async_client_impl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <memory>

#include "envoy/config/core/v3/base.pb.h"
#include "envoy/config/core/v3/grpc_service.pb.h"
#include "envoy/grpc/async_client.h"
Expand All @@ -13,7 +15,9 @@ namespace Envoy {
namespace Grpc {

class AsyncRequestImpl;

class AsyncStreamImpl;
using AsyncStreamImplPtr = std::unique_ptr<AsyncStreamImpl>;

class AsyncClientImpl final : public RawAsyncClient {
public:
Expand All @@ -34,7 +38,7 @@ class AsyncClientImpl final : public RawAsyncClient {
Upstream::ClusterManager& cm_;
const std::string remote_cluster_name_;
const Protobuf::RepeatedPtrField<envoy::config::core::v3::HeaderValue> initial_metadata_;
std::list<std::unique_ptr<AsyncStreamImpl>> active_streams_;
std::list<AsyncStreamImplPtr> active_streams_;
TimeSource& time_source_;

friend class AsyncRequestImpl;
Expand Down
4 changes: 2 additions & 2 deletions source/common/grpc/google_async_client_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ AsyncRequest* GoogleAsyncClientImpl::sendRaw(absl::string_view service_full_name
const Http::AsyncClient::RequestOptions& options) {
auto* const async_request = new GoogleAsyncRequestImpl(
*this, service_full_name, method_name, std::move(request), callbacks, parent_span, options);
std::unique_ptr<GoogleAsyncStreamImpl> grpc_stream{async_request};
GoogleAsyncStreamImplPtr grpc_stream{async_request};

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

void GoogleAsyncStreamImpl::cleanup() {
Expand Down
7 changes: 6 additions & 1 deletion source/common/grpc/google_async_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ namespace Envoy {
namespace Grpc {

class GoogleAsyncStreamImpl;

using GoogleAsyncStreamImplPtr = std::unique_ptr<GoogleAsyncStreamImpl>;

class GoogleAsyncRequestImpl;

struct GoogleAsyncTag {
Expand Down Expand Up @@ -109,6 +112,8 @@ class GoogleAsyncClientThreadLocal : public ThreadLocal::ThreadLocalObject,
std::unordered_set<GoogleAsyncStreamImpl*> streams_;
};

using GoogleAsyncClientThreadLocalPtr = std::unique_ptr<GoogleAsyncClientThreadLocal>;

// Google gRPC client stats. TODO(htuch): consider how a wider set of stats collected by the
// library, such as the census related ones, can be externalized as needed.
struct GoogleAsyncClientStats {
Expand Down Expand Up @@ -189,7 +194,7 @@ class GoogleAsyncClientImpl final : public RawAsyncClient, Logger::Loggable<Logg
// the client if it gets destructed. The streams need to wait for their tags
// to drain from the CQ.
GoogleStubSharedPtr stub_;
std::list<std::unique_ptr<GoogleAsyncStreamImpl>> active_streams_;
std::list<GoogleAsyncStreamImplPtr> active_streams_;
const std::string stat_prefix_;
const Protobuf::RepeatedPtrField<envoy::config::core::v3::HeaderValue> initial_metadata_;
Stats::ScopeSharedPtr scope_;
Expand Down
11 changes: 7 additions & 4 deletions source/common/grpc/typed_async_client.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <chrono>
#include <memory>

#include "envoy/grpc/async_client.h"

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

template <typename Response> using ResponsePtr = std::unique_ptr<Response>;

/**
* Convenience subclasses for AsyncRequestCallbacks.
*/
template <typename Response> class AsyncRequestCallbacks : public RawAsyncRequestCallbacks {
public:
~AsyncRequestCallbacks() override = default;
virtual void onSuccess(std::unique_ptr<Response>&& response, Tracing::Span& span) PURE;
virtual void onSuccess(ResponsePtr<Response>&& response, Tracing::Span& span) PURE;

private:
void onSuccessRaw(Buffer::InstancePtr&& response, Tracing::Span& span) override {
auto message = std::unique_ptr<Response>(dynamic_cast<Response*>(
auto message = ResponsePtr<Response>(dynamic_cast<Response*>(
Internal::parseMessageUntyped(std::make_unique<Response>(), std::move(response))
.release()));
if (!message) {
Expand Down Expand Up @@ -138,11 +141,11 @@ class VersionedMethods {
template <typename Response> class AsyncStreamCallbacks : public RawAsyncStreamCallbacks {
public:
~AsyncStreamCallbacks() override = default;
virtual void onReceiveMessage(std::unique_ptr<Response>&& message) PURE;
virtual void onReceiveMessage(ResponsePtr<Response>&& message) PURE;

private:
bool onReceiveMessageRaw(Buffer::InstancePtr&& response) override {
auto message = std::unique_ptr<Response>(dynamic_cast<Response*>(
auto message = ResponsePtr<Response>(dynamic_cast<Response*>(
Internal::parseMessageUntyped(std::make_unique<Response>(), std::move(response))
.release()));
if (!message) {
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/access_loggers/grpc/config_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace GrpcCommon {
// Singleton registration via macro defined in envoy/singleton/manager.h
SINGLETON_MANAGER_REGISTRATION(grpc_access_logger_cache);

std::shared_ptr<GrpcCommon::GrpcAccessLoggerCache>
GrpcCommon::GrpcAccessLoggerCacheSharedPtr
getGrpcAccessLoggerCacheSingleton(Server::Configuration::FactoryContext& context) {
return context.singletonManager().getTyped<GrpcCommon::GrpcAccessLoggerCache>(
SINGLETON_MANAGER_REGISTERED_NAME(grpc_access_logger_cache), [&context] {
Expand Down
5 changes: 5 additions & 0 deletions source/extensions/access_loggers/grpc/grpc_access_log_impl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <memory>
#include <unordered_map>
#include <vector>

Expand Down Expand Up @@ -129,6 +130,8 @@ class GrpcAccessLoggerImpl : public GrpcAccessLogger {
const envoy::config::core::v3::ApiVersion transport_api_version_;
};

using GrpcAccessLoggerImplPtr = std::unique_ptr<GrpcAccessLoggerImpl>;

class GrpcAccessLoggerCacheImpl : public Singleton::Instance, public GrpcAccessLoggerCache {
public:
GrpcAccessLoggerCacheImpl(Grpc::AsyncClientManager& async_client_manager, Stats::Scope& scope,
Expand Down Expand Up @@ -158,6 +161,8 @@ class GrpcAccessLoggerCacheImpl : public Singleton::Instance, public GrpcAccessL
const LocalInfo::LocalInfo& local_info_;
};

using GrpcAccessLoggerCacheImplPtr = std::unique_ptr<GrpcAccessLoggerCacheImpl>;

} // namespace GrpcCommon
} // namespace AccessLoggers
} // namespace Extensions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <memory>
#include <unordered_map>
#include <vector>

Expand Down Expand Up @@ -59,6 +60,8 @@ class HttpGrpcAccessLog : public Common::ImplBase {
std::vector<std::string> filter_states_to_log_;
};

using HttpGrpcAccessLogPtr = std::unique_ptr<HttpGrpcAccessLog>;

} // namespace HttpGrpc
} // namespace AccessLoggers
} // namespace Extensions
Expand Down
3 changes: 3 additions & 0 deletions source/extensions/common/aws/region_provider.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <memory>

#include "envoy/common/pure.h"

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

using RegionProviderPtr = std::unique_ptr<RegionProvider>;
using RegionProviderSharedPtr = std::shared_ptr<RegionProvider>;

} // namespace Aws
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <chrono>
#include <cstdint>
#include <memory>
#include <string>
#include <vector>

Expand Down Expand Up @@ -73,6 +74,8 @@ class GrpcClientImpl : public Client,
const envoy::config::core::v3::ApiVersion transport_api_version_;
};

using GrpcClientImplPtr = std::unique_ptr<GrpcClientImpl>;

} // namespace ExtAuthz
} // namespace Common
} // namespace Filters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <memory>
#include <string>

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

using FilterPtr = std::unique_ptr<Filter>;

class FilterConfigPerRoute : public Router::RouteSpecificFilterConfig {
public:
FilterConfigPerRoute(
Expand Down
Loading

0 comments on commit 6f55a3e

Please sign in to comment.