GRPC Core 0.10.0.0

- Main Page
- Data Structures
- Files

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
lb_policy.h
Go to the documentation of this file.
1 /*
2 *
3 * Copyright 2015, 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
34 #ifndef GRPC_INTERNAL_CORE_CLIENT_CONFIG_LB_POLICY_H
35 #define GRPC_INTERNAL_CORE_CLIENT_CONFIG_LB_POLICY_H
36
37 #include "src/core/client_config/subchannel.h"
38
41 typedef struct grpc_lb_policy grpc_lb_policy;
42 typedef struct grpc_lb_policy_vtable grpc_lb_policy_vtable;
43
44 typedef void (*grpc_lb_completion)(void *cb_arg, grpc_subchannel *subchannel,
45 grpc_status_code status, const char *errmsg);
46
47 struct grpc_lb_policy {
48 const grpc_lb_policy_vtable *vtable;
49 gpr_refcount refs;
50 };
51
52 struct grpc_lb_policy_vtable {
53 void (*destroy)(grpc_lb_policy *policy);
54
55 void (*shutdown)(grpc_lb_policy *policy);
56
58 void (*pick)(grpc_lb_policy *policy, grpc_pollset *pollset,
59 grpc_metadata_batch *initial_metadata, grpc_subchannel **target,
60 grpc_iomgr_closure *on_complete);
61
63 void (*exit_idle)(grpc_lb_policy *policy);
64
66 void (*broadcast)(grpc_lb_policy *policy, grpc_transport_op *op);
67
69 grpc_connectivity_state (*check_connectivity)(grpc_lb_policy *policy);
70
73 void (*notify_on_state_change)(grpc_lb_policy *policy,
74 grpc_connectivity_state *state,
75 grpc_iomgr_closure *closure);
76 };
77
78 #ifdef GRPC_LB_POLICY_REFCOUNT_DEBUG
79 #define GRPC_LB_POLICY_REF(p, r) \
80 grpc_lb_policy_ref((p), __FILE__, __LINE__, (r))
81 #define GRPC_LB_POLICY_UNREF(p, r) \
82 grpc_lb_policy_unref((p), __FILE__, __LINE__, (r))
83 void grpc_lb_policy_ref(grpc_lb_policy *policy, const char *file, int line,
84 const char *reason);
85 void grpc_lb_policy_unref(grpc_lb_policy *policy, const char *file, int line,
86 const char *reason);
87 #else
88 #define GRPC_LB_POLICY_REF(p, r) grpc_lb_policy_ref((p))
89 #define GRPC_LB_POLICY_UNREF(p, r) grpc_lb_policy_unref((p))
90 void grpc_lb_policy_ref(grpc_lb_policy *policy);
91 void grpc_lb_policy_unref(grpc_lb_policy *policy);
92 #endif
93
95 void grpc_lb_policy_init(grpc_lb_policy *policy,
96 const grpc_lb_policy_vtable *vtable);
97
99 void grpc_lb_policy_shutdown(grpc_lb_policy *policy);
100
105 void grpc_lb_policy_pick(grpc_lb_policy *policy, grpc_pollset *pollset,
106 grpc_metadata_batch *initial_metadata,
107 grpc_subchannel **target,
108 grpc_iomgr_closure *on_complete);
109
110 void grpc_lb_policy_broadcast(grpc_lb_policy *policy, grpc_transport_op *op);
111
112 void grpc_lb_policy_exit_idle(grpc_lb_policy *policy);
113
114 void grpc_lb_policy_notify_on_state_change(grpc_lb_policy *policy,
115 grpc_connectivity_state *state,
116 grpc_iomgr_closure *closure);
117
118 grpc_connectivity_state grpc_lb_policy_check_connectivity(
119 grpc_lb_policy *policy);
120
121 #endif /* GRPC_INTERNAL_CORE_CONFIG_LB_POLICY_H */
grpc_lb_policy::vtable
const grpc_lb_policy_vtable * vtable
Definition: lb_policy.h:48
grpc_connectivity_state
grpc_connectivity_state
Connectivity state of a channel.
Definition: grpc.h:139
gpr_refcount
Definition: sync_generic.h:49
grpc_lb_policy_exit_idle
void grpc_lb_policy_exit_idle(grpc_lb_policy *policy)
Definition: lb_policy.c:81
grpc_metadata_batch
Definition: stream_op.h:87
grpc_lb_policy_check_connectivity
grpc_connectivity_state grpc_lb_policy_check_connectivity(grpc_lb_policy *policy)
Definition: lb_policy.c:91
grpc_lb_policy_vtable::pick
void(* pick)(grpc_lb_policy *policy, grpc_pollset *pollset, grpc_metadata_batch *initial_metadata, grpc_subchannel **target, grpc_iomgr_closure *on_complete)
implement grpc_lb_policy_pick
Definition: lb_policy.h:58
grpc_lb_policy_vtable::broadcast
void(* broadcast)(grpc_lb_policy *policy, grpc_transport_op *op)
broadcast a transport op to all subchannels
Definition: lb_policy.h:66
grpc_pollset
Definition: pollset_posix.h:48
grpc_subchannel
Definition: subchannel.c:77
grpc_lb_completion
void(* grpc_lb_completion)(void *cb_arg, grpc_subchannel *subchannel, grpc_status_code status, const char *errmsg)
Definition: lb_policy.h:44
grpc_lb_policy_broadcast
void grpc_lb_policy_broadcast(grpc_lb_policy *policy, grpc_transport_op *op)
Definition: lb_policy.c:77
grpc_lb_policy_vtable
Definition: lb_policy.h:52
grpc_lb_policy_shutdown
void grpc_lb_policy_shutdown(grpc_lb_policy *policy)
Start shutting down (fail any pending picks)
Definition: lb_policy.c:66
grpc_lb_policy_vtable::destroy
void(* destroy)(grpc_lb_policy *policy)
Definition: lb_policy.h:53
grpc_iomgr_closure
A closure over a grpc_iomgr_cb_func.
Definition: iomgr.h:45
grpc_lb_policy::refs
gpr_refcount refs
Definition: lb_policy.h:49
grpc_lb_policy_pick
void grpc_lb_policy_pick(grpc_lb_policy *policy, grpc_pollset *pollset, grpc_metadata_batch *initial_metadata, grpc_subchannel **target, grpc_iomgr_closure *on_complete)
Given initial metadata in initial_metadata, find an appropriate target for this rpc, and 'return' it by calling on_complete after setting target.
Definition: lb_policy.c:70
grpc_lb_policy_vtable::shutdown
void(* shutdown)(grpc_lb_policy *policy)
Definition: lb_policy.h:55
subchannel.h
grpc_lb_policy_ref
void grpc_lb_policy_ref(grpc_lb_policy *policy)
Definition: lb_policy.c:48
grpc_lb_policy_vtable::notify_on_state_change
void(* notify_on_state_change)(grpc_lb_policy *policy, grpc_connectivity_state *state, grpc_iomgr_closure *closure)
call notify when the connectivity state of a channel changes from *state.
Definition: lb_policy.h:73
grpc_status_code
grpc_status_code
Definition: status.h:41
grpc_lb_policy_unref
void grpc_lb_policy_unref(grpc_lb_policy *policy)
Definition: lb_policy.c:59
grpc_lb_policy_vtable::exit_idle
void(* exit_idle)(grpc_lb_policy *policy)
try to enter a READY connectivity state
Definition: lb_policy.h:63
grpc_lb_policy_notify_on_state_change
void grpc_lb_policy_notify_on_state_change(grpc_lb_policy *policy, grpc_connectivity_state *state, grpc_iomgr_closure *closure)
Definition: lb_policy.c:85
grpc_lb_policy_init
void grpc_lb_policy_init(grpc_lb_policy *policy, const grpc_lb_policy_vtable *vtable)
called by concrete implementations to initialize the base struct
Definition: lb_policy.c:36
grpc_lb_policy
Definition: lb_policy.h:47
grpc_transport_op
Transport op: a set of operations to perform on a transport as a whole.
Definition: transport.h:90
grpc_lb_policy_vtable::check_connectivity
grpc_connectivity_state(* check_connectivity)(grpc_lb_policy *policy)
check the current connectivity of the lb_policy
Definition: lb_policy.h:69