diff --git a/src/frontend/qt_sdl/CMakeLists.txt b/src/frontend/qt_sdl/CMakeLists.txt index 24261030..c3e86dcb 100644 --- a/src/frontend/qt_sdl/CMakeLists.txt +++ b/src/frontend/qt_sdl/CMakeLists.txt @@ -25,6 +25,7 @@ set(SOURCES_QT_SDL RAMInfoDialog.cpp TitleManagerDialog.cpp Input.cpp + IPC.cpp LAN_PCap.cpp LAN_Socket.cpp LocalMP.cpp diff --git a/src/frontend/qt_sdl/IPC.cpp b/src/frontend/qt_sdl/IPC.cpp new file mode 100644 index 00000000..c8edf511 --- /dev/null +++ b/src/frontend/qt_sdl/IPC.cpp @@ -0,0 +1,88 @@ +/* + Copyright 2016-2022 melonDS team + + This file is part of melonDS. + + melonDS is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + melonDS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#include +#include +#include +#include + +#include "IPC.h" + + +namespace IPC +{ + +QSharedMemory* Buffer = nullptr; +int InstanceID; + + +void Init() +{ + InstanceID = 0; + + Buffer = new QSharedMemory("melonIPC"); + + if (!Buffer->attach()) + { + printf("IPC sharedmem doesn't exist. creating\n"); + if (!Buffer->create(1024)) + { + printf("IPC sharedmem create failed :(\n"); + delete Buffer; + Buffer = nullptr; + return; + } + + Buffer->lock(); + memset(Buffer->data(), 0, Buffer->size()); + Buffer->unlock(); + } + + Buffer->lock(); + u8* data = (u8*)Buffer->data(); + u16 mask = *(u16*)&data[0]; + for (int i = 0; i < 16; i++) + { + if (!(mask & (1<unlock(); + + printf("IPC: instance ID %d\n", InstanceID); +} + +void DeInit() +{ + if (Buffer) + { + Buffer->lock(); + u8* data = (u8*)Buffer->data(); + *(u16*)&data[0] &= ~(1<unlock(); + + Buffer->detach(); + delete Buffer; + } + Buffer = nullptr; +} + +} diff --git a/src/frontend/qt_sdl/IPC.h b/src/frontend/qt_sdl/IPC.h new file mode 100644 index 00000000..bd71fd70 --- /dev/null +++ b/src/frontend/qt_sdl/IPC.h @@ -0,0 +1,34 @@ +/* + Copyright 2016-2022 melonDS team + + This file is part of melonDS. + + melonDS is free software: you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + melonDS is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with melonDS. If not, see http://www.gnu.org/licenses/. +*/ + +#ifndef IPC_H +#define IPC_H + +#include "types.h" + +namespace IPC +{ + +extern int InstanceID; + +void Init(); +void DeInit(); + +} + +#endif // IPC_H diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 5263377e..c68a817a 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -38,6 +38,7 @@ #include "LAN_Socket.h" #include "LAN_PCap.h" #include "LocalMP.h" +#include "IPC.h" #include "OSD.h" #ifdef __WIN32__ @@ -55,64 +56,6 @@ void emuStop(); namespace Platform { -QSharedMemory* IPCBuffer = nullptr; -int IPCInstanceID; - -void IPCInit() -{ - IPCInstanceID = 0; - - IPCBuffer = new QSharedMemory("melonIPC"); - - if (!IPCBuffer->attach()) - { - Log(LogLevel::Info, "IPC sharedmem doesn't exist. creating\n"); - if (!IPCBuffer->create(1024)) - { - Log(LogLevel::Error, "IPC sharedmem create failed :(\n"); - delete IPCBuffer; - IPCBuffer = nullptr; - return; - } - - IPCBuffer->lock(); - memset(IPCBuffer->data(), 0, IPCBuffer->size()); - IPCBuffer->unlock(); - } - - IPCBuffer->lock(); - u8* data = (u8*)IPCBuffer->data(); - u16 mask = *(u16*)&data[0]; - for (int i = 0; i < 16; i++) - { - if (!(mask & (1<unlock(); - - Log(LogLevel::Info, "IPC: instance ID %d\n", IPCInstanceID); -} - -void IPCDeInit() -{ - if (IPCBuffer) - { - IPCBuffer->lock(); - u8* data = (u8*)IPCBuffer->data(); - *(u16*)&data[0] &= ~(1<unlock(); - - IPCBuffer->detach(); - delete IPCBuffer; - } - IPCBuffer = nullptr; -} - - void Init(int argc, char** argv) { #if defined(__WIN32__) || defined(PORTABLE) @@ -147,12 +90,12 @@ void Init(int argc, char** argv) EmuDirectory = confdir.toStdString(); #endif - IPCInit(); + IPC::Init(); } void DeInit() { - IPCDeInit(); + IPC::DeInit(); } void SignalStop(StopReason reason) @@ -178,12 +121,12 @@ void SignalStop(StopReason reason) int InstanceID() { - return IPCInstanceID; + return IPC::InstanceID; } std::string InstanceFileSuffix() { - int inst = IPCInstanceID; + int inst = IPC::InstanceID; if (inst == 0) return ""; char suffix[16] = {0};