Trace Parser: fix map forwarding
[platform/core/system/swap-manager.git] / src / cli / trace_parser / include / parser.h
1 /*
2  *  SWAP Trace Parser
3  *
4  * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:
7  *
8  * Alexander Aksenov <a.aksenov@samsung.com>
9  *
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
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
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.
21  *
22  * Contributors:
23  * - Samsung RnD Institute Russia
24  *
25  */
26
27
28
29 #ifndef __PARSER_H__
30 #define __PARSER_H__
31
32 //! \file parser.h
33 //! Contains Parser interface
34
35 #include <memory>
36 #include <string>
37 #include <map>
38 #include <data_writer.h>
39
40
41 class Protocol;
42
43 //! # Header {#HeaderDef}
44 //! Contains parsed message header, returned from parse_header().
45 class Header
46 {
47 public:
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_; };
61
62 private:
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
68 };
69
70 //! # ParserOptions (#ParserOptionsDef)
71 //! Structure used to initialize Parser.
72 struct ParserOptions
73 {
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
79
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) :
83         version(version),
84         cpu_num(cpu_num),
85         devs_num(devs_num),
86         writer(writer),
87         api_map(api_map)
88     {}
89 };
90
91 //! # Parser {#ParserDef}
92 //! Main Parser class, encapsulates Protocol classes instances
93 class Parser
94 {
95 public:
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;
111
112 private:
113     std::shared_ptr<Protocol> protocol_;
114 };
115
116 #endif /* __PARSER_H__ */