Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed RemoteIR SuperTweet ConfigFile EthernetNetIf
Diff: mylib/appconf/appconf.cpp
- Revision:
- 0:db299c5a18ba
- Child:
- 1:c4cfd136f9c7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/mylib/appconf/appconf.cpp Fri Oct 29 23:17:01 2010 +0000
@@ -0,0 +1,57 @@
+#include "appconf.h"
+#include "ConfigFile.h"
+
+#define KEY_SUPERTWEET_ACCOUNT "SUPERTWEET_ACCOUNT"
+#define KEY_SUPERTWEET_PASSWORD "SUPERTWEET_PASSWORD"
+
+/**
+ * Initialize configuration.
+ *
+ * @param p A pointer to a application config.
+ */
+void appconf_init(appconf_t *p) {
+ memset(p->account, 0, sizeof(p->account));
+ memset(p->password, 0, sizeof(p->password));
+}
+
+/**
+ * Read configuration.
+ *
+ * @param filename Filename.
+ * @param p A pointer to a application config.
+ * @return Return zero if it succeed.
+ */
+int appconf_read(char *filename, appconf_t *p) {
+ ConfigFile cf;
+ if (!cf.read(filename)) {
+ return -1;
+ }
+ if (!cf.getValue(KEY_SUPERTWEET_ACCOUNT, p->account, sizeof(p->account))) {
+ return -2;
+ }
+ if (!cf.getValue(KEY_SUPERTWEET_PASSWORD, p->password, sizeof(p->password))) {
+ return -3;
+ }
+ return 0;
+}
+
+/**
+ * Write configuration.
+ *
+ * @param filename Filename.
+ * @param p A pointer to a application config.
+ * @return Return zero if it succeed.
+ */
+int appconf_write(char *filename, appconf_t *p) {
+ ConfigFile cf;
+ if (!cf.setValue(KEY_SUPERTWEET_ACCOUNT, p->account)) {
+ return -1;
+ }
+ if (!cf.setValue(KEY_SUPERTWEET_PASSWORD, p->password)) {
+ return -2;
+ }
+ if (!cf.write(filename)) {
+ return -3;
+ }
+ return 0;
+}