GRPC C++  1.39.1
xds_server_builder.h
Go to the documentation of this file.
1 //
2 //
3 // Copyright 2020 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 //
18 
19 #ifndef GRPCPP_XDS_SERVER_BUILDER_H
20 #define GRPCPP_XDS_SERVER_BUILDER_H
21 
23 
24 #include <grpcpp/server_builder.h>
25 
26 namespace grpc {
27 namespace experimental {
28 
30  public:
32 
33  // \a uri contains the listening target associated with the notification. Note
34  // that a single target provided to XdsServerBuilder can get resolved to
35  // multiple listening addresses.
36  // The callback is invoked each time there is an update to the serving status.
37  // The API does not provide any guarantees around duplicate updates.
38  // Status::OK signifies that the server is serving, while a non-OK status
39  // signifies that the server is not serving.
40  virtual void OnServingStatusUpdate(std::string uri, grpc::Status status) = 0;
41 };
42 
44  public:
45  // It is the responsibility of the application to make sure that \a notifier
46  // outlasts the life of the server. Notifications will start being made
47  // asynchronously once `BuildAndStart()` has been called. Note that it is
48  // possible for notifications to be made before `BuildAndStart()` returns.
50  notifier_ = notifier;
51  }
52 
53  private:
54  // Called at the beginning of BuildAndStart().
55  ChannelArguments BuildChannelArgs() override {
57  grpc_channel_args c_channel_args = args.c_channel_args();
59  {OnServingStatusUpdate, notifier_}, &c_channel_args);
60  if (fetcher != nullptr) set_fetcher(fetcher);
61  return args;
62  }
63 
64  static void OnServingStatusUpdate(void* user_data, const char* uri,
65  grpc_status_code code,
66  const char* error_message) {
67  if (user_data == nullptr) return;
68  XdsServerServingStatusNotifierInterface* notifier =
69  static_cast<XdsServerServingStatusNotifierInterface*>(user_data);
70  notifier->OnServingStatusUpdate(
71  uri, grpc::Status(static_cast<StatusCode>(code), error_message));
72  }
73 
74  XdsServerServingStatusNotifierInterface* notifier_ = nullptr;
75 };
76 
77 } // namespace experimental
78 } // namespace grpc
79 
80 #endif /* GRPCPP_XDS_SERVER_BUILDER_H */
Options for channel creation.
Definition: channel_arguments.h:39
grpc_channel_args c_channel_args() const
Return (by value) a C grpc_channel_args structure which points to arguments owned by this ChannelArgu...
Definition: channel_arguments.h:115
A builder class for the creation and startup of grpc::Server instances.
Definition: server_builder.h:85
virtual ChannelArguments BuildChannelArgs()
Experimental API, subject to change.
void set_fetcher(grpc_server_config_fetcher *server_config_fetcher)
Experimental API, subject to change.
Definition: server_builder.h:346
Did it work? If it didn't, why?
Definition: status.h:31
Definition: xds_server_builder.h:43
void set_status_notifier(XdsServerServingStatusNotifierInterface *notifier)
Definition: xds_server_builder.h:49
virtual void OnServingStatusUpdate(std::string uri, grpc::Status status)=0
grpc_status_code
Definition: status.h:26
struct grpc_server_config_fetcher grpc_server_config_fetcher
Definition: grpc.h:422
GRPCAPI grpc_server_config_fetcher * grpc_server_config_fetcher_xds_create(grpc_server_xds_status_notifier notifier, const grpc_channel_args *args)
EXPERIMENTAL.
An Alarm posts the user-provided tag to its associated completion queue or invokes the user-provided ...
Definition: alarm.h:33
StatusCode
Definition: status_code_enum.h:24
An array of arguments that can be passed around.
Definition: grpc_types.h:132