• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #include <grpc/support/port_platform.h>
20 
21 #include "src/core/lib/surface/event_string.h"
22 
23 #include <stdio.h>
24 
25 #include <grpc/byte_buffer.h>
26 #include <grpc/support/string_util.h>
27 #include "src/core/lib/gpr/string.h"
28 
addhdr(gpr_strvec * buf,grpc_event * ev)29 static void addhdr(gpr_strvec* buf, grpc_event* ev) {
30   char* tmp;
31   gpr_asprintf(&tmp, "tag:%p", ev->tag);
32   gpr_strvec_add(buf, tmp);
33 }
34 
errstr(int success)35 static const char* errstr(int success) { return success ? "OK" : "ERROR"; }
36 
adderr(gpr_strvec * buf,int success)37 static void adderr(gpr_strvec* buf, int success) {
38   char* tmp;
39   gpr_asprintf(&tmp, " %s", errstr(success));
40   gpr_strvec_add(buf, tmp);
41 }
42 
grpc_event_string(grpc_event * ev)43 char* grpc_event_string(grpc_event* ev) {
44   char* out;
45   gpr_strvec buf;
46 
47   if (ev == nullptr) return gpr_strdup("null");
48 
49   gpr_strvec_init(&buf);
50 
51   switch (ev->type) {
52     case GRPC_QUEUE_TIMEOUT:
53       gpr_strvec_add(&buf, gpr_strdup("QUEUE_TIMEOUT"));
54       break;
55     case GRPC_QUEUE_SHUTDOWN:
56       gpr_strvec_add(&buf, gpr_strdup("QUEUE_SHUTDOWN"));
57       break;
58     case GRPC_OP_COMPLETE:
59       gpr_strvec_add(&buf, gpr_strdup("OP_COMPLETE: "));
60       addhdr(&buf, ev);
61       adderr(&buf, ev->success);
62       break;
63   }
64 
65   out = gpr_strvec_flatten(&buf, nullptr);
66   gpr_strvec_destroy(&buf);
67   return out;
68 }
69