Refactor some common utilities out of main

Signed-off-by: Jim Ramsay <i.am@jimramsay.com>
pull/178/head
Jim Ramsay 2022-10-29 19:12:47 -04:00 committed by Andri Yngvason
parent 1a0e8aae97
commit 5043f8e149
6 changed files with 51 additions and 23 deletions

View File

@ -30,8 +30,6 @@ struct ctl_server_actions {
const char* output_name); const char* output_name);
}; };
const char* default_ctl_socket_path();
struct ctl* ctl_server_new(const char* socket_path, struct ctl* ctl_server_new(const char* socket_path,
const struct ctl_server_actions* actions); const struct ctl_server_actions* actions);
void ctl_server_destroy(struct ctl*); void ctl_server_destroy(struct ctl*);

View File

@ -17,3 +17,7 @@
#pragma once #pragma once
#define UDIV_UP(a, b) (((a) + (b) - 1) / (b)) #define UDIV_UP(a, b) (((a) + (b) - 1) / (b))
extern const char* wayvnc_version;
const char* default_ctl_socket_path();

View File

@ -90,6 +90,7 @@ sources = [
'src/buffer.c', 'src/buffer.c',
'src/pixels.c', 'src/pixels.c',
'src/transform-util.c', 'src/transform-util.c',
'src/util.c',
'src/json-ipc.c', 'src/json-ipc.c',
'src/ctl-server.c', 'src/ctl-server.c',
] ]

View File

@ -499,19 +499,6 @@ accept_failure:
free(client); free(client);
} }
const char* default_ctl_socket_path()
{
static char buffer[128];
char* xdg_runtime = getenv("XDG_RUNTIME_DIR");
if (xdg_runtime)
snprintf(buffer, sizeof(buffer),
"%s/wayvncctl", xdg_runtime);
else
snprintf(buffer, sizeof(buffer),
"/tmp/wayvncctl-%d", getuid());
return buffer;
}
int ctl_server_init(struct ctl* self, const char* socket_path) int ctl_server_init(struct ctl* self, const char* socket_path)
{ {
if (!socket_path) { if (!socket_path) {

View File

@ -51,6 +51,7 @@
#include "transform-util.h" #include "transform-util.h"
#include "usdt.h" #include "usdt.h"
#include "ctl-server.h" #include "ctl-server.h"
#include "util.h"
#ifdef ENABLE_PAM #ifdef ENABLE_PAM
#include "pam_auth.h" #include "pam_auth.h"
@ -114,14 +115,6 @@ void switch_to_output(struct wayvnc*, struct output*);
void switch_to_next_output(struct wayvnc*); void switch_to_next_output(struct wayvnc*);
void switch_to_prev_output(struct wayvnc*); void switch_to_prev_output(struct wayvnc*);
#if defined(GIT_VERSION)
static const char wayvnc_version[] = GIT_VERSION;
#elif defined(PROJECT_VERSION)
static const char wayvnc_version[] = PROJECT_VERSION;
#else
static const char wayvnc_version[] = "UNKNOWN";
#endif
struct wl_shm* wl_shm = NULL; struct wl_shm* wl_shm = NULL;
struct zwp_linux_dmabuf_v1* zwp_linux_dmabuf = NULL; struct zwp_linux_dmabuf_v1* zwp_linux_dmabuf = NULL;
struct gbm_device* gbm_device = NULL; struct gbm_device* gbm_device = NULL;

45
src/util.c 100644
View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2019 - 2022 Andri Yngvason
* Copyright (c) 2022 Jim Ramsay
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "util.h"
const char* wayvnc_version =
#if defined(GIT_VERSION)
GIT_VERSION;
#elif defined(PROJECT_VERSION)
PROJECT_VERSION;
#else
"UNKNOWN";
#endif
const char* default_ctl_socket_path()
{
static char buffer[128];
char* xdg_runtime = getenv("XDG_RUNTIME_DIR");
if (xdg_runtime)
snprintf(buffer, sizeof(buffer),
"%s/wayvncctl", xdg_runtime);
else
snprintf(buffer, sizeof(buffer),
"/tmp/wayvncctl-%d", getuid());
return buffer;
}