mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-06-07 08:07:20 +02:00
Merge pull request #129 from gicmo/client_count_property
Introduce a ClientCount dbus Property
This commit is contained in:
commit
dbf9974fed
@ -182,22 +182,48 @@ static int method_query_status_by_pid(sd_bus_message *m, void *userdata,
|
|||||||
|
|
||||||
return sd_bus_reply_method_return(m, "i", status);
|
return sd_bus_reply_method_return(m, "i", status);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Handles the Active D-BUS Method
|
||||||
|
*/
|
||||||
|
static int property_get_client_count(sd_bus *local_bus, const char *path, const char *interface,
|
||||||
|
const char *property, sd_bus_message *reply, void *userdata,
|
||||||
|
__attribute__((unused)) sd_bus_error *ret_error)
|
||||||
|
{
|
||||||
|
GameModeContext *context = userdata;
|
||||||
|
int count;
|
||||||
|
|
||||||
|
count = game_mode_context_num_clients(context);
|
||||||
|
|
||||||
|
return sd_bus_message_append_basic(reply, 'i', &count);
|
||||||
|
}
|
||||||
|
|
||||||
|
void game_mode_client_count_changed(void)
|
||||||
|
{
|
||||||
|
(void)sd_bus_emit_properties_changed(bus,
|
||||||
|
"/com/feralinteractive/GameMode",
|
||||||
|
"com.feralinteractive.GameMode",
|
||||||
|
"ClientCount",
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* D-BUS vtable to dispatch virtual methods
|
* D-BUS vtable to dispatch virtual methods
|
||||||
*/
|
*/
|
||||||
static const sd_bus_vtable gamemode_vtable[] =
|
static const sd_bus_vtable gamemode_vtable[] = {
|
||||||
{ SD_BUS_VTABLE_START(0),
|
SD_BUS_VTABLE_START(0),
|
||||||
SD_BUS_METHOD("RegisterGame", "i", "i", method_register_game, SD_BUS_VTABLE_UNPRIVILEGED),
|
SD_BUS_PROPERTY("ClientCount", "i", property_get_client_count, 0,
|
||||||
SD_BUS_METHOD("UnregisterGame", "i", "i", method_unregister_game, SD_BUS_VTABLE_UNPRIVILEGED),
|
SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
|
||||||
SD_BUS_METHOD("QueryStatus", "i", "i", method_query_status, SD_BUS_VTABLE_UNPRIVILEGED),
|
SD_BUS_METHOD("RegisterGame", "i", "i", method_register_game, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
SD_BUS_METHOD("RegisterGameByPID", "ii", "i", method_register_game_by_pid,
|
SD_BUS_METHOD("UnregisterGame", "i", "i", method_unregister_game, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
SD_BUS_VTABLE_UNPRIVILEGED),
|
SD_BUS_METHOD("QueryStatus", "i", "i", method_query_status, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
SD_BUS_METHOD("UnregisterGameByPID", "ii", "i", method_unregister_game_by_pid,
|
SD_BUS_METHOD("RegisterGameByPID", "ii", "i", method_register_game_by_pid,
|
||||||
SD_BUS_VTABLE_UNPRIVILEGED),
|
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
SD_BUS_METHOD("QueryStatusByPID", "ii", "i", method_query_status_by_pid,
|
SD_BUS_METHOD("UnregisterGameByPID", "ii", "i", method_unregister_game_by_pid,
|
||||||
SD_BUS_VTABLE_UNPRIVILEGED),
|
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
SD_BUS_VTABLE_END };
|
SD_BUS_METHOD("QueryStatusByPID", "ii", "i", method_query_status_by_pid,
|
||||||
|
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
|
SD_BUS_VTABLE_END
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main process loop for the daemon. Run until quitting has been requested.
|
* Main process loop for the daemon. Run until quitting has been requested.
|
||||||
|
@ -44,3 +44,8 @@ void game_mode_context_loop(GameModeContext *context) __attribute__((noreturn));
|
|||||||
* Inhibit the screensaver
|
* Inhibit the screensaver
|
||||||
*/
|
*/
|
||||||
int game_mode_inhibit_screensaver(bool inhibit);
|
int game_mode_inhibit_screensaver(bool inhibit);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Signal the ClientCount property has changed
|
||||||
|
*/
|
||||||
|
void game_mode_client_count_changed(void);
|
||||||
|
@ -89,7 +89,6 @@ static volatile bool had_context_init = false;
|
|||||||
static GameModeClient *game_mode_client_new(pid_t pid, char *exe);
|
static GameModeClient *game_mode_client_new(pid_t pid, char *exe);
|
||||||
static void game_mode_client_free(GameModeClient *client);
|
static void game_mode_client_free(GameModeClient *client);
|
||||||
static const GameModeClient *game_mode_context_has_client(GameModeContext *self, pid_t client);
|
static const GameModeClient *game_mode_context_has_client(GameModeContext *self, pid_t client);
|
||||||
static int game_mode_context_num_clients(GameModeContext *self);
|
|
||||||
static void *game_mode_context_reaper(void *userdata);
|
static void *game_mode_context_reaper(void *userdata);
|
||||||
static void game_mode_context_enter(GameModeContext *self);
|
static void game_mode_context_enter(GameModeContext *self);
|
||||||
static void game_mode_context_leave(GameModeContext *self);
|
static void game_mode_context_leave(GameModeContext *self);
|
||||||
@ -316,10 +315,7 @@ static const GameModeClient *game_mode_context_has_client(GameModeContext *self,
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
int game_mode_context_num_clients(GameModeContext *self)
|
||||||
* Helper to grab the current number of clients we know about
|
|
||||||
*/
|
|
||||||
static int game_mode_context_num_clients(GameModeContext *self)
|
|
||||||
{
|
{
|
||||||
return atomic_load(&self->refcount);
|
return atomic_load(&self->refcount);
|
||||||
}
|
}
|
||||||
@ -419,6 +415,8 @@ int game_mode_context_register(GameModeContext *self, pid_t client, pid_t reques
|
|||||||
/* Apply io priorities */
|
/* Apply io priorities */
|
||||||
game_mode_apply_ioprio(self, client);
|
game_mode_apply_ioprio(self, client);
|
||||||
|
|
||||||
|
game_mode_client_count_changed();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error_cleanup:
|
error_cleanup:
|
||||||
@ -502,6 +500,8 @@ int game_mode_context_unregister(GameModeContext *self, pid_t client, pid_t requ
|
|||||||
game_mode_context_leave(self);
|
game_mode_context_leave(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
game_mode_client_count_changed();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +63,13 @@ void game_mode_context_init(GameModeContext *self);
|
|||||||
*/
|
*/
|
||||||
void game_mode_context_destroy(GameModeContext *self);
|
void game_mode_context_destroy(GameModeContext *self);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query the number of currently registered clients.
|
||||||
|
*
|
||||||
|
* @returns The number of clients. A number > 0 means that gamemode is active.
|
||||||
|
*/
|
||||||
|
int game_mode_context_num_clients(GameModeContext *self);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a new game client with the context
|
* Register a new game client with the context
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user