• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * \file       device_parser.h
3  * \brief      OpenCSD : Snapshot parser library
4  *
5  * \copyright  Copyright (c) 2015, ARM Limited. All Rights Reserved.
6  */
7 
8 
9 /*
10  * Redistribution and use in source and binary forms, with or without modification,
11  * are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright notice,
17  * this list of conditions and the following disclaimer in the documentation
18  * and/or other materials provided with the distribution.
19  *
20  * 3. Neither the name of the copyright holder nor the names of its contributors
21  * may be used to endorse or promote products derived from this software without
22  * specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef DEVICE_PARSER_H
37 #define DEVICE_PARSER_H
38 
39 #include "device_info.h"
40 #include <memory>
41 
42 #include <map>
43 #include <istream>
44 #include <vector>
45 #include <cstdint>
46 
47 #include "snapshot_info.h"
48 
49 class DeviceParser
50 {
51 public:
~DeviceParser()52     virtual ~DeviceParser() {};
53     typedef std::shared_ptr<DeviceInfo> DevPtr;
54     virtual DevPtr getDevice(int devNo) =0;
55     virtual void getDeviceList(std::vector<int> &devices)  const = 0;
56     virtual size_t getDeviceCount() const = 0;
57 
58 };
59 
60 class SnapshotParser
61 {
62 public:
~SnapshotParser()63     virtual ~SnapshotParser() {};
64     virtual std::string getDescription() const = 0;
65     virtual std::string getVersion() const = 0;
66 };
67 
68 class ModernSnapshotParser : public DeviceParser, SnapshotParser
69 {
70 public:
71     ModernSnapshotParser( std::istream &iss);
72     ModernSnapshotParser();
73     virtual ~ModernSnapshotParser();
74 
75     typedef std::shared_ptr<DeviceInfo> DevPtr;
76     DevPtr getDevice(int devNo);
77     void getDeviceList(std::vector<int> &devices) const;
78 
79     bool isInitialised() const;
80     size_t getDeviceCount() const;
81 
82     std::string getTraceMetadataFile() const;
83 
84     // Snapshot Info
85     std::string getDescription() const;
86     std::string getVersion() const;
87 
88 
89 private:
90     void addDevice(std::string rawName, std::string path);
91     uint32_t getUniqueDeviceID(std::string &rawName);
92 
93     void addSnapshotInfo(SnapshotInfo snap);
94 
95     SnapshotInfo snaphotInfo;
96 
97     // map stores deviceId and associated data
98     std::map<int, DevPtr> deviceMap;
99     bool initialised;
100 
101     std::string traceMetaDataIni;
102 };
103 
104 #endif
105 
106 /* End of File device_parser.h */
107