mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-06-06 07:37:21 +02:00
Hook up interfaces for functions to register another process
This commit is contained in:
parent
0f7950245a
commit
c5f58c56d0
@ -120,6 +120,48 @@ static int method_query_status(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 RegisterGameByPID D-BUS Method
|
||||||
|
*/
|
||||||
|
static int method_register_game_by_pid(sd_bus_message *m, void *userdata,
|
||||||
|
__attribute__((unused)) sd_bus_error *ret_error)
|
||||||
|
{
|
||||||
|
int callerpid = 0;
|
||||||
|
int gamepid = 0;
|
||||||
|
GameModeContext *context = userdata;
|
||||||
|
|
||||||
|
int ret = sd_bus_message_read(m, "ii", &callerpid, &gamepid);
|
||||||
|
if (ret < 0) {
|
||||||
|
LOG_ERROR("Failed to parse input parameters: %s\n", strerror(-ret));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int reply = game_mode_context_register_by_pid(context, (pid_t)callerpid, (pid_t)gamepid);
|
||||||
|
|
||||||
|
return sd_bus_reply_method_return(m, "i", reply);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the UnregisterGameByPID D-BUS Method
|
||||||
|
*/
|
||||||
|
static int method_unregister_game_by_pid(sd_bus_message *m, void *userdata,
|
||||||
|
__attribute__((unused)) sd_bus_error *ret_error)
|
||||||
|
{
|
||||||
|
int callerpid = 0;
|
||||||
|
int gamepid = 0;
|
||||||
|
GameModeContext *context = userdata;
|
||||||
|
|
||||||
|
int ret = sd_bus_message_read(m, "ii", &callerpid, &gamepid);
|
||||||
|
if (ret < 0) {
|
||||||
|
LOG_ERROR("Failed to parse input parameters: %s\n", strerror(-ret));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int reply = game_mode_context_unregister_by_pid(context, (pid_t)callerpid, (pid_t)gamepid);
|
||||||
|
|
||||||
|
return sd_bus_reply_method_return(m, "i", reply);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* D-BUS vtable to dispatch virtual methods
|
* D-BUS vtable to dispatch virtual methods
|
||||||
*/
|
*/
|
||||||
@ -128,6 +170,10 @@ static const sd_bus_vtable gamemode_vtable[] =
|
|||||||
SD_BUS_METHOD("RegisterGame", "i", "i", method_register_game, SD_BUS_VTABLE_UNPRIVILEGED),
|
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("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_METHOD("QueryStatus", "i", "i", method_query_status, SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
|
SD_BUS_METHOD("RegisterGameByPID", "ii", "i", method_register_game_by_pid,
|
||||||
|
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
|
SD_BUS_METHOD("UnregisterGameByPID", "ii", "i", method_unregister_game_by_pid,
|
||||||
|
SD_BUS_VTABLE_UNPRIVILEGED),
|
||||||
SD_BUS_VTABLE_END };
|
SD_BUS_VTABLE_END };
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -502,6 +502,28 @@ int game_mode_context_query_status(GameModeContext *self, pid_t client)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stub to register on behalf of caller
|
||||||
|
*/
|
||||||
|
int game_mode_context_register_by_pid(GameModeContext *self, pid_t callerpid, pid_t gamepid)
|
||||||
|
{
|
||||||
|
(void)self;
|
||||||
|
(void)callerpid;
|
||||||
|
(void)gamepid;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stub to unregister on behalf of caller
|
||||||
|
*/
|
||||||
|
int game_mode_context_unregister_by_pid(GameModeContext *self, pid_t callerpid, pid_t gamepid)
|
||||||
|
{
|
||||||
|
(void)self;
|
||||||
|
(void)callerpid;
|
||||||
|
(void)gamepid;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new GameModeClient for the given process ID
|
* Construct a new GameModeClient for the given process ID
|
||||||
*
|
*
|
||||||
|
@ -89,6 +89,28 @@ bool game_mode_context_unregister(GameModeContext *self, pid_t pid);
|
|||||||
*/
|
*/
|
||||||
int game_mode_context_query_status(GameModeContext *self, pid_t pid);
|
int game_mode_context_query_status(GameModeContext *self, pid_t pid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a new game client with the context on behalf of another process
|
||||||
|
*
|
||||||
|
* @param callerpid Process ID for the remote client making the request
|
||||||
|
* @param gamepid Process ID for the process to be registered
|
||||||
|
* @returns 0 if the request was accepted and the client could be registered
|
||||||
|
* -1 if the request was accepted but the client could not be registered
|
||||||
|
* -2 if the request was rejected
|
||||||
|
*/
|
||||||
|
int game_mode_context_register_by_pid(GameModeContext *self, pid_t callerpid, pid_t gamepid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unregister an existing remote game client from the context on behalf of another process
|
||||||
|
*
|
||||||
|
* @param callerpid Process ID for the remote client making the request
|
||||||
|
* @param gamepid Process ID for the process to be registered
|
||||||
|
* @returns 0 if the request was accepted and the client existed
|
||||||
|
* -1 if the request was accepted but the client did not exist
|
||||||
|
* -2 if the request was rejected
|
||||||
|
*/
|
||||||
|
int game_mode_context_unregister_by_pid(GameModeContext *self, pid_t callerpid, pid_t gamepid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the config of a gamemode context
|
* Query the config of a gamemode context
|
||||||
*
|
*
|
||||||
|
@ -43,7 +43,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
static char error_string[512] = { 0 };
|
static char error_string[512] = { 0 };
|
||||||
|
|
||||||
// Simple requestor function for a gamemode
|
// Simple requestor function for a gamemode
|
||||||
static int gamemode_request(const char *function)
|
static int gamemode_request(const char *function, int arg)
|
||||||
{
|
{
|
||||||
sd_bus_message *msg = NULL;
|
sd_bus_message *msg = NULL;
|
||||||
sd_bus *bus = NULL;
|
sd_bus *bus = NULL;
|
||||||
@ -66,8 +66,9 @@ static int gamemode_request(const char *function)
|
|||||||
function,
|
function,
|
||||||
NULL,
|
NULL,
|
||||||
&msg,
|
&msg,
|
||||||
"i",
|
arg ? "ii" : "i",
|
||||||
getpid());
|
getpid(),
|
||||||
|
arg);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
snprintf(error_string,
|
snprintf(error_string,
|
||||||
sizeof(error_string),
|
sizeof(error_string),
|
||||||
@ -97,17 +98,29 @@ extern const char *real_gamemode_error_string(void)
|
|||||||
// Wrapper to call RegisterGame
|
// Wrapper to call RegisterGame
|
||||||
extern int real_gamemode_request_start(void)
|
extern int real_gamemode_request_start(void)
|
||||||
{
|
{
|
||||||
return gamemode_request("RegisterGame");
|
return gamemode_request("RegisterGame", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrapper to call UnregisterGame
|
// Wrapper to call UnregisterGame
|
||||||
extern int real_gamemode_request_end(void)
|
extern int real_gamemode_request_end(void)
|
||||||
{
|
{
|
||||||
return gamemode_request("UnregisterGame");
|
return gamemode_request("UnregisterGame", 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wrapper to call UnregisterGame
|
// Wrapper to call QueryStatus
|
||||||
extern int real_gamemode_query_status(void)
|
extern int real_gamemode_query_status(void)
|
||||||
{
|
{
|
||||||
return gamemode_request("QueryStatus");
|
return gamemode_request("QueryStatus", 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrapper to call RegisterGameByPID
|
||||||
|
extern int real_gamemode_register_start_for(pid_t pid)
|
||||||
|
{
|
||||||
|
return gamemode_request("RegisterGameByPID", pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrapper to call UnregisterGameByPID
|
||||||
|
extern int real_gamemode_register_end_for(pid_t pid)
|
||||||
|
{
|
||||||
|
return gamemode_request("UnregisterGameByPID", pid);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user