4 * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
8 * Alexander Aksenov <a.aksenov@samsung.com>
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
23 * - Samsung RnD Institute Russia
33 //! Contains Parser interface
38 #include <data_writer.h>
43 //! # Header {#HeaderDef}
44 //! Contains parsed message header, returned from parse_header().
48 //! Initialized with message header data
49 Header(uint32_t id, uint32_t seq, uint32_t sec, uint32_t usec, uint32_t len) :
50 id_(id), seq_(seq), sec_(sec), usec_(usec),len_(len) {}
51 //! Returns message ID
52 uint32_t get_id() const { return id_; };
53 //! Returns message sequence number
54 uint32_t get_seq() const { return seq_; };
55 //! Returns second of the event
56 uint32_t get_sec() const { return sec_; };
57 //! Returns microsecond of the event
58 uint32_t get_usec() const { return usec_; };
59 //! Returns message specific data length
60 size_t get_msg_len() const { return len_; };
63 uint32_t id_; //!< Message id
64 uint32_t seq_; //!< Message sequence number
65 uint32_t sec_; //!< Second of the event
66 uint32_t usec_; //!< Microsecond of the event
67 uint32_t len_; //!< Message-specific data length
70 //! # ParserOptions (#ParserOptionsDef)
71 //! Structure used to initialize Parser.
74 const std::string version; //!< Trace's protocol version
75 const int cpu_num; //!< Number of traget CPUs
76 const int devs_num; //!< Number of target energy devices
77 std::shared_ptr<DataWriter> writer; //!< Writer pointer
78 const std::map<int, std::string> &api_map; //!< Reference to API map list
80 //! Initialized with structure members
81 ParserOptions(const std::string &version, const int cpu_num, const int devs_num,
82 std::shared_ptr<DataWriter> writer, const std::map<int, std::string> &api_map) :
91 //! # Parser {#ParserDef}
92 //! Main Parser class, encapsulates Protocol classes instances
96 //! Initialization with init structure
97 Parser(const ParserOptions &init_data);
98 //! Function for trace parsing beginning
99 void start_file() const;
100 //! Function for trace parsing finishing
101 void finish_file() const;
102 //! Returns header size for specified protocol
103 size_t get_header_size() const;
104 //! Parses header and returns it in Header object.
105 //! buf - reference to binary data bundle
106 const Header parse_header(const std::vector<char> &buf) const;
107 //! Parses message payload.
108 //! buf - reference to binary data bundle;
109 //! header - to parsed message header.
110 void parse_payload(const std::vector<char> &buf, const Header &header) const;
113 std::shared_ptr<Protocol> protocol_;
116 #endif /* __PARSER_H__ */