/src/connectedhomeip/examples/common/tracing/TraceDecoder.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2022 Project CHIP Authors |
3 | | * All rights reserved. |
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 | | #pragma once |
20 | | |
21 | | #include "TraceDecoderOptions.h" |
22 | | #include "TraceHandlers.h" |
23 | | |
24 | | #include <json/json.h> |
25 | | #include <lib/core/CHIPError.h> |
26 | | |
27 | | #include <string> |
28 | | |
29 | | namespace chip { |
30 | | namespace trace { |
31 | | |
32 | | class TraceDecoder : public TraceStream |
33 | | { |
34 | | public: |
35 | | CHIP_ERROR ReadFile(const char * fp); |
36 | | CHIP_ERROR ReadString(const char * str); |
37 | | |
38 | 0 | void SetOptions(TraceDecoderOptions options) { mOptions = options; } |
39 | | |
40 | | // TraceStream Interface |
41 | 0 | void StartEvent(const std::string & label) override { TEMPORARY_RETURN_IGNORED ReadString(label.c_str()); } |
42 | | |
43 | | void AddField(const std::string & tag, const std::string & data) override |
44 | 0 | { |
45 | 0 | char buffer[4096] = {}; |
46 | 0 | snprintf(buffer, sizeof(buffer), " %s\t %s", tag.c_str(), data.c_str()); |
47 | 0 | CHIP_ERROR err = ReadString(buffer); |
48 | |
|
49 | 0 | if (err != CHIP_NO_ERROR) |
50 | 0 | { |
51 | 0 | ChipLogError(Automation, "Failed to add field: %" CHIP_ERROR_FORMAT, err.Format()); |
52 | 0 | } |
53 | 0 | } |
54 | | |
55 | 0 | void FinishEvent() override {} |
56 | | |
57 | | private: |
58 | | CHIP_ERROR LogJSON(Json::Value & value); |
59 | | CHIP_ERROR LogAndConsumeProtocol(Json::Value & value); |
60 | | CHIP_ERROR MaybeLogAndConsumeHeaderFlags(Json::Value & value); |
61 | | CHIP_ERROR MaybeLogAndConsumeSecurityFlags(Json::Value & value); |
62 | | CHIP_ERROR MaybeLogAndConsumeMessageFlags(Json::Value & value); |
63 | | CHIP_ERROR MaybeLogAndConsumeExchangeFlags(Json::Value & value); |
64 | | CHIP_ERROR MaybeLogAndConsumePayload(Json::Value & value, bool isResponse); |
65 | | CHIP_ERROR MaybeLogAndConsumeOthers(Json::Value & value); |
66 | | |
67 | | private: |
68 | | TraceDecoderOptions mOptions; |
69 | | }; |
70 | | |
71 | | } // namespace trace |
72 | | } // namespace chip |