From 136672723ac2730ca6ea051ffe1a4943b995b34b Mon Sep 17 00:00:00 2001 From: sletz Date: Fri, 13 Nov 2009 15:56:10 +0000 Subject: [PATCH] Simplify server temporary mode : now use a JackTemporaryException. git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@3784 0c269be4-1314-0410-8aa9-9f06e86f4224 --- ChangeLog | 1 + common/JackArgParser.cpp | 4 ++++ common/JackEngine.cpp | 2 +- common/JackException.h | 20 +++++++++++++++++++- common/JackLockedEngine.h | 6 ++++++ common/JackServerGlobals.cpp | 1 - common/JackServerGlobals.h | 1 - macosx/JackMachServerChannel.cpp | 4 ---- posix/JackSocketServerChannel.cpp | 7 +------ windows/JackWinNamedPipeServerChannel.cpp | 9 +-------- 10 files changed, 33 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 05e340c5..9deac71a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -30,6 +30,7 @@ Paul Davis * Better memory allocation error checking in ringbuffer.c, weak import improvements. * Memory allocation error checking for jack_client_new and jack_client_open (server and client side). * Memory allocation error checking in server for RPC. + * Simplify server temporary mode : now use a JackTemporaryException. 2009-11-12 Stephane Letz diff --git a/common/JackArgParser.cpp b/common/JackArgParser.cpp index fcccaa23..e9b8f6f9 100644 --- a/common/JackArgParser.cpp +++ b/common/JackArgParser.cpp @@ -128,6 +128,10 @@ namespace Jack { return -1; //else allocate and fill it argv = (char**)calloc (fArgv.size(), sizeof(char*)); + if (argv == NULL) + { + return -1; + } for ( unsigned int i = 0; i < fArgv.size(); i++ ) { argv[i] = (char*)calloc(fArgv[i].length(), sizeof(char)); diff --git a/common/JackEngine.cpp b/common/JackEngine.cpp index 3a0bb2ae..537c4160 100644 --- a/common/JackEngine.cpp +++ b/common/JackEngine.cpp @@ -119,7 +119,7 @@ void JackEngine::ReleaseRefnum(int ref) // last client and temporay case: quit the server jack_log("JackEngine::ReleaseRefnum server quit"); fEngineControl->fTemporary = false; - JackServerGlobals::fKilled = true; + throw JackTemporaryException(); } } } diff --git a/common/JackException.h b/common/JackException.h index af899b8a..3270f20a 100644 --- a/common/JackException.h +++ b/common/JackException.h @@ -58,7 +58,25 @@ class SERVER_EXPORT JackException : public std::runtime_error { }; /*! -\brief Exception possibly thrown by Net Slaves. + \brief Exception thrown by JackEngine in temporary mode. + */ + +class SERVER_EXPORT JackTemporaryException : public JackException { + + public: + + JackTemporaryException(const std::string& msg) : JackException(msg) + {} + JackTemporaryException(char* msg) : JackException(msg) + {} + JackTemporaryException(const char* msg) : JackException(msg) + {} + JackTemporaryException() : JackException("") + {} +}; + +/*! +\brief Exception possibly thrown by Net slaves. */ class SERVER_EXPORT JackNetException : public JackException { diff --git a/common/JackLockedEngine.h b/common/JackLockedEngine.h index 07ba57bc..941cca9a 100644 --- a/common/JackLockedEngine.h +++ b/common/JackLockedEngine.h @@ -22,6 +22,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "JackEngine.h" #include "JackMutex.h" +#include "JackTools.h" +#include "JackException.h" namespace Jack { @@ -33,6 +35,10 @@ namespace Jack } catch(std::bad_alloc& e) { \ jack_error("Memory allocation error..."); \ return -1; \ + } catch(JackTemporaryException& e) { \ + jack_error("JackTemporaryException : now quits..."); \ + kill(JackTools::GetPID(), SIGINT); \ + return -1; \ } catch (...) { \ jack_error("Unknown error..."); \ return -1; \ diff --git a/common/JackServerGlobals.cpp b/common/JackServerGlobals.cpp index 18dfaf66..7698c640 100644 --- a/common/JackServerGlobals.cpp +++ b/common/JackServerGlobals.cpp @@ -28,7 +28,6 @@ static char* server_name = NULL; namespace Jack { -bool JackServerGlobals::fKilled = false; JackServer* JackServerGlobals::fInstance; unsigned int JackServerGlobals::fUserCount; bool (* JackServerGlobals::on_device_acquire)(const char * device_name) = NULL; diff --git a/common/JackServerGlobals.h b/common/JackServerGlobals.h index e037f69b..00d8b0ff 100644 --- a/common/JackServerGlobals.h +++ b/common/JackServerGlobals.h @@ -36,7 +36,6 @@ class JackClient; struct SERVER_EXPORT JackServerGlobals { - static bool fKilled; static JackServer* fInstance; static unsigned int fUserCount; static bool (* on_device_acquire)(const char * device_name); diff --git a/macosx/JackMachServerChannel.cpp b/macosx/JackMachServerChannel.cpp index 5b646c56..19295f79 100644 --- a/macosx/JackMachServerChannel.cpp +++ b/macosx/JackMachServerChannel.cpp @@ -143,10 +143,6 @@ boolean_t JackMachServerChannel::MessageHandler(mach_msg_header_t* Request, mach channel->ClientKill(Request->msgh_local_port); } else { JackRPCEngine_server(Request, Reply); - // Issued by JackEngine::ReleaseRefnum when temporary mode is used - if (JackServerGlobals::fKilled) { - kill(JackTools::GetPID(), SIGINT); - } } return true; } diff --git a/posix/JackSocketServerChannel.cpp b/posix/JackSocketServerChannel.cpp index eb988aef..a5625219 100644 --- a/posix/JackSocketServerChannel.cpp +++ b/posix/JackSocketServerChannel.cpp @@ -396,12 +396,7 @@ bool JackSocketServerChannel::HandleRequest(int fd) jack_error("Unknown request %ld", header.fType); break; } - - // Issued by JackEngine::ReleaseRefnum when temporary mode is used - if (JackServerGlobals::fKilled) { - kill(JackTools::GetPID(), SIGINT); - } - + return true; } diff --git a/windows/JackWinNamedPipeServerChannel.cpp b/windows/JackWinNamedPipeServerChannel.cpp index 03d9effc..da0da443 100644 --- a/windows/JackWinNamedPipeServerChannel.cpp +++ b/windows/JackWinNamedPipeServerChannel.cpp @@ -317,14 +317,7 @@ bool JackClientPipeThread::HandleRequest() break; } } - - /* TODO - // Issued by JackEngine::ReleaseRefnum when temporary mode is used - if (JackServerGlobals::fKilled) { - kill(JackTools::GetPID(), SIGINT); - } - */ - + // Unlock the global mutex ReleaseMutex(fMutex); return ret;