X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f0838d63f30556cb7c74257a4612b3d418153ce4..fb8d7eb7a880f1f2e32d8830f9c5e12b2536e05f:/src/os2/snglinst.cpp diff --git a/src/os2/snglinst.cpp b/src/os2/snglinst.cpp index eb95aa3c39..8d66f31a3b 100644 --- a/src/os2/snglinst.cpp +++ b/src/os2/snglinst.cpp @@ -1,132 +1,132 @@ -/////////////////////////////////////////////////////////////////////////////// -// Name: os2/snglinst.cpp -// Purpose: implements wxSingleInstanceChecker class for OS/2 using -// named mutexes -// Author: Vadim Zeitlin -// Modified by: Lauri Nurmi (modified for OS/2) -// Created: 08.02.2009 -// RCS-ID: $Id$ -// Copyright: (c) 2001 Vadim Zeitlin -// License: wxWindows licence -/////////////////////////////////////////////////////////////////////////////// - -// ============================================================================ -// declarations -// ============================================================================ - -// ---------------------------------------------------------------------------- -// headers -// ---------------------------------------------------------------------------- - -// For compilers that support precompilation, includes "wx.h". -#include "wx/wxprec.h" - -#ifdef __BORLANDC__ - #pragma hdrstop -#endif - -#if wxUSE_SNGLINST_CHECKER - -#ifndef WX_PRECOMP - #include "wx/string.h" - #include "wx/log.h" -#endif //WX_PRECOMP - -#include "wx/snglinst.h" - -#define INCL_DOSSEMAPHORES -#define INCL_DOSERRORS -#include - -#include "wx/os2/private.h" - -// ---------------------------------------------------------------------------- -// wxSingleInstanceCheckerImpl: the real implementation class -// ---------------------------------------------------------------------------- - -class WXDLLEXPORT wxSingleInstanceCheckerImpl -{ -public: - wxSingleInstanceCheckerImpl() - { - m_hMutex = NULL; - m_anotherRunning = false; - } - - bool Create(const wxString& name) - { - wxString semName; - semName.Printf(wxT("\\SEM32\\%s"), name.c_str()); - int rc = DosCreateMutexSem(semName.c_str(), &m_hMutex, DC_SEM_SHARED, 1); - - if ( rc == NO_ERROR ) { - m_anotherRunning = false; - return true; - } else if ( rc == ERROR_DUPLICATE_NAME ) { - m_anotherRunning = true; - return true; - } else { - m_anotherRunning = false; // we don't know for sure in this case - wxLogLastError(_T("DosCreateMutexSem")); - return false; - } - } - - bool IsAnotherRunning() const - { - return m_anotherRunning; - } - - ~wxSingleInstanceCheckerImpl() - { - if ( m_hMutex ) - { - if ( !::DosCloseMutexSem(m_hMutex) ) - { - wxLogLastError(_T("DosCloseMutexSem")); - } - } - } - -private: - // if true, creating the mutex either succeeded - // or we know it failed because another app is running. - bool m_anotherRunning; - - // the mutex handle, may be NULL - HMTX m_hMutex; - - DECLARE_NO_COPY_CLASS(wxSingleInstanceCheckerImpl) -}; - -// ============================================================================ -// wxSingleInstanceChecker implementation -// ============================================================================ - -bool wxSingleInstanceChecker::Create(const wxString& name, - const wxString& WXUNUSED(path)) -{ - wxASSERT_MSG( !m_impl, - _T("calling wxSingleInstanceChecker::Create() twice?") ); - - // creating unnamed mutex doesn't have the same semantics! - wxASSERT_MSG( !name.empty(), _T("mutex name can't be empty") ); - - m_impl = new wxSingleInstanceCheckerImpl; - - return m_impl->Create(name); -} - -bool wxSingleInstanceChecker::IsAnotherRunning() const -{ - wxCHECK_MSG( m_impl, false, _T("must call Create() first") ); - - return m_impl->IsAnotherRunning(); -} - -wxSingleInstanceChecker::~wxSingleInstanceChecker() -{ - delete m_impl; -} - -#endif // wxUSE_SNGLINST_CHECKER +/////////////////////////////////////////////////////////////////////////////// +// Name: src/os2/snglinst.cpp +// Purpose: implements wxSingleInstanceChecker class for OS/2 using +// named mutexes +// Author: Vadim Zeitlin +// Modified by: Lauri Nurmi (modified for OS/2) +// Created: 08.02.2009 +// RCS-ID: $Id$ +// Copyright: (c) 2001 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#if wxUSE_SNGLINST_CHECKER + +#ifndef WX_PRECOMP + #include "wx/string.h" + #include "wx/log.h" +#endif //WX_PRECOMP + +#include "wx/snglinst.h" + +#define INCL_DOSSEMAPHORES +#define INCL_DOSERRORS +#include + +#include "wx/os2/private.h" + +// ---------------------------------------------------------------------------- +// wxSingleInstanceCheckerImpl: the real implementation class +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxSingleInstanceCheckerImpl +{ +public: + wxSingleInstanceCheckerImpl() + { + m_hMutex = NULL; + m_anotherRunning = false; + } + + bool Create(const wxString& name) + { + wxString semName; + semName.Printf(wxT("\\SEM32\\%s"), name.c_str()); + int rc = DosCreateMutexSem(semName.c_str(), &m_hMutex, DC_SEM_SHARED, 1); + + if ( rc == NO_ERROR ) { + m_anotherRunning = false; + return true; + } else if ( rc == ERROR_DUPLICATE_NAME ) { + m_anotherRunning = true; + return true; + } else { + m_anotherRunning = false; // we don't know for sure in this case + wxLogLastError(wxT("DosCreateMutexSem")); + return false; + } + } + + bool IsAnotherRunning() const + { + return m_anotherRunning; + } + + ~wxSingleInstanceCheckerImpl() + { + if ( m_hMutex ) + { + if ( !::DosCloseMutexSem(m_hMutex) ) + { + wxLogLastError(wxT("DosCloseMutexSem")); + } + } + } + +private: + // if true, creating the mutex either succeeded + // or we know it failed because another app is running. + bool m_anotherRunning; + + // the mutex handle, may be NULL + HMTX m_hMutex; + + DECLARE_NO_COPY_CLASS(wxSingleInstanceCheckerImpl) +}; + +// ============================================================================ +// wxSingleInstanceChecker implementation +// ============================================================================ + +bool wxSingleInstanceChecker::Create(const wxString& name, + const wxString& WXUNUSED(path)) +{ + wxASSERT_MSG( !m_impl, + wxT("calling wxSingleInstanceChecker::Create() twice?") ); + + // creating unnamed mutex doesn't have the same semantics! + wxASSERT_MSG( !name.empty(), wxT("mutex name can't be empty") ); + + m_impl = new wxSingleInstanceCheckerImpl; + + return m_impl->Create(name); +} + +bool wxSingleInstanceChecker::DoIsAnotherRunning() const +{ + wxCHECK_MSG( m_impl, false, wxT("must call Create() first") ); + + return m_impl->IsAnotherRunning(); +} + +wxSingleInstanceChecker::~wxSingleInstanceChecker() +{ + delete m_impl; +} + +#endif // wxUSE_SNGLINST_CHECKER