1 /* 2 * 3 * Copyright 2016 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 GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_LOAD_BALANCER_API_H 20 #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_LOAD_BALANCER_API_H 21 22 #include <grpc/support/port_platform.h> 23 24 #include <grpc/slice_buffer.h> 25 26 #include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h" 27 #include "src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h" 28 #include "src/core/ext/filters/client_channel/lb_policy_factory.h" 29 30 #define GRPC_GRPCLB_SERVICE_NAME_MAX_LENGTH 128 31 32 typedef grpc_lb_v1_Server_ip_address_t grpc_grpclb_ip_address; 33 typedef grpc_lb_v1_LoadBalanceRequest grpc_grpclb_request; 34 typedef grpc_lb_v1_InitialLoadBalanceResponse grpc_grpclb_initial_response; 35 typedef grpc_lb_v1_Server grpc_grpclb_server; 36 typedef google_protobuf_Duration grpc_grpclb_duration; 37 typedef google_protobuf_Timestamp grpc_grpclb_timestamp; 38 39 typedef struct { 40 grpc_grpclb_server** servers; 41 size_t num_servers; 42 } grpc_grpclb_serverlist; 43 44 /** Create a request for a gRPC LB service under \a lb_service_name */ 45 grpc_grpclb_request* grpc_grpclb_request_create(const char* lb_service_name); 46 grpc_grpclb_request* grpc_grpclb_load_report_request_create_locked( 47 grpc_core::GrpcLbClientStats* client_stats); 48 49 /** Protocol Buffers v3-encode \a request */ 50 grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request* request); 51 52 /** Destroy \a request */ 53 void grpc_grpclb_request_destroy(grpc_grpclb_request* request); 54 55 /** Parse (ie, decode) the bytes in \a encoded_grpc_grpclb_response as a \a 56 * grpc_grpclb_initial_response */ 57 grpc_grpclb_initial_response* grpc_grpclb_initial_response_parse( 58 grpc_slice encoded_grpc_grpclb_response); 59 60 /** Parse the list of servers from an encoded \a grpc_grpclb_response */ 61 grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist( 62 grpc_slice encoded_grpc_grpclb_response); 63 64 /** Return a copy of \a sl. The caller is responsible for calling \a 65 * grpc_grpclb_destroy_serverlist on the returned copy. */ 66 grpc_grpclb_serverlist* grpc_grpclb_serverlist_copy( 67 const grpc_grpclb_serverlist* sl); 68 69 bool grpc_grpclb_serverlist_equals(const grpc_grpclb_serverlist* lhs, 70 const grpc_grpclb_serverlist* rhs); 71 72 bool grpc_grpclb_server_equals(const grpc_grpclb_server* lhs, 73 const grpc_grpclb_server* rhs); 74 75 /** Destroy \a serverlist */ 76 void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist* serverlist); 77 78 /** Compare \a lhs against \a rhs and return 0 if \a lhs and \a rhs are equal, 79 * < 0 if \a lhs represents a duration shorter than \a rhs and > 0 otherwise */ 80 int grpc_grpclb_duration_compare(const grpc_grpclb_duration* lhs, 81 const grpc_grpclb_duration* rhs); 82 83 grpc_millis grpc_grpclb_duration_to_millis(grpc_grpclb_duration* duration_pb); 84 85 /** Destroy \a initial_response */ 86 void grpc_grpclb_initial_response_destroy( 87 grpc_grpclb_initial_response* response); 88 89 #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_LOAD_BALANCER_API_H \ 90 */ 91