Sfoglia il codice sorgente

daemon: export GameModeClient::Timestamp on D-Bus

Expose the timestamp that a client was created as 'Timestamp'
property of the com.feralinteractive.GameMode.Game interface.
Christian Kellner 5 anni fa
parent
commit
288b3a005e
1 ha cambiato i file con 34 aggiunte e 0 eliminazioni
  1. 34 0
      daemon/gamemode-dbus.c

+ 34 - 0
daemon/gamemode-dbus.c

@@ -462,6 +462,38 @@ static int game_object_get_executable(sd_bus *local_bus, const char *path, const
 	return ret;
 }
 
+/**
+ * Handles the Timestamp property for Game objects
+ */
+static int game_object_get_timestamp(sd_bus *local_bus, const char *path, const char *interface,
+				     const char *property, sd_bus_message *reply, void *userdata,
+				     sd_bus_error *ret_error)
+{
+	GameModeClient *client;
+	GameModeContext *context;
+	uint64_t timestamp;
+	pid_t pid;
+	int ret;
+
+	pid = pid_from_pointer(userdata);
+
+	context = game_mode_context_instance();
+	client = game_mode_context_lookup_client(context, pid);
+
+	if (client == NULL) {
+		return sd_bus_error_setf(ret_error,
+					 SD_BUS_ERROR_UNKNOWN_OBJECT,
+					 "No client registered with id '%d'", (int) pid);
+	}
+
+	timestamp = game_mode_client_get_timestamp(client);
+	ret = sd_bus_message_append_basic(reply, 't', &timestamp);
+	game_mode_client_unref(client);
+
+	return ret;
+}
+
+
 /* Same as above: this bit seems to be formatted differently by different clang-format versions */
 /* clang-format off */
 static const sd_bus_vtable game_vtable[] = {
@@ -470,6 +502,8 @@ static const sd_bus_vtable game_vtable[] = {
 	                SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
 	SD_BUS_PROPERTY("Executable", "s", game_object_get_executable, 0,
 	                SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+	SD_BUS_PROPERTY("Timestamp", "t", game_object_get_timestamp, 0,
+	                SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
 	SD_BUS_VTABLE_END
 };
 /* clang-format on */