From e8b43b85a49fa6ac515336bcda340a118e7fee0f Mon Sep 17 00:00:00 2001 From: armink Date: Wed, 7 Oct 2020 12:50:21 +0800 Subject: [PATCH] [sample] update code style. --- samples/kvdb_type_blob_sample.c | 2 +- samples/kvdb_type_string_sample.c | 2 +- samples/tsdb_sample.c | 21 ++++++++++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/samples/kvdb_type_blob_sample.c b/samples/kvdb_type_blob_sample.c index 06c11f1..f37983c 100644 --- a/samples/kvdb_type_blob_sample.c +++ b/samples/kvdb_type_blob_sample.c @@ -47,7 +47,7 @@ void kvdb_type_blob_sample(fdb_kvdb_t kvdb) { /* CHANGE the KV value */ 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_INFO("set 'temp' value to %d\n", temp_data); } diff --git a/samples/kvdb_type_string_sample.c b/samples/kvdb_type_string_sample.c index bf097c2..90e6598 100644 --- a/samples/kvdb_type_string_sample.c +++ b/samples/kvdb_type_string_sample.c @@ -20,8 +20,8 @@ void kvdb_type_string_sample(fdb_kvdb_t kvdb) { - FDB_INFO("==================== kvdb_type_string_sample ====================\n"); + { /* CREATE new Key-Value */ char temp_data[10] = "36C"; diff --git a/samples/tsdb_sample.c b/samples/tsdb_sample.c index 5fd9ad3..26034b9 100644 --- a/samples/tsdb_sample.c +++ b/samples/tsdb_sample.c @@ -26,6 +26,7 @@ struct env_status { }; 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); 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); size_t count; /* 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 */ count = fdb_tsl_query_count(tsdb, from_time, to_time, FDB_TSL_WRITE); 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 * * 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); } @@ -87,7 +90,19 @@ static bool query_cb(fdb_tsl_t tsl, void *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_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; }