Skip to content

Commit

Permalink
Reintroduce: Avoid fully qualifying namespaces (and add check) (grpc#…
Browse files Browse the repository at this point in the history
…28917)

Based on a handful of https://abseil.io/tips, it's generally advised to
only fully-qualify namespaces when in a `using` statement, or when it's
otherwise required for compilation. In all other cases, the general
recommendation is to not fully-qualify.

This change fixes most `grpc.*` namespace uses. There are potential
challenges in trying to make blanket changes to non-gRPC namespace uses,
such as `::testing`, since there is also a `grpc::testing` namespace.
  • Loading branch information
drfloob authored Feb 19, 2022
1 parent bbfcb7c commit 85189b2
Show file tree
Hide file tree
Showing 135 changed files with 1,328 additions and 1,232 deletions.
17 changes: 8 additions & 9 deletions include/grpcpp/alarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

namespace grpc {

class Alarm : private ::grpc::GrpcLibraryCodegen {
class Alarm : private grpc::GrpcLibraryCodegen {
public:
/// Create an unset completion queue alarm
Alarm();
Expand All @@ -48,8 +48,8 @@ class Alarm : private ::grpc::GrpcLibraryCodegen {
/// internal::GrpcLibraryInitializer instance would need to be introduced
/// here. \endinternal.
template <typename T>
Alarm(::grpc::CompletionQueue* cq, const T& deadline, void* tag) : Alarm() {
SetInternal(cq, ::grpc::TimePoint<T>(deadline).raw_time(), tag);
Alarm(grpc::CompletionQueue* cq, const T& deadline, void* tag) : Alarm() {
SetInternal(cq, grpc::TimePoint<T>(deadline).raw_time(), tag);
}

/// Trigger an alarm instance on completion queue \a cq at the specified time.
Expand All @@ -61,8 +61,8 @@ class Alarm : private ::grpc::GrpcLibraryCodegen {
// setting an immediate deadline. Such usage allows synchronizing an external
// event with an application's \a grpc::CompletionQueue::Next loop.
template <typename T>
void Set(::grpc::CompletionQueue* cq, const T& deadline, void* tag) {
SetInternal(cq, ::grpc::TimePoint<T>(deadline).raw_time(), tag);
void Set(grpc::CompletionQueue* cq, const T& deadline, void* tag) {
SetInternal(cq, grpc::TimePoint<T>(deadline).raw_time(), tag);
}

/// Alarms aren't copyable.
Expand All @@ -86,15 +86,14 @@ class Alarm : private ::grpc::GrpcLibraryCodegen {
/// (false)
template <typename T>
void Set(const T& deadline, std::function<void(bool)> f) {
SetInternal(::grpc::TimePoint<T>(deadline).raw_time(), std::move(f));
SetInternal(grpc::TimePoint<T>(deadline).raw_time(), std::move(f));
}

private:
void SetInternal(::grpc::CompletionQueue* cq, gpr_timespec deadline,
void* tag);
void SetInternal(grpc::CompletionQueue* cq, gpr_timespec deadline, void* tag);
void SetInternal(gpr_timespec deadline, std::function<void(bool)> f);

::grpc::internal::CompletionQueueTag* alarm_;
grpc::internal::CompletionQueueTag* alarm_;
};

} // namespace grpc
Expand Down
40 changes: 20 additions & 20 deletions include/grpcpp/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ void ChannelResetConnectionBackoff(Channel* channel);
} // namespace experimental

/// Channels represent a connection to an endpoint. Created by \a CreateChannel.
class Channel final : public ::grpc::ChannelInterface,
public ::grpc::internal::CallHook,
class Channel final : public grpc::ChannelInterface,
public grpc::internal::CallHook,
public std::enable_shared_from_this<Channel>,
private ::grpc::GrpcLibraryCodegen {
private grpc::GrpcLibraryCodegen {
public:
~Channel() override;

Expand All @@ -71,38 +71,38 @@ class Channel final : public ::grpc::ChannelInterface,

private:
template <class InputMessage, class OutputMessage>
friend class ::grpc::internal::BlockingUnaryCallImpl;
friend class ::grpc::testing::ChannelTestPeer;
friend class grpc::internal::BlockingUnaryCallImpl;
friend class grpc::testing::ChannelTestPeer;
friend void experimental::ChannelResetConnectionBackoff(Channel* channel);
friend std::shared_ptr<Channel> grpc::CreateChannelInternal(
const std::string& host, grpc_channel* c_channel,
std::vector<std::unique_ptr<
::grpc::experimental::ClientInterceptorFactoryInterface>>
grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators);
friend class ::grpc::internal::InterceptedChannel;
friend class grpc::internal::InterceptedChannel;
Channel(const std::string& host, grpc_channel* c_channel,
std::vector<std::unique_ptr<
::grpc::experimental::ClientInterceptorFactoryInterface>>
grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators);

::grpc::internal::Call CreateCall(const ::grpc::internal::RpcMethod& method,
::grpc::ClientContext* context,
::grpc::CompletionQueue* cq) override;
void PerformOpsOnCall(::grpc::internal::CallOpSetInterface* ops,
::grpc::internal::Call* call) override;
grpc::internal::Call CreateCall(const grpc::internal::RpcMethod& method,
grpc::ClientContext* context,
grpc::CompletionQueue* cq) override;
void PerformOpsOnCall(grpc::internal::CallOpSetInterface* ops,
grpc::internal::Call* call) override;
void* RegisterMethod(const char* method) override;

void NotifyOnStateChangeImpl(grpc_connectivity_state last_observed,
gpr_timespec deadline,
::grpc::CompletionQueue* cq, void* tag) override;
gpr_timespec deadline, grpc::CompletionQueue* cq,
void* tag) override;
bool WaitForStateChangeImpl(grpc_connectivity_state last_observed,
gpr_timespec deadline) override;

::grpc::CompletionQueue* CallbackCQ() override;
grpc::CompletionQueue* CallbackCQ() override;

::grpc::internal::Call CreateCallInternal(
const ::grpc::internal::RpcMethod& method, ::grpc::ClientContext* context,
::grpc::CompletionQueue* cq, size_t interceptor_pos) override;
grpc::internal::Call CreateCallInternal(
const grpc::internal::RpcMethod& method, grpc::ClientContext* context,
grpc::CompletionQueue* cq, size_t interceptor_pos) override;

const std::string host_;
grpc_channel* const c_channel_; // owned
Expand All @@ -117,7 +117,7 @@ class Channel final : public ::grpc::ChannelInterface,
std::atomic<CompletionQueue*> callback_cq_{nullptr};

std::vector<
std::unique_ptr<::grpc::experimental::ClientInterceptorFactoryInterface>>
std::unique_ptr<grpc::experimental::ClientInterceptorFactoryInterface>>
interceptor_creators_;
};

Expand Down
2 changes: 1 addition & 1 deletion include/grpcpp/ext/proto_server_reflection_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ServerInitializer;

namespace reflection {

class ProtoServerReflectionPlugin : public ::grpc::ServerBuilderPlugin {
class ProtoServerReflectionPlugin : public grpc::ServerBuilderPlugin {
public:
ProtoServerReflectionPlugin();
::std::string name() override;
Expand Down
4 changes: 2 additions & 2 deletions include/grpcpp/ext/server_load_reporting.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ namespace experimental {
class LoadReportingServiceServerBuilderOption
: public grpc::ServerBuilderOption {
public:
void UpdateArguments(::grpc::ChannelArguments* args) override;
void UpdatePlugins(std::vector<std::unique_ptr<::grpc::ServerBuilderPlugin>>*
void UpdateArguments(grpc::ChannelArguments* args) override;
void UpdatePlugins(std::vector<std::unique_ptr<grpc::ServerBuilderPlugin>>*
plugins) override;
};

Expand Down
8 changes: 4 additions & 4 deletions include/grpcpp/generic/generic_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class TemplatedGenericStub final {
/// succeeded (i.e. the call won't proceed if the return value is nullptr).
std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>>
PrepareCall(ClientContext* context, const std::string& method,
::grpc::CompletionQueue* cq) {
grpc::CompletionQueue* cq) {
return CallInternal(channel_.get(), context, method, /*options=*/{}, cq,
false, nullptr);
}
Expand All @@ -64,7 +64,7 @@ class TemplatedGenericStub final {
/// succeeded (i.e. the call won't proceed if the return value is nullptr).
std::unique_ptr<ClientAsyncResponseReader<ResponseType>> PrepareUnaryCall(
ClientContext* context, const std::string& method,
const RequestType& request, ::grpc::CompletionQueue* cq) {
const RequestType& request, grpc::CompletionQueue* cq) {
return std::unique_ptr<ClientAsyncResponseReader<ResponseType>>(
internal::ClientAsyncResponseReaderHelper::Create<ResponseType>(
channel_.get(), cq,
Expand All @@ -82,7 +82,7 @@ class TemplatedGenericStub final {
/// succeeded (i.e. the call won't proceed if the return value is nullptr).
std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>> Call(
ClientContext* context, const std::string& method,
::grpc::CompletionQueue* cq, void* tag) {
grpc::CompletionQueue* cq, void* tag) {
return CallInternal(channel_.get(), context, method, /*options=*/{}, cq,
true, tag);
}
Expand Down Expand Up @@ -157,7 +157,7 @@ class TemplatedGenericStub final {
std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>>
CallInternal(grpc::ChannelInterface* channel, ClientContext* context,
const std::string& method, StubOptions options,
::grpc::CompletionQueue* cq, bool start, void* tag) {
grpc::CompletionQueue* cq, bool start, void* tag) {
return std::unique_ptr<ClientAsyncReaderWriter<RequestType, ResponseType>>(
internal::ClientAsyncReaderWriterFactory<RequestType, ResponseType>::
Create(channel, cq,
Expand Down
8 changes: 4 additions & 4 deletions include/grpcpp/impl/codegen/async_generic_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class AsyncGenericService final {

void RequestCall(GenericServerContext* ctx,
GenericServerAsyncReaderWriter* reader_writer,
::grpc::CompletionQueue* call_cq,
::grpc::ServerCompletionQueue* notification_cq, void* tag);
grpc::CompletionQueue* call_cq,
grpc::ServerCompletionQueue* notification_cq, void* tag);

private:
friend class grpc::Server;
Expand All @@ -92,7 +92,7 @@ class GenericCallbackServerContext final : public grpc::CallbackServerContext {
const std::string& host() const { return host_; }

private:
friend class ::grpc::Server;
friend class grpc::Server;

std::string method_;
std::string host_;
Expand Down Expand Up @@ -124,7 +124,7 @@ class CallbackGenericService {

internal::CallbackBidiHandler<ByteBuffer, ByteBuffer>* Handler() {
return new internal::CallbackBidiHandler<ByteBuffer, ByteBuffer>(
[this](::grpc::CallbackServerContext* ctx) {
[this](grpc::CallbackServerContext* ctx) {
return CreateReactor(static_cast<GenericCallbackServerContext*>(ctx));
});
}
Expand Down
Loading

0 comments on commit 85189b2

Please sign in to comment.