Restructure files and libraries

Rename a bunch of files to make the consistent
	Create two new subdirectories for common code, and utilities
This commit is contained in:
Marc Di Luzio 2019-05-22 18:55:52 +01:00
parent 41988b7f1c
commit 1b78d0dcf7
28 changed files with 151 additions and 174 deletions

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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 {

View File

@ -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

View File

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

20
common/meson.build Normal file
View File

@ -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('.')

View File

@ -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);

View File

@ -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"

View File

@ -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>

View File

@ -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.

View File

@ -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

View File

@ -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>

View File

@ -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>

View File

@ -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)

View File

@ -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>

View File

@ -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);

View File

@ -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>

View File

@ -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,
)
)

View File

@ -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

View File

@ -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>

View File

@ -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
util/meson.build Normal file
View File

@ -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,
)