blob: a4d8271ca6a8abc23fcd8a184d1f3ee365000f4f [file] [log] [blame]
Craig Tiller178edfa2016-02-17 20:54:46 -08001/*
2 *
Craig Tiller9b524122016-02-18 08:23:08 -08003 * Copyright 2016, Google Inc.
Craig Tiller178edfa2016-02-17 20:54:46 -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 Tiller9a4dddd2016-03-25 17:08:13 -070034#ifndef GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H
35#define GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H
Craig Tiller178edfa2016-02-17 20:54:46 -080036
Craig Tiller9533d042016-03-25 17:11:06 -070037#include "src/core/lib/channel/channel_stack_builder.h"
38#include "src/core/lib/surface/channel_stack_type.h"
39#include "src/core/lib/transport/transport.h"
Craig Tiller178edfa2016-02-17 20:54:46 -080040
Craig Tillerb88e9622016-02-22 21:34:41 -080041/// This module provides a way for plugins (and the grpc core library itself)
42/// to register mutators for channel stacks.
43/// It also provides a universal entry path to run those mutators to build
44/// a channel stack for various subsystems.
Craig Tiller178edfa2016-02-17 20:54:46 -080045
Craig Tillerb88e9622016-02-22 21:34:41 -080046/// One stage of mutation: call functions against \a builder to influence the
47/// finally constructed channel stack
Craig Tiller178edfa2016-02-17 20:54:46 -080048typedef bool (*grpc_channel_init_stage)(grpc_channel_stack_builder *builder,
49 void *arg);
50
Craig Tillerb88e9622016-02-22 21:34:41 -080051/// Global initialization of the system
Craig Tiller178edfa2016-02-17 20:54:46 -080052void grpc_channel_init_init(void);
53
Craig Tillerb88e9622016-02-22 21:34:41 -080054/// Register one stage of mutators.
55/// Stages are run in priority order (lowest to highest), and then in
56/// registration order (in the case of a tie).
57/// Stages are registered against one of the pre-determined channel stack
58/// types.
Craig Tiller178edfa2016-02-17 20:54:46 -080059void grpc_channel_init_register_stage(grpc_channel_stack_type type,
60 int priority,
Craig Tillerb88e9622016-02-22 21:34:41 -080061 grpc_channel_init_stage stage_fn,
Craig Tiller178edfa2016-02-17 20:54:46 -080062 void *stage_arg);
63
Craig Tillerb88e9622016-02-22 21:34:41 -080064/// Finalize registration. No more calls to grpc_channel_init_register_stage are
65/// allowed.
Craig Tiller178edfa2016-02-17 20:54:46 -080066void grpc_channel_init_finalize(void);
Craig Tillerb88e9622016-02-22 21:34:41 -080067/// Shutdown the channel init system
Craig Tiller178edfa2016-02-17 20:54:46 -080068void grpc_channel_init_shutdown(void);
69
Craig Tillerb88e9622016-02-22 21:34:41 -080070/// Construct a channel stack of some sort: see channel_stack.h for details
71/// \a type is the type of channel stack to create
72/// \a prefix_bytes is the number of bytes before the channel stack to allocate
73/// \a args are configuration arguments for the channel stack
74/// \a initial_refs is the initial refcount to give the channel stack
75/// \a destroy and \a destroy_arg specify how to destroy the channel stack
76/// if destroy_arg is NULL, the returned value from this function will be
77/// substituted
78/// \a optional_transport is either NULL or a constructed transport object
79/// Returns a pointer to the base of the memory allocated (the actual channel
80/// stack object will be prefix_bytes past that pointer)
Craig Tiller178edfa2016-02-17 20:54:46 -080081void *grpc_channel_init_create_stack(
82 grpc_exec_ctx *exec_ctx, grpc_channel_stack_type type, size_t prefix_bytes,
83 const grpc_channel_args *args, int initial_refs, grpc_iomgr_cb_func destroy,
84 void *destroy_arg, grpc_transport *optional_transport);
85
Craig Tiller9a4dddd2016-03-25 17:08:13 -070086#endif /* GRPC_CORE_LIB_SURFACE_CHANNEL_INIT_H */