Add gamemode_query_status and teach gamemoded '-s'

This allows the client to query the daemon about the status of gamemode.

	Returns the following:
		 0 if gamemode is inactive
		 1 if gamemode is active
		 2 if gamemode is active and this client is registered
		-1 if the query failed

	Passing -s to gamemoded will simply query and print the current status.

	Allows for more comprehensive testing when using 'gamemoded -r' as well as more reactionary program behaviour
This commit is contained in:
Marc Di Luzio
2018-04-25 14:39:05 +01:00
parent 966c207a33
commit 4f3bc2c9a2
8 changed files with 140 additions and 4 deletions

View File

@@ -101,6 +101,26 @@ static int method_unregister_game(sd_bus_message *m, void *userdata,
return sd_bus_reply_method_return(m, "i", 0);
}
/**
* Handles the QueryStatus D-BUS Method
*/
static int method_query_status(sd_bus_message *m, void *userdata,
__attribute__((unused)) sd_bus_error *ret_error)
{
int pid = 0;
GameModeContext *context = userdata;
int ret = sd_bus_message_read(m, "i", &pid);
if (ret < 0) {
LOG_ERROR("Failed to parse input parameters: %s\n", strerror(-ret));
return ret;
}
int status = game_mode_context_query_status(context, (pid_t)pid);
return sd_bus_reply_method_return(m, "i", status);
}
/**
* D-BUS vtable to dispatch virtual methods
*/
@@ -108,6 +128,7 @@ static const sd_bus_vtable gamemode_vtable[] =
{ SD_BUS_VTABLE_START(0),
SD_BUS_METHOD("RegisterGame", "i", "i", method_register_game, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("UnregisterGame", "i", "i", method_unregister_game, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("QueryStatus", "i", "i", method_query_status, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_VTABLE_END };
/**