Browse Source

Restructure files and libraries

	Rename a bunch of files to make the consistent
	Create two new subdirectories for common code, and utilities
Marc Di Luzio 5 years ago
parent
commit
1b78d0dcf7

+ 2 - 2
daemon/external-helper.c → common/common-external.c

@@ -31,8 +31,8 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #define _GNU_SOURCE
 
-#include "external-helper.h"
-#include "logging.h"
+#include "common-external.h"
+#include "common-logging.h"
 
 #include <linux/limits.h>
 #include <stdio.h>

+ 0 - 0
daemon/external-helper.h → common/common-external.h


+ 2 - 2
daemon/governors-query.c → common/common-governors.c

@@ -31,8 +31,8 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #define _GNU_SOURCE
 
-#include "governors-query.h"
-#include "logging.h"
+#include "common-governors.h"
+#include "common-logging.h"
 
 #include <assert.h>
 #include <glob.h>

+ 0 - 0
daemon/governors-query.h → common/common-governors.h


+ 2 - 2
daemon/gpu-control.c → common/common-gpu.c

@@ -28,8 +28,8 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 POSSIBILITY OF SUCH DAMAGE.
 
  */
-#include "gpu-control.h"
-#include "logging.h"
+#include "common-gpu.h"
+#include "common-logging.h"
 
 #include <stdio.h>
 

+ 1 - 1
daemon/gpu-control.h → common/common-gpu.h

@@ -30,7 +30,7 @@ POSSIBILITY OF SUCH DAMAGE.
  */
 
 #pragma once
