Sample program for config data handling.

Dependencies:   dconfig mbed

Files at this revision

API Documentation at this revision

Comitter:
hillkim7
Date:
Tue Feb 17 14:41:36 2015 +0000
Commit message:
The dconfig library example.

Changed in this revision

dconfig.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dconfig.lib	Tue Feb 17 14:41:36 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/mbed_controller/code/dconfig/#7e982de4d3f5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Feb 17 14:41:36 2015 +0000
@@ -0,0 +1,52 @@
+/*
+Demo application for the dconfig library for handling app configuration setting.
+*/
+#include <stdio.h>
+#include "dconfig.h"
+
+class MyConfig : public DConfig
+{
+public:
+	virtual void reset_default(void)
+	{
+		(*this)["tz"] = "9";
+		(*this)["name"] = "my_app";
+	}
+};
+
+static bool save_to_str(void *user_data, char c)
+{
+	std::string *buf = (std::string*)user_data;
+
+	buf->push_back(c);
+	return true;
+}
+
+int main(int argc, char* argv[])
+{
+	MyConfig mycfg;
+	std::string serialized_data;
+
+	// setup initial key & value
+	mycfg.reset_default();
+
+	printf("name=%s\r\n", mycfg.lookup_as_cstr("name", ""));
+	printf("tz=%d\r\n", mycfg.lookup_as_int("tz", 0));
+
+	// save data to serialized_data and clear mycfg
+	mycfg.save_to(save_to_str, &serialized_data);
+	mycfg.clear();
+
+	// make sure data is clean
+	printf("name=%s\r\n", mycfg.lookup_as_cstr("name", ""));
+	printf("tz=%d\r\n", mycfg.lookup_as_int("tz", 0));
+
+	// restore and see its contents
+	mycfg.load_from(serialized_data.c_str(), serialized_data.size());
+	printf("name=%s\r\n", mycfg.lookup_as_cstr("name", ""));
+	printf("tz=%d\r\n", mycfg.lookup_as_int("tz", 0));
+
+	return 0;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Feb 17 14:41:36 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9ad691361fac
\ No newline at end of file