blob: 968f7d278ae86649d29445f6acbc9cec4f0bb53c [file] [log] [blame]
Craig Tillereb841e22016-02-11 15:49:16 -08001/*
2 *
3 * Copyright 2016, Google Inc.
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following disclaimer
14 * in the documentation and/or other materials provided with the
15 * distribution.
16 * * Neither the name of Google Inc. nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 */
33
Craig Tiller9c84fc32016-03-28 17:11:55 -070034#ifndef GRPC_CORE_EXT_LB_POLICY_GRPCLB_LOAD_BALANCER_API_H
35#define GRPC_CORE_EXT_LB_POLICY_GRPCLB_LOAD_BALANCER_API_H
Craig Tillereb841e22016-02-11 15:49:16 -080036
37#include <grpc/support/slice_buffer.h>
38
Craig Tillerd4c98332016-03-31 13:45:47 -070039#include "src/core/ext/client_config/lb_policy_factory.h"
Craig Tiller4a6dad32016-04-01 13:51:14 -070040#include "src/core/ext/lb_policy/grpclb/proto/grpc/lb/v0/load_balancer.pb.h"
Craig Tillereb841e22016-02-11 15:49:16 -080041
42#ifdef __cplusplus
43extern "C" {
44#endif
45
46#define GRPC_GRPCLB_SERVICE_NAME_MAX_LENGTH 128
47
48typedef grpc_lb_v0_LoadBalanceRequest grpc_grpclb_request;
49typedef grpc_lb_v0_LoadBalanceResponse grpc_grpclb_response;
50typedef grpc_lb_v0_Server grpc_grpclb_server;
51typedef grpc_lb_v0_Duration grpc_grpclb_duration;
52typedef struct grpc_grpclb_serverlist {
53 grpc_grpclb_server **servers;
54 size_t num_servers;
55 grpc_grpclb_duration expiration_interval;
56} grpc_grpclb_serverlist;
57
58/** Create a request for a gRPC LB service under \a lb_service_name */
59grpc_grpclb_request *grpc_grpclb_request_create(const char *lb_service_name);
60
61/** Protocol Buffers v3-encode \a request */
62gpr_slice grpc_grpclb_request_encode(const grpc_grpclb_request *request);
63
64/** Destroy \a request */
65void grpc_grpclb_request_destroy(grpc_grpclb_request *request);
66
67/** Parse (ie, decode) the bytes in \a encoded_response as a \a
68 * grpc_grpclb_response */
69grpc_grpclb_response *grpc_grpclb_response_parse(gpr_slice encoded_response);
70
71/** Destroy \a serverlist */
72void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist *serverlist);
73
74/** Parse the list of servers from an encoded \a grpc_grpclb_response */
75grpc_grpclb_serverlist *grpc_grpclb_response_parse_serverlist(
76 gpr_slice encoded_response);
77
78/** Destroy \a response */
79void grpc_grpclb_response_destroy(grpc_grpclb_response *response);
80
81#ifdef __cplusplus
82}
83#endif
84
Craig Tiller9c84fc32016-03-28 17:11:55 -070085#endif /* GRPC_CORE_EXT_LB_POLICY_GRPCLB_LOAD_BALANCER_API_H */