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
mylib/appconf/appconf.cpp
- Committer:
- shintamainjp
- Date:
- 2010-10-29
- Revision:
- 0:db299c5a18ba
- Child:
- 1:c4cfd136f9c7
File content as of revision 0:db299c5a18ba:
#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;
}