Line data Source code
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 : #include "src/core/client_config/lb_policy.h"
35 :
36 1445 : void grpc_lb_policy_init(grpc_lb_policy *policy,
37 : const grpc_lb_policy_vtable *vtable) {
38 1445 : policy->vtable = vtable;
39 1445 : gpr_ref_init(&policy->refs, 1);
40 1445 : }
41 :
42 : #ifdef GRPC_LB_POLICY_REFCOUNT_DEBUG
43 : void grpc_lb_policy_ref(grpc_lb_policy *policy, const char *file, int line,
44 : const char *reason) {
45 : gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "LB_POLICY:%p ref %d -> %d %s",
46 : policy, (int)policy->refs.count, (int)policy->refs.count + 1, reason);
47 : #else
48 1409628 : void grpc_lb_policy_ref(grpc_lb_policy *policy) {
49 : #endif
50 1409628 : gpr_ref(&policy->refs);
51 1410747 : }
52 :
53 : #ifdef GRPC_LB_POLICY_REFCOUNT_DEBUG
54 : void grpc_lb_policy_unref(grpc_lb_policy *policy,
55 : grpc_closure_list *closure_list, const char *file,
56 : int line, const char *reason) {
57 : gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "LB_POLICY:%p unref %d -> %d %s",
58 : policy, (int)policy->refs.count, (int)policy->refs.count - 1, reason);
59 : #else
60 1412195 : void grpc_lb_policy_unref(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy) {
61 : #endif
62 1412195 : if (gpr_unref(&policy->refs)) {
63 1445 : policy->vtable->destroy(exec_ctx, policy);
64 : }
65 1412205 : }
66 :
67 1386 : void grpc_lb_policy_shutdown(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy) {
68 1386 : policy->vtable->shutdown(exec_ctx, policy);
69 1386 : }
70 :
71 1402382 : void grpc_lb_policy_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
72 : grpc_pollset *pollset,
73 : grpc_metadata_batch *initial_metadata,
74 : grpc_subchannel **target, grpc_closure *on_complete) {
75 1402382 : policy->vtable->pick(exec_ctx, policy, pollset, initial_metadata, target,
76 : on_complete);
77 1402380 : }
78 :
79 1386 : void grpc_lb_policy_broadcast(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
80 : grpc_transport_op *op) {
81 1386 : policy->vtable->broadcast(exec_ctx, policy, op);
82 1386 : }
83 :
84 17 : void grpc_lb_policy_exit_idle(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy) {
85 17 : policy->vtable->exit_idle(exec_ctx, policy);
86 17 : }
87 :
88 5592 : void grpc_lb_policy_notify_on_state_change(grpc_exec_ctx *exec_ctx,
89 : grpc_lb_policy *policy,
90 : grpc_connectivity_state *state,
91 : grpc_closure *closure) {
92 5592 : policy->vtable->notify_on_state_change(exec_ctx, policy, state, closure);
93 5592 : }
94 :
95 1386 : grpc_connectivity_state grpc_lb_policy_check_connectivity(
96 : grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy) {
97 1386 : return policy->vtable->check_connectivity(exec_ctx, policy);
98 : }
|