Skip to content

Commit 47b9a57

Browse files
authored
Remove g_glip and class GrpcLibraryInterface (grpc#30414)
* Remove `g_glip` and `class GrpcLibraryInterface` * Update * Update * Update * Automated change: Fix sanity tests (#20) * Update * Update * Update * Test * Fix * Revert "Test" This reverts commit 2f5c77e. * More fix * More fix * More fix * Minor fix * Revert "Minor fix" This reverts commit 1ee3ae4. * Revert "More fix" This reverts commit 1fc2348. * Revert "More fix" This reverts commit 851393c. * Revert "More fix" This reverts commit ed342a5. * Revert "Fix" This reverts commit 286ad8e.
1 parent cf63689 commit 47b9a57

32 files changed

+57
-182
lines changed

BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,6 @@ GRPCXX_PUBLIC_HDRS = [
400400
"include/grpc++/impl/codegen/config.h",
401401
"include/grpc++/impl/codegen/core_codegen_interface.h",
402402
"include/grpc++/impl/codegen/create_auth_context.h",
403-
"include/grpc++/impl/codegen/grpc_library.h",
404403
"include/grpc++/impl/codegen/metadata_map.h",
405404
"include/grpc++/impl/codegen/method_handler_impl.h",
406405
"include/grpc++/impl/codegen/rpc_method.h",
@@ -437,7 +436,6 @@ GRPCXX_PUBLIC_HDRS = [
437436
"include/grpcpp/impl/codegen/core_codegen_interface.h",
438437
"include/grpcpp/impl/codegen/create_auth_context.h",
439438
"include/grpcpp/impl/codegen/delegating_channel.h",
440-
"include/grpcpp/impl/codegen/grpc_library.h",
441439
"include/grpcpp/impl/codegen/intercepted_channel.h",
442440
"include/grpcpp/impl/codegen/interceptor_common.h",
443441
"include/grpcpp/impl/codegen/interceptor.h",

CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build_autogenerated.yaml

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gRPC-C++.podspec

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

include/grpc++/impl/codegen/grpc_library.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

include/grpcpp/alarm.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@
2626
#include <grpc/grpc.h>
2727
#include <grpcpp/completion_queue.h>
2828
#include <grpcpp/impl/codegen/completion_queue_tag.h>
29-
#include <grpcpp/impl/codegen/grpc_library.h>
3029
#include <grpcpp/impl/grpc_library.h>
3130
#include <grpcpp/support/time.h>
3231

3332
namespace grpc {
3433

35-
class Alarm : private grpc::GrpcLibraryCodegen {
34+
class Alarm : private grpc::internal::GrpcLibrary {
3635
public:
3736
/// Create an unset completion queue alarm
3837
Alarm();

include/grpcpp/channel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
#include <grpcpp/completion_queue.h>
2626
#include <grpcpp/impl/call.h>
2727
#include <grpcpp/impl/channel_interface.h>
28-
#include <grpcpp/impl/codegen/grpc_library.h>
2928
#include <grpcpp/impl/codegen/sync.h>
29+
#include <grpcpp/impl/grpc_library.h>
3030
#include <grpcpp/support/client_interceptor.h>
3131
#include <grpcpp/support/config.h>
3232

@@ -54,7 +54,7 @@ void ChannelResetConnectionBackoff(Channel* channel);
5454
class Channel final : public grpc::ChannelInterface,
5555
public grpc::internal::CallHook,
5656
public std::enable_shared_from_this<Channel>,
57-
private grpc::GrpcLibraryCodegen {
57+
private grpc::internal::GrpcLibrary {
5858
public:
5959
~Channel() override;
6060

include/grpcpp/completion_queue.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@
3434

3535
#include <list>
3636

37-
#include <grpc/support/atm.h>
37+
#include <grpc/impl/codegen/atm.h>
3838
#include <grpcpp/impl/codegen/completion_queue_tag.h>
3939
#include <grpcpp/impl/codegen/core_codegen_interface.h>
40-
#include <grpcpp/impl/codegen/grpc_library.h>
40+
#include <grpcpp/impl/codegen/rpc_service_method.h>
41+
#include <grpcpp/impl/codegen/status.h>
4142
#include <grpcpp/impl/codegen/sync.h>
42-
#include <grpcpp/impl/rpc_service_method.h>
43-
#include <grpcpp/support/status.h>
44-
#include <grpcpp/support/time.h>
43+
#include <grpcpp/impl/codegen/time.h>
44+
#include <grpcpp/impl/grpc_library.h>
4545

4646
struct grpc_completion_queue;
4747

@@ -99,7 +99,7 @@ extern CoreCodegenInterface* g_core_codegen_interface;
9999
/// src/core/lib/surface/completion_queue.h).
100100
/// See \ref doc/cpp/perf_notes.md for notes on best practices for high
101101
/// performance servers.
102-
class CompletionQueue : private grpc::GrpcLibraryCodegen {
102+
class CompletionQueue : private grpc::internal::GrpcLibrary {
103103
public:
104104
/// Default constructor. Implicitly creates a \a grpc_completion_queue
105105
/// instance.

include/grpcpp/impl/codegen/grpc_library.h

Lines changed: 0 additions & 67 deletions
This file was deleted.

include/grpcpp/impl/grpc_library.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,34 @@
2424
#include <grpc/grpc.h>
2525
#include <grpcpp/impl/codegen/config.h>
2626
#include <grpcpp/impl/codegen/core_codegen.h>
27-
#include <grpcpp/impl/codegen/grpc_library.h> // IWYU pragma: export
2827

2928
namespace grpc {
3029

3130
namespace internal {
32-
class GrpcLibrary final : public GrpcLibraryInterface {
31+
32+
/// Classes that require gRPC to be initialized should inherit from this class.
33+
class GrpcLibrary {
3334
public:
34-
void init() override { grpc_init(); }
35-
void shutdown() override { grpc_shutdown(); }
35+
explicit GrpcLibrary(bool call_grpc_init = true) : grpc_init_called_(false) {
36+
if (call_grpc_init) {
37+
grpc_init();
38+
grpc_init_called_ = true;
39+
}
40+
}
41+
virtual ~GrpcLibrary() {
42+
if (grpc_init_called_) {
43+
grpc_shutdown();
44+
}
45+
}
46+
47+
private:
48+
bool grpc_init_called_;
3649
};
3750

3851
/// Instantiating this class ensures the proper initialization of gRPC.
3952
class GrpcLibraryInitializer final {
4053
public:
4154
GrpcLibraryInitializer() {
42-
if (grpc::g_glip == nullptr) {
43-
static auto* const g_gli = new GrpcLibrary();
44-
grpc::g_glip = g_gli;
45-
}
4655
if (grpc::g_core_codegen_interface == nullptr) {
4756
static auto* const g_core_codegen = new CoreCodegen();
4857
grpc::g_core_codegen_interface = g_core_codegen;

include/grpcpp/resource_quota.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
struct grpc_resource_quota;
2323

24-
#include <grpcpp/impl/codegen/grpc_library.h>
24+
#include <grpcpp/impl/grpc_library.h>
2525
#include <grpcpp/support/config.h>
2626

2727
namespace grpc {
@@ -31,7 +31,7 @@ namespace grpc {
3131
/// or a client channel (via \a ChannelArguments).
3232
/// gRPC will attempt to keep memory and threads used by all attached entities
3333
/// below the ResourceQuota bound.
34-
class ResourceQuota final : private grpc::GrpcLibraryCodegen {
34+
class ResourceQuota final : private grpc::internal::GrpcLibrary {
3535
public:
3636
/// \param name - a unique name for this ResourceQuota.
3737
explicit ResourceQuota(const std::string& name);

include/grpcpp/security/authorization_policy_provider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <grpc/grpc_security.h>
2121
#include <grpc/status.h>
22-
#include <grpcpp/impl/codegen/grpc_library.h>
22+
#include <grpcpp/impl/codegen/status.h>
2323

2424
namespace grpc {
2525
namespace experimental {

include/grpcpp/security/credentials.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
#include <grpc/grpc_security_constants.h>
2727
#include <grpcpp/channel.h>
28-
#include <grpcpp/impl/codegen/grpc_library.h>
28+
#include <grpcpp/impl/grpc_library.h>
2929
#include <grpcpp/security/auth_context.h>
3030
#include <grpcpp/security/tls_credentials_options.h>
3131
#include <grpcpp/support/channel_arguments.h>
@@ -66,7 +66,7 @@ std::shared_ptr<ChannelCredentials> XdsCredentials(
6666
/// for all the calls on that channel.
6767
///
6868
/// \see https://grpc.io/docs/guides/auth.html
69-
class ChannelCredentials : private grpc::GrpcLibraryCodegen {
69+
class ChannelCredentials : private grpc::internal::GrpcLibrary {
7070
public:
7171
ChannelCredentials();
7272
~ChannelCredentials() override;
@@ -123,7 +123,7 @@ class ChannelCredentials : private grpc::GrpcLibraryCodegen {
123123
/// authenticate with a server for a given call on a channel.
124124
///
125125
/// \see https://grpc.io/docs/guides/auth.html
126-
class CallCredentials : private grpc::GrpcLibraryCodegen {
126+
class CallCredentials : private grpc::internal::GrpcLibrary {
127127
public:
128128
CallCredentials();
129129
~CallCredentials() override;

include/grpcpp/security/server_credentials.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <vector>
2424

2525
#include <grpc/grpc_security_constants.h>
26+
#include <grpcpp/impl/grpc_library.h>
2627
#include <grpcpp/security/auth_metadata_processor.h>
2728
#include <grpcpp/security/tls_credentials_options.h>
2829
#include <grpcpp/support/config.h>
@@ -65,7 +66,7 @@ std::shared_ptr<ServerCredentials> XdsServerCredentials(
6566
const std::shared_ptr<ServerCredentials>& fallback_credentials);
6667

6768
/// Wrapper around \a grpc_server_credentials, a way to authenticate a server.
68-
class ServerCredentials : private grpc::GrpcLibraryCodegen {
69+
class ServerCredentials : private grpc::internal::GrpcLibrary {
6970
public:
7071
ServerCredentials();
7172
~ServerCredentials() override;

include/grpcpp/security/tls_certificate_provider.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#include <grpc/grpc_security_constants.h>
2525
#include <grpc/status.h>
2626
#include <grpc/support/log.h>
27-
#include <grpcpp/impl/codegen/grpc_library.h>
2827
#include <grpcpp/support/config.h>
2928

3029
namespace grpc {

include/grpcpp/security/tls_certificate_verifier.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <grpc/grpc_security_constants.h>
2727
#include <grpc/status.h>
2828
#include <grpc/support/log.h>
29-
#include <grpcpp/impl/codegen/grpc_library.h>
3029
#include <grpcpp/impl/codegen/sync.h>
3130
#include <grpcpp/impl/grpc_library.h>
3231
#include <grpcpp/support/config.h>

include/grpcpp/server.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
#include <grpcpp/completion_queue.h>
3232
#include <grpcpp/health_check_service_interface.h>
3333
#include <grpcpp/impl/call.h>
34-
#include <grpcpp/impl/codegen/grpc_library.h>
3534
#include <grpcpp/impl/codegen/server_interface.h>
35+
#include <grpcpp/impl/grpc_library.h>
3636
#include <grpcpp/impl/rpc_service_method.h>
3737
#include <grpcpp/security/server_credentials.h>
3838
#include <grpcpp/support/channel_arguments.h>
@@ -55,7 +55,7 @@ class ExternalConnectionAcceptorImpl;
5555
///
5656
/// Use a \a grpc::ServerBuilder to create, configure, and start
5757
/// \a Server instances.
58-
class Server : public ServerInterface, private GrpcLibraryCodegen {
58+
class Server : public ServerInterface, private internal::GrpcLibrary {
5959
public:
6060
~Server() ABSL_LOCKS_EXCLUDED(mu_) override;
6161

0 commit comments

Comments
 (0)