mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2025-12-17 04:08:53 +01:00
catch USR1 signal to poweroff quicker
Signed-off-by: Vincent-FK <vincent.buso@funkey-project.com>
This commit is contained in:
parent
b7b91d4aae
commit
6cff159abf
@ -177,6 +177,10 @@ void MenuMode::end( )
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MenuMode::stop( ){
|
||||||
|
stop_menu_loop = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void MenuMode::draw_progress_bar(SDL_Surface * surface, uint16_t x, uint16_t y, uint16_t width,
|
void MenuMode::draw_progress_bar(SDL_Surface * surface, uint16_t x, uint16_t y, uint16_t width,
|
||||||
uint16_t height, uint8_t percentage, uint16_t nb_bars){
|
uint16_t height, uint8_t percentage, uint16_t nb_bars){
|
||||||
|
|||||||
@ -52,15 +52,17 @@ typedef enum {ASPECT_RATIOS} ENUM_ASPECT_RATIOS_TYPES;
|
|||||||
#define SHELL_CMD_USB_UNMOUNT "share stop"
|
#define SHELL_CMD_USB_UNMOUNT "share stop"
|
||||||
#define SHELL_CMD_USB_CHECK_IS_SHARING "share is_sharing"
|
#define SHELL_CMD_USB_CHECK_IS_SHARING "share is_sharing"
|
||||||
#define SHELL_CMD_POWERDOWN "shutdown_funkey"
|
#define SHELL_CMD_POWERDOWN "shutdown_funkey"
|
||||||
|
#define SHELL_CMD_SCHEDULE_POWERDOWN "sched_shutdown"
|
||||||
|
|
||||||
class MenuMode
|
class MenuMode
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//MenuMode();
|
//MenuMode();
|
||||||
static void init(Configuration &c);
|
static void init(Configuration &c);
|
||||||
static void end();
|
static void end();
|
||||||
static int launch( );
|
static int launch( );
|
||||||
|
static void stop( );
|
||||||
|
|
||||||
/*static SDL_Surface * draw_screen;
|
/*static SDL_Surface * draw_screen;
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,7 @@
|
|||||||
#include "Utility/Utils.h"
|
#include "Utility/Utils.h"
|
||||||
#include "Collection/MenuParser.h"
|
#include "Collection/MenuParser.h"
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
#include <SDL/SDL_ttf.h>
|
||||||
#include "Control/UserInput.h"
|
#include "Control/UserInput.h"
|
||||||
#include "Graphics/PageBuilder.h"
|
#include "Graphics/PageBuilder.h"
|
||||||
#include "Graphics/Page.h"
|
#include "Graphics/Page.h"
|
||||||
@ -41,7 +42,7 @@
|
|||||||
#include <tuple>
|
#include <tuple>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <SDL/SDL_ttf.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#if defined(__linux) || defined(__APPLE__)
|
#if defined(__linux) || defined(__APPLE__)
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -180,6 +181,10 @@ int RetroFE::initialize( void *context )
|
|||||||
Logger::write( Logger::ZONE_INFO, "RetroFE", "Initialized meta database" );
|
Logger::write( Logger::ZONE_INFO, "RetroFE", "Initialized meta database" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Init Signals */
|
||||||
|
Logger::write( Logger::ZONE_INFO, "RetroFE", "Initializing signal USR1..." );
|
||||||
|
signal(SIGUSR1, instance->handle_sigusr1);
|
||||||
|
|
||||||
instance->initialized = true;
|
instance->initialized = true;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@ -979,7 +984,7 @@ void RetroFE::run( )
|
|||||||
default:
|
default:
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Wrong state: " << state;
|
ss << "Wrong state: " << state;
|
||||||
Logger::write( Logger::ZONE_ERROR, "RetroFE", "Wrong state: " + ss.str() );
|
Logger::write( Logger::ZONE_ERROR, "RetroFE", ss.str() );
|
||||||
state = RETROFE_IDLE;
|
state = RETROFE_IDLE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1527,3 +1532,49 @@ CollectionInfo *RetroFE::getMenuCollection( std::string collectionName )
|
|||||||
collection->playlists["all"] = &collection->items;
|
collection->playlists["all"] = &collection->items;
|
||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Handler for SIGUSR1, caused by closing the console */
|
||||||
|
void RetroFE::handle_sigusr1(int sig)
|
||||||
|
{
|
||||||
|
printf("Caught signal USR1 %d\n", sig);
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Caught signal USR1: " << sig;
|
||||||
|
Logger::write( Logger::ZONE_ERROR, "RetroFE", ss.str() );
|
||||||
|
|
||||||
|
/* Exit menu if it was launched */
|
||||||
|
MenuMode::stop();
|
||||||
|
|
||||||
|
/** Poweroff */
|
||||||
|
quick_poweroff();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Quick save and turn off the console */
|
||||||
|
void RetroFE::quick_poweroff()
|
||||||
|
{
|
||||||
|
/* Vars */
|
||||||
|
char shell_cmd[200];
|
||||||
|
FILE *fp;
|
||||||
|
|
||||||
|
/* Send command to kill any previously scheduled shutdown */
|
||||||
|
sprintf(shell_cmd, "pkill %s", SHELL_CMD_SCHEDULE_POWERDOWN);
|
||||||
|
fp = popen(shell_cmd, "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
printf("Failed to run command %s\n", shell_cmd);
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Failed to run command " << shell_cmd;
|
||||||
|
Logger::write( Logger::ZONE_ERROR, "RetroFE", ss.str() );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clean Poweroff */
|
||||||
|
sprintf(shell_cmd, "%s", SHELL_CMD_POWERDOWN);
|
||||||
|
fp = popen(shell_cmd, "r");
|
||||||
|
if (fp == NULL) {
|
||||||
|
printf("Failed to run command %s\n", shell_cmd);
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Failed to run command " << shell_cmd;
|
||||||
|
Logger::write( Logger::ZONE_ERROR, "RetroFE", ss.str() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -89,11 +89,13 @@ public:
|
|||||||
void launchExit( );
|
void launchExit( );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
volatile bool initialized;
|
volatile bool initialized;
|
||||||
volatile bool initializeError;
|
volatile bool initializeError;
|
||||||
volatile bool initMetaDb;
|
volatile bool initMetaDb;
|
||||||
SDL_Thread *initializeThread;
|
SDL_Thread *initializeThread;
|
||||||
static int initialize( void *context );
|
static int initialize( void *context );
|
||||||
|
static void handle_sigusr1(int sig);
|
||||||
|
static void quick_poweroff( );
|
||||||
|
|
||||||
#undef X
|
#undef X
|
||||||
#define X(a, b) a,
|
#define X(a, b) a,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user