make db file a config option.
This commit is contained in:
@@ -72,11 +72,48 @@ void _freeData(void *bp, void *p)
|
||||
|
||||
xmgr=(AQH_MSG_MANAGER*) p;
|
||||
AQH_NodeDb_free(xmgr->nodeDb);
|
||||
free(xmgr->dbFilename);
|
||||
GWEN_FREE_OBJECT(xmgr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char *AQH_MsgManager_GetDbFilename(const GWEN_MSG_ENDPOINT_MGR *emgr)
|
||||
{
|
||||
AQH_MSG_MANAGER *xmgr;
|
||||
|
||||
xmgr=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT_MGR, AQH_MSG_MANAGER, emgr);
|
||||
if (xmgr)
|
||||
return xmgr->dbFilename;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_MsgManager_SetDbFilename(GWEN_MSG_ENDPOINT_MGR *emgr, const char *s)
|
||||
{
|
||||
AQH_MSG_MANAGER *xmgr;
|
||||
|
||||
xmgr=GWEN_INHERIT_GETDATA(GWEN_MSG_ENDPOINT_MGR, AQH_MSG_MANAGER, emgr);
|
||||
if (xmgr) {
|
||||
free(xmgr->dbFilename);
|
||||
xmgr->dbFilename=s?strdup(s):NULL;
|
||||
if (xmgr->dbFilename) {
|
||||
GWEN_DB_NODE *dbNodeDb;
|
||||
int rv;
|
||||
|
||||
dbNodeDb=GWEN_DB_Group_new("dbNodes");
|
||||
rv=GWEN_DB_ReadFile(dbNodeDb, xmgr->dbFilename, GWEN_DB_FLAGS_DEFAULT);
|
||||
if (rv==0) {
|
||||
AQH_NodeDb_fromDb(xmgr->nodeDb, dbNodeDb);
|
||||
GWEN_DB_Group_free(dbNodeDb);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int AQH_MsgManager_LoopOnce(GWEN_MSG_ENDPOINT_MGR *emgr)
|
||||
{
|
||||
int rv;
|
||||
@@ -116,13 +153,15 @@ void _loopOnceOverEndpoints(GWEN_MSG_ENDPOINT_MGR *emgr)
|
||||
}
|
||||
|
||||
if (AQH_NodeDb_IsModified(xmgr->nodeDb)) {
|
||||
if (xmgr->dbFilename) {
|
||||
GWEN_DB_NODE *dbNodeDb;
|
||||
|
||||
dbNodeDb=GWEN_DB_Group_new("nodeDb");
|
||||
AQH_NodeDb_toDb(xmgr->nodeDb, dbNodeDb);
|
||||
GWEN_DB_WriteFile(dbNodeDb, "nodedb.db", GWEN_DB_FLAGS_DEFAULT);
|
||||
GWEN_DB_WriteFile(dbNodeDb, xmgr->dbFilename, GWEN_DB_FLAGS_DEFAULT);
|
||||
GWEN_DB_Group_free(dbNodeDb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@
|
||||
AQHOME_API GWEN_MSG_ENDPOINT_MGR *AQH_MsgManager_new(uint8_t busAddr);
|
||||
AQHOME_API int AQH_MsgManager_LoopOnce(GWEN_MSG_ENDPOINT_MGR *emgr);
|
||||
|
||||
AQHOME_API const char *AQH_MsgManager_GetDbFilename(const GWEN_MSG_ENDPOINT_MGR *emgr);
|
||||
AQHOME_API void AQH_MsgManager_SetDbFilename(GWEN_MSG_ENDPOINT_MGR *emgr, const char *s);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
typedef struct AQH_MSG_MANAGER AQH_MSG_MANAGER;
|
||||
struct AQH_MSG_MANAGER {
|
||||
AQH_NODE_DB *nodeDb;
|
||||
char *dbFilename;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user