RetroArch/tasks/task_powerstate.c

95 lines
2.5 KiB
C
Raw Normal View History

2016-12-20 14:18:07 +00:00
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2017-01-22 12:40:32 +00:00
* Copyright (C) 2011-2017 - Daniel De Matteis
2019-02-22 21:31:54 +00:00
* Copyright (C) 2016-2019 - Brad Parker
2016-12-20 14:18:07 +00:00
*
* 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 <stdlib.h>
#include <queues/task_queue.h>
2016-12-20 14:18:07 +00:00
#include "../../frontend/frontend_driver.h"
#include "tasks_internal.h"
2017-05-13 20:30:45 +00:00
typedef struct powerstate powerstate_t;
struct powerstate
2016-12-20 14:18:07 +00:00
{
2020-03-12 05:59:07 +00:00
int percent;
2020-08-14 22:35:15 +00:00
enum frontend_powerstate state;
2017-05-13 20:30:45 +00:00
};
2016-12-20 14:18:07 +00:00
2020-05-29 04:10:53 +00:00
/* TODO/FIXME - global state - perhaps move outside this file */
static int powerstate_percent = 0;
static enum frontend_powerstate powerstate_status = FRONTEND_POWERSTATE_NONE;
2016-12-20 14:18:07 +00:00
enum frontend_powerstate get_last_powerstate(int *percent)
{
if (percent)
*percent = powerstate_percent;
2016-12-20 14:18:07 +00:00
return powerstate_status;
2016-12-20 14:18:07 +00:00
}
static void task_powerstate_cb(retro_task_t *task,
void *task_data,
void *user_data, const char *error)
2016-12-20 14:18:07 +00:00
{
powerstate_t *powerstate = (powerstate_t*)task_data;
powerstate_percent = powerstate->percent;
powerstate_status = powerstate->state;
2016-12-20 14:18:07 +00:00
free(powerstate);
}
static void task_powerstate_handler(retro_task_t *task)
{
const frontend_ctx_driver_t *frontend = frontend_get_ptr();
powerstate_t *powerstate = (powerstate_t*)task->state;
if (frontend && frontend->get_powerstate)
{
int seconds = 0;
powerstate->state = frontend->get_powerstate(
&seconds, &powerstate->percent);
2016-12-20 14:18:07 +00:00
}
task_set_data(task, powerstate);
task_set_finished(task, true);
2016-12-20 14:18:07 +00:00
}
2016-12-20 20:46:12 +00:00
void task_push_get_powerstate(void)
2016-12-20 14:18:07 +00:00
{
retro_task_t *task = task_init();
powerstate_t *state = NULL;
2016-12-20 14:18:07 +00:00
if (!task)
return;
state = (powerstate_t*)calloc(1, sizeof(*state));
if (!state)
{
free(task);
return;
}
2016-12-20 14:18:07 +00:00
task->type = TASK_TYPE_NONE;
task->state = state;
task->handler = task_powerstate_handler;
task->callback = task_powerstate_cb;
task->mute = true;
2017-05-14 18:43:39 +00:00
task_queue_push(task);
2016-12-20 14:18:07 +00:00
}