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
|
|
|
|
* Copyright (C) 2016-2017 - 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 "../../frontend/frontend_driver.h"
|
|
|
|
#include "tasks_internal.h"
|
|
|
|
|
2016-12-20 20:46:12 +00:00
|
|
|
static int power_percent = 0;
|
2016-12-20 14:18:07 +00:00
|
|
|
static enum frontend_powerstate state = FRONTEND_POWERSTATE_NONE;
|
|
|
|
|
2017-05-13 20:30:45 +00:00
|
|
|
typedef struct powerstate powerstate_t;
|
|
|
|
|
|
|
|
struct powerstate
|
2016-12-20 14:18:07 +00:00
|
|
|
{
|
|
|
|
int percent;
|
|
|
|
enum frontend_powerstate state;
|
2017-05-13 20:30:45 +00:00
|
|
|
};
|
2016-12-20 14:18:07 +00:00
|
|
|
|
|
|
|
enum frontend_powerstate get_last_powerstate(int *percent)
|
|
|
|
{
|
|
|
|
if (percent)
|
|
|
|
*percent = power_percent;
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void task_powerstate_cb(void *task_data,
|
|
|
|
void *user_data, const char *error)
|
|
|
|
{
|
|
|
|
powerstate_t *powerstate = (powerstate_t*)task_data;
|
|
|
|
|
|
|
|
power_percent = powerstate->percent;
|
|
|
|
state = powerstate->state;
|
|
|
|
|
|
|
|
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-29 05:50:18 +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 = (retro_task_t*)calloc(1, sizeof(*task));
|
|
|
|
powerstate_t *state = (powerstate_t*)calloc(1, sizeof(*state));
|
|
|
|
|
|
|
|
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
|
|
|
}
|