blob: 32b3684230d8801af21875c9e655726a9c084663 [file] [log] [blame]
Vadim Iosevichd50ea462017-03-30 16:19:08 +03001/*
2 * Copyright (c) 2017, The Linux Foundation. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
Vadim Iosevich40679a12017-06-06 14:24:07 +030030#ifndef _PMC_DATA_H_
31#define _PMC_DATA_H_
Vadim Iosevichd50ea462017-03-30 16:19:08 +030032
Vadim Iosevich40679a12017-06-06 14:24:07 +030033#include "OperationStatus.h"
34
Vadim Iosevichd50ea462017-03-30 16:19:08 +030035#include <string>
Vadim Iosevich40679a12017-06-06 14:24:07 +030036#include <iostream>
Vadim Iosevichd50ea462017-03-30 16:19:08 +030037
38// *************************************************************************************************
39
Vadim Iosevich40679a12017-06-06 14:24:07 +030040// Locates a PMC data file path according to its ID.
41class PmcDataFileLocator
Vadim Iosevichd50ea462017-03-30 16:19:08 +030042{
43public:
44
Vadim Iosevich40679a12017-06-06 14:24:07 +030045 explicit PmcDataFileLocator(int fileId);
Vadim Iosevichd50ea462017-03-30 16:19:08 +030046
47 int GetFileId() const { return m_FileId; }
48 const char* GetFileName() const { return m_FileName.c_str(); }
Vadim Iosevich40679a12017-06-06 14:24:07 +030049 bool FileExists() const;
Vadim Iosevichd50ea462017-03-30 16:19:08 +030050
51 static const char* GetDirectory() { return s_pDirectory; }
52
53private:
54
55 static const char* const s_pDirectory;
56 static const char* const s_pFileNamePrefix;
57
58 const int m_FileId; // File ID (expected to be unique)
59 std::string m_FileName; // File Name Buffer
60
61};
62
Vadim Iosevich40679a12017-06-06 14:24:07 +030063std::ostream& operator<<(std::ostream& os, const PmcDataFileLocator& pmcDataFileLocator);
Vadim Iosevichd50ea462017-03-30 16:19:08 +030064
65// *************************************************************************************************
66
67// Creates a PMC data file according to a provided ID.
Vadim Iosevich40679a12017-06-06 14:24:07 +030068class PmcDataFileWriter
Vadim Iosevichd50ea462017-03-30 16:19:08 +030069{
70public:
71
Vadim Iosevich40679a12017-06-06 14:24:07 +030072 PmcDataFileWriter(int fileId, const char* szDebugFsPath);
73 OperationStatus WriteFile() const;
Vadim Iosevichd50ea462017-03-30 16:19:08 +030074
75private:
76
Vadim Iosevich40679a12017-06-06 14:24:07 +030077 OperationStatus MeetWritePrerequisites() const;
Vadim Iosevichd50ea462017-03-30 16:19:08 +030078
Vadim Iosevich40679a12017-06-06 14:24:07 +030079 const PmcDataFileLocator m_PmcDataFileLocator;
80 std::string m_SrcPmcDataPath;
Vadim Iosevichd50ea462017-03-30 16:19:08 +030081
82};
83
84
Vadim Iosevich40679a12017-06-06 14:24:07 +030085#endif // _PMC_DATA_H_