From 2cb1617a3872f6073cd925fa1ba45089e1971450 Mon Sep 17 00:00:00 2001 From: falkTX Date: Wed, 12 Mar 2014 13:40:50 +0000 Subject: [PATCH] Cleanup --- source/backend/engine/CarlaEngineNative.cpp | 30 +++++--- source/modules/CarlaNative.hpp | 8 +-- source/modules/CarlaNativeExtUI.hpp | 37 ++++++---- source/utils/CarlaBridgeUtils.hpp | 2 +- source/utils/CarlaExternalUI.hpp | 5 +- source/utils/CarlaPipeUtils.hpp | 80 ++++++++++++--------- source/utils/JucePluginWindow.hpp | 2 +- source/utils/Lv2AtomQueue.hpp | 28 ++++---- 8 files changed, 115 insertions(+), 77 deletions(-) diff --git a/source/backend/engine/CarlaEngineNative.cpp b/source/backend/engine/CarlaEngineNative.cpp index 9cd751ce5..84eb658df 100644 --- a/source/backend/engine/CarlaEngineNative.cpp +++ b/source/backend/engine/CarlaEngineNative.cpp @@ -60,7 +60,7 @@ public: } protected: - bool msgReceived(const char* const msg) override + bool msgReceived(const char* const msg) noexcept override { if (CarlaExternalUI::msgReceived(msg)) return true; @@ -77,7 +77,9 @@ protected: CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(value), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(valueStr), true); - fEngine->setOption(static_cast(option), value, valueStr); + try { + fEngine->setOption(static_cast(option), value, valueStr); + } catch(...) {} delete[] valueStr; } @@ -87,7 +89,9 @@ protected: CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename), true); - ok = fEngine->loadFile(filename); + try { + ok = fEngine->loadFile(filename); + } catch(...) {} delete[] filename; } @@ -97,7 +101,9 @@ protected: CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename), true); - ok = fEngine->loadProject(filename); + try { + ok = fEngine->loadProject(filename); + } catch(...) {} delete[] filename; } @@ -107,7 +113,9 @@ protected: CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(filename), true); - ok = fEngine->saveProject(filename); + try { + ok = fEngine->saveProject(filename); + } catch(...) {} delete[] filename; } @@ -120,7 +128,9 @@ protected: CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(groupB), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsInt(portB), true); - ok = fEngine->patchbayConnect(groupA, portA, groupB, portB); + try { + ok = fEngine->patchbayConnect(groupA, portA, groupB, portB); + } catch(...) {} } else if (std::strcmp(msg, "patchbay_disconnect") == 0) { @@ -128,11 +138,15 @@ protected: CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(connectionId), true); - ok = fEngine->patchbayDisconnect(connectionId); + try { + ok = fEngine->patchbayDisconnect(connectionId); + } catch(...) {} } else if (std::strcmp(msg, "patchbay_refresh") == 0) { - ok = fEngine->patchbayRefresh(); + try { + ok = fEngine->patchbayRefresh(); + } catch(...) {} } else if (std::strcmp(msg, "transport_play") == 0) { diff --git a/source/modules/CarlaNative.hpp b/source/modules/CarlaNative.hpp index 725516a7f..125b437be 100644 --- a/source/modules/CarlaNative.hpp +++ b/source/modules/CarlaNative.hpp @@ -66,28 +66,28 @@ protected: return pHost->uiName; } - uint32_t getBufferSize() const noexcept + uint32_t getBufferSize() const { CARLA_SAFE_ASSERT_RETURN(pHost != nullptr, 0); return pHost->get_buffer_size(pHost->handle); } - double getSampleRate() const noexcept + double getSampleRate() const { CARLA_SAFE_ASSERT_RETURN(pHost != nullptr, 0.0); return pHost->get_sample_rate(pHost->handle); } - bool isOffline() const noexcept + bool isOffline() const { CARLA_SAFE_ASSERT_RETURN(pHost != nullptr, false); return pHost->is_offline(pHost->handle); } - const NativeTimeInfo* getTimeInfo() const noexcept + const NativeTimeInfo* getTimeInfo() const { CARLA_SAFE_ASSERT_RETURN(pHost != nullptr, nullptr); diff --git a/source/modules/CarlaNativeExtUI.hpp b/source/modules/CarlaNativeExtUI.hpp index a135d63d6..7cc04f249 100644 --- a/source/modules/CarlaNativeExtUI.hpp +++ b/source/modules/CarlaNativeExtUI.hpp @@ -19,7 +19,6 @@ #define CARLA_NATIVE_EXTERNAL_UI_HPP_INCLUDED #include "CarlaNative.hpp" - #include "CarlaExternalUI.hpp" /*! @@ -126,7 +125,7 @@ protected: // ------------------------------------------------------------------- // Pipe Server calls - bool msgReceived(const char* const msg) override + bool msgReceived(const char* const msg) noexcept override { if (CarlaExternalUI::msgReceived(msg)) return true; @@ -139,20 +138,30 @@ protected: CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(param), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsFloat(value), true); - uiParameterChanged(param, value); + try { + uiParameterChanged(param, value); + } catch(...) {} + + return true; } - else if (std::strcmp(msg, "program") == 0) + + if (std::strcmp(msg, "program") == 0) { uint32_t channel, bank, program; - CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(channel), true);; + CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(channel), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(bank), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsUInt(program), true); CARLA_SAFE_ASSERT_RETURN(channel < MAX_MIDI_CHANNELS, true); - uiMidiProgramChanged(channel, bank, program); + try { + uiMidiProgramChanged(channel, bank, program); + } catch(...) {} + + return true; } - else if (std::strcmp(msg, "configure") == 0) + + if (std::strcmp(msg, "configure") == 0) { const char* key; const char* value; @@ -160,18 +169,18 @@ protected: CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(key), true); CARLA_SAFE_ASSERT_RETURN(readNextLineAsString(value), true); - uiCustomDataChanged(key, value); + try { + uiCustomDataChanged(key, value); + } catch(...) {} delete[] key; delete[] value; - } - else - { - carla_stderr("msgReceived : %s", msg); - return false; + + return true; } - return true; + carla_stderr("msgReceived : %s", msg); + return false; } private: diff --git a/source/utils/CarlaBridgeUtils.hpp b/source/utils/CarlaBridgeUtils.hpp index 2d6cf75b5..c7f10c009 100644 --- a/source/utils/CarlaBridgeUtils.hpp +++ b/source/utils/CarlaBridgeUtils.hpp @@ -19,7 +19,7 @@ #define CARLA_BRIDGE_UTILS_HPP_INCLUDED //#include "CarlaBackend.h" -#include "CarlaEngine.hpp" +//#include "CarlaEngine.hpp" #include "CarlaRingBuffer.hpp" // ----------------------------------------------------------------------- diff --git a/source/utils/CarlaExternalUI.hpp b/source/utils/CarlaExternalUI.hpp index 6a69c5f2d..c62c3d79f 100644 --- a/source/utils/CarlaExternalUI.hpp +++ b/source/utils/CarlaExternalUI.hpp @@ -56,14 +56,15 @@ public: fUiTitle = uiTitle; } - void start() + void start() noexcept { CarlaPipeServer::start(fFilename, fSampleRate, fUiTitle); writeMsg("show\n", 5); } protected: - bool msgReceived(const char* const msg) override + // returns true if msg was handled + bool msgReceived(const char* const msg) noexcept override { if (std::strcmp(msg, "exiting") == 0) { diff --git a/source/utils/CarlaPipeUtils.hpp b/source/utils/CarlaPipeUtils.hpp index cc3f402fb..4a8415fa5 100644 --- a/source/utils/CarlaPipeUtils.hpp +++ b/source/utils/CarlaPipeUtils.hpp @@ -63,7 +63,7 @@ public: return (fPipeRecv != -1 && fPipeSend != -1 && fPid != -1); } - bool start(const char* const filename, const char* const arg1, const char* const arg2) + bool start(const char* const filename, const char* const arg1, const char* const arg2) noexcept { CARLA_SAFE_ASSERT_RETURN(filename != nullptr && filename[0] != '\0', false); CARLA_SAFE_ASSERT_RETURN(arg1 != nullptr, false); @@ -99,8 +99,10 @@ public: if (::pipe(pipe2) != 0) { - ::close(pipe1[0]); - ::close(pipe1[1]); + try { + ::close(pipe1[0]); + ::close(pipe1[1]); + } catch (...) {} fail("pipe2 creation failed"); return false; } @@ -124,10 +126,14 @@ public: if ((! fork_exec(argv, &ret)) || ret == -1) { - ::close(pipe1[0]); - ::close(pipe1[1]); - ::close(pipe2[0]); - ::close(pipe2[1]); + try { + ::close(pipe1[0]); + ::close(pipe1[1]); + } catch (...) {} + try { + ::close(pipe2[0]); + ::close(pipe2[1]); + } catch (...) {} fail("fork_exec() failed"); return false; } @@ -135,15 +141,19 @@ public: fPid = ret; // fork duplicated the handles, close pipe ends that are used by the child process - ::close(pipe1[0]); - ::close(pipe2[1]); + try { + ::close(pipe1[0]); + } catch(...) {} + try { + ::close(pipe2[1]); + } catch(...) {} fPipeSend = pipe1[1]; // [1] means writting end fPipeRecv = pipe2[0]; // [0] means reading end // set non-block try { - ret = fcntl(fPipeRecv, F_SETFL, fcntl(fPipeRecv, F_GETFL) | O_NONBLOCK); + ret = ::fcntl(fPipeRecv, F_SETFL, ::fcntl(fPipeRecv, F_GETFL) | O_NONBLOCK); } catch (...) { ret = -1; fail("failed to set pipe as non-block"); @@ -199,10 +209,10 @@ public: break; } - - carla_stderr("force killing misbehaved child %i (start)", int(fPid)); } + carla_stderr("force killing misbehaved child %i (start)", int(fPid)); + if (kill(fPid, SIGKILL) == -1) { carla_stderr("kill() failed: %s (start)\n", strerror(errno)); @@ -287,7 +297,7 @@ public: // ------------------------------------------------------------------- - bool readNextLineAsBool(bool& value) + bool readNextLineAsBool(bool& value) noexcept { CARLA_SAFE_ASSERT_RETURN(fIsReading, false); @@ -301,7 +311,7 @@ public: return false; } - bool readNextLineAsInt(int32_t& value) + bool readNextLineAsInt(int32_t& value) noexcept { CARLA_SAFE_ASSERT_RETURN(fIsReading, false); @@ -315,7 +325,7 @@ public: return false; } - bool readNextLineAsUInt(uint32_t& value) + bool readNextLineAsUInt(uint32_t& value) noexcept { CARLA_SAFE_ASSERT_RETURN(fIsReading, false); @@ -334,7 +344,7 @@ public: return false; } - bool readNextLineAsLong(int64_t& value) + bool readNextLineAsLong(int64_t& value) noexcept { CARLA_SAFE_ASSERT_RETURN(fIsReading, false); @@ -348,7 +358,7 @@ public: return false; } - bool readNextLineAsULong(uint64_t& value) + bool readNextLineAsULong(uint64_t& value) noexcept { CARLA_SAFE_ASSERT_RETURN(fIsReading, false); @@ -367,7 +377,7 @@ public: return false; } - bool readNextLineAsFloat(float& value) + bool readNextLineAsFloat(float& value) noexcept { CARLA_SAFE_ASSERT_RETURN(fIsReading, false); @@ -381,7 +391,7 @@ public: return false; } - bool readNextLineAsString(const char*& value) + bool readNextLineAsString(const char*& value) noexcept { CARLA_SAFE_ASSERT_RETURN(fIsReading, false); @@ -416,7 +426,7 @@ public: } catch (...) {} } - void writeAndFixMsg(const char* const msg) + void writeAndFixMsg(const char* const msg) noexcept { CARLA_SAFE_ASSERT_RETURN(fPipeSend != -1,); @@ -458,7 +468,7 @@ public: } catch (...) {} } - void waitChildClose() + void waitChildClose() noexcept { if (! wait_child(fPid)) { @@ -481,7 +491,7 @@ protected: } // returns true if msg handled - virtual bool msgReceived(const char* const msg) = 0; + virtual bool msgReceived(const char* const msg) noexcept = 0; // ------------------------------------------------------------------- @@ -496,7 +506,7 @@ private: // ------------------------------------------------------------------- - const char* readline() + const char* readline() noexcept { char ch; char* ptr = fTmpBuf; @@ -507,7 +517,7 @@ private: for (int i=0; i < 0xff; ++i) { try { - ret = read(fPipeRecv, &ch, 1); + ret = ::read(fPipeRecv, &ch, 1); } catch (...) { break; @@ -538,7 +548,12 @@ private: fTmpStr += fTmpBuf; } - return fTmpStr.dup(); + try { + return fTmpStr.dup(); + } + catch(...) { + return nullptr; + } } break; @@ -549,13 +564,13 @@ private: // ------------------------------------------------------------------- - static bool fork_exec(const char* const argv[5], int* const retp) + static bool fork_exec(const char* const argv[5], int* const retp) noexcept { const pid_t ret = *retp = vfork(); switch (ret) { - case 0: /* child process */ + case 0: // child process execlp(argv[0], argv[0], argv[1], argv[2], argv[3], argv[4], #ifdef CARLA_OS_MAC // fix warning NULL); @@ -563,18 +578,19 @@ private: nullptr); #endif carla_stderr2("exec failed: %s", std::strerror(errno)); - _exit(0); + _exit(0); // this is not noexcept safe but doesn't matter anyway return false; - case -1: /* error */ + + case -1: // error carla_stderr2("fork() failed: %s", std::strerror(errno)); - _exit(0); + _exit(0); // this is not noexcept safe but doesn't matter anyway return false; } return true; } - static bool wait_child(const pid_t pid) + static bool wait_child(const pid_t pid) noexcept { if (pid == -1) { @@ -589,7 +605,7 @@ private: try { ret = ::waitpid(pid, nullptr, WNOHANG); } - catch (...) { + catch(...) { break; } diff --git a/source/utils/JucePluginWindow.hpp b/source/utils/JucePluginWindow.hpp index b990d76d4..7678b14d4 100644 --- a/source/utils/JucePluginWindow.hpp +++ b/source/utils/JucePluginWindow.hpp @@ -65,7 +65,7 @@ public: clearContentComponent(); } - bool wasClosedByUser() const + bool wasClosedByUser() const noexcept { return fClosed; } diff --git a/source/utils/Lv2AtomQueue.hpp b/source/utils/Lv2AtomQueue.hpp index 707435e14..7b04eb90f 100644 --- a/source/utils/Lv2AtomQueue.hpp +++ b/source/utils/Lv2AtomQueue.hpp @@ -28,7 +28,7 @@ class Lv2AtomRingBufferControl : public RingBufferControl { public: - Lv2AtomRingBufferControl() + Lv2AtomRingBufferControl() noexcept : RingBufferControl(nullptr), fIsDummy(false) { @@ -36,7 +36,7 @@ public: fBuffer.buf = nullptr; } - ~Lv2AtomRingBufferControl() + ~Lv2AtomRingBufferControl() noexcept { if (fBuffer.buf != nullptr && ! fIsDummy) { @@ -47,7 +47,7 @@ public: // ------------------------------------------------------------------- - void createBuffer(const uint32_t size) + void createBuffer(const uint32_t size) noexcept { if (fBuffer.buf != nullptr) { @@ -65,7 +65,7 @@ public: } // used for tmp buffers only - void copyDump(HeapRingBuffer& rb, char dumpBuf[]) + void copyDump(HeapRingBuffer& rb, char dumpBuf[]) noexcept { CARLA_SAFE_ASSERT_RETURN(fBuffer.size == 0,); CARLA_SAFE_ASSERT_RETURN(fBuffer.buf == nullptr,); @@ -153,13 +153,11 @@ private: class Lv2AtomQueue { public: - Lv2AtomQueue() - { - } + Lv2AtomQueue() noexcept {} // ------------------------------------------------------------------- - void createBuffer(const uint32_t size) + void createBuffer(const uint32_t size) noexcept { fRingBufferCtrl.createBuffer(size); } @@ -177,7 +175,7 @@ public: } // must have been locked before - bool get(const LV2_Atom** const atom, uint32_t* const portIndex) + bool get(const LV2_Atom** const atom, uint32_t* const portIndex) noexcept { CARLA_SAFE_ASSERT_RETURN(atom != nullptr && portIndex != nullptr, false); @@ -194,7 +192,7 @@ public: } // must NOT been locked, we do that here - bool put(const LV2_Atom* const atom, const uint32_t portIndex) + bool put(const LV2_Atom* const atom, const uint32_t portIndex) noexcept { CARLA_SAFE_ASSERT_RETURN(atom != nullptr && atom->size > 0, false); @@ -204,7 +202,7 @@ public: } // must NOT been locked, we do that here - bool putChunk(const LV2_Atom* const atom, const void* const data, const uint32_t portIndex) + bool putChunk(const LV2_Atom* const atom, const void* const data, const uint32_t portIndex) noexcept { CARLA_SAFE_ASSERT_RETURN(atom != nullptr && atom->size > 0, false); CARLA_SAFE_ASSERT_RETURN(data != nullptr, false); @@ -233,14 +231,14 @@ public: // ------------------------------------------------------------------- - void copyDataFromQueue(Lv2AtomQueue& queue) + void copyDataFromQueue(Lv2AtomQueue& queue) noexcept { // lock source - const CarlaMutexLocker qsl(queue.fMutex); + const CarlaMutexLocker cml1(queue.fMutex); { // copy data from source - const CarlaMutexLocker cml(fMutex); + const CarlaMutexLocker cml2(fMutex); fRingBufferCtrl.fBuffer = queue.fRingBufferCtrl.fBuffer; } @@ -248,7 +246,7 @@ public: queue.fRingBufferCtrl.clear(); } - void copyAndDumpDataFromQueue(Lv2AtomQueue& queue, char dumpBuf[]) + void copyAndDumpDataFromQueue(Lv2AtomQueue& queue, char dumpBuf[]) noexcept { // lock source const CarlaMutexLocker cml1(queue.fMutex);