-#include "daemon_config.h"
+#define CONFIG_VALUE_MAX 256
 
 /* Enums for GPU vendors */
 enum GPUVendor {

+ 1 - 1
daemon/helpers.c → common/common-helpers.c

@@ -31,7 +31,7 @@ POSSIBILITY OF SUCH DAMAGE.
  */
 
 #define _GNU_SOURCE
-#include "helpers.h"
+#include "common-helpers.h"
 
 /* Starting with C99 we can use "inline" without "static" and thus avoid
  * having multiple (local) definitions of the same inline function. One

+ 0 - 0
daemon/helpers.h → common/common-helpers.h


+ 2 - 1
daemon/logging.c → common/common-logging.c

@@ -29,7 +29,8 @@ POSSIBILITY OF SUCH DAMAGE.
 
  */
 
-#include "logging.h"
+#include "common-logging.h"
+
 #include "syslog.h"
 
 static bool use_syslog = false;

+ 0 - 0
daemon/logging.h → common/common-logging.h


+ 20 - 0
common/meson.build

@@ -0,0 +1,20 @@
+# Convenience library for the duplicated logging functionality
+common_sources = [
+    'common-logging.c',
+    'common-governors.c',
+    'common-external.c',
+    'common-helpers.c',
+    'common-gpu.c',
+]
+
+daemon_common = static_library(
+    'daemon-common',
+    sources: common_sources,
+    install: false,
+)
+
+link_daemon_common = declare_dependency(
+    link_with: daemon_common,
+)
+
+include_daemon_common = include_directories('.')

+ 0 - 51
daemon/dbus_messaging.h

@@ -1,51 +0,0 @@
-/*
-
-Copyright (c) 2017-2019, Feral Interactive
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
- * Redistributions of source code must retain the above copyright notice,
-   this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
- * Neither the name of Feral Interactive nor the names of its contributors
-   may be used to endorse or promote products derived from this software
-   without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-
- */
-
-#pragma once
-
-#include <stdbool.h>
-
-#include "gamemode.h"
-
-/**
- * Run the main D-BUS loop "forever"
- */
-void game_mode_context_loop(GameModeContext *context) __attribute__((noreturn));
-
-/**
- * Inhibit the screensaver
- */
-int game_mode_inhibit_screensaver(bool inhibit);
-
-/**
- * Signal the ClientCount property has changed
- */
-void game_mode_client_count_changed(void);

+ 4 - 3
daemon/daemon_config.c → daemon/gamemode-config.c

@@ -30,9 +30,10 @@ POSSIBILITY OF SUCH DAMAGE.
  */
 #define _GNU_SOURCE
 
-#include "daemon_config.h"
-#include "helpers.h"
-#include "logging.h"
+#include "gamemode-config.h"
+
+#include "common-helpers.h"
+#include "common-logging.h"
 
 /* Ben Hoyt's inih library */
 #include "ini.h"

+ 0 - 0
daemon/daemon_config.h → daemon/gamemode-config.h


+ 7 - 7
daemon/gamemode.c → daemon/gamemode-context.c

@@ -31,14 +31,14 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #define _GNU_SOURCE
 
+#include "common-external.h"
+#include "common-governors.h"
+#include "common-helpers.h"
+#include "common-logging.h"
+#include "gamemode-config.h"
 #include "gamemode.h"
-#include "config.h"
-#include "daemon_config.h"
-#include "dbus_messaging.h"
-#include "external-helper.h"
-#include "governors-query.h"
-#include "helpers.h"
-#include "logging.h"
+
+#include "build-config.h"
 
 #include <fcntl.h>
 #include <pthread.h>

+ 17 - 17
daemon/dbus_messaging.c → daemon/gamemode-dbus.c

@@ -31,9 +31,8 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #define _GNU_SOURCE
 
-#include "dbus_messaging.h"
+#include "common-logging.h"
 #include "gamemode.h"
-#include "logging.h"
 
 #include <stdlib.h>
 
@@ -219,21 +218,22 @@ static int method_refresh_config(sd_bus_message *m, void *userdata,
 /**
  * D-BUS vtable to dispatch virtual methods
  */
-static const sd_bus_vtable gamemode_vtable[] =
-    { SD_BUS_VTABLE_START(0),
-	  SD_BUS_PROPERTY("ClientCount", "i", property_get_client_count, 0,
-	                  SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
-	  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_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_METHOD("QueryStatusByPID", "ii", "i", method_query_status_by_pid,
-	                SD_BUS_VTABLE_UNPRIVILEGED),
-	  SD_BUS_METHOD("RefreshConfig", "", "i", method_refresh_config, SD_BUS_VTABLE_UNPRIVILEGED),
-	  SD_BUS_VTABLE_END };
+static const sd_bus_vtable gamemode_vtable[] = {
+	SD_BUS_VTABLE_START(0),
+	SD_BUS_PROPERTY("ClientCount", "i", property_get_client_count, 0,
+	                SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+	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_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_METHOD("QueryStatusByPID", "ii", "i", method_query_status_by_pid,
+	              SD_BUS_VTABLE_UNPRIVILEGED),
+	SD_BUS_METHOD("RefreshConfig", "", "i", method_refresh_config, SD_BUS_VTABLE_UNPRIVILEGED),
+	SD_BUS_VTABLE_END
+};
 
 /**
  * Main process loop for the daemon. Run until quitting has been requested.

+ 6 - 7
daemon/gamemode-gpu.c

@@ -32,15 +32,14 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #define _GNU_SOURCE
 
-#include "config.h"
-#include "external-helper.h"
-#include "helpers.h"
-#include "logging.h"
-
+#include "common-external.h"
+#include "common-gpu.h"
+#include "common-helpers.h"
+#include "common-logging.h"
+#include "gamemode-config.h"
 #include "gamemode.h"
 
-#include "daemon_config.h"
-#include "gpu-control.h"
+#include "build-config.h"
 
 /**
  * Attempts to identify the current in use GPU information

+ 3 - 3
daemon/gamemode-ioprio.c

@@ -31,10 +31,10 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #define _GNU_SOURCE
 
-#include "daemon_config.h"
+#include "common-helpers.h"
+#include "common-logging.h"
+#include "gamemode-config.h"
 #include "gamemode.h"
-#include "helpers.h"
-#include "logging.h"
 
 #include <dirent.h>
 #include <errno.h>

+ 2 - 2
daemon/gamemode-sched.c

@@ -31,9 +31,9 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #define _GNU_SOURCE
 
-#include "daemon_config.h"
+#include "common-logging.h"
+#include "gamemode-config.h"
 #include "gamemode.h"
-#include "logging.h"
 
 #include <dirent.h>
 #include <errno.h>

+ 8 - 7
daemon/gamemode-tests.c

@@ -31,9 +31,14 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #define _GNU_SOURCE
 
+#include "common-external.h"
+#include "common-governors.h"
+#include "common-gpu.h"
+#include "common-helpers.h"
+#include "common-logging.h"
+#include "gamemode-config.h"
 #include "gamemode.h"
-#include "helpers.h"
-#include "logging.h"
+#include "gamemode_client.h"
 
 #include <libgen.h>
 #include <pthread.h>
@@ -42,11 +47,7 @@ POSSIBILITY OF SUCH DAMAGE.
 #include <sys/wait.h>
 #include <unistd.h>
 
-#include "daemon_config.h"
-#include "external-helper.h"
-#include "gamemode_client.h"
-#include "governors-query.h"
-#include "gpu-control.h"
+struct GameModeConfig;
 
 /* Initial verify step to ensure gamemode isn't already active */
 static int verify_gamemode_initial(struct GameModeConfig *config)

+ 2 - 2
daemon/gamemode-wine.c

@@ -31,9 +31,9 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #define _GNU_SOURCE
 
+#include "common-helpers.h"
+#include "common-logging.h"
 #include "gamemode.h"
-#include "helpers.h"
-#include "logging.h"
 
 #include <ctype.h>
 #include <fcntl.h>

+ 15 - 0
daemon/gamemode.h

@@ -150,3 +150,18 @@ int game_mode_initialise_gpu(GameModeConfig *config, GameModeGPUInfo **info);
 void game_mode_free_gpu(GameModeGPUInfo **info);
 int game_mode_apply_gpu(const GameModeGPUInfo *info);
 int game_mode_get_gpu(GameModeGPUInfo *info);
+
+/**
+ * Run the main D-BUS loop "forever"
+ */
+void game_mode_context_loop(GameModeContext *context) __attribute__((noreturn));
+
+/**
+ * Inhibit the screensaver
+ */
+int game_mode_inhibit_screensaver(bool inhibit);
+
+/**
+ * Signal the ClientCount property has changed
+ */
+void game_mode_client_count_changed(void);

+ 5 - 3
daemon/main.c → daemon/gamemoded.c

@@ -49,11 +49,13 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #define _GNU_SOURCE
 
-#include "config.h"
-#include "dbus_messaging.h"
+#include "common-logging.h"
+#include "gamemode-config.h"
 #include "gamemode.h"
+
 #include "gamemode_client.h"
-#include "logging.h"
+
+#include "build-config.h"
 
 #include <fcntl.h>
 #include <getopt.h>

+ 8 - 56
daemon/meson.build

@@ -1,35 +1,14 @@
-# Convenience library for the duplicated logging functionality
-common_sources = [
-    'logging.c',
-    'governors-query.c',
-    'external-helper.c',
-    'gpu-control.c',
-]
-
-daemon_common = static_library(
-    'daemon-common',
-    sources: common_sources,
-    install: false,
-)
-
-link_daemon_common = declare_dependency(
-    link_with: daemon_common,
-)
-
 # Main daemon
 daemon_sources = [
-    'main.c',
-    'gamemode.c',
-    'gamemode-env.c',
+    'gamemoded.c',
+    'gamemode-context.c',
     'gamemode-ioprio.c',
-    'gamemode-proc.c',
     'gamemode-sched.c',
     'gamemode-wine.c',
     'gamemode-tests.c',
     'gamemode-gpu.c',
-    'dbus_messaging.c',
-    'daemon_config.c',
-    'helpers.c',
+    'gamemode-dbus.c',
+    'gamemode-config.c',
 ]
 
 gamemoded_includes = libgamemode_includes
@@ -45,36 +24,9 @@ executable(
         inih_dependency,
         libdl,
     ],
-    include_directories: gamemoded_includes,
-    install: true,
-)
-
-# Small target util to get and set cpu governors
-cpugovctl_sources = [
-    'cpugovctl.c',
-]
-
-cpugovctl = executable(
-    'cpugovctl',
-    sources: cpugovctl_sources,
-    dependencies: [
-        link_daemon_common,
-    ],
-    install: true,
-    install_dir: path_libexecdir,
-)
-
-# Small target util to get and set gpu clocks values
-gpuclockctl_sources = [
-    'gpuclockctl.c',
-]
-
-gpuclockctl = executable(
-    'gpuclockctl',
-    sources: gpuclockctl_sources,
-    dependencies: [
-        link_daemon_common,
+    include_directories: [
+        gamemoded_includes,
+        include_daemon_common,
     ],
     install: true,
-    install_dir: path_libexecdir,
-)
+)

+ 7 - 1
meson.build

@@ -132,13 +132,19 @@ cdata.set_quoted('LIBEXECDIR', path_libexecdir)
 cdata.set_quoted('GAMEMODE_VERSION', meson.project_version())
 config_h = configure_file(
     configuration: cdata,
-    output: 'config.h',
+    output: 'build-config.h',
 )
 config_h_dir = include_directories('.')
 
 # Library is always required
 subdir('lib')
 
+# common lib is always required
+subdir('common')
+
+# Utilities are always required
+subdir('util')
+
 # The daemon can be disabled if necessary, allowing multilib builds of the
 # main library
 if with_daemon == true

+ 2 - 2
daemon/cpugovctl.c → util/cpugovctl.c

@@ -31,8 +31,8 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #define _GNU_SOURCE
 
-#include "governors-query.h"
-#include "logging.h"
+#include "common-governors.h"
+#include "common-logging.h"
 
 #include <ctype.h>
 #include <errno.h>

+ 3 - 4
daemon/gpuclockctl.c → util/gpuclockctl.c

@@ -31,10 +31,9 @@ POSSIBILITY OF SUCH DAMAGE.
 
 #define _GNU_SOURCE
 
-#include "logging.h"
-
-#include "external-helper.h"
-#include "gpu-control.h"
+#include "common-external.h"
+#include "common-gpu.h"
+#include "common-logging.h"
 
 #include <limits.h>
 

+ 32 - 0
util/meson.build

@@ -0,0 +1,32 @@
+
+# Small target util to get and set cpu governors
+cpugovctl_sources = [
+    'cpugovctl.c',
+]
+
+cpugovctl = executable(
+    'cpugovctl',
+    sources: cpugovctl_sources,
+    dependencies: [
+        link_daemon_common,
+    ],
+    install: true,
+    include_directories: include_daemon_common,
+    install_dir: path_libexecdir,
+)
+
+# Small target util to get and set gpu clocks values
+gpuclockctl_sources = [
+    'gpuclockctl.c',
+]
+
+gpuclockctl = executable(
+    'gpuclockctl',
+    sources: gpuclockctl_sources,
+    dependencies: [
+        link_daemon_common,
+    ],
+    install: true,
+    include_directories: include_daemon_common,
+    install_dir: path_libexecdir,
+)