blob: 6b8d063855e52479e1b22778cf3e17a365e736cd [file] [log] [blame]
Craig Tiller694cf8b2016-01-15 21:13:25 -08001/*
2 *
Craig Tiller19482442016-01-25 09:59:20 -08003 * Copyright 2016, Google Inc.
Craig Tiller694cf8b2016-01-15 21:13:25 -08004 * 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 Tiller5aceb272016-03-31 13:50:42 -070034#ifndef GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_INDEX_H
35#define GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_INDEX_H
Craig Tiller694cf8b2016-01-15 21:13:25 -080036
Craig Tillerd4c98332016-03-31 13:45:47 -070037#include "src/core/ext/client_config/connector.h"
38#include "src/core/ext/client_config/subchannel.h"
Craig Tiller694cf8b2016-01-15 21:13:25 -080039
Craig Tiller19482442016-01-25 09:59:20 -080040/** \file Provides an index of active subchannels so that they can be
41 shared amongst channels */
42
Craig Tiller7391f132016-01-22 06:39:54 -080043typedef struct grpc_subchannel_key grpc_subchannel_key;
44
Craig Tiller19482442016-01-25 09:59:20 -080045/** Create a key that can be used to uniquely identify a subchannel */
Craig Tiller5de79ee2016-01-25 08:16:02 -080046grpc_subchannel_key *grpc_subchannel_key_create(grpc_connector *con,
47 grpc_subchannel_args *args);
Craig Tiller7391f132016-01-22 06:39:54 -080048
Craig Tiller19482442016-01-25 09:59:20 -080049/** Destroy a subchannel key */
50void grpc_subchannel_key_destroy(grpc_exec_ctx *exec_ctx,
51 grpc_subchannel_key *key);
Craig Tiller7391f132016-01-22 06:39:54 -080052
Craig Tiller19482442016-01-25 09:59:20 -080053/** Given a subchannel key, find the subchannel registered for it.
54 Returns NULL if no such channel exists.
55 Thread-safe. */
Craig Tiller5de79ee2016-01-25 08:16:02 -080056grpc_subchannel *grpc_subchannel_index_find(grpc_exec_ctx *exec_ctx,
57 grpc_subchannel_key *key);
Craig Tiller7391f132016-01-22 06:39:54 -080058
Craig Tiller2d50f372016-01-28 11:48:18 -080059/** Register a subchannel against a key.
Craig Tiller19482442016-01-25 09:59:20 -080060 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 Tiller5de79ee2016-01-25 08:16:02 -080063grpc_subchannel *grpc_subchannel_index_register(grpc_exec_ctx *exec_ctx,
64 grpc_subchannel_key *key,
65 grpc_subchannel *constructed);
Craig Tiller7391f132016-01-22 06:39:54 -080066
Craig Tiller19482442016-01-25 09:59:20 -080067/** Remove \a constructed as the registered subchannel for \a key. */
Craig Tiller5de79ee2016-01-25 08:16:02 -080068void grpc_subchannel_index_unregister(grpc_exec_ctx *exec_ctx,
69 grpc_subchannel_key *key,
70 grpc_subchannel *constructed);
Craig Tiller694cf8b2016-01-15 21:13:25 -080071
Craig Tiller19482442016-01-25 09:59:20 -080072/** Initialize the subchannel index (global) */
Craig Tiller8cdba662016-01-22 20:01:55 -080073void grpc_subchannel_index_init(void);
Craig Tiller19482442016-01-25 09:59:20 -080074/** Shutdown the subchannel index (global) */
Craig Tiller8cdba662016-01-22 20:01:55 -080075void grpc_subchannel_index_shutdown(void);
76
Craig Tiller5aceb272016-03-31 13:50:42 -070077#endif /* GRPC_CORE_EXT_CLIENT_CONFIG_SUBCHANNEL_INDEX_H */