gRPC  0.6.0
 All Classes Namespaces Functions Variables Enumerations Properties Pages
call.h
1 /*
2  *
3  * Copyright 2015, 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 #ifndef GRPC_INTERNAL_CORE_SURFACE_CALL_H
35 #define GRPC_INTERNAL_CORE_SURFACE_CALL_H
36 
37 #include "src/core/channel/channel_stack.h"
38 #include "src/core/channel/context.h"
39 #include <grpc/grpc.h>
40 
41 /* Primitive operation types - grpc_op's get rewritten into these */
42 typedef enum {
43  GRPC_IOREQ_RECV_INITIAL_METADATA,
44  GRPC_IOREQ_RECV_MESSAGE,
45  GRPC_IOREQ_RECV_TRAILING_METADATA,
46  GRPC_IOREQ_RECV_STATUS,
47  GRPC_IOREQ_RECV_STATUS_DETAILS,
48  GRPC_IOREQ_RECV_CLOSE,
49  GRPC_IOREQ_SEND_INITIAL_METADATA,
50  GRPC_IOREQ_SEND_MESSAGE,
51  GRPC_IOREQ_SEND_TRAILING_METADATA,
52  GRPC_IOREQ_SEND_STATUS,
53  GRPC_IOREQ_SEND_CLOSE,
54  GRPC_IOREQ_OP_COUNT
55 } grpc_ioreq_op;
56 
57 typedef union {
58  grpc_metadata_array *recv_metadata;
59  grpc_byte_buffer **recv_message;
60  struct {
61  void (*set_value)(grpc_status_code status, void *user_data);
62  void *user_data;
63  } recv_status;
64  struct {
65  char **details;
66  size_t *details_capacity;
67  } recv_status_details;
68  struct {
69  size_t count;
70  grpc_metadata *metadata;
71  } send_metadata;
72  grpc_byte_buffer *send_message;
73  struct {
74  grpc_status_code code;
75  const char *details;
76  } send_status;
78 
79 typedef struct {
80  grpc_ioreq_op op;
81  grpc_ioreq_data data;
82 } grpc_ioreq;
83 
84 typedef void (*grpc_ioreq_completion_func)(grpc_call *call, int success,
85  void *user_data);
86 
87 grpc_call *grpc_call_create(grpc_channel *channel, grpc_completion_queue *cq,
88  const void *server_transport_data,
89  grpc_mdelem **add_initial_metadata,
90  size_t add_initial_metadata_count,
91  gpr_timespec send_deadline);
92 
93 void grpc_call_set_completion_queue(grpc_call *call, grpc_completion_queue *cq);
94 grpc_completion_queue *grpc_call_get_completion_queue(grpc_call *call);
95 
96 #ifdef GRPC_CALL_REF_COUNT_DEBUG
97 void grpc_call_internal_ref(grpc_call *call, const char *reason);
98 void grpc_call_internal_unref(grpc_call *call, const char *reason, int allow_immediate_deletion);
99 #define GRPC_CALL_INTERNAL_REF(call, reason) grpc_call_internal_ref(call, reason)
100 #define GRPC_CALL_INTERNAL_UNREF(call, reason, allow_immediate_deletion) \
101  grpc_call_internal_unref(call, reason, allow_immediate_deletion)
102 #else
103 void grpc_call_internal_ref(grpc_call *call);
104 void grpc_call_internal_unref(grpc_call *call, int allow_immediate_deletion);
105 #define GRPC_CALL_INTERNAL_REF(call, reason) grpc_call_internal_ref(call)
106 #define GRPC_CALL_INTERNAL_UNREF(call, reason, allow_immediate_deletion) \
107  grpc_call_internal_unref(call, allow_immediate_deletion)
108 #endif
109 
110 grpc_call_error grpc_call_start_ioreq_and_call_back(
111  grpc_call *call, const grpc_ioreq *reqs, size_t nreqs,
112  grpc_ioreq_completion_func on_complete, void *user_data);
113 
114 grpc_call_stack *grpc_call_get_call_stack(grpc_call *call);
115 
116 /* Given the top call_element, get the call object. */
117 grpc_call *grpc_call_from_top_element(grpc_call_element *surface_element);
118 
119 extern int grpc_trace_batch;
120 
121 void grpc_call_log_batch(char *file, int line, gpr_log_severity severity,
122  grpc_call *call, const grpc_op *ops, size_t nops,
123  void *tag);
124 
125 /* Set a context pointer.
126  No thread safety guarantees are made wrt this value. */
127 void grpc_call_context_set(grpc_call *call, grpc_context_index elem, void *value,
128  void (*destroy)(void *value));
129 /* Get a context pointer. */
130 void *grpc_call_context_get(grpc_call *call, grpc_context_index elem);
131 
132 #define GRPC_CALL_LOG_BATCH(sev, call, ops, nops, tag) \
133  if (grpc_trace_batch) grpc_call_log_batch(sev, call, ops, nops, tag)
134 
135 gpr_uint8 grpc_call_is_client(grpc_call *call);
136 
137 #endif /* GRPC_INTERNAL_CORE_SURFACE_CALL_H */
Definition: call.h:57
Definition: channel.c:52
Definition: byte_buffer.h:43
Definition: grpc.h:207
Definition: grpc.h:182
Definition: metadata.h:78
Definition: grpc.h:258
Definition: completion_queue.c:61
Definition: channel_stack.h:177
Definition: time.h:48
Definition: channel_stack.h:160
Definition: call.c:128
Definition: call.h:79