RetroArch/tasks/task_file_transfer.c

112 lines
2.6 KiB
C
Raw Normal View History

/* RetroArch - A frontend for libretro.
2016-01-10 03:06:50 +00:00
* Copyright (C) 2011-2016 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <string.h>
#include <errno.h>
2015-07-08 19:35:24 +00:00
#include <file/nbio.h>
#include <formats/image.h>
2015-06-14 15:11:48 +00:00
#include <compat/strl.h>
#include <retro_assert.h>
#include <retro_miscellaneous.h>
#include <lists/string_list.h>
2015-06-14 15:11:48 +00:00
#include <rhash.h>
#include "tasks_internal.h"
2015-11-23 11:03:38 +00:00
#include "../verbosity.h"
2016-05-13 08:19:53 +00:00
static int task_file_transfer_iterate_transfer(nbio_handle_t *nbio)
{
size_t i;
if (!nbio)
return -1;
nbio->pos_increment = 5;
if (nbio->is_finished)
return 0;
for (i = 0; i < nbio->pos_increment; i++)
{
if (nbio_iterate(nbio->handle))
2015-05-23 15:16:19 +00:00
return -1;
}
return 0;
}
2016-05-13 08:19:53 +00:00
static int task_file_transfer_iterate_parse(nbio_handle_t *nbio)
{
if (!nbio)
return -1;
if (nbio->cb)
{
int len = 0;
if (nbio->cb(nbio, len) == -1)
return -1;
}
return 0;
}
2016-05-10 05:54:47 +00:00
void rarch_task_file_load_handler(retro_task_t *task)
{
2015-11-23 03:17:27 +00:00
nbio_handle_t *nbio = (nbio_handle_t*)task->state;
switch (nbio->status)
{
case NBIO_STATUS_TRANSFER_PARSE:
if (task_file_transfer_iterate_parse(nbio) == -1)
2016-05-18 15:37:43 +00:00
task->cancelled = true;
nbio->status = NBIO_STATUS_TRANSFER_PARSE_FREE;
break;
2015-05-23 15:16:19 +00:00
case NBIO_STATUS_TRANSFER:
2016-05-13 08:19:53 +00:00
if (task_file_transfer_iterate_transfer(nbio) == -1)
2015-05-23 15:16:19 +00:00
nbio->status = NBIO_STATUS_TRANSFER_PARSE;
break;
case NBIO_STATUS_TRANSFER_PARSE_FREE:
case NBIO_STATUS_POLL:
2015-05-23 15:16:19 +00:00
default:
break;
}
if (nbio->image)
2015-11-23 03:17:27 +00:00
{
2016-05-10 05:54:47 +00:00
if (!rarch_task_image_load_handler(task))
2015-11-23 03:17:27 +00:00
goto task_finished;
2016-02-10 04:41:53 +00:00
}
else
if (nbio->is_finished)
goto task_finished;
2015-11-23 03:17:27 +00:00
if (task->cancelled)
{
task->error = strdup("Task canceled.");
goto task_finished;
}
2015-11-23 03:17:27 +00:00
return;
task_finished:
task->finished = true;
nbio_free(nbio->handle);
nbio->handle = NULL;
nbio->is_finished = false;
free(nbio);
}