[tsdb&kvdb] improve the database control function.
This commit is contained in:
parent
2673a71ca8
commit
9ea4a0e729
|
@ -64,7 +64,8 @@ int main(void)
|
||||||
default_kv.kvs = default_kv_table;
|
default_kv.kvs = default_kv_table;
|
||||||
default_kv.num = sizeof(default_kv_table) / sizeof(default_kv_table[0]);
|
default_kv.num = sizeof(default_kv_table) / sizeof(default_kv_table[0]);
|
||||||
/* set the lock and unlock function if you want */
|
/* set the lock and unlock function if you want */
|
||||||
fdb_lock_set((fdb_db_t)&kvdb, lock, unlock);
|
fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_LOCK, lock);
|
||||||
|
fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_UNLOCK, unlock);
|
||||||
/* Key-Value database initialization
|
/* Key-Value database initialization
|
||||||
*
|
*
|
||||||
* &kvdb: database object
|
* &kvdb: database object
|
||||||
|
@ -92,7 +93,8 @@ int main(void)
|
||||||
#ifdef FDB_USING_TSDB
|
#ifdef FDB_USING_TSDB
|
||||||
{ /* TSDB Sample */
|
{ /* TSDB Sample */
|
||||||
/* set the lock and unlock function if you want */
|
/* set the lock and unlock function if you want */
|
||||||
fdb_lock_set((fdb_db_t)&tsdb, lock, unlock);
|
fdb_tsdb_control(&tsdb, FDB_TSDB_CTRL_SET_LOCK, lock);
|
||||||
|
fdb_tsdb_control(&tsdb, FDB_TSDB_CTRL_SET_UNLOCK, unlock);
|
||||||
/* Time series database initialization
|
/* Time series database initialization
|
||||||
*
|
*
|
||||||
* &tsdb: database object
|
* &tsdb: database object
|
||||||
|
|
|
@ -64,7 +64,8 @@ int main(void)
|
||||||
default_kv.kvs = default_kv_table;
|
default_kv.kvs = default_kv_table;
|
||||||
default_kv.num = sizeof(default_kv_table) / sizeof(default_kv_table[0]);
|
default_kv.num = sizeof(default_kv_table) / sizeof(default_kv_table[0]);
|
||||||
/* set the lock and unlock function if you want */
|
/* set the lock and unlock function if you want */
|
||||||
fdb_lock_set((fdb_db_t)&kvdb, lock, unlock);
|
fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_LOCK, lock);
|
||||||
|
fdb_kvdb_control(&kvdb, FDB_KVDB_CTRL_SET_UNLOCK, unlock);
|
||||||
/* Key-Value database initialization
|
/* Key-Value database initialization
|
||||||
*
|
*
|
||||||
* &kvdb: database object
|
* &kvdb: database object
|
||||||
|
@ -92,7 +93,8 @@ int main(void)
|
||||||
#ifdef FDB_USING_TSDB
|
#ifdef FDB_USING_TSDB
|
||||||
{ /* TSDB Sample */
|
{ /* TSDB Sample */
|
||||||
/* set the lock and unlock function if you want */
|
/* set the lock and unlock function if you want */
|
||||||
fdb_lock_set((fdb_db_t)&tsdb, lock, unlock);
|
fdb_tsdb_control(&tsdb, FDB_TSDB_CTRL_SET_LOCK, lock);
|
||||||
|
fdb_tsdb_control(&tsdb, FDB_TSDB_CTRL_SET_UNLOCK, unlock);
|
||||||
/* Time series database initialization
|
/* Time series database initialization
|
||||||
*
|
*
|
||||||
* &tsdb: database object
|
* &tsdb: database object
|
||||||
|
|
|
@ -61,8 +61,17 @@ if (!(EXPR)) \
|
||||||
while (1); \
|
while (1); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FDB_TSDB_CTRL_SET_ROLLOVER 0x0 /**< set rollover control command */
|
#define FDB_KVDB_CTRL_SET_SEC_SIZE 0x0 /**< get sector size control command */
|
||||||
#define FDB_TSDB_CTRL_GET_ROLLOVER 0x1 /**< get rollover control command */
|
#define FDB_KVDB_CTRL_GET_SEC_SIZE 0x1 /**< get sector size control command */
|
||||||
|
#define FDB_KVDB_CTRL_SET_LOCK 0x2 /**< set lock function control command */
|
||||||
|
#define FDB_KVDB_CTRL_SET_UNLOCK 0x3 /**< set unlock function control command */
|
||||||
|
|
||||||
|
#define FDB_TSDB_CTRL_SET_SEC_SIZE 0x0 /**< get sector size control command */
|
||||||
|
#define FDB_TSDB_CTRL_GET_SEC_SIZE 0x1 /**< get sector size control command */
|
||||||
|
#define FDB_TSDB_CTRL_SET_LOCK 0x2 /**< set lock function control command */
|
||||||
|
#define FDB_TSDB_CTRL_SET_UNLOCK 0x3 /**< set unlock function control command */
|
||||||
|
#define FDB_TSDB_CTRL_SET_ROLLOVER 0x4 /**< set rollover control command */
|
||||||
|
#define FDB_TSDB_CTRL_GET_ROLLOVER 0x5 /**< get rollover control command */
|
||||||
|
|
||||||
typedef time_t fdb_time_t;
|
typedef time_t fdb_time_t;
|
||||||
#ifdef FDB_USING_TIMESTAMP_64BIT
|
#ifdef FDB_USING_TIMESTAMP_64BIT
|
||||||
|
|
|
@ -25,10 +25,9 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* FlashDB database API */
|
/* FlashDB database API */
|
||||||
void fdb_lock_set (fdb_db_t db, void (*lock)(fdb_db_t db), void (*unlock)(fdb_db_t db));
|
|
||||||
void fdb_sec_size_set(fdb_db_t db, uint32_t sec_size);
|
|
||||||
fdb_err_t fdb_kvdb_init (fdb_kvdb_t db, const char *name, const char *part_name, struct fdb_default_kv *default_kv,
|
fdb_err_t fdb_kvdb_init (fdb_kvdb_t db, const char *name, const char *part_name, struct fdb_default_kv *default_kv,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
void fdb_kvdb_control(fdb_kvdb_t db, int cmd, void *arg);
|
||||||
fdb_err_t fdb_tsdb_init (fdb_tsdb_t db, const char *name, const char *part_name, fdb_get_time get_time, size_t max_len,
|
fdb_err_t fdb_tsdb_init (fdb_tsdb_t db, const char *name, const char *part_name, fdb_get_time get_time, size_t max_len,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
void fdb_tsdb_control(fdb_tsdb_t db, int cmd, void *arg);
|
void fdb_tsdb_control(fdb_tsdb_t db, int cmd, void *arg);
|
||||||
|
|
|
@ -1518,6 +1518,33 @@ __retry:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function will get or set some options of the database
|
||||||
|
*
|
||||||
|
* @param db database object
|
||||||
|
* @param cmd the control command
|
||||||
|
* @param arg the argument
|
||||||
|
*/
|
||||||
|
void fdb_kvdb_control(fdb_kvdb_t db, int cmd, void *arg)
|
||||||
|
{
|
||||||
|
FDB_ASSERT(db);
|
||||||
|
|
||||||
|
switch (cmd) {
|
||||||
|
case FDB_KVDB_CTRL_SET_SEC_SIZE:
|
||||||
|
db->parent.sec_size = *(uint32_t *)arg;
|
||||||
|
break;
|
||||||
|
case FDB_KVDB_CTRL_GET_SEC_SIZE:
|
||||||
|
*(uint32_t *)arg = db->parent.sec_size;
|
||||||
|
break;
|
||||||
|
case FDB_KVDB_CTRL_SET_LOCK:
|
||||||
|
db->parent.lock = (void (*)(fdb_db_t db))arg;
|
||||||
|
break;
|
||||||
|
case FDB_KVDB_CTRL_SET_UNLOCK:
|
||||||
|
db->parent.unlock = (void (*)(fdb_db_t db))arg;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The KV database initialization.
|
* The KV database initialization.
|
||||||
*
|
*
|
||||||
|
|
|
@ -668,12 +668,23 @@ void fdb_tsdb_control(fdb_tsdb_t db, int cmd, void *arg)
|
||||||
FDB_ASSERT(db);
|
FDB_ASSERT(db);
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
|
case FDB_TSDB_CTRL_SET_ROLLOVER:
|
||||||
|
db->rollover = *(bool *)arg;
|
||||||
|
break;
|
||||||
case FDB_TSDB_CTRL_GET_ROLLOVER:
|
case FDB_TSDB_CTRL_GET_ROLLOVER:
|
||||||
*(bool *)arg = db->rollover;
|
*(bool *)arg = db->rollover;
|
||||||
break;
|
break;
|
||||||
|
case FDB_TSDB_CTRL_SET_SEC_SIZE:
|
||||||
case FDB_TSDB_CTRL_SET_ROLLOVER:
|
db->parent.sec_size = *(uint32_t *)arg;
|
||||||
db->rollover = *(bool *)arg;
|
break;
|
||||||
|
case FDB_TSDB_CTRL_GET_SEC_SIZE:
|
||||||
|
*(uint32_t *)arg = db->parent.sec_size;
|
||||||
|
break;
|
||||||
|
case FDB_TSDB_CTRL_SET_LOCK:
|
||||||
|
db->parent.lock = (void (*)(fdb_db_t db))arg;
|
||||||
|
break;
|
||||||
|
case FDB_TSDB_CTRL_SET_UNLOCK:
|
||||||
|
db->parent.unlock = (void (*)(fdb_db_t db))arg;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue