aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/ext/filters/client_channel/resolver.h
blob: 73fbbbbc3b1519bb19b0cbf99f8fabd813142698 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 *
 * Copyright 2015 gRPC authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_H
#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_H

#include "src/core/ext/filters/client_channel/subchannel.h"
#include "src/core/lib/iomgr/iomgr.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct grpc_resolver grpc_resolver;
typedef struct grpc_resolver_vtable grpc_resolver_vtable;

#ifndef NDEBUG
extern grpc_tracer_flag grpc_trace_resolver_refcount;
#endif

/** \a grpc_resolver provides \a grpc_channel_args objects to its caller */
struct grpc_resolver {
  const grpc_resolver_vtable *vtable;
  gpr_refcount refs;
  grpc_combiner *combiner;
};

struct grpc_resolver_vtable {
  void (*destroy)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver);
  void (*shutdown_locked)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver);
  void (*channel_saw_error_locked)(grpc_exec_ctx *exec_ctx,
                                   grpc_resolver *resolver);
  void (*next_locked)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver,
                      grpc_channel_args **result, grpc_closure *on_complete);
};

#ifndef NDEBUG
#define GRPC_RESOLVER_REF(p, r) grpc_resolver_ref((p), __FILE__, __LINE__, (r))
#define GRPC_RESOLVER_UNREF(e, p, r) \
  grpc_resolver_unref((e), (p), __FILE__, __LINE__, (r))
void grpc_resolver_ref(grpc_resolver *policy, const char *file, int line,
                       const char *reason);
void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *policy,
                         const char *file, int line, const char *reason);
#else
#define GRPC_RESOLVER_REF(p, r) grpc_resolver_ref((p))
#define GRPC_RESOLVER_UNREF(e, p, r) grpc_resolver_unref((e), (p))
void grpc_resolver_ref(grpc_resolver *policy);
void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *policy);
#endif

void grpc_resolver_init(grpc_resolver *resolver,
                        const grpc_resolver_vtable *vtable,
                        grpc_combiner *combiner);

void grpc_resolver_shutdown_locked(grpc_exec_ctx *exec_ctx,
                                   grpc_resolver *resolver);

/** Notification that the channel has seen an error on some address.
    Can be used as a hint that re-resolution is desirable soon.

    Must be called from the combiner passed as a resolver_arg at construction
    time.*/
void grpc_resolver_channel_saw_error_locked(grpc_exec_ctx *exec_ctx,
                                            grpc_resolver *resolver);

/** Get the next result from the resolver.  Expected to set \a *result with
    new channel args and then schedule \a on_complete for execution.

    If resolution is fatally broken, set \a *result to NULL and
    schedule \a on_complete.

    Must be called from the combiner passed as a resolver_arg at construction
    time.*/
void grpc_resolver_next_locked(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver,
                               grpc_channel_args **result,
                               grpc_closure *on_complete);

#ifdef __cplusplus
}
#endif

#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_H */