mbed_controller
/
dconfig_demo
Sample program for config data handling.
Revision 0:7cfa4f091512, committed 2015-02-17
- Comitter:
- hillkim7
- Date:
- Tue Feb 17 14:41:36 2015 +0000
- Commit message:
- The dconfig library example.
Changed in this revision
diff -r 000000000000 -r 7cfa4f091512 dconfig.lib --- /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
diff -r 000000000000 -r 7cfa4f091512 main.cpp --- /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; +} + +
diff -r 000000000000 -r 7cfa4f091512 mbed.bld --- /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