From d5d61fed236a1ca57299743a955c073879814f43 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Thu, 20 Jan 2011 22:54:10 +0100 Subject: [PATCH] Refactor some global structs. --- src/Config.h | 8 +-- src/Dialog_About.cpp | 10 ++- src/Global.cpp | 120 +++++++++++++++++++++------------- src/Thread_Initialization.cpp | 9 ++- 4 files changed, 85 insertions(+), 62 deletions(-) diff --git a/src/Config.h b/src/Config.h index dd500a9a..3193d7d5 100644 --- a/src/Config.h +++ b/src/Config.h @@ -25,7 +25,7 @@ #define VER_LAMEXP_MAJOR 4 #define VER_LAMEXP_MINOR_HI 0 #define VER_LAMEXP_MINOR_LO 0 -#define VER_LAMEXP_BUILD 240 +#define VER_LAMEXP_BUILD 241 #define VER_LAMEXP_SUFFIX Beta-1 /* @@ -40,9 +40,9 @@ #define VER_LAMEXP_STR_HLP2(V,W,X,Y,Z) VER_LAMEXP_STR_HLP1(v##V.W##X Z [Build Y]) #define VER_LAMEXP_STR_HLP3(V,W,X,Y,Z) VER_LAMEXP_STR_HLP2(V,W,X,Y,Z) #define VER_LAMEXP_STR VER_LAMEXP_STR_HLP3(VER_LAMEXP_MAJOR,VER_LAMEXP_MINOR_HI,VER_LAMEXP_MINOR_LO,VER_LAMEXP_BUILD,VER_LAMEXP_SUFFIX) -#define VER_LAMEXP_SUFFIX_STR_HLP1(X) #X -#define VER_LAMEXP_SUFFIX_STR_HLP2(X) VER_LAMEXP_SUFFIX_STR_HLP1(X) -#define VER_LAMEXP_SUFFIX_STR VER_LAMEXP_SUFFIX_STR_HLP2(VER_LAMEXP_SUFFIX) +#define VER_LAMEXP_RNAME_HLP1(X) #X +#define VER_LAMEXP_RNAME_HLP2(X) VER_LAMEXP_RNAME_HLP1(X) +#define VER_LAMEXP_RNAME VER_LAMEXP_RNAME_HLP2(VER_LAMEXP_SUFFIX) #define VER_LAMEXP_MINOR_HLP1(X,Y) X##Y #define VER_LAMEXP_MINOR_HLP2(X,Y) VER_LAMEXP_MINOR_HLP1(X,Y) #define VER_LAMEXP_MINOR VER_LAMEXP_MINOR_HLP2(VER_LAMEXP_MINOR_HI,VER_LAMEXP_MINOR_LO) diff --git a/src/Dialog_About.cpp b/src/Dialog_About.cpp index e9ac5cab..412d0de8 100644 --- a/src/Dialog_About.cpp +++ b/src/Dialog_About.cpp @@ -45,17 +45,15 @@ //Constants const char *AboutDialog::neroAacUrl = "http://www.nero.com/eng/technologies-aac-codec.html"; -//Typedef -struct lamexp_contrib_t +//Contributors +static const struct { char *pcFlag; char *pcLanguage; char *pcName; char *pcMail; -}; - -//Contributors -static const struct lamexp_contrib_t g_lamexp_contributors[] = +} +g_lamexp_contributors[] = { {"en", "Englisch", "LoRd_MuldeR", "MuldeR2@GMX.de" }, {"de", "Deutsch", "LoRd_MuldeR", "MuldeR2@GMX.de" }, diff --git a/src/Global.cpp b/src/Global.cpp index 9733f45f..6bc2654c 100644 --- a/src/Global.cpp +++ b/src/Global.cpp @@ -85,10 +85,20 @@ typedef struct /////////////////////////////////////////////////////////////////////////////// //Build version -static const unsigned int g_lamexp_version_major = VER_LAMEXP_MAJOR; -static const unsigned int g_lamexp_version_minor = VER_LAMEXP_MINOR; -static const unsigned int g_lamexp_version_build = VER_LAMEXP_BUILD; -static const char *g_lamexp_version_release = VER_LAMEXP_SUFFIX_STR; +static const struct +{ + unsigned int ver_major; + unsigned int ver_minor; + unsigned int ver_build; + char *ver_release_name; +} +g_lamexp_version = +{ + VER_LAMEXP_MAJOR, + VER_LAMEXP_MINOR, + VER_LAMEXP_BUILD, + VER_LAMEXP_RNAME +}; //Build date static QDate g_lamexp_version_date; @@ -127,12 +137,28 @@ static QMap g_lamexp_translation_sysid; static QTranslator *g_lamexp_currentTranslator = NULL; //Shared memory -static const char *g_lamexp_sharedmem_uuid = "{21A68A42-6923-43bb-9CF6-64BF151942EE}"; -static QSharedMemory *g_lamexp_sharedmem_ptr = NULL; -static const char *g_lamexp_semaphore_read_uuid = "{7A605549-F58C-4d78-B4E5-06EFC34F405B}"; -static QSystemSemaphore *g_lamexp_semaphore_read_ptr = NULL; -static const char *g_lamexp_semaphore_write_uuid = "{60AA8D04-F6B8-497d-81EB-0F600F4A65B5}"; -static QSystemSemaphore *g_lamexp_semaphore_write_ptr = NULL; +static const struct +{ + char *sharedmem; + char *semaphore_read; + char *semaphore_write; +} +g_lamexp_ipc_uuid = +{ + "{21A68A42-6923-43bb-9CF6-64BF151942EE}", + "{7A605549-F58C-4d78-B4E5-06EFC34F405B}", + "{60AA8D04-F6B8-497d-81EB-0F600F4A65B5}" +}; +static struct +{ + QSharedMemory *sharedmem; + QSystemSemaphore *semaphore_read; + QSystemSemaphore *semaphore_write; +} +g_lamexp_ipc_ptr = +{ + NULL, NULL, NULL +}; //Image formats static const char *g_lamexp_imageformats[] = {"png", "gif", "ico", "svg", NULL}; @@ -147,17 +173,17 @@ static QMutex g_lamexp_message_mutex; /* * Version getters */ -unsigned int lamexp_version_major(void) { return g_lamexp_version_major; } -unsigned int lamexp_version_minor(void) { return g_lamexp_version_minor; } -unsigned int lamexp_version_build(void) { return g_lamexp_version_build; } -const char *lamexp_version_release(void) { return g_lamexp_version_release; } +unsigned int lamexp_version_major(void) { return g_lamexp_version.ver_major; } +unsigned int lamexp_version_minor(void) { return g_lamexp_version.ver_minor; } +unsigned int lamexp_version_build(void) { return g_lamexp_version.ver_build; } +const char *lamexp_version_release(void) { return g_lamexp_version.ver_release_name; } const char *lamexp_version_compiler(void) {return g_lamexp_version_compiler; } unsigned int lamexp_toolver_neroaac(void) { return g_lamexp_toolver_neroaac; } bool lamexp_version_demo(void) { - return LAMEXP_DEBUG || !(strstr(g_lamexp_version_release, "Final") || strstr(g_lamexp_version_release, "Hotfix")); + return LAMEXP_DEBUG || !(strstr(g_lamexp_version.ver_release_name, "Final") || strstr(g_lamexp_version.ver_release_name, "Hotfix")); } QDate lamexp_version_expires(void) @@ -564,59 +590,59 @@ bool lamexp_init_qt(int argc, char* argv[]) */ int lamexp_init_ipc(void) { - if(g_lamexp_sharedmem_ptr && g_lamexp_semaphore_read_ptr && g_lamexp_semaphore_write_ptr) + if(g_lamexp_ipc_ptr.sharedmem && g_lamexp_ipc_ptr.semaphore_read && g_lamexp_ipc_ptr.semaphore_write) { return 0; } - g_lamexp_semaphore_read_ptr = new QSystemSemaphore(QString(g_lamexp_semaphore_read_uuid), 0); - g_lamexp_semaphore_write_ptr = new QSystemSemaphore(QString(g_lamexp_semaphore_write_uuid), 0); + g_lamexp_ipc_ptr.semaphore_read = new QSystemSemaphore(QString(g_lamexp_ipc_uuid.semaphore_read), 0); + g_lamexp_ipc_ptr.semaphore_write = new QSystemSemaphore(QString(g_lamexp_ipc_uuid.semaphore_write), 0); - if(g_lamexp_semaphore_read_ptr->error() != QSystemSemaphore::NoError) + if(g_lamexp_ipc_ptr.semaphore_read->error() != QSystemSemaphore::NoError) { - QString errorMessage = g_lamexp_semaphore_read_ptr->errorString(); - LAMEXP_DELETE(g_lamexp_semaphore_read_ptr); - LAMEXP_DELETE(g_lamexp_semaphore_write_ptr); + QString errorMessage = g_lamexp_ipc_ptr.semaphore_read->errorString(); + LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_read); + LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_write); qFatal("Failed to create system smaphore: %s", errorMessage.toUtf8().constData()); return -1; } - if(g_lamexp_semaphore_write_ptr->error() != QSystemSemaphore::NoError) + if(g_lamexp_ipc_ptr.semaphore_write->error() != QSystemSemaphore::NoError) { - QString errorMessage = g_lamexp_semaphore_write_ptr->errorString(); - LAMEXP_DELETE(g_lamexp_semaphore_read_ptr); - LAMEXP_DELETE(g_lamexp_semaphore_write_ptr); + QString errorMessage = g_lamexp_ipc_ptr.semaphore_write->errorString(); + LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_read); + LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_write); qFatal("Failed to create system smaphore: %s", errorMessage.toUtf8().constData()); return -1; } - g_lamexp_sharedmem_ptr = new QSharedMemory(QString(g_lamexp_sharedmem_uuid), NULL); + g_lamexp_ipc_ptr.sharedmem = new QSharedMemory(QString(g_lamexp_ipc_uuid.sharedmem), NULL); - if(!g_lamexp_sharedmem_ptr->create(sizeof(lamexp_ipc_t))) + if(!g_lamexp_ipc_ptr.sharedmem->create(sizeof(lamexp_ipc_t))) { - if(g_lamexp_sharedmem_ptr->error() == QSharedMemory::AlreadyExists) + if(g_lamexp_ipc_ptr.sharedmem->error() == QSharedMemory::AlreadyExists) { - g_lamexp_sharedmem_ptr->attach(); - if(g_lamexp_sharedmem_ptr->error() == QSharedMemory::NoError) + g_lamexp_ipc_ptr.sharedmem->attach(); + if(g_lamexp_ipc_ptr.sharedmem->error() == QSharedMemory::NoError) { return 1; } else { - QString errorMessage = g_lamexp_sharedmem_ptr->errorString(); + QString errorMessage = g_lamexp_ipc_ptr.sharedmem->errorString(); qFatal("Failed to attach to shared memory: %s", errorMessage.toUtf8().constData()); return -1; } } else { - QString errorMessage = g_lamexp_sharedmem_ptr->errorString(); + QString errorMessage = g_lamexp_ipc_ptr.sharedmem->errorString(); qFatal("Failed to create shared memory: %s", errorMessage.toUtf8().constData()); return -1; } } - memset(g_lamexp_sharedmem_ptr->data(), 0, sizeof(lamexp_ipc_t)); - g_lamexp_semaphore_write_ptr->release(); + memset(g_lamexp_ipc_ptr.sharedmem->data(), 0, sizeof(lamexp_ipc_t)); + g_lamexp_ipc_ptr.semaphore_write->release(); return 0; } @@ -626,7 +652,7 @@ int lamexp_init_ipc(void) */ void lamexp_ipc_send(unsigned int command, const char* message) { - if(!g_lamexp_sharedmem_ptr || !g_lamexp_semaphore_read_ptr || !g_lamexp_semaphore_write_ptr) + if(!g_lamexp_ipc_ptr.sharedmem || !g_lamexp_ipc_ptr.semaphore_read || !g_lamexp_ipc_ptr.semaphore_write) { throw "Shared memory for IPC not initialized yet."; } @@ -639,10 +665,10 @@ void lamexp_ipc_send(unsigned int command, const char* message) strcpy_s(lamexp_ipc->parameter, 4096, message); } - if(g_lamexp_semaphore_write_ptr->acquire()) + if(g_lamexp_ipc_ptr.semaphore_write->acquire()) { - memcpy(g_lamexp_sharedmem_ptr->data(), lamexp_ipc, sizeof(lamexp_ipc_t)); - g_lamexp_semaphore_read_ptr->release(); + memcpy(g_lamexp_ipc_ptr.sharedmem->data(), lamexp_ipc, sizeof(lamexp_ipc_t)); + g_lamexp_ipc_ptr.semaphore_read->release(); } LAMEXP_DELETE(lamexp_ipc); @@ -656,7 +682,7 @@ void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize) *command = 0; message[0] = '\0'; - if(!g_lamexp_sharedmem_ptr || !g_lamexp_semaphore_read_ptr || !g_lamexp_semaphore_write_ptr) + if(!g_lamexp_ipc_ptr.sharedmem || !g_lamexp_ipc_ptr.semaphore_read || !g_lamexp_ipc_ptr.semaphore_write) { throw "Shared memory for IPC not initialized yet."; } @@ -664,10 +690,10 @@ void lamexp_ipc_read(unsigned int *command, char* message, size_t buffSize) lamexp_ipc_t *lamexp_ipc = new lamexp_ipc_t; memset(lamexp_ipc, 0, sizeof(lamexp_ipc_t)); - if(g_lamexp_semaphore_read_ptr->acquire()) + if(g_lamexp_ipc_ptr.semaphore_read->acquire()) { - memcpy(lamexp_ipc, g_lamexp_sharedmem_ptr->data(), sizeof(lamexp_ipc_t)); - g_lamexp_semaphore_write_ptr->release(); + memcpy(lamexp_ipc, g_lamexp_ipc_ptr.sharedmem->data(), sizeof(lamexp_ipc_t)); + g_lamexp_ipc_ptr.semaphore_write->release(); if(!(lamexp_ipc->reserved_1 || lamexp_ipc->reserved_2)) { @@ -1181,10 +1207,10 @@ void lamexp_finalization(void) LAMEXP_DELETE(application); //Detach from shared memory - if(g_lamexp_sharedmem_ptr) g_lamexp_sharedmem_ptr->detach(); - LAMEXP_DELETE(g_lamexp_sharedmem_ptr); - LAMEXP_DELETE(g_lamexp_semaphore_read_ptr); - LAMEXP_DELETE(g_lamexp_semaphore_write_ptr); + if(g_lamexp_ipc_ptr.sharedmem) g_lamexp_ipc_ptr.sharedmem->detach(); + LAMEXP_DELETE(g_lamexp_ipc_ptr.sharedmem); + LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_read); + LAMEXP_DELETE(g_lamexp_ipc_ptr.semaphore_write); } /* diff --git a/src/Thread_Initialization.cpp b/src/Thread_Initialization.cpp index 1c861a0a..100cff68 100644 --- a/src/Thread_Initialization.cpp +++ b/src/Thread_Initialization.cpp @@ -38,16 +38,15 @@ // TOOLS //////////////////////////////////////////////////////////// -struct lamexp_tool_t +static const struct { char *pcHash; char *pcName; unsigned int uiVersion; -}; - -static const struct lamexp_tool_t g_lamexp_tools[] = +} +g_lamexp_tools[] = { - {"153f4274702f3629093b561a31dbf50e2c146305", "alac.exe", UINT_MAX}, + {"3b41f85dde8d4a5a0f4cd5f461099d0db24610ba", "alac.exe", UINT_MAX}, {"fb74ac8b73ad8cba2c3b4e6e61f23401d630dc22", "elevator.exe", UINT_MAX}, {"3c647950bccfcc75d0746c0772e7115684be4dc5", "faad.exe", UINT_MAX}, {"d33cd86f04bd4067e244d2804466583c7b90a4e2", "flac.exe", 121},