mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-25 15:19:53 -06:00
lay base for IPC work
This commit is contained in:
@ -25,6 +25,7 @@ set(SOURCES_QT_SDL
|
|||||||
RAMInfoDialog.cpp
|
RAMInfoDialog.cpp
|
||||||
TitleManagerDialog.cpp
|
TitleManagerDialog.cpp
|
||||||
Input.cpp
|
Input.cpp
|
||||||
|
IPC.cpp
|
||||||
LAN_PCap.cpp
|
LAN_PCap.cpp
|
||||||
LAN_Socket.cpp
|
LAN_Socket.cpp
|
||||||
LocalMP.cpp
|
LocalMP.cpp
|
||||||
|
88
src/frontend/qt_sdl/IPC.cpp
Normal file
88
src/frontend/qt_sdl/IPC.cpp
Normal file
@ -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 <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <QSharedMemory>
|
||||||
|
|
||||||
|
#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<<i)))
|
||||||
|
{
|
||||||
|
InstanceID = i;
|
||||||
|
*(u16*)&data[0] |= (1<<i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Buffer->unlock();
|
||||||
|
|
||||||
|
printf("IPC: instance ID %d\n", InstanceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeInit()
|
||||||
|
{
|
||||||
|
if (Buffer)
|
||||||
|
{
|
||||||
|
Buffer->lock();
|
||||||
|
u8* data = (u8*)Buffer->data();
|
||||||
|
*(u16*)&data[0] &= ~(1<<InstanceID);
|
||||||
|
Buffer->unlock();
|
||||||
|
|
||||||
|
Buffer->detach();
|
||||||
|
delete Buffer;
|
||||||
|
}
|
||||||
|
Buffer = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
34
src/frontend/qt_sdl/IPC.h
Normal file
34
src/frontend/qt_sdl/IPC.h
Normal file
@ -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
|
@ -38,6 +38,7 @@
|
|||||||
#include "LAN_Socket.h"
|
#include "LAN_Socket.h"
|
||||||
#include "LAN_PCap.h"
|
#include "LAN_PCap.h"
|
||||||
#include "LocalMP.h"
|
#include "LocalMP.h"
|
||||||
|
#include "IPC.h"
|
||||||
#include "OSD.h"
|
#include "OSD.h"
|
||||||
|
|
||||||
#ifdef __WIN32__
|
#ifdef __WIN32__
|
||||||
@ -55,64 +56,6 @@ void emuStop();
|
|||||||
namespace Platform
|
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<<i)))
|
|
||||||
{
|
|
||||||
IPCInstanceID = i;
|
|
||||||
*(u16*)&data[0] |= (1<<i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IPCBuffer->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<<IPCInstanceID);
|
|
||||||
IPCBuffer->unlock();
|
|
||||||
|
|
||||||
IPCBuffer->detach();
|
|
||||||
delete IPCBuffer;
|
|
||||||
}
|
|
||||||
IPCBuffer = nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Init(int argc, char** argv)
|
void Init(int argc, char** argv)
|
||||||
{
|
{
|
||||||
#if defined(__WIN32__) || defined(PORTABLE)
|
#if defined(__WIN32__) || defined(PORTABLE)
|
||||||
@ -147,12 +90,12 @@ void Init(int argc, char** argv)
|
|||||||
EmuDirectory = confdir.toStdString();
|
EmuDirectory = confdir.toStdString();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
IPCInit();
|
IPC::Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeInit()
|
void DeInit()
|
||||||
{
|
{
|
||||||
IPCDeInit();
|
IPC::DeInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SignalStop(StopReason reason)
|
void SignalStop(StopReason reason)
|
||||||
@ -178,12 +121,12 @@ void SignalStop(StopReason reason)
|
|||||||
|
|
||||||
int InstanceID()
|
int InstanceID()
|
||||||
{
|
{
|
||||||
return IPCInstanceID;
|
return IPC::InstanceID;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string InstanceFileSuffix()
|
std::string InstanceFileSuffix()
|
||||||
{
|
{
|
||||||
int inst = IPCInstanceID;
|
int inst = IPC::InstanceID;
|
||||||
if (inst == 0) return "";
|
if (inst == 0) return "";
|
||||||
|
|
||||||
char suffix[16] = {0};
|
char suffix[16] = {0};
|
||||||
|
Reference in New Issue
Block a user