From fadd2f3475aed347d2a06a08cc9c2e7fe53fbba9 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 22 Sep 2014 15:25:19 +0200 Subject: fix Wine bitrot rather than only saying so name mangling has issues so partial revert --- .../opentrack-wrapper-wine-main.cxx | 75 ++++++++++++++-------- 1 file changed, 50 insertions(+), 25 deletions(-) (limited to 'ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx') diff --git a/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx b/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx index fe5a95f9..40f36f8d 100644 --- a/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx +++ b/ftnoir_protocol_wine/opentrack-wrapper-wine-main.cxx @@ -10,33 +10,57 @@ #include "compat/compat.h" void create_registry_key(void); -ptr make_shm_posix(); -ptr make_shm_win32(); + +class ShmPosix { +public: + ShmPosix(const char *shmName, const char *mutexName, int mapSize); + ~ShmPosix(); + void lock(); + void unlock(); + bool success(); + inline void* ptr() { return mem; } +private: + void* mem; + int fd, size; +}; + +class ShmWine { +public: + ShmWine(const char *shmName, const char *mutexName, int mapSize); + ~ShmWine(); + void lock(); + void unlock(); + bool success(); + inline void* ptr() { return mem; } +private: + void* mem; + void *hMutex, *hMapFile; +}; +#include int main(void) { - ptr lck_posix = make_shm_posix(); - ptr lck_wine = make_shm_win32(); - if(!lck_posix->success()) { - printf("Can't open posix map: %d\n", errno); - return 1; - } - if(!lck_wine->success()) { - printf("Can't open Wine map\n"); - return 1; - } - WineSHM* shm_posix = (WineSHM*) lck_posix->ptr(); - FTHeap* shm_wine = (FTHeap*) lck_wine->ptr(); + ShmPosix lck_posix(WINE_SHM_NAME, WINE_MTX_NAME, sizeof(WineSHM)); + ShmWine lck_wine("FT_SharedMem", "FT_Mutext", sizeof(FTHeap)); + if(!lck_posix.success()) { + printf("Can't open posix map: %d\n", errno); + return 1; + } + if(!lck_wine.success()) { + printf("Can't open Wine map\n"); + return 1; + } + WineSHM* shm_posix = (WineSHM*) lck_posix.ptr(); + FTHeap* shm_wine = (FTHeap*) lck_wine.ptr(); FTData* data = &shm_wine->data; create_registry_key(); - while (1) { - (void) Sleep(4); - lck_posix->lock(); - if (shm_posix->stop) { - lck_posix->unlock(); - break; - } - lck_wine->lock(); + while (1) { + lck_posix.lock(); + if (shm_posix->stop) { + lck_posix.unlock(); + break; + } + lck_wine.lock(); data->Yaw = shm_posix->data[Yaw]; data->Pitch = shm_posix->data[Pitch]; data->Roll = shm_posix->data[Roll]; @@ -50,7 +74,8 @@ int main(void) shm_posix->gameid = shm_wine->GameID; for (int i = 0; i < 8; i++) shm_wine->table[i] = shm_posix->table[i]; - lck_wine->unlock(); - lck_posix->unlock(); - } + lck_wine.unlock(); + lck_posix.unlock(); + (void) Sleep(4); + } } -- cgit v1.2.3