3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <grpc/support/port_platform.h>
21 #include "src/core/lib/surface/event_string.h"
25 #include <grpc/byte_buffer.h>
26 #include <grpc/support/string_util.h>
27 #include "src/core/lib/gpr/string.h"
29 static void addhdr(gpr_strvec* buf, grpc_event* ev) {
31 gpr_asprintf(&tmp, "tag:%p", ev->tag);
32 gpr_strvec_add(buf, tmp);
35 static const char* errstr(int success) { return success ? "OK" : "ERROR"; }
37 static void adderr(gpr_strvec* buf, int success) {
39 gpr_asprintf(&tmp, " %s", errstr(success));
40 gpr_strvec_add(buf, tmp);
43 char* grpc_event_string(grpc_event* ev) {
47 if (ev == nullptr) return gpr_strdup("null");
49 gpr_strvec_init(&buf);
52 case GRPC_QUEUE_TIMEOUT:
53 gpr_strvec_add(&buf, gpr_strdup("QUEUE_TIMEOUT"));
55 case GRPC_QUEUE_SHUTDOWN:
56 gpr_strvec_add(&buf, gpr_strdup("QUEUE_SHUTDOWN"));
58 case GRPC_OP_COMPLETE:
59 gpr_strvec_add(&buf, gpr_strdup("OP_COMPLETE: "));
61 adderr(&buf, ev->success);
65 out = gpr_strvec_flatten(&buf, nullptr);
66 gpr_strvec_destroy(&buf);