-
Notifications
You must be signed in to change notification settings - Fork 8.5k
mcumgr: fs_mgmt: Add a hook on download/upload complete. #87526
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
Conversation
248e873 to
bccc023
Compare
| status = mgmt_callback_notify(MGMT_EVT_OP_FS_MGMT_UPLOAD_DOWNLOAD_DONE, | ||
| &upload_or_download, sizeof(upload_or_download), &err_rc, &err_group); |
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.
it should be a struct which also has the filename
| enum mgmt_cb_return status; | ||
| int32_t err_rc; | ||
| uint16_t err_group; | ||
| zcbor_state_t *zse = ctxt->writer->zs; |
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.
variables declared at top of scope
| enum { | ||
| STATE_NO_UPLOAD_OR_DOWNLOAD = 0, | ||
| STATE_UPLOAD, | ||
| STATE_DOWNLOAD, | ||
| }; |
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.
this needs a name for the enum starting with fs_mgmt_ and FS_MGMT_ prefix on values. Also as other comment states, should be encapsulated within a struct which includes the filename
| /** Callback when a file has been accessed, data is fs_mgmt_file_access(). */ | ||
| MGMT_EVT_OP_FS_MGMT_FILE_ACCESS = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_FS, 0), | ||
|
|
||
| MGMT_EVT_OP_FS_MGMT_UPLOAD_DOWNLOAD_DONE = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_FS, 1), |
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.
MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_COMPLETE or
MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_FINISHED or MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_DONE perhaps so it fits in the alignment?
|
I did the requested changes by using the already existing fs_mgmt_file_access struct to store the filename and operation (read = download, write = upload). I also fixed an error in the comments around the fs_mgmt_file_access_types enum where upload and download where switched. |
94a592f to
0935965
Compare
nordicjm
left a comment
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.
Not tested but changes look OK, some changes to tidy up and remove status since this is a notification hook, doesn't make sense to be able to return an error
|
|
||
| strcpy(path, fs_mgmt_ctxt.path); | ||
| file_access_data.filename = path; | ||
| LOG_ERR("fs_mgmt.c path: %s", file_access_data.filename); |
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.
| LOG_ERR("fs_mgmt.c path: %s", file_access_data.filename); |
| enum fs_mgmt_group_events { | ||
| /** Callback when a file has been accessed, data is fs_mgmt_file_access(). */ | ||
| MGMT_EVT_OP_FS_MGMT_FILE_ACCESS = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_FS, 0), | ||
| MGMT_EVT_OP_FS_MGMT_FILE_ACCESS = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_FS, 0), |
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.
go back to old alignment
| #if defined(CONFIG_MCUMGR_GRP_FS_FILE_ACCESS_HOOK) | ||
| /* Warn application that file download/upload is done. */ | ||
| status = mgmt_callback_notify(MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_DONE, | ||
| &file_access_data, sizeof(file_access_data), &err_rc, &err_group); |
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.
align to the variable on the previous line
| enum mgmt_cb_return status; | ||
| int32_t err_rc; | ||
| uint16_t err_group; | ||
| zcbor_state_t *zse = ctxt->writer->zs; |
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.
| zcbor_state_t *zse = ctxt->writer->zs; |
| struct fs_mgmt_file_access file_access_data; | ||
| char path[CONFIG_MCUMGR_GRP_FS_PATH_LEN + 1]; |
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.
| struct fs_mgmt_file_access file_access_data; | |
| char path[CONFIG_MCUMGR_GRP_FS_PATH_LEN + 1]; | |
| char path[CONFIG_MCUMGR_GRP_FS_PATH_LEN + 1]; | |
| struct fs_mgmt_file_access file_access_data = { | |
| .filename = path, | |
| }; |
| zcbor_state_t *zse = ctxt->writer->zs; | ||
|
|
||
| strcpy(path, fs_mgmt_ctxt.path); | ||
| file_access_data.filename = path; |
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.
| file_access_data.filename = path; |
|
|
||
| if (status != MGMT_CB_OK) { | ||
| smp_add_cmd_err(zse, err_group, (uint16_t)err_rc); | ||
| } |
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.
| if (status != MGMT_CB_OK) { | |
| smp_add_cmd_err(zse, err_group, (uint16_t)err_rc); | |
| } |
The file has been uploaded/downloaded, doesn't really make sense to be able to return an error here
| #if defined(CONFIG_MCUMGR_GRP_FS_FILE_ACCESS_HOOK) | ||
| struct fs_mgmt_file_access file_access_data; | ||
| char path[CONFIG_MCUMGR_GRP_FS_PATH_LEN + 1]; | ||
| enum mgmt_cb_return status; |
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.
| enum mgmt_cb_return status; |
|
|
||
| #if defined(CONFIG_MCUMGR_GRP_FS_FILE_ACCESS_HOOK) | ||
| /* Warn application that file download/upload is done. */ | ||
| status = mgmt_callback_notify(MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_DONE, |
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.
| status = mgmt_callback_notify(MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_DONE, | |
| (void)mgmt_callback_notify(MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_DONE, &file_access_data, |
f637e0a to
d6e6425
Compare
4bf671a to
c6ddf87
Compare
|
@nordicjm took a little while to come back to this, but I made the requested changes |
| /** Callback when a file has been accessed, data is fs_mgmt_file_access(). */ | ||
| MGMT_EVT_OP_FS_MGMT_FILE_ACCESS = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_FS, 0), | ||
|
|
||
| MGMT_EVT_OP_FS_MGMT_FILE_ACCESS_DONE = MGMT_DEF_EVT_OP_ID(MGMT_EVT_GRP_FS, 1), |
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.
missing a doxygen comment
Added a hook on the FS group that notify applications when a file download/upload has completed. Signed-off-by: Nicolas Goualard <nicolas.goualard@sfr.fr>
Added a hook on the FS group that notify applications when a file download/upload has completed.
#87380