From 30152b9604db1c3b2f270b2f20a2aa1afbb788f2 Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Sun, 22 Oct 2017 01:02:18 +0100 Subject: [PATCH] redirect: Begin working on new Profile bits The Profile will allow us to construct reusable/extendable rules to handle various game issues. Signed-off-by: Ikey Doherty --- src/redirect/meson.build | 1 + src/redirect/profile.c | 58 ++++++++++++++++++++++++++++++++++++++++ src/redirect/redirect.h | 22 ++++++++++++++- 3 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 src/redirect/profile.c diff --git a/src/redirect/meson.build b/src/redirect/meson.build index 2ed35d0..1b86e24 100644 --- a/src/redirect/meson.build +++ b/src/redirect/meson.build @@ -7,6 +7,7 @@ if with_libredirect == true redirect_sources = [ 'main.c', + 'profile.c', ] main_redirect = shared_library( diff --git a/src/redirect/profile.c b/src/redirect/profile.c new file mode 100644 index 0000000..44a3090 --- /dev/null +++ b/src/redirect/profile.c @@ -0,0 +1,58 @@ +/* + * This file is part of linux-steam-integration. + * + * Copyright © 2017 Ikey Doherty + * + * linux-steam-integration is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + */ + +#define _GNU_SOURCE + +#include +#include + +#include "redirect.h" + +LsiRedirectProfile *lsi_redirect_profile_new(const char *name) +{ + LsiRedirectProfile p = { + .name = strdup(name), + .op_table = {{ 0 }}, + }; + LsiRedirectProfile *ret = NULL; + if (!p.name) { + return NULL; + } + + ret = calloc(1, sizeof(LsiRedirectProfile)); + if (!ret) { + return NULL; + } + *ret = p; + return ret; +} + +void lsi_redirect_profile_free(LsiRedirectProfile *self) +{ + if (!self) { + return; + } + free(self->name); + free(self); +} + +/* + * Editor modelines - https://www.wireshark.org/tools/modelines.html + * + * Local variables: + * c-basic-offset: 8 + * tab-width: 8 + * indent-tabs-mode: nil + * End: + * + * vi: set shiftwidth=8 tabstop=8 expandtab: + * :indentSize=8:tabSize=8:noTabs=true: + */ diff --git a/src/redirect/redirect.h b/src/redirect/redirect.h index 8a3cb55..08f6bb8 100644 --- a/src/redirect/redirect.h +++ b/src/redirect/redirect.h @@ -11,6 +11,9 @@ #pragma once +#include +#include + /** * The type of redirect required */ @@ -48,11 +51,28 @@ typedef enum { LSI_OPERATION_OPEN = 0, LSI_NUM_OPERATIONS } LsiRedirectOperation * op_table[LSI_OPERATION_OPEN] */ typedef struct LsiRedirectProfile { - const char *name; /**< Name for this profile */ + char *name; /**< Name for this profile */ LsiRedirect op_table[LSI_NUM_OPERATIONS]; /* vtable information */ } LsiRedirectProfile; + +/** + * Construct a new LsiRedirectProfile + * + * @param name Profile name + * @returns A newly allocated LsiRedirectProfile + */ +LsiRedirectProfile *lsi_redirect_profile_new(const char *name); + +/** + * Free a previously allocated LsiRedirectProfile + * + * @param profile Pointer to an allocated LsiRedirectProfile + */ +void lsi_redirect_profile_free(LsiRedirectProfile *profile); + + /* * Editor modelines - https://www.wireshark.org/tools/modelines.html *