From 1b78d0dcf71cf4a24ae487cedf78ef40c74d72fc Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Wed, 22 May 2019 18:55:52 +0100 Subject: [PATCH] Restructure files and libraries Rename a bunch of files to make the consistent Create two new subdirectories for common code, and utilities --- .../common-external.c | 4 +- .../common-external.h | 0 .../common-governors.c | 4 +- .../common-governors.h | 0 daemon/gpu-control.c => common/common-gpu.c | 4 +- daemon/gpu-control.h => common/common-gpu.h | 2 +- daemon/helpers.c => common/common-helpers.c | 2 +- daemon/helpers.h => common/common-helpers.h | 0 daemon/logging.c => common/common-logging.c | 3 +- daemon/logging.h => common/common-logging.h | 0 common/meson.build | 20 ++++++ daemon/dbus_messaging.h | 51 --------------- daemon/{daemon_config.c => gamemode-config.c} | 7 +- daemon/{daemon_config.h => gamemode-config.h} | 0 daemon/{gamemode.c => gamemode-context.c} | 14 ++-- daemon/{dbus_messaging.c => gamemode-dbus.c} | 34 +++++----- daemon/gamemode-gpu.c | 13 ++-- daemon/gamemode-ioprio.c | 6 +- daemon/gamemode-sched.c | 4 +- daemon/gamemode-tests.c | 15 +++-- daemon/gamemode-wine.c | 4 +- daemon/gamemode.h | 15 +++++ daemon/{main.c => gamemoded.c} | 8 ++- daemon/meson.build | 64 +++---------------- meson.build | 8 ++- {daemon => util}/cpugovctl.c | 4 +- {daemon => util}/gpuclockctl.c | 7 +- util/meson.build | 32 ++++++++++ 28 files changed, 151 insertions(+), 174 deletions(-) rename daemon/external-helper.c => common/common-external.c (98%) rename daemon/external-helper.h => common/common-external.h (100%) rename daemon/governors-query.c => common/common-governors.c (98%) rename daemon/governors-query.h => common/common-governors.h (100%) rename daemon/gpu-control.c => common/common-gpu.c (98%) rename daemon/gpu-control.h => common/common-gpu.h (98%) rename daemon/helpers.c => common/common-helpers.c (98%) rename daemon/helpers.h => common/common-helpers.h (100%) rename daemon/logging.c => common/common-logging.c (98%) rename daemon/logging.h => common/common-logging.h (100%) create mode 100644 common/meson.build delete mode 100644 daemon/dbus_messaging.h rename daemon/{daemon_config.c => gamemode-config.c} (99%) rename daemon/{daemon_config.h => gamemode-config.h} (100%) rename daemon/{gamemode.c => gamemode-context.c} (99%) rename daemon/{dbus_messaging.c => gamemode-dbus.c} (91%) rename daemon/{main.c => gamemoded.c} (99%) rename {daemon => util}/cpugovctl.c (97%) rename {daemon => util}/gpuclockctl.c (99%) create mode 100644 util/meson.build diff --git a/daemon/external-helper.c b/common/common-external.c similarity index 98% rename from daemon/external-helper.c rename to common/common-external.c index 62cf29a..12f30fb 100644 --- a/daemon/external-helper.c +++ b/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 #include diff --git a/daemon/external-helper.h b/common/common-external.h similarity index 100% rename from daemon/external-helper.h rename to common/common-external.h diff --git a/daemon/governors-query.c b/common/common-governors.c similarity index 98% rename from daemon/governors-query.c rename to common/common-governors.c index 9d483c0..eb5e27f 100644 --- a/daemon/governors-query.c +++ b/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 #include diff --git a/daemon/governors-query.h b/common/common-governors.h similarity index 100% rename from daemon/governors-query.h rename to common/common-governors.h diff --git a/daemon/gpu-control.c b/common/common-gpu.c similarity index 98% rename from daemon/gpu-control.c rename to common/common-gpu.c index a2699c0..392a9d2 100644 --- a/daemon/gpu-control.c +++ b/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 diff --git a/daemon/gpu-control.h b/common/common-gpu.h similarity index 98% rename from daemon/gpu-control.h rename to common/common-gpu.h index 4be055a..59749c0 100644 --- a/daemon/gpu-control.h +++ b/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 { diff --git a/daemon/helpers.c b/common/common-helpers.c similarity index 98% rename from daemon/helpers.c rename to common/common-helpers.c index 50fde33..5cffc82 100644 --- a/daemon/helpers.c +++ b/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 diff --git a/daemon/helpers.h b/common/common-helpers.h similarity index 100% rename from daemon/helpers.h rename to common/common-helpers.h diff --git a/daemon/logging.c b/common/common-logging.c similarity index 98% rename from daemon/logging.c rename to common/common-logging.c index b75547c..cd8e18f 100644 --- a/daemon/logging.c +++ b/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; diff --git a/daemon/logging.h b/common/common-logging.h similarity index 100% rename from daemon/logging.h rename to common/common-logging.h diff --git a/common/meson.build b/common/meson.build new file mode 100644 index 0000000..78d1c03 --- /dev/null +++ b/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('.') \ No newline at end of file diff --git a/daemon/dbus_messaging.h b/daemon/dbus_messaging.h deleted file mode 100644 index 6edbc0d..0000000 --- a/daemon/dbus_messaging.h +++ /dev/null @@ -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 - -#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); diff --git a/daemon/daemon_config.c b/daemon/gamemode-config.c similarity index 99% rename from daemon/daemon_config.c rename to daemon/gamemode-config.c index 9602408..b482d02 100644 --- a/daemon/daemon_config.c +++ b/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" diff --git a/daemon/daemon_config.h b/daemon/gamemode-config.h similarity index 100% rename from daemon/daemon_config.h rename to daemon/gamemode-config.h diff --git a/daemon/gamemode.c b/daemon/gamemode-context.c similarity index 99% rename from daemon/gamemode.c rename to daemon/gamemode-context.c index 115280a..0cd1b05 100644 --- a/daemon/gamemode.c +++ b/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 #include diff --git a/daemon/dbus_messaging.c b/daemon/gamemode-dbus.c similarity index 91% rename from daemon/dbus_messaging.c rename to daemon/gamemode-dbus.c index eee022f..8f1eea9 100644 --- a/daemon/dbus_messaging.c +++ b/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 @@ -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. diff --git a/daemon/gamemode-gpu.c b/daemon/gamemode-gpu.c index 6a054e2..26d9f5b 100644 --- a/daemon/gamemode-gpu.c +++ b/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 diff --git a/daemon/gamemode-ioprio.c b/daemon/gamemode-ioprio.c index 6af6779..32eb40d 100644 --- a/daemon/gamemode-ioprio.c +++ b/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 #include diff --git a/daemon/gamemode-sched.c b/daemon/gamemode-sched.c index 2c82d64..06aa31a 100644 --- a/daemon/gamemode-sched.c +++ b/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 #include diff --git a/daemon/gamemode-tests.c b/daemon/gamemode-tests.c index eefc941..db7474e 100644 --- a/daemon/gamemode-tests.c +++ b/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 #include @@ -42,11 +47,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#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) diff --git a/daemon/gamemode-wine.c b/daemon/gamemode-wine.c index b23f8e5..a50112b 100644 --- a/daemon/gamemode-wine.c +++ b/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 #include diff --git a/daemon/gamemode.h b/daemon/gamemode.h index ae89f6f..fedef7b 100644 --- a/daemon/gamemode.h +++ b/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); \ No newline at end of file diff --git a/daemon/main.c b/daemon/gamemoded.c similarity index 99% rename from daemon/main.c rename to daemon/gamemoded.c index f26785b..1401652 100644 --- a/daemon/main.c +++ b/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 #include diff --git a/daemon/meson.build b/daemon/meson.build index aae53e6..7a3544e 100644 --- a/daemon/meson.build +++ b/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, + include_directories: [ + gamemoded_includes, + include_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, - ], - install: true, - install_dir: path_libexecdir, -) +) \ No newline at end of file diff --git a/meson.build b/meson.build index b7bb874..c6f3032 100644 --- a/meson.build +++ b/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 diff --git a/daemon/cpugovctl.c b/util/cpugovctl.c similarity index 97% rename from daemon/cpugovctl.c rename to util/cpugovctl.c index f72ed67..adf275a 100644 --- a/daemon/cpugovctl.c +++ b/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 #include diff --git a/daemon/gpuclockctl.c b/util/gpuclockctl.c similarity index 99% rename from daemon/gpuclockctl.c rename to util/gpuclockctl.c index 850bd05..6fa7e2b 100644 --- a/daemon/gpuclockctl.c +++ b/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 diff --git a/util/meson.build b/util/meson.build new file mode 100644 index 0000000..700f5c6 --- /dev/null +++ b/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, +)