blob: 7b029ae3eed201c8a89301aeb6494e933d246b14 [file] [log] [blame]
David Garcia Quintas862c8e92016-04-06 16:30:51 -07001/*
2 *
3 * Copyright 2016, Google Inc.
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
34#include <string.h>
35
36#include <grpc/support/log.h>
37
38#include "src/core/ext/load_reporting/load_reporting_filter.h"
39#include "src/core/lib/channel/channel_args.h"
40#include "src/core/lib/load_reporting/load_reporting.h"
41#include "src/core/lib/profiling/timers.h"
42#include "src/core/lib/support/string.h"
43
44typedef struct call_data { load_reporting_data lr_data; } call_data;
45
46typedef struct channel_data { void *dummy; } channel_data;
47
48static void load_reporting_start_transport_stream_op(
49 grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
50 grpc_transport_stream_op *op) {
51 call_data *calld = elem->call_data;
52
53 GPR_TIMER_BEGIN("load_reporting_start_transport_stream_op", 0);
54 grpc_load_reporting_call(&calld->lr_data);
55 grpc_call_next_op(exec_ctx, elem, op);
56 GPR_TIMER_END("load_reporting_start_transport_stream_op", 0);
57}
58
59/* Constructor for call_data */
60static void init_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
61 grpc_call_element_args *args) {
62 /* grab pointers to our data from the call element */
63 call_data *calld = elem->call_data;
64
65 /* initialize members */
66 memset(&calld->lr_data, 0, sizeof(load_reporting_data));
67}
68
69/* Destructor for call_data */
70static void destroy_call_elem(grpc_exec_ctx *exec_ctx,
71 grpc_call_element *elem) {
72 /* grab pointers to our data from the call element */
73 /*call_data *calld = elem->call_data;*/
74}
75
76/* Constructor for channel_data */
77static void init_channel_elem(grpc_exec_ctx *exec_ctx,
78 grpc_channel_element *elem,
79 grpc_channel_element_args *args) {
80 /*channel_data *channeld = elem->channel_data;*/
81 GPR_ASSERT(!args->is_last);
82}
83
84/* Destructor for channel data */
85static void destroy_channel_elem(grpc_exec_ctx *exec_ctx,
86 grpc_channel_element *elem) {}
87
88const grpc_channel_filter grpc_load_reporting_filter = {
89 load_reporting_start_transport_stream_op,
90 grpc_channel_next_op,
91 sizeof(call_data),
92 init_call_elem,
93 grpc_call_stack_ignore_set_pollset,
94 destroy_call_elem,
95 sizeof(channel_data),
96 init_channel_elem,
97 destroy_channel_elem,
98 grpc_call_next_get_peer,
99 "load_reporting"};