DataManager Updates

The goal of this change is to make DataManager use InfoManager to reduce
code duplication.

Change-Id: Ia4f4c4324453a192995e0f442db0a03628c13e46
diff --git a/infomanager.cpp b/infomanager.cpp
index 2a4c3c8..275c70c 100644
--- a/infomanager.cpp
+++ b/infomanager.cpp
@@ -16,22 +16,7 @@
 	along with TWRP.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-#include <linux/input.h>
-#include <pthread.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-#include <stdlib.h>
-
 #include <string>
-#include <utility>
 #include <map>
 #include <fstream>
 #include <sstream>
@@ -43,11 +28,34 @@
 
 using namespace std;
 
-InfoManager::InfoManager(const string filename) {
-	File = filename;
+InfoManager::InfoManager() {
+	file_version = 0;
+	is_const = false;
+}
+
+InfoManager::InfoManager(const string& filename) {
+	file_version = 0;
+	is_const = false;
+	SetFile(filename);
 }
 
 InfoManager::~InfoManager(void) {
+	Clear();
+}
+
+void InfoManager::SetFile(const string& filename) {
+	File = filename;
+}
+
+void InfoManager::SetFileVersion(int version) {
+	file_version = version;
+}
+
+void InfoManager::SetConst(void) {
+	is_const = true;
+}
+
+void InfoManager::Clear(void) {
 	mValues.clear();
 }
 
@@ -63,6 +71,16 @@
 		LOGINFO("InfoManager loading from '%s'.\n", File.c_str());
 	}
 
+	if (file_version) {
+		int read_file_version;
+		if (fread(&read_file_version, 1, sizeof(int), in) != sizeof(int))
+			goto error;
+		if (read_file_version != file_version) {
+			LOGINFO("InfoManager file version has changed, not reading file\n");
+			goto error;
+		}
+	}
+
 	while (!feof(in)) {
 		string Name;
 		string Value;
@@ -105,6 +123,10 @@
 	if (!out)
 		return -1;
 
+	if (file_version) {
+		fwrite(&file_version, 1, sizeof(int), out);
+	}
+
 	map<string, string>::iterator iter;
 	for (iter = mValues.begin(); iter != mValues.end(); ++iter) {
 		unsigned short length = (unsigned short) iter->first.length() + 1;
@@ -119,7 +141,7 @@
 	return 0;
 }
 
-int InfoManager::GetValue(const string varName, string& value) {
+int InfoManager::GetValue(const string& varName, string& value) {
 	string localStr = varName;
 
 	map<string, string>::iterator pos;
@@ -131,7 +153,7 @@
 	return 0;
 }
 
-int InfoManager::GetValue(const string varName, int& value) {
+int InfoManager::GetValue(const string& varName, int& value) {
 	string data;
 
 	if (GetValue(varName,data) != 0)
@@ -141,7 +163,7 @@
 	return 0;
 }
 
-int InfoManager::GetValue(const string varName, float& value) {
+int InfoManager::GetValue(const string& varName, float& value) {
 	string data;
 
 	if (GetValue(varName,data) != 0)
@@ -151,7 +173,7 @@
 	return 0;
 }
 
-unsigned long long InfoManager::GetValue(const string varName, unsigned long long& value) {
+unsigned long long InfoManager::GetValue(const string& varName, unsigned long long& value) {
 	string data;
 
 	if (GetValue(varName,data) != 0)
@@ -162,7 +184,7 @@
 }
 
 // This function will return an empty string if the value doesn't exist
-string InfoManager::GetStrValue(const string varName) {
+string InfoManager::GetStrValue(const string& varName) {
 	string retVal;
 
 	GetValue(varName, retVal);
@@ -170,14 +192,14 @@
 }
 
 // This function will return 0 if the value doesn't exist
-int InfoManager::GetIntValue(const string varName) {
+int InfoManager::GetIntValue(const string& varName) {
 	string retVal;
 	GetValue(varName, retVal);
 	return atoi(retVal.c_str());
 }
 
-int InfoManager::SetValue(const string varName, string value) {
-	// Don't allow empty values or numerical starting values
+int InfoManager::SetValue(const string& varName, const string& value) {
+	// Don't allow empty names or numerical starting values
 	if (varName.empty() || (varName[0] >= '0' && varName[0] <= '9'))
 		return -1;
 
@@ -185,25 +207,25 @@
 	pos = mValues.find(varName);
 	if (pos == mValues.end())
 		mValues.insert(make_pair(varName, value));
-	else
+	else if (!is_const)
 		pos->second = value;
 
 	return 0;
 }
 
-int InfoManager::SetValue(const string varName, int value) {
+int InfoManager::SetValue(const string& varName, const int value) {
 	ostringstream valStr;
 	valStr << value;
 	return SetValue(varName, valStr.str());
 }
 
-int InfoManager::SetValue(const string varName, float value) {
+int InfoManager::SetValue(const string& varName, const float value) {
 	ostringstream valStr;
 	valStr << value;
 	return SetValue(varName, valStr.str());
 }
 
-int InfoManager::SetValue(const string varName, unsigned long long value) {
+int InfoManager::SetValue(const string& varName, const unsigned long long& value) {
 	ostringstream valStr;
 	valStr << value;
 	return SetValue(varName, valStr.str());