forked from Imagelibrary/rtems
media-server: Add ability for retry.
This adds the possibility to request a retry in the media-listener if an operation failed. Usefull for example if you want to automatically reformat a disk if it wasn't possible to mount it.
This commit is contained in:
@@ -281,6 +281,9 @@ typedef enum {
|
|||||||
*
|
*
|
||||||
* @retval RTEMS_SUCCESSFUL Successful operation.
|
* @retval RTEMS_SUCCESSFUL Successful operation.
|
||||||
* @retval RTEMS_IO_ERROR In the inquiry state this will abort the action.
|
* @retval RTEMS_IO_ERROR In the inquiry state this will abort the action.
|
||||||
|
* @retval RTEMS_INCORRECT_STATE In the failed state this will cause a retry.
|
||||||
|
* Make sure to have a retry counter or similar to avoid endless loops if you
|
||||||
|
* use this value.
|
||||||
*/
|
*/
|
||||||
typedef rtems_status_code (*rtems_media_listener)(
|
typedef rtems_status_code (*rtems_media_listener)(
|
||||||
rtems_media_event event,
|
rtems_media_event event,
|
||||||
|
|||||||
@@ -420,26 +420,30 @@ static rtems_status_code process_event(
|
|||||||
)
|
)
|
||||||
{
|
{
|
||||||
rtems_status_code sc = RTEMS_SUCCESSFUL;
|
rtems_status_code sc = RTEMS_SUCCESSFUL;
|
||||||
|
rtems_status_code sc_retry = RTEMS_SUCCESSFUL;
|
||||||
rtems_media_state state = RTEMS_MEDIA_STATE_FAILED;
|
rtems_media_state state = RTEMS_MEDIA_STATE_FAILED;
|
||||||
char *dest = NULL;
|
char *dest = NULL;
|
||||||
|
|
||||||
sc = notify(event, RTEMS_MEDIA_STATE_INQUIRY, src, NULL);
|
do {
|
||||||
if (sc == RTEMS_SUCCESSFUL) {
|
sc = notify(event, RTEMS_MEDIA_STATE_INQUIRY, src, NULL);
|
||||||
state = RTEMS_MEDIA_STATE_READY;
|
|
||||||
} else {
|
|
||||||
state = RTEMS_MEDIA_STATE_ABORTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
sc = (*worker)(state, src, &dest, worker_arg);
|
|
||||||
if (state == RTEMS_MEDIA_STATE_READY) {
|
|
||||||
if (sc == RTEMS_SUCCESSFUL) {
|
if (sc == RTEMS_SUCCESSFUL) {
|
||||||
state = RTEMS_MEDIA_STATE_SUCCESS;
|
state = RTEMS_MEDIA_STATE_READY;
|
||||||
} else {
|
} else {
|
||||||
state = RTEMS_MEDIA_STATE_FAILED;
|
state = RTEMS_MEDIA_STATE_ABORTED;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
notify(event, state, src, dest);
|
sc = (*worker)(state, src, &dest, worker_arg);
|
||||||
|
if (state == RTEMS_MEDIA_STATE_READY) {
|
||||||
|
if (sc == RTEMS_SUCCESSFUL) {
|
||||||
|
state = RTEMS_MEDIA_STATE_SUCCESS;
|
||||||
|
} else {
|
||||||
|
state = RTEMS_MEDIA_STATE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sc_retry = notify(event, state, src, dest);
|
||||||
|
} while (state == RTEMS_MEDIA_STATE_FAILED
|
||||||
|
&& sc_retry == RTEMS_INCORRECT_STATE);
|
||||||
remember_event(event, state, src, dest);
|
remember_event(event, state, src, dest);
|
||||||
|
|
||||||
if (state == RTEMS_MEDIA_STATE_SUCCESS) {
|
if (state == RTEMS_MEDIA_STATE_SUCCESS) {
|
||||||
|
|||||||
Reference in New Issue
Block a user