mirror of
https://github.com/armink/FlashDB.git
synced 2025-01-16 20:12:52 +08:00
[sample] update code style.
This commit is contained in:
parent
8a4dabed62
commit
e8b43b85a4
@ -47,7 +47,7 @@ void kvdb_type_blob_sample(fdb_kvdb_t kvdb)
|
|||||||
{ /* CHANGE the KV value */
|
{ /* CHANGE the KV value */
|
||||||
int temp_data = 38;
|
int temp_data = 38;
|
||||||
|
|
||||||
/* change the "temp" KV's value to 38.1 */
|
/* change the "temp" KV's value to 38 */
|
||||||
fdb_kv_set_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data)));
|
fdb_kv_set_blob(kvdb, "temp", fdb_blob_make(&blob, &temp_data, sizeof(temp_data)));
|
||||||
FDB_INFO("set 'temp' value to %d\n", temp_data);
|
FDB_INFO("set 'temp' value to %d\n", temp_data);
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
|
|
||||||
void kvdb_type_string_sample(fdb_kvdb_t kvdb)
|
void kvdb_type_string_sample(fdb_kvdb_t kvdb)
|
||||||
{
|
{
|
||||||
|
|
||||||
FDB_INFO("==================== kvdb_type_string_sample ====================\n");
|
FDB_INFO("==================== kvdb_type_string_sample ====================\n");
|
||||||
|
|
||||||
{ /* CREATE new Key-Value */
|
{ /* CREATE new Key-Value */
|
||||||
char temp_data[10] = "36C";
|
char temp_data[10] = "36C";
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ struct env_status {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static bool query_cb(fdb_tsl_t tsl, void *arg);
|
static bool query_cb(fdb_tsl_t tsl, void *arg);
|
||||||
|
static bool query_by_time_cb(fdb_tsl_t tsl, void *arg);
|
||||||
static bool set_status_cb(fdb_tsl_t tsl, void *arg);
|
static bool set_status_cb(fdb_tsl_t tsl, void *arg);
|
||||||
|
|
||||||
void tsdb_sample(fdb_tsdb_t tsdb)
|
void tsdb_sample(fdb_tsdb_t tsdb)
|
||||||
@ -61,7 +62,7 @@ void tsdb_sample(fdb_tsdb_t tsdb)
|
|||||||
time_t from_time = mktime(&tm_from), to_time = mktime(&tm_to);
|
time_t from_time = mktime(&tm_from), to_time = mktime(&tm_to);
|
||||||
size_t count;
|
size_t count;
|
||||||
/* query all TSL in TSDB by time */
|
/* query all TSL in TSDB by time */
|
||||||
fdb_tsl_iter_by_time(tsdb, from_time, to_time, query_cb, tsdb);
|
fdb_tsl_iter_by_time(tsdb, from_time, to_time, query_by_time_cb, tsdb);
|
||||||
/* query all FDB_TSL_WRITE status TSL's count in TSDB by time */
|
/* query all FDB_TSL_WRITE status TSL's count in TSDB by time */
|
||||||
count = fdb_tsl_query_count(tsdb, from_time, to_time, FDB_TSL_WRITE);
|
count = fdb_tsl_query_count(tsdb, from_time, to_time, FDB_TSL_WRITE);
|
||||||
FDB_INFO("query count is: %u\n", count);
|
FDB_INFO("query count is: %u\n", count);
|
||||||
@ -72,7 +73,9 @@ void tsdb_sample(fdb_tsdb_t tsdb)
|
|||||||
* set_status_cb: the change operation will in this callback
|
* set_status_cb: the change operation will in this callback
|
||||||
*
|
*
|
||||||
* NOTE: The actions to modify the state must be in order.
|
* NOTE: The actions to modify the state must be in order.
|
||||||
* FDB_TSL_WRITE -> FDB_TSL_USER_STATUS1 -> FDB_TSL_DELETED -> FDB_TSL_USER_STATUS2
|
* like: FDB_TSL_WRITE -> FDB_TSL_USER_STATUS1 -> FDB_TSL_DELETED -> FDB_TSL_USER_STATUS2
|
||||||
|
* The intermediate states can also be ignored.
|
||||||
|
* such as: FDB_TSL_WRITE -> FDB_TSL_DELETED
|
||||||
*/
|
*/
|
||||||
fdb_tsl_iter(tsdb, set_status_cb, tsdb);
|
fdb_tsl_iter(tsdb, set_status_cb, tsdb);
|
||||||
}
|
}
|
||||||
@ -87,7 +90,19 @@ static bool query_cb(fdb_tsl_t tsl, void *arg)
|
|||||||
fdb_tsdb_t db = arg;
|
fdb_tsdb_t db = arg;
|
||||||
|
|
||||||
fdb_blob_read((fdb_db_t) db, fdb_tsl_to_blob(tsl, fdb_blob_make(&blob, &status, sizeof(status))));
|
fdb_blob_read((fdb_db_t) db, fdb_tsl_to_blob(tsl, fdb_blob_make(&blob, &status, sizeof(status))));
|
||||||
FDB_INFO("queried a TSL: time: %ld, temp: %d, humi: %d\n", tsl->time, status.temp, status.humi);
|
FDB_INFO("[query_cb] queried a TSL: time: %ld, temp: %d, humi: %d\n", tsl->time, status.temp, status.humi);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool query_by_time_cb(fdb_tsl_t tsl, void *arg)
|
||||||
|
{
|
||||||
|
struct fdb_blob blob;
|
||||||
|
struct env_status status;
|
||||||
|
fdb_tsdb_t db = arg;
|
||||||
|
|
||||||
|
fdb_blob_read((fdb_db_t) db, fdb_tsl_to_blob(tsl, fdb_blob_make(&blob, &status, sizeof(status))));
|
||||||
|
FDB_INFO("[query_by_time_cb] queried a TSL: time: %ld, temp: %d, humi: %d\n", tsl->time, status.temp, status.humi);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user