Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 24 | using namespace std; |
| 25 | |
| 26 | class DataManager |
| 27 | { |
| 28 | public: |
| 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); |
| 36 | |
| 37 | // This is a dangerous function. It will create the value if it doesn't exist so it has a valid c_str |
| 38 | static string& GetValueRef(const string varName); |
| 39 | |
| 40 | // Helper functions |
| 41 | static string GetStrValue(const string varName); |
| 42 | static int GetIntValue(const string varName); |
| 43 | |
| 44 | // Core set routines |
| 45 | static int SetValue(const string varName, string value, int persist = 0); |
| 46 | static int SetValue(const string varName, int value, int persist = 0); |
| 47 | static int SetValue(const string varName, float value, int persist = 0); |
| 48 | |
| 49 | static void DumpValues(); |
Dees_Troy | 8170a92 | 2012-09-18 15:40:25 -0400 | [diff] [blame] | 50 | static void update_tz_environment_variables(); |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 51 | static void SetDefaultValues(); |
| 52 | static void ReadSettingsFile(void); |
| 53 | |
| 54 | static string GetCurrentStoragePath(void); |
| 55 | static string& CGetCurrentStoragePath(); |
| 56 | static string GetCurrentStorageMount(void); |
| 57 | static string& CGetCurrentStorageMount(); |
| 58 | static string GetSettingsStoragePath(void); |
| 59 | static string& CGetSettingsStoragePath(); |
| 60 | static string GetSettingsStorageMount(void); |
| 61 | static string& CGetSettingsStorageMount(); |
| 62 | |
| 63 | protected: |
| 64 | typedef pair<string, int> TStrIntPair; |
| 65 | typedef pair<string, TStrIntPair> TNameValuePair; |
| 66 | static map<string, TStrIntPair> mValues; |
| 67 | static string mBackingFile; |
| 68 | static int mInitialized; |
| 69 | |
| 70 | static map<string, string> mConstValues; |
| 71 | |
| 72 | protected: |
| 73 | static int SaveValues(); |
| 74 | |
| 75 | static int GetMagicValue(string varName, string& value); |
| 76 | |
Dees_Troy | fdf5fcc | 2012-09-11 10:27:01 -0400 | [diff] [blame] | 77 | private: |
| 78 | static void sanitize_device_id(char* device_id); |
| 79 | static void get_device_id(void); |
| 80 | |
Dees_Troy | 51a0e82 | 2012-09-05 15:24:24 -0400 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | #endif // _DATAMANAGER_HPP_HEADER |
| 84 | |