-
Notifications
You must be signed in to change notification settings - Fork 770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
迭代器 #94
Open
zrw269113179
wants to merge
1
commit into
armink:master
Choose a base branch
from
zrw269113179:iterator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+103
−3
Open
迭代器 #94
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -184,6 +184,13 @@ struct env_hdr_data { | |
}; | ||
typedef struct env_hdr_data *env_hdr_data_t; | ||
|
||
|
||
struct env_iterator_obj { | ||
struct sector_meta_data sector; | ||
struct env_node_obj env; | ||
}; | ||
typedef struct env_iterator_obj *env_iterator_obj_t; | ||
|
||
struct env_cache_node { | ||
uint16_t name_crc; /**< ENV name's CRC32 low 16bit value */ | ||
uint16_t active; /**< ENV node access active degree */ | ||
|
@@ -507,7 +514,7 @@ static uint32_t get_next_env_addr(sector_meta_data_t sector, env_node_obj_t pre_ | |
addr = find_next_env_addr(addr, sector->addr + SECTOR_SIZE - SECTOR_HDR_DATA_SIZE); | ||
|
||
if (addr > sector->addr + SECTOR_SIZE || pre_env->len == 0) { | ||
//TODO ��������ģʽ | ||
//TODO 扇区连续模式 | ||
return FAILED_ADDR; | ||
} | ||
} else { | ||
|
@@ -542,7 +549,7 @@ static EfErrCode read_env(env_node_obj_t env) | |
env->crc_is_ok = false; | ||
return EF_READ_ERR; | ||
} else if (env->len > SECTOR_SIZE - SECTOR_HDR_DATA_SIZE && env->len < ENV_AREA_SIZE) { | ||
//TODO ��������ģʽ������д�볤��û��д������ | ||
//TODO 扇区连续模式,或者写入长度没有写入完整 | ||
EF_ASSERT(0); | ||
} | ||
|
||
|
@@ -1195,7 +1202,94 @@ static uint32_t new_env(sector_meta_data_t sector, size_t env_size) | |
|
||
return empty_env; | ||
} | ||
static struct env_iterator_obj _g_env_iter_obj; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 定义在 ef_def.h 后,迭代器就可以支持多实例模式,这里的定义也不需要了 对应的,这些 API 可能也不需要了 你觉得呢? |
||
/** | ||
* @brief Traversing from scratch | ||
* | ||
*/ | ||
void ef_env_iterator_to_first() | ||
{ | ||
_g_env_iter_obj.sector.addr = FAILED_ADDR; | ||
_g_env_iter_obj.env.addr.start = FAILED_ADDR; | ||
} | ||
/** | ||
* @brief get the name of env now | ||
* | ||
* @return char* name | ||
*/ | ||
char *ef_env_iterator_now_name() | ||
{ | ||
return _g_env_iter_obj.env.name; | ||
} | ||
/** | ||
* @brief get the size of value | ||
* | ||
* @return size_t the size of value | ||
*/ | ||
size_t ef_env_iterator_now_value_len() | ||
{ | ||
return _g_env_iter_obj.env.value_len; | ||
} | ||
/** | ||
* @brief get value of env now | ||
* | ||
* @param value_buf ENV blob buffer | ||
* @param buf_len value_buf length | ||
* @return size_t 0:Read the complete;nonzero:unread length | ||
*/ | ||
size_t f_env_iterator_now_value(void *value_buf, size_t buf_len) | ||
{ | ||
if (buf_len < _g_env_iter_obj.env.value_len) { | ||
ef_port_read(_g_env_iter_obj.env.addr.value, (uint32_t *) value_buf, buf_len); | ||
return _g_env_iter_obj.env.value_len - buf_len; | ||
} else { | ||
ef_port_read(_g_env_iter_obj.env.addr.value, (uint32_t *) value_buf, _g_env_iter_obj.env.value_len); | ||
return 0; | ||
} | ||
|
||
|
||
} | ||
/** | ||
* @brief Get next blob ENV | ||
* | ||
* @param value_len ENV blob buffer length | ||
* @return char* 0:Traversal complete nonzero:ENV | ||
*/ | ||
env_node_obj_t ef_env_iterator_next() | ||
{ | ||
uint32_t sec_addr; | ||
ef_port_env_lock(); | ||
if (_g_env_iter_obj.sector.addr == FAILED_ADDR) { | ||
_reload: | ||
if ((sec_addr = get_next_sector_addr(&_g_env_iter_obj.sector)) == FAILED_ADDR) { | ||
ef_port_env_unlock(); | ||
return 0; | ||
} | ||
if (read_sector_meta_data(sec_addr, &_g_env_iter_obj.sector, false) != EF_NO_ERR) { | ||
goto _reload; | ||
} | ||
} | ||
if (_g_env_iter_obj.sector.status.store == SECTOR_STORE_USING || _g_env_iter_obj.sector.status.store == SECTOR_STORE_FULL) { | ||
/* search all ENV */ | ||
_next: | ||
if ((_g_env_iter_obj.env.addr.start = get_next_env_addr(&_g_env_iter_obj.sector, &_g_env_iter_obj.env)) != FAILED_ADDR) { | ||
read_env(&_g_env_iter_obj.env); | ||
/* iterator is interrupted when callback return true */ | ||
if (_g_env_iter_obj.env.status == ENV_WRITE) { | ||
_g_env_iter_obj.env.name[_g_env_iter_obj.env.name_len] = 0; | ||
|
||
ef_port_env_unlock(); | ||
return &_g_env_iter_obj.env; | ||
} else { | ||
goto _next; | ||
} | ||
} else { | ||
goto _reload; | ||
} | ||
} else { | ||
goto _reload; | ||
} | ||
} | ||
static uint32_t new_env_by_kv(sector_meta_data_t sector, size_t key_len, size_t buf_len) | ||
{ | ||
size_t env_len = ENV_HDR_DATA_SIZE + EF_WG_ALIGN(key_len) + EF_WG_ALIGN(buf_len); | ||
|
@@ -1718,7 +1812,7 @@ static bool check_and_recovery_env_cb(env_node_obj_t env, void *arg1, void *arg2 | |
} else if (env->status == ENV_PRE_WRITE) { | ||
uint8_t status_table[ENV_STATUS_TABLE_SIZE]; | ||
/* the ENV has not write finish, change the status to error */ | ||
//TODO �����쳣������״̬װ��ͼ | ||
//TODO 绘制异常处理的状态装换图 | ||
write_status(env->addr.start, status_table, ENV_STATUS_NUM, ENV_ERR_HDR); | ||
return true; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个迭代器对象类型声明可以定义在 ef_def.h 里
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sector_meta_data 这个类型没有在 ef_def.h里,如果迭代器定义在 ef_def.h里,一堆类型声明都要移过来
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对应的都搬过去就好了