Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 6169d5f | 2016-03-31 07:46:18 -0700 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 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 | |
Mark D. Roth | 1519574 | 2016-10-07 09:02:28 -0700 | [diff] [blame] | 34 | #ifndef GRPC_CORE_EXT_CLIENT_CHANNEL_RESOLVER_H |
| 35 | #define GRPC_CORE_EXT_CLIENT_CHANNEL_RESOLVER_H |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 36 | |
Mark D. Roth | 2137cd8 | 2016-09-14 09:04:00 -0700 | [diff] [blame] | 37 | #include "src/core/ext/client_channel/subchannel.h" |
Craig Tiller | 9533d04 | 2016-03-25 17:11:06 -0700 | [diff] [blame] | 38 | #include "src/core/lib/iomgr/iomgr.h" |
Craig Tiller | af69180 | 2015-06-23 14:57:07 -0700 | [diff] [blame] | 39 | |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 40 | typedef struct grpc_resolver grpc_resolver; |
| 41 | typedef struct grpc_resolver_vtable grpc_resolver_vtable; |
| 42 | |
Mark D. Roth | e917f5d | 2016-10-25 07:48:28 -0700 | [diff] [blame] | 43 | /** \a grpc_resolver provides \a grpc_channel_args objects to its caller */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 44 | struct grpc_resolver { |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 45 | const grpc_resolver_vtable *vtable; |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 46 | gpr_refcount refs; |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 47 | }; |
| 48 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 49 | struct 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 Tiller | cb2609f | 2015-11-24 17:19:19 -0800 | [diff] [blame] | 52 | void (*channel_saw_error)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 53 | void (*next)(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, |
Mark D. Roth | af84245 | 2016-10-21 15:05:15 -0700 | [diff] [blame] | 54 | grpc_channel_args **result, grpc_closure *on_complete); |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 57 | #ifdef GRPC_RESOLVER_REFCOUNT_DEBUG |
Craig Tiller | 079a11b | 2015-06-30 10:07:15 -0700 | [diff] [blame] | 58 | #define GRPC_RESOLVER_REF(p, r) grpc_resolver_ref((p), __FILE__, __LINE__, (r)) |
Craig Tiller | 8af4c33 | 2015-09-22 12:32:31 -0700 | [diff] [blame] | 59 | #define GRPC_RESOLVER_UNREF(cl, p, r) \ |
| 60 | grpc_resolver_unref((cl), (p), __FILE__, __LINE__, (r)) |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 61 | void grpc_resolver_ref(grpc_resolver *policy, const char *file, int line, |
| 62 | const char *reason); |
| 63 | void grpc_resolver_unref(grpc_resolver *policy, grpc_closure_list *closure_list, |
| 64 | const char *file, int line, const char *reason); |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 65 | #else |
| 66 | #define GRPC_RESOLVER_REF(p, r) grpc_resolver_ref((p)) |
Craig Tiller | 8af4c33 | 2015-09-22 12:32:31 -0700 | [diff] [blame] | 67 | #define GRPC_RESOLVER_UNREF(cl, p, r) grpc_resolver_unref((cl), (p)) |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 68 | void grpc_resolver_ref(grpc_resolver *policy); |
| 69 | void grpc_resolver_unref(grpc_exec_ctx *exec_ctx, grpc_resolver *policy); |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 70 | #endif |
| 71 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 72 | void grpc_resolver_init(grpc_resolver *resolver, |
| 73 | const grpc_resolver_vtable *vtable); |
Craig Tiller | 9846503 | 2015-06-29 14:36:42 -0700 | [diff] [blame] | 74 | |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 75 | void grpc_resolver_shutdown(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver); |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 76 | |
| 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 Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 79 | void grpc_resolver_channel_saw_error(grpc_exec_ctx *exec_ctx, |
Craig Tiller | cb2609f | 2015-11-24 17:19:19 -0800 | [diff] [blame] | 80 | grpc_resolver *resolver); |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 81 | |
Mark D. Roth | e917f5d | 2016-10-25 07:48:28 -0700 | [diff] [blame] | 82 | /** 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 Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 84 | |
Mark D. Roth | e917f5d | 2016-10-25 07:48:28 -0700 | [diff] [blame] | 85 | If resolution is fatally broken, set \a *result to NULL and |
| 86 | schedule \a on_complete. */ |
Craig Tiller | a82950e | 2015-09-22 12:33:20 -0700 | [diff] [blame] | 87 | void grpc_resolver_next(grpc_exec_ctx *exec_ctx, grpc_resolver *resolver, |
Mark D. Roth | 557c990 | 2016-10-24 11:12:05 -0700 | [diff] [blame] | 88 | grpc_channel_args **result, grpc_closure *on_complete); |
Craig Tiller | 9d0e047 | 2015-06-23 09:12:48 -0700 | [diff] [blame] | 89 | |
Mark D. Roth | 1519574 | 2016-10-07 09:02:28 -0700 | [diff] [blame] | 90 | #endif /* GRPC_CORE_EXT_CLIENT_CHANNEL_RESOLVER_H */ |