本文整理汇总了C++中ARM_CFSTORE_DRIVER::Flush方法的典型用法代码示例。如果您正苦于以下问题:C++ ARM_CFSTORE_DRIVER::Flush方法的具体用法?C++ ARM_CFSTORE_DRIVER::Flush怎么用?C++ ARM_CFSTORE_DRIVER::Flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ARM_CFSTORE_DRIVER
的用法示例。
在下文中一共展示了ARM_CFSTORE_DRIVER::Flush方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cfstore_flush_fsm_flush_on_entry
/* @brief fsm handler called on entry to flushing state */
static void cfstore_flush_fsm_flush_on_entry(void* context)
{
bool bfound = false;
int32_t ivalue = 0;
int32_t ret = ARM_DRIVER_ERROR;
ARM_CFSTORE_DRIVER* drv = &cfstore_driver;
const char* key_name_query = "*";
char value[CFSTORE_KEY_NAME_MAX_LENGTH+1];
ARM_CFSTORE_SIZE len = CFSTORE_KEY_NAME_MAX_LENGTH+1;
ARM_CFSTORE_HANDLE_INIT(next);
ARM_CFSTORE_HANDLE_INIT(prev);
ARM_CFSTORE_KEYDESC kdesc;
cfstore_flush_ctx_t* ctx = (cfstore_flush_ctx_t*) context;
/* check that the mtd is in synchronous mode */
CFSTORE_FENTRYLOG("%s:entered: \r\n", __func__);
memset(&kdesc, 0, sizeof(kdesc));
CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: entered handler(%s) but not in flushing state (fsm->state=%d)\r\n", __func__, __func__, (int) ctx->fsm.state);
TEST_ASSERT_MESSAGE(ctx->fsm.state == cfstore_flush_fsm_state_flushing, cfstore_flush_utest_msg_g);
/* try to read key; should not be found */
ret = cfstore_test_kv_is_found(cfstore_flush_test_02_kv_data->key_name, &bfound);
if(ret != ARM_DRIVER_OK && ret != ARM_CFSTORE_DRIVER_ERROR_KEY_NOT_FOUND){
CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: cfstore_test_kv_is_found() call failed (ret=%d).\r\n", __func__, (int) ret);
TEST_ASSERT_MESSAGE(false, cfstore_flush_utest_msg_g);
}
if(!bfound)
{
/* first time start up. nothing is stored in cfstore flash. check this is the case */
while(drv->Find(key_name_query, prev, next) == ARM_DRIVER_OK)
{
CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: have found an entry in cfstore when none should be present", __func__);
TEST_ASSERT_MESSAGE(false, cfstore_flush_utest_msg_g);
}
/* no entries found, which is correct.
* store a value */
len = strlen(cfstore_flush_test_02_kv_data->value);
ret = cfstore_test_create(cfstore_flush_test_02_kv_data->key_name, cfstore_flush_test_02_kv_data->value, &len, &kdesc);
CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error:1: failed to write kv data (ret=%d).\r\n", __func__, (int) ret);
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g);
/* flush to flash */
ret = drv->Flush();
CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to flush data to cfstore flash (ret=%d).\r\n", __func__, (int) ret);
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g);
/* revert to CFSTORE_LOG if more trace required */
CFSTORE_DBGLOG("FLUSH: Success pending for new KV creation (name=%s, value=%s)\n", cfstore_flush_test_02_kv_data->key_name, cfstore_flush_test_02_kv_data->value);
} else {
/*read the value, increment by 1 and write value back */
len = CFSTORE_KEY_NAME_MAX_LENGTH+1;
ret = cfstore_test_read(cfstore_flush_test_02_kv_data->key_name, value, &len);
CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to read kv data (ret=%d).\r\n", __func__, (int) ret);
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g);
ivalue = atoi(value);
/* revert to CFSTORE_LOG if more trace required */
CFSTORE_DBGLOG("FLUSH: Read KV from flash (name=%s, value=%d)\n", cfstore_flush_test_02_kv_data->key_name, (int) ivalue);
/* increment value */
++ivalue;
snprintf(value, CFSTORE_KEY_NAME_MAX_LENGTH+1, "%d", (int) ivalue);
len = strlen(value);
ret = cfstore_test_write(cfstore_flush_test_02_kv_data->key_name, value, &len);
CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to write kv data (ret=%d).\r\n", __func__, (int) ret);
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g);
/* flush to flash */
ret = drv->Flush();
CFSTORE_TEST_UTEST_MESSAGE(cfstore_flush_utest_msg_g, CFSTORE_FLUSH_UTEST_MSG_BUF_SIZE, "%s:Error: failed to flush data to cfstore flash (ret=%d).\r\n", __func__, (int) ret);
TEST_ASSERT_MESSAGE(ret >= ARM_DRIVER_OK, cfstore_flush_utest_msg_g);
/* revert to CFSTORE_LOG if more trace required */
CFSTORE_DBGLOG("FLUSH: Success pending for new KV value to flash (name=%s, value=%d)\n", cfstore_flush_test_02_kv_data->key_name, (int) ivalue);
}
return;
}