data.hpp 2.69 KB
Newer Older
Dees_Troy's avatar
Dees_Troy committed
1
/*
Dees Troy's avatar
Dees Troy committed
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
	Copyright 2012 bigbiff/Dees_Troy TeamWin
	This file is part of TWRP/TeamWin Recovery Project.

	TWRP is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	TWRP is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with TWRP.  If not, see <http://www.gnu.org/licenses/>.
*/
Dees_Troy's avatar
Dees_Troy committed
18 19 20 21 22

#ifndef _DATAMANAGER_HPP_HEADER
#define _DATAMANAGER_HPP_HEADER

#include <string>
23
#include <pthread.h>
Ethan Yonker's avatar
Ethan Yonker committed
24
#include "infomanager.hpp"
Dees_Troy's avatar
Dees_Troy committed
25 26 27 28 29 30

using namespace std;

class DataManager
{
public:
31
	static int ResetDefaults();
Ethan Yonker's avatar
Ethan Yonker committed
32
	static int LoadValues(const string& filename);
33
	static int Flush();
Dees_Troy's avatar
Dees_Troy committed
34

35
	// Core get routines
Ethan Yonker's avatar
Ethan Yonker committed
36 37 38 39
	static int GetValue(const string& varName, string& value);
	static int GetValue(const string& varName, int& value);
	static int GetValue(const string& varName, float& value);
	static unsigned long long GetValue(const string& varName, unsigned long long& value);
Dees_Troy's avatar
Dees_Troy committed
40

41
	// Helper functions
Ethan Yonker's avatar
Ethan Yonker committed
42 43
	static string GetStrValue(const string& varName);
	static int GetIntValue(const string& varName);
Dees_Troy's avatar
Dees_Troy committed
44

45
	// Core set routines
Ethan Yonker's avatar
Ethan Yonker committed
46 47 48 49 50 51
	static int SetValue(const string& varName, const string& value, const int persist = 0);
	static int SetValue(const string& varName, const int value, const int persist = 0);
	static int SetValue(const string& varName, const float value, const int persist = 0);
	static int SetValue(const string& varName, const unsigned long long& value, const int persist = 0);
	static int SetProgress(const float Fraction);
	static int ShowProgress(const float Portion, const float Seconds);
Dees_Troy's avatar
Dees_Troy committed
52

53
	static void DumpValues();
Dees_Troy's avatar
Dees_Troy committed
54
	static void update_tz_environment_variables();
Ethan Yonker's avatar
Ethan Yonker committed
55
	static void Vibrate(const string& varName);
Dees_Troy's avatar
Dees_Troy committed
56
	static void SetBackupFolder();
Dees_Troy's avatar
Dees_Troy committed
57
	static void SetDefaultValues();
Dees_Troy's avatar
Dees_Troy committed
58
	static void Output_Version(void); // Outputs the version to a file in the TWRP folder
Dees_Troy's avatar
Dees_Troy committed
59
	static void ReadSettingsFile(void);
60

Dees_Troy's avatar
Dees_Troy committed
61 62 63 64
	static string GetCurrentStoragePath(void);
	static string GetSettingsStoragePath(void);

protected:
65 66
	static string mBackingFile;
	static int mInitialized;
Ethan Yonker's avatar
Ethan Yonker committed
67 68 69
	static InfoManager mPersist;
	static InfoManager mData;
	static InfoManager mConst;
Dees_Troy's avatar
Dees_Troy committed
70

71
	static map<string, string> mConstValues;
Dees_Troy's avatar
Dees_Troy committed
72 73

protected:
74
	static int SaveValues();
Dees_Troy's avatar
Dees_Troy committed
75

Ethan Yonker's avatar
Ethan Yonker committed
76
	static int GetMagicValue(const string& varName, string& value);
Dees_Troy's avatar
Dees_Troy committed
77

78 79 80 81
private:
	static void sanitize_device_id(char* device_id);
	static void get_device_id(void);

82
	static pthread_mutex_t m_valuesLock;
Dees_Troy's avatar
Dees_Troy committed
83 84 85 86
};

#endif // _DATAMANAGER_HPP_HEADER