mirror of
https://forgejo.xatacraft.ru/Sunshine/mkxp-sunshine.git
synced 2026-08-19 21:39:57 +00:00
Create jounal-binding.h
This commit is contained in:
parent
86b3f26c2a
commit
b8c3531bff
3 changed files with 90 additions and 70 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include "journal-binding.h"
|
||||||
#include "binding-util.h"
|
#include "binding-util.h"
|
||||||
#include "binding-types.h"
|
#include "binding-types.h"
|
||||||
#include "pipe.h"
|
#include "pipe.h"
|
||||||
|
|
@ -6,17 +7,7 @@
|
||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
//OS-Specific code
|
#ifdef LINUX
|
||||||
#if defined _WIN32
|
|
||||||
#define OS_W32
|
|
||||||
#elif defined __APPLE__ || __linux__
|
|
||||||
#define LINUX
|
|
||||||
#ifdef __APPLE__
|
|
||||||
#define OS_OSX
|
|
||||||
#else
|
|
||||||
#define OS_LINUX
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
@ -25,66 +16,8 @@
|
||||||
#endif
|
#endif
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#else
|
|
||||||
#error "Operating system not detected."
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BUFFER_SIZE 256
|
|
||||||
|
|
||||||
static SDL_Thread *thread = NULL;
|
|
||||||
static SDL_mutex *mutex = NULL;
|
|
||||||
static volatile char lang_buffer[BUFFER_SIZE];
|
|
||||||
static volatile char message_buffer[BUFFER_SIZE];
|
|
||||||
static volatile bool active = false;
|
|
||||||
static volatile int message_len = 0;
|
|
||||||
|
|
||||||
#ifdef LINUX
|
|
||||||
#define PIPE_PATH "/tmp/oneshot-pipe"
|
|
||||||
static volatile int out_pipe = -1;
|
|
||||||
void cleanup_pipe()
|
|
||||||
{
|
|
||||||
unlink(PIPE_PATH);
|
|
||||||
remove(PIPE_PATH);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int server_thread(void *data)
|
|
||||||
{
|
|
||||||
(void)data;
|
|
||||||
#if defined OS_W32
|
|
||||||
HANDLE pipe = CreateNamedPipeW(L"\\\\.\\pipe\\oneshot-journal-to-game",
|
|
||||||
PIPE_ACCESS_OUTBOUND,
|
|
||||||
PIPE_TYPE_BYTE | PIPE_WAIT,
|
|
||||||
PIPE_UNLIMITED_INSTANCES,
|
|
||||||
BUFFER_SIZE,
|
|
||||||
BUFFER_SIZE,
|
|
||||||
0,
|
|
||||||
NULL);
|
|
||||||
for (;;) {
|
|
||||||
ConnectNamedPipe(pipe, NULL);
|
|
||||||
SDL_LockMutex(mutex);
|
|
||||||
DWORD written;
|
|
||||||
WriteFile(pipe, (const void*)message_buffer, BUFFER_SIZE, &written, NULL);
|
|
||||||
active = true;
|
|
||||||
SDL_UnlockMutex(mutex);
|
|
||||||
FlushFileBuffers(pipe);
|
|
||||||
DisconnectNamedPipe(pipe);
|
|
||||||
}
|
|
||||||
CloseHandle(pipe);
|
|
||||||
#else
|
|
||||||
if (FILE *file = fopen(PIPE_PATH, "r")) {
|
|
||||||
fclose(file);
|
|
||||||
out_pipe = open(PIPE_PATH, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
|
||||||
SDL_LockMutex(mutex);
|
|
||||||
active = true;
|
|
||||||
if (message_len > 0)
|
|
||||||
write(out_pipe, (char*)message_buffer, message_len);
|
|
||||||
SDL_UnlockMutex(mutex);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
RB_METHOD(journalSet)
|
RB_METHOD(journalSet)
|
||||||
{
|
{
|
||||||
RB_UNUSED_PARAM;
|
RB_UNUSED_PARAM;
|
||||||
|
|
|
||||||
86
binding-mri/journal-binding.h
Normal file
86
binding-mri/journal-binding.h
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
#include "binding-util.h"
|
||||||
|
#include "binding-types.h"
|
||||||
|
#include "pipe.h"
|
||||||
|
#include "debugwriter.h"
|
||||||
|
#include "i18n.h"
|
||||||
|
|
||||||
|
#include <SDL.h>
|
||||||
|
|
||||||
|
//OS-Specific code
|
||||||
|
#if defined _WIN32
|
||||||
|
#define OS_W32
|
||||||
|
#elif defined __APPLE__ || __linux__
|
||||||
|
#define LINUX
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#define OS_OSX
|
||||||
|
#else
|
||||||
|
#define OS_LINUX
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#ifdef OS_LINUX
|
||||||
|
#include <sys/inotify.h>
|
||||||
|
#endif
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#else
|
||||||
|
#error "Operating system not detected."
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BUFFER_SIZE 256
|
||||||
|
|
||||||
|
static SDL_Thread *thread = NULL;
|
||||||
|
static SDL_mutex *mutex = NULL;
|
||||||
|
static volatile char lang_buffer[BUFFER_SIZE];
|
||||||
|
static volatile char message_buffer[BUFFER_SIZE];
|
||||||
|
static volatile bool active = false;
|
||||||
|
static volatile int message_len = 0;
|
||||||
|
|
||||||
|
#ifdef LINUX
|
||||||
|
#define PIPE_PATH "/tmp/oneshot-pipe"
|
||||||
|
static volatile int out_pipe = -1;
|
||||||
|
void cleanup_pipe()
|
||||||
|
{
|
||||||
|
unlink(PIPE_PATH);
|
||||||
|
remove(PIPE_PATH);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int server_thread(void *data)
|
||||||
|
{
|
||||||
|
(void)data;
|
||||||
|
#if defined OS_W32
|
||||||
|
HANDLE pipe = CreateNamedPipeW(L"\\\\.\\pipe\\oneshot-journal-to-game",
|
||||||
|
PIPE_ACCESS_OUTBOUND,
|
||||||
|
PIPE_TYPE_BYTE | PIPE_WAIT,
|
||||||
|
PIPE_UNLIMITED_INSTANCES,
|
||||||
|
BUFFER_SIZE,
|
||||||
|
BUFFER_SIZE,
|
||||||
|
0,
|
||||||
|
NULL);
|
||||||
|
for (;;) {
|
||||||
|
ConnectNamedPipe(pipe, NULL);
|
||||||
|
SDL_LockMutex(mutex);
|
||||||
|
DWORD written;
|
||||||
|
WriteFile(pipe, (const void*)message_buffer, BUFFER_SIZE, &written, NULL);
|
||||||
|
active = true;
|
||||||
|
SDL_UnlockMutex(mutex);
|
||||||
|
FlushFileBuffers(pipe);
|
||||||
|
DisconnectNamedPipe(pipe);
|
||||||
|
}
|
||||||
|
CloseHandle(pipe);
|
||||||
|
#else
|
||||||
|
if (FILE *file = fopen(PIPE_PATH, "r")) {
|
||||||
|
fclose(file);
|
||||||
|
out_pipe = open(PIPE_PATH, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||||
|
SDL_LockMutex(mutex);
|
||||||
|
active = true;
|
||||||
|
if (message_len > 0)
|
||||||
|
write(out_pipe, (char*)message_buffer, message_len);
|
||||||
|
SDL_UnlockMutex(mutex);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
3
mkxp.pro
3
mkxp.pro
|
|
@ -271,7 +271,8 @@ BINDING_MRI {
|
||||||
binding-mri/disposable-binding.h \
|
binding-mri/disposable-binding.h \
|
||||||
binding-mri/sceneelement-binding.h \
|
binding-mri/sceneelement-binding.h \
|
||||||
binding-mri/viewportelement-binding.h \
|
binding-mri/viewportelement-binding.h \
|
||||||
binding-mri/flashable-binding.h
|
binding-mri/flashable-binding.h \
|
||||||
|
binding-mri/journal-binding.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
binding-mri/binding-mri.cpp \
|
binding-mri/binding-mri.cpp \
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue