blob: 55966a1c37ba75a449f67895aa80d728f1c8842a [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _DATAMANAGER_HPP_HEADER
18#define _DATAMANAGER_HPP_HEADER
19
20#include <string>
21#include <utility>
22#include <map>
23
24using namespace std;
25
26class DataManager
27{
28public:
29 static int ResetDefaults();
30 static int LoadValues(const string filename);
31 static int Flush();
32
33 // Core get routines
34 static int GetValue(const string varName, string& value);
35 static int GetValue(const string varName, int& value);
bigbiff bigbiff2c57d782013-02-19 10:09:21 -050036 static unsigned long long GetValue(const string varName, unsigned long long& value);
Dees_Troy51a0e822012-09-05 15:24:24 -040037
38 // This is a dangerous function. It will create the value if it doesn't exist so it has a valid c_str
39 static string& GetValueRef(const string varName);
40
41 // Helper functions
42 static string GetStrValue(const string varName);
43 static int GetIntValue(const string varName);
44
45 // Core set routines
46 static int SetValue(const string varName, string value, int persist = 0);
47 static int SetValue(const string varName, int value, int persist = 0);
48 static int SetValue(const string varName, float value, int persist = 0);
bigbiff bigbiff2c57d782013-02-19 10:09:21 -050049 static int SetValue(const string varName, unsigned long long value, int persist = 0);
Dees_Troy51a0e822012-09-05 15:24:24 -040050
51 static void DumpValues();
Dees_Troy8170a922012-09-18 15:40:25 -040052 static void update_tz_environment_variables();
Dees_Troy16b74352012-11-14 22:27:31 +000053 static void SetBackupFolder();
Dees_Troy51a0e822012-09-05 15:24:24 -040054 static void SetDefaultValues();
Dees_Troy01a9b7a2012-10-01 09:01:03 -040055 static void Output_Version(void); // Outputs the version to a file in the TWRP folder
Dees_Troy51a0e822012-09-05 15:24:24 -040056 static void ReadSettingsFile(void);
bigbiff bigbiff2c57d782013-02-19 10:09:21 -050057
Dees_Troy51a0e822012-09-05 15:24:24 -040058 static string GetCurrentStoragePath(void);
59 static string& CGetCurrentStoragePath();
60 static string GetCurrentStorageMount(void);
61 static string& CGetCurrentStorageMount();
62 static string GetSettingsStoragePath(void);
63 static string& CGetSettingsStoragePath();
64 static string GetSettingsStorageMount(void);
65 static string& CGetSettingsStorageMount();
66
67protected:
68 typedef pair<string, int> TStrIntPair;
bigbiff bigbiff2c57d782013-02-19 10:09:21 -050069 typedef pair<string, unsigned long long> TStrULLPair;
Dees_Troy51a0e822012-09-05 15:24:24 -040070 typedef pair<string, TStrIntPair> TNameValuePair;
71 static map<string, TStrIntPair> mValues;
bigbiff bigbiff2c57d782013-02-19 10:09:21 -050072 static map<string, TStrULLPair> mULLValues;
Dees_Troy51a0e822012-09-05 15:24:24 -040073 static string mBackingFile;
74 static int mInitialized;
75
76 static map<string, string> mConstValues;
77
78protected:
79 static int SaveValues();
80
81 static int GetMagicValue(string varName, string& value);
82
Dees_Troyfdf5fcc2012-09-11 10:27:01 -040083private:
84 static void sanitize_device_id(char* device_id);
85 static void get_device_id(void);
86
Dees_Troy51a0e822012-09-05 15:24:24 -040087};
88
89#endif // _DATAMANAGER_HPP_HEADER
90