Craig Tiller | 694cf8b | 2016-01-15 21:13:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 1948244 | 2016-01-25 09:59:20 -0800 | [diff] [blame] | 3 | * Copyright 2016, Google Inc. |
Craig Tiller | 694cf8b | 2016-01-15 21:13:25 -0800 | [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 | |
Craig Tiller | 5aceb27 | 2016-03-31 13:50:42 -0700 | [diff] [blame] | 34 | #ifndef GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_INDEX_H |
| 35 | #define GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_INDEX_H |
Craig Tiller | 694cf8b | 2016-01-15 21:13:25 -0800 | [diff] [blame] | 36 | |
Craig Tiller | d4c9833 | 2016-03-31 13:45:47 -0700 | [diff] [blame] | 37 | #include "src/core/ext/client_config/connector.h" |
| 38 | #include "src/core/ext/client_config/subchannel.h" |
Craig Tiller | 694cf8b | 2016-01-15 21:13:25 -0800 | [diff] [blame] | 39 | |
Craig Tiller | 1948244 | 2016-01-25 09:59:20 -0800 | [diff] [blame] | 40 | /** \file Provides an index of active subchannels so that they can be |
| 41 | shared amongst channels */ |
| 42 | |
Craig Tiller | 7391f13 | 2016-01-22 06:39:54 -0800 | [diff] [blame] | 43 | typedef struct grpc_subchannel_key grpc_subchannel_key; |
| 44 | |
Craig Tiller | 1948244 | 2016-01-25 09:59:20 -0800 | [diff] [blame] | 45 | /** Create a key that can be used to uniquely identify a subchannel */ |
Craig Tiller | 5de79ee | 2016-01-25 08:16:02 -0800 | [diff] [blame] | 46 | grpc_subchannel_key *grpc_subchannel_key_create(grpc_connector *con, |
| 47 | grpc_subchannel_args *args); |
Craig Tiller | 7391f13 | 2016-01-22 06:39:54 -0800 | [diff] [blame] | 48 | |
Craig Tiller | 1948244 | 2016-01-25 09:59:20 -0800 | [diff] [blame] | 49 | /** Destroy a subchannel key */ |
| 50 | void grpc_subchannel_key_destroy(grpc_exec_ctx *exec_ctx, |
| 51 | grpc_subchannel_key *key); |
Craig Tiller | 7391f13 | 2016-01-22 06:39:54 -0800 | [diff] [blame] | 52 | |
Craig Tiller | 1948244 | 2016-01-25 09:59:20 -0800 | [diff] [blame] | 53 | /** Given a subchannel key, find the subchannel registered for it. |
| 54 | Returns NULL if no such channel exists. |
| 55 | Thread-safe. */ |
Craig Tiller | 5de79ee | 2016-01-25 08:16:02 -0800 | [diff] [blame] | 56 | grpc_subchannel *grpc_subchannel_index_find(grpc_exec_ctx *exec_ctx, |
| 57 | grpc_subchannel_key *key); |
Craig Tiller | 7391f13 | 2016-01-22 06:39:54 -0800 | [diff] [blame] | 58 | |
Craig Tiller | 2d50f37 | 2016-01-28 11:48:18 -0800 | [diff] [blame] | 59 | /** Register a subchannel against a key. |
Craig Tiller | 1948244 | 2016-01-25 09:59:20 -0800 | [diff] [blame] | 60 | Takes ownership of \a constructed. |
| 61 | Returns the registered subchannel. This may be different from |
| 62 | \a constructed in the case of a registration race. */ |
Craig Tiller | 5de79ee | 2016-01-25 08:16:02 -0800 | [diff] [blame] | 63 | grpc_subchannel *grpc_subchannel_index_register(grpc_exec_ctx *exec_ctx, |
| 64 | grpc_subchannel_key *key, |
| 65 | grpc_subchannel *constructed); |
Craig Tiller | 7391f13 | 2016-01-22 06:39:54 -0800 | [diff] [blame] | 66 | |
Craig Tiller | 1948244 | 2016-01-25 09:59:20 -0800 | [diff] [blame] | 67 | /** Remove \a constructed as the registered subchannel for \a key. */ |
Craig Tiller | 5de79ee | 2016-01-25 08:16:02 -0800 | [diff] [blame] | 68 | void grpc_subchannel_index_unregister(grpc_exec_ctx *exec_ctx, |
| 69 | grpc_subchannel_key *key, |
| 70 | grpc_subchannel *constructed); |
Craig Tiller | 694cf8b | 2016-01-15 21:13:25 -0800 | [diff] [blame] | 71 | |
Craig Tiller | 1948244 | 2016-01-25 09:59:20 -0800 | [diff] [blame] | 72 | /** Initialize the subchannel index (global) */ |
Craig Tiller | 8cdba66 | 2016-01-22 20:01:55 -0800 | [diff] [blame] | 73 | void grpc_subchannel_index_init(void); |
Craig Tiller | 1948244 | 2016-01-25 09:59:20 -0800 | [diff] [blame] | 74 | /** Shutdown the subchannel index (global) */ |
Craig Tiller | 8cdba66 | 2016-01-22 20:01:55 -0800 | [diff] [blame] | 75 | void grpc_subchannel_index_shutdown(void); |
| 76 | |
Craig Tiller | 5aceb27 | 2016-03-31 13:50:42 -0700 | [diff] [blame] | 77 | #endif /* GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_INDEX_H */ |