blob: 96ece92b9d82e30f25f9591cfe905014dad5515a [file] [log] [blame]
Craig Tiller9d0e0472015-06-23 09:12:48 -07001/*
2 *
Craig Tiller6169d5f2016-03-31 07:46:18 -07003 * Copyright 2015, Google Inc.
Craig Tiller9d0e0472015-06-23 09:12:48 -07004 * 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
Mark D. Roth15195742016-10-07 09:02:28 -070034#ifndef GRPC_CORE_EXT_CLIENT_CHANNEL_RESOLVER_H
35#define GRPC_CORE_EXT_CLIENT_CHANNEL_RESOLVER_H
Craig Tiller9d0e0472015-06-23 09:12:48 -070036
Mark D. Roth2137cd82016-09-14 09:04:00 -070037#include "src/core/ext/client_channel/subchannel.h"
Craig Tiller9533d042016-03-25 17:11:06 -070038#include "src/core/lib/iomgr/iomgr.h"
Craig Tilleraf691802015-06-23 14:57:07 -070039
Craig Tiller9d0e0472015-06-23 09:12:48 -070040typedef struct grpc_resolver grpc_resolver;
41typedef struct grpc_resolver_vtable grpc_resolver_vtable;
42
Mark D. Rothe917f5d2016-10-25 07:48:28 -070043/** \a grpc_resolver provides \a grpc_channel_args objects to its caller */
Craig Tillera82950e2015-09-22 12:33:20 -070044struct grpc_resolver {
Craig Tiller9d0e0472015-06-23 09:12:48 -070045 const grpc_resolver_vtable *vtable;
Craig Tiller98465032015-06-29 14:36:42 -070046 gpr_refcount refs;
Craig Tiller9d0e0472015-06-23 09:12:48 -070047};
48
Craig Tillera82950e2015-09-22 12:33:20 -070049struct grpc_resolver_vtable {
50 void (*destroy)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver);
51 void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver);
Craig Tillercb2609f2015-11-24 17:19:19 -080052 void (*channel_saw_error)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver);
Craig Tillera82950e2015-09-22 12:33:20 -070053 void (*next)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver,
Mark D. Rothaf842452016-10-21 15:05:15 -070054 grpc_channel_args **result, grpc_closure *on_complete);
Craig Tiller9d0e0472015-06-23 09:12:48 -070055};
56
Craig Tiller98465032015-06-29 14:36:42 -070057#ifdef GRPC_RESOLVER_REFCOUNT_DEBUG
Craig Tiller079a11b2015-06-30 10:07:15 -070058#define GRPC_RESOLVER_REF(p, r) grpc_resolver_ref((p), __FILE__, __LINE__, (r))
Craig Tiller8af4c332015-09-22 12:32:31 -070059#define GRPC_RESOLVER_UNREF(cl, p, r) \
60 grpc_resolver_unref((cl), (p), __FILE__, __LINE__, (r))
Craig Tillera82950e2015-09-22 12:33:20 -070061void grpc_resolver_ref(grpc_resolver *policy, const char *file, int line,
62 const char *reason);
63void grpc_resolver_unref(grpc_resolver *policy, grpc_closure_list *closure_list,
64 const char *file, int line, const char *reason);
Craig Tiller98465032015-06-29 14:36:42 -070065#else
66#define GRPC_RESOLVER_REF(p, r) grpc_resolver_ref((p))
Craig Tiller8af4c332015-09-22 12:32:31 -070067#define GRPC_RESOLVER_UNREF(cl, p, r) grpc_resolver_unref((cl), (p))
Craig Tillera82950e2015-09-22 12:33:20 -070068void grpc_resolver_ref(grpc_resolver *policy);
69void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *policy);
Craig Tiller98465032015-06-29 14:36:42 -070070#endif
71
Craig Tillera82950e2015-09-22 12:33:20 -070072void grpc_resolver_init(grpc_resolver *resolver,
73 const grpc_resolver_vtable *vtable);
Craig Tiller98465032015-06-29 14:36:42 -070074
Craig Tillera82950e2015-09-22 12:33:20 -070075void grpc_resolver_shutdown(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver);
Craig Tiller9d0e0472015-06-23 09:12:48 -070076
77/** Notification that the channel has seen an error on some address.
78 Can be used as a hint that re-resolution is desirable soon. */
Craig Tillera82950e2015-09-22 12:33:20 -070079void grpc_resolver_channel_saw_error(grpc_exec_ctx *exec_ctx,
Craig Tillercb2609f2015-11-24 17:19:19 -080080 grpc_resolver *resolver);
Craig Tiller9d0e0472015-06-23 09:12:48 -070081
Mark D. Rothe917f5d2016-10-25 07:48:28 -070082/** Get the next result from the resolver. Expected to set \a *result with
83 new channel args and then schedule \a on_complete for execution.
Craig Tiller9d0e0472015-06-23 09:12:48 -070084
Mark D. Rothe917f5d2016-10-25 07:48:28 -070085 If resolution is fatally broken, set \a *result to NULL and
86 schedule \a on_complete. */
Craig Tillera82950e2015-09-22 12:33:20 -070087void grpc_resolver_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver,
Mark D. Roth557c9902016-10-24 11:12:05 -070088 grpc_channel_args **result, grpc_closure *on_complete);
Craig Tiller9d0e0472015-06-23 09:12:48 -070089
Mark D. Roth15195742016-10-07 09:02:28 -070090#endif /* GRPC_CORE_EXT_CLIENT_CHANNEL_RESOLVER_H */