diff options
author | FernetMenta <fernetmenta@online.de> | 2012-05-02 12:44:32 +0200 |
---|---|---|
committer | Jim Carroll <thecarrolls@jiminger.com> | 2012-05-12 11:08:52 -0400 |
commit | cf3383acaee5381627dca140480ec53cee1084b2 (patch) | |
tree | 9ad8d88a310a918a9b4c9b64f8119aae0e469874 | |
parent | 22980d8e8df2fb727d05f3e22c825a6747b7e387 (diff) |
Adds back signal handling and windows translated exception handling in a less platform specific manner while preserving the library dependency hierarchy.
26 files changed, 360 insertions, 403 deletions
diff --git a/Makefile.in b/Makefile.in index 4500b2c7a5..f12cc57be3 100755 --- a/Makefile.in +++ b/Makefile.in @@ -29,7 +29,6 @@ DIRECTORY_ARCHIVES=$(DVDPLAYER_ARCHIVES) \ lib/xbmc-dll-symbols/dll-symbols.a \ xbmc/addons/addons.a \ xbmc/cdrip/cdrip.a \ - xbmc/commons/commons.a \ xbmc/cores/AudioEngine/audioengine.a \ xbmc/cores/DllLoader/dllloader.a \ xbmc/cores/DllLoader/exports/exports.a \ @@ -74,7 +73,6 @@ DIRECTORY_ARCHIVES=$(DVDPLAYER_ARCHIVES) \ xbmc/rendering/rendering.a \ xbmc/settings/settings.a \ xbmc/storage/storage.a \ - xbmc/threads/threads.a \ xbmc/utils/utils.a \ xbmc/video/dialogs/videodialogs.a \ xbmc/video/video.a \ @@ -84,6 +82,10 @@ DIRECTORY_ARCHIVES=$(DVDPLAYER_ARCHIVES) \ xbmc/xbmc.a \ +NWAOBJSXBMC= xbmc/commons/commons.a \ + xbmc/threads/threads.a \ + + ifeq (@USE_WEB_SERVER@,1) DIRECTORY_ARCHIVES += xbmc/network/httprequesthandler/httprequesthandlers.a endif @@ -338,9 +340,9 @@ LIBS += @PYTHON_LDFLAGS@ xbmc.bin: $(OBJSXBMC) $(DYNOBJSXBMC) $(NWAOBJSXBMC) ifeq ($(findstring osx,@ARCH@), osx) - $(SILENT_LD) $(CXX) $(LDFLAGS) -o xbmc.bin -Wl,-all_load,-ObjC $(DYNOBJSXBMC) $(OBJSXBMC) $(LIBS) -rdynamic + $(SILENT_LD) $(CXX) $(LDFLAGS) -o xbmc.bin -Wl,-all_load,-ObjC $(DYNOBJSXBMC) $(NWAOBJSXBMC) $(OBJSXBMC) $(LIBS) -rdynamic else - $(SILENT_LD) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o xbmc.bin -Wl,--whole-archive $(DYNOBJSXBMC) $(OBJSXBMC) -Wl,--no-whole-archive $(LIBS) -rdynamic + $(SILENT_LD) $(CXX) $(CXXFLAGS) $(LDFLAGS) -o xbmc.bin -Wl,--whole-archive $(DYNOBJSXBMC) $(OBJSXBMC) -Wl,--no-whole-archive $(NWAOBJSXBMC) $(LIBS) -rdynamic endif xbmc-xrandr: xbmc-xrandr.c diff --git a/project/VS2010Express/XBMC.vcxproj b/project/VS2010Express/XBMC.vcxproj index 64d865b0cf..58ff836bcf 100644 --- a/project/VS2010Express/XBMC.vcxproj +++ b/project/VS2010Express/XBMC.vcxproj @@ -1115,7 +1115,6 @@ <ClCompile Include="..\..\xbmc\utils\URIUtils.cpp" /> <ClCompile Include="..\..\xbmc\utils\Variant.cpp" /> <ClCompile Include="..\..\xbmc\utils\Weather.cpp" /> - <ClCompile Include="..\..\xbmc\utils\Win32Exception.cpp" /> <ClCompile Include="..\..\xbmc\utils\XBMCTinyXML.cpp" /> <ClCompile Include="..\..\xbmc\utils\XMLUtils.cpp" /> <ClCompile Include="..\..\xbmc\video\Bookmark.cpp" /> @@ -1911,7 +1910,6 @@ <ClInclude Include="..\..\xbmc\utils\URIUtils.h" /> <ClInclude Include="..\..\xbmc\utils\Variant.h" /> <ClInclude Include="..\..\xbmc\utils\Weather.h" /> - <ClInclude Include="..\..\xbmc\utils\Win32Exception.h" /> <ClInclude Include="..\..\xbmc\utils\XBMCTinyXML.h" /> <ClInclude Include="..\..\xbmc\utils\XMLUtils.h" /> <ClInclude Include="..\..\xbmc\video\Bookmark.h" /> @@ -2278,4 +2276,4 @@ </VisualStudio> </ProjectExtensions> <Import Project="$(SolutionDir)\$(ProjectFileName).targets.user" Condition="Exists('$(SolutionDir)\$(ProjectFileName).targets.user')" /> -</Project> +</Project>
\ No newline at end of file diff --git a/project/VS2010Express/XBMC.vcxproj.filters b/project/VS2010Express/XBMC.vcxproj.filters index 3de0c6a731..338eb5e5eb 100644 --- a/project/VS2010Express/XBMC.vcxproj.filters +++ b/project/VS2010Express/XBMC.vcxproj.filters @@ -1672,9 +1672,6 @@ <ClCompile Include="..\..\xbmc\utils\Weather.cpp"> <Filter>utils</Filter> </ClCompile> - <ClCompile Include="..\..\xbmc\utils\Win32Exception.cpp"> - <Filter>utils</Filter> - </ClCompile> <ClCompile Include="..\..\xbmc\utils\XMLUtils.cpp"> <Filter>utils</Filter> </ClCompile> @@ -4262,9 +4259,6 @@ <ClInclude Include="..\..\xbmc\utils\Weather.h"> <Filter>utils</Filter> </ClInclude> - <ClInclude Include="..\..\xbmc\utils\Win32Exception.h"> - <Filter>utils</Filter> - </ClInclude> <ClInclude Include="..\..\xbmc\utils\XMLUtils.h"> <Filter>utils</Filter> </ClInclude> @@ -5204,4 +5198,4 @@ <Filter>win32</Filter> </CustomBuild> </ItemGroup> -</Project> +</Project>
\ No newline at end of file diff --git a/project/VS2010Express/XbmcCommons.vcxproj b/project/VS2010Express/XbmcCommons.vcxproj index 4e06597654..988468cc73 100644 --- a/project/VS2010Express/XbmcCommons.vcxproj +++ b/project/VS2010Express/XbmcCommons.vcxproj @@ -11,9 +11,11 @@ </ProjectConfiguration> </ItemGroup> <ItemGroup> + <ClCompile Include="..\..\xbmc\commons\Exception.cpp" /> <ClCompile Include="..\..\xbmc\commons\ilog.cpp" /> </ItemGroup> <ItemGroup> + <ClInclude Include="..\..\xbmc\commons\Exception.h" /> <ClInclude Include="..\..\xbmc\commons\ilog.h" /> </ItemGroup> <PropertyGroup Label="Globals"> diff --git a/project/VS2010Express/XbmcCommons.vcxproj.filters b/project/VS2010Express/XbmcCommons.vcxproj.filters index 7d6142ac1f..7a3faa57a4 100644 --- a/project/VS2010Express/XbmcCommons.vcxproj.filters +++ b/project/VS2010Express/XbmcCommons.vcxproj.filters @@ -2,8 +2,10 @@ <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <ClCompile Include="..\..\xbmc\commons\ilog.cpp" /> + <ClCompile Include="..\..\xbmc\commons\Exception.cpp" /> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\xbmc\commons\ilog.h" /> + <ClInclude Include="..\..\xbmc\commons\Exception.h" /> </ItemGroup> </Project>
\ No newline at end of file diff --git a/project/VS2010Express/XbmcThreads.vcxproj b/project/VS2010Express/XbmcThreads.vcxproj index b89159310a..0ed3b8079c 100644 --- a/project/VS2010Express/XbmcThreads.vcxproj +++ b/project/VS2010Express/XbmcThreads.vcxproj @@ -19,6 +19,7 @@ <ClInclude Include="..\..\xbmc\threads\platform\ThreadImpl.cpp" /> <ClCompile Include="..\..\xbmc\threads\platform\Implementation.cpp" /> <ClInclude Include="..\..\xbmc\threads\platform\win\Implementation.cpp" /> + <ClCompile Include="..\..\xbmc\threads\platform\win\Win32Exception.cpp" /> <ClCompile Include="..\..\xbmc\threads\SystemClock.cpp" /> <ClCompile Include="..\..\xbmc\threads\Thread.cpp" /> </ItemGroup> @@ -37,6 +38,7 @@ <ClInclude Include="..\..\xbmc\threads\platform\win\CriticalSection.h" /> <ClInclude Include="..\..\xbmc\threads\platform\win\ThreadImpl.h" /> <ClInclude Include="..\..\xbmc\threads\platform\win\ThreadLocal.h" /> + <ClInclude Include="..\..\xbmc\threads\platform\win\Win32Exception.h" /> <ClInclude Include="..\..\xbmc\threads\SharedSection.h" /> <ClInclude Include="..\..\xbmc\threads\SingleLock.h" /> <ClInclude Include="..\..\xbmc\threads\SystemClock.h" /> diff --git a/project/VS2010Express/XbmcThreads.vcxproj.filters b/project/VS2010Express/XbmcThreads.vcxproj.filters index 14353ed658..84cde3b920 100644 --- a/project/VS2010Express/XbmcThreads.vcxproj.filters +++ b/project/VS2010Express/XbmcThreads.vcxproj.filters @@ -9,6 +9,9 @@ <ClCompile Include="..\..\xbmc\threads\platform\Implementation.cpp"> <Filter>platform</Filter> </ClCompile> + <ClCompile Include="..\..\xbmc\threads\platform\win\Win32Exception.cpp"> + <Filter>platform\win</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\..\xbmc\threads\Atomics.h" /> @@ -57,6 +60,9 @@ <ClInclude Include="..\..\xbmc\threads\platform\win\Implementation.cpp"> <Filter>platform\win</Filter> </ClInclude> + <ClInclude Include="..\..\xbmc\threads\platform\win\Win32Exception.h"> + <Filter>platform\win</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <Filter Include="platform"> diff --git a/xbmc/Application.cpp b/xbmc/Application.cpp index b7e43d99e9..04745e14f1 100644 --- a/xbmc/Application.cpp +++ b/xbmc/Application.cpp @@ -143,7 +143,7 @@ #include "network/Zeroconf.h" #include "network/ZeroconfBrowser.h" #ifndef _LINUX -#include "utils/Win32Exception.h" +#include "threads/platform/win/Win32Exception.h" #endif #ifdef HAS_EVENT_SERVER #include "network/EventServer.h" diff --git a/xbmc/XbmcContext.cpp b/xbmc/XbmcContext.cpp index 72b14ae500..109474f257 100644 --- a/xbmc/XbmcContext.cpp +++ b/xbmc/XbmcContext.cpp @@ -22,6 +22,7 @@ #include "XbmcContext.h" #include "threads/Thread.h" +#include "commons/Exception.h" #include "utils/log.h" namespace XBMC @@ -43,6 +44,7 @@ namespace XBMC impl->loggerImpl = new XbmcUtils::LogImplementation; // set + XbmcCommons::Exception::SetLogger(impl->loggerImpl); CThread::SetLogger(impl->loggerImpl); } diff --git a/xbmc/commons/Exception.cpp b/xbmc/commons/Exception.cpp new file mode 100644 index 0000000000..867d1dc5a8 --- /dev/null +++ b/xbmc/commons/Exception.cpp @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2005-2012 Team XBMC + * http://www.xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#include "Exception.h" + +namespace XbmcCommons +{ + ILogger* Exception::logger = NULL; + + Exception::~Exception() {} +} + diff --git a/xbmc/commons/Exception.h b/xbmc/commons/Exception.h new file mode 100644 index 0000000000..810c1b041b --- /dev/null +++ b/xbmc/commons/Exception.h @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2005-2012 Team XBMC + * http://www.xbmc.org + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with XBMC; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#pragma once + +//--------------------------------------------------------- +// This include should be moved to commons but even as it is, +// it wont cause a linker circular dependency since it's just +// a header. +#include "utils/StdString.h" +//--------------------------------------------------------- +#include "ilog.h" + +#define XBMCCOMMONS_COPYVARARGS(fmt) va_list argList; va_start(argList, fmt); Set(fmt, argList); va_end(argList) +#define XBMCCOMMONS_STANDARD_EXCEPTION(E) \ + class E : public XbmcCommons::Exception \ + { \ + public: \ + inline E(const char* message,...) : Exception(#E) { XBMCCOMMONS_COPYVARARGS(message); } \ + \ + inline E(const E& other) : Exception(other) {} \ + } + +namespace XbmcCommons +{ + /** + * This class a superclass for exceptions that want to utilize some + * utility functionality including autologging with the specific + * exception name. + */ + class Exception + { + private: + + std::string classname; + CStdString message; + + protected: + static ILogger* logger; + + inline Exception(const char* classname_) : classname(classname_) { } + inline Exception(const char* classname_, const char* message_) : classname(classname_), message(message_) { } + inline Exception(const Exception& other) : classname(other.classname), message(other.message) { } + + /** + * This method is called from the constructor of subclasses. It + * will set the message from varargs as well as call log message + */ + inline void Set(const char* fmt, va_list& argList) + { + message.FormatV(fmt, argList); + } + + /** + * This message can be called from the constructor of subclasses. + * It will set the message and log the throwing. + */ + inline void SetMessage(const char* fmt, ...) + { + // calls 'set' + XBMCCOMMONS_COPYVARARGS(fmt); + } + + public: + virtual ~Exception(); + + inline virtual void LogThrowMessage(const char* prefix = NULL) const + { + if (logger) + logger->Log(LOGERROR,"EXCEPTION Thrown (%s) : %s", classname.c_str(), message.c_str()); + } + + inline virtual const char* GetMessage() const { return message.c_str(); } + + inline static void SetLogger(ILogger* exceptionLogger) { logger = exceptionLogger; } + }; + + /** + * This class forms the base class for unchecked exceptions. Unchecked exceptions + * are those that really shouldn't be handled explicitly. For example, on windows + * when a access violaton is converted to a win32_exception, there's nothing + * that can be done in most code. The outer most stack frame might try to + * do some error logging prior to shutting down, but that's really it. + */ + XBMCCOMMONS_STANDARD_EXCEPTION(UncheckedException); + +/** + * In cases where you catch(...){} you will (may) inadvertently be + * catching UncheckedException's. Therefore this macro will allow + * you to do something equivalent to: + * catch (anything except UncheckedException) {} + * + * In order to avoid catching UncheckedException, use the macro as follows: + * + * try { ... } + * XBMCCOMMONS_HANDLE_UNCHECKED + * catch(...){ ... } + */ +// Yes. I recognize that the name of this macro is an oxymoron. +#define XBMCCOMMONS_HANDLE_UNCHECKED \ + catch (const XbmcCommons::UncheckedException& ) { throw; } \ + catch (const XbmcCommons::UncheckedException* ) { throw; } + +} + diff --git a/xbmc/commons/Makefile b/xbmc/commons/Makefile index 97fdc2f404..b6403f4616 100644 --- a/xbmc/commons/Makefile +++ b/xbmc/commons/Makefile @@ -1,7 +1,7 @@ SRCS= \ + Exception.cpp \ ilog.cpp - LIB=commons.a include ../../Makefile.include diff --git a/xbmc/cores/DllLoader/DllLoader.cpp b/xbmc/cores/DllLoader/DllLoader.cpp index b7b23e1fac..1500d4925f 100644 --- a/xbmc/cores/DllLoader/DllLoader.cpp +++ b/xbmc/cores/DllLoader/DllLoader.cpp @@ -38,7 +38,7 @@ typedef struct _UNICODE_STRING { USHORT MaximumLength; PWSTR Buffer; } UNICODE_STRING, *PUNICODE_STRING; -#include "utils/Win32Exception.h" +#include "commons/Exception.h" #define DLL_PROCESS_DETACH 0 #define DLL_PROCESS_ATTACH 1 @@ -683,11 +683,7 @@ bool DllLoader::Load() #endif } - catch(win32_exception &e) - { - e.writelog(__FUNCTION__); - return false; - } + XBMCCOMMONS_HANDLE_UNCHECKED catch(...) { CLog::Log(LOGERROR, "%s - Unhandled exception during DLL_PROCESS_ATTACH", __FUNCTION__); diff --git a/xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecFFmpeg.cpp b/xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecFFmpeg.cpp index 238c855dcf..2d87cd22e9 100644 --- a/xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecFFmpeg.cpp +++ b/xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecFFmpeg.cpp @@ -25,7 +25,6 @@ #include "DVDOverlayImage.h" #include "DVDStreamInfo.h" #include "DVDClock.h" -#include "utils/Win32Exception.h" #include "utils/log.h" #include "utils/EndianSwap.h" @@ -160,15 +159,7 @@ int CDVDOverlayCodecFFmpeg::Decode(BYTE* data, int size, double pts, double dura avpkt.data = data; avpkt.size = size; - try - { - len = m_dllAvCodec.avcodec_decode_subtitle2(m_pCodecContext, &m_Subtitle, &gotsub, &avpkt); - } - catch (win32_exception e) - { - e.writelog("avcodec_decode_subtitle"); - return OC_ERROR; - } + len = m_dllAvCodec.avcodec_decode_subtitle2(m_pCodecContext, &m_Subtitle, &gotsub, &avpkt); if (len < 0) { @@ -197,13 +188,7 @@ void CDVDOverlayCodecFFmpeg::Flush() FreeSubtitle(m_Subtitle); m_SubtitleIndex = -1; - try { - m_dllAvCodec.avcodec_flush_buffers(m_pCodecContext); - - } catch (win32_exception e) { - e.writelog(__FUNCTION__); - } } CDVDOverlay* CDVDOverlayCodecFFmpeg::GetOverlay() diff --git a/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp b/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp index f70ecefeba..e9b9c8ce03 100644 --- a/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp +++ b/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp @@ -29,7 +29,6 @@ #include "DVDClock.h" #include "DVDCodecs/DVDCodecs.h" #include "DVDCodecs/DVDCodecUtils.h" -#include "../../../../utils/Win32Exception.h" #if defined(_LINUX) || defined(_WIN32) #include "utils/CPUInfo.h" #endif diff --git a/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp b/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp index d1b51af5fa..73dd8463c0 100644 --- a/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp +++ b/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp @@ -37,7 +37,7 @@ #endif #include "DVDDemuxUtils.h" #include "DVDClock.h" // for DVD_TIME_BASE -#include "utils/Win32Exception.h" +#include "commons/Exception.h" #include "settings/AdvancedSettings.h" #include "settings/GUISettings.h" #include "filesystem/File.h" @@ -643,16 +643,7 @@ DemuxPacket* CDVDDemuxFFmpeg::Read() // timeout reads after 100ms m_timeout.Set(20000); - int result = 0; - try - { - result = m_dllAvFormat.av_read_frame(m_pFormatContext, &pkt); - } - catch(const win32_exception &e) - { - e.writelog(__FUNCTION__); - result = AVERROR(EFAULT); - } + int result = m_dllAvFormat.av_read_frame(m_pFormatContext, &pkt); m_timeout.SetInfinite(); if (result == AVERROR(EINTR) || result == AVERROR(EAGAIN)) diff --git a/xbmc/filesystem/Directory.cpp b/xbmc/filesystem/Directory.cpp index ecf5b50622..4f780927a2 100644 --- a/xbmc/filesystem/Directory.cpp +++ b/xbmc/filesystem/Directory.cpp @@ -22,9 +22,7 @@ #include "Directory.h" #include "DirectoryFactory.h" #include "FileDirectoryFactory.h" -#ifndef _LINUX -#include "utils/Win32Exception.h" -#endif +#include "commons/Exception.h" #include "FileItem.h" #include "DirectoryCache.h" #include "settings/GUISettings.h" @@ -218,12 +216,7 @@ bool CDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items, c return true; } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch (...) { CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__); @@ -242,12 +235,7 @@ bool CDirectory::Create(const CStdString& strPath) if(pDirectory->Create(realPath.c_str())) return true; } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch (...) { CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__); @@ -265,12 +253,7 @@ bool CDirectory::Exists(const CStdString& strPath) if (pDirectory.get()) return pDirectory->Exists(realPath.c_str()); } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch (...) { CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__); @@ -289,12 +272,7 @@ bool CDirectory::Remove(const CStdString& strPath) if(pDirectory->Remove(realPath.c_str())) return true; } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch (...) { CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__); diff --git a/xbmc/filesystem/File.cpp b/xbmc/filesystem/File.cpp index 29a809381a..78c96ea04f 100644 --- a/xbmc/filesystem/File.cpp +++ b/xbmc/filesystem/File.cpp @@ -29,10 +29,7 @@ #include "utils/BitstreamStats.h" #include "Util.h" -#ifndef _LINUX -#include "utils/Win32Exception.h" -#endif -#include "URL.h" +#include "commons/Exception.h" using namespace XFILE; using namespace std; @@ -299,12 +296,7 @@ bool CFile::Open(const CStdString& strFileName, unsigned int flags) return true; } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch(...) { CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__); @@ -328,12 +320,7 @@ bool CFile::OpenForWrite(const CStdString& strFileName, bool bOverWrite) } return false; } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch(...) { CLog::Log(LOGERROR, "%s - Unhandled exception opening %s", __FUNCTION__, strFileName.c_str()); @@ -367,12 +354,7 @@ bool CFile::Exists(const CStdString& strFileName, bool bUseCache /* = true */) return pFile->Exists(url); } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch (CRedirectException *pRedirectEx) { // the file implementation decided this item should use a different implementation. @@ -426,12 +408,7 @@ int CFile::Stat(const CStdString& strFileName, struct __stat64* buffer) return -1; return pFile->Stat(url, buffer); } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch (CRedirectException *pRedirectEx) { // the file implementation decided this item should use a different implementation. @@ -517,12 +494,7 @@ unsigned int CFile::Read(void *lpBuf, int64_t uiBufSize) return done; } } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch(...) { CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__); @@ -538,12 +510,7 @@ void CFile::Close() SAFE_DELETE(m_pBuffer); SAFE_DELETE(m_pFile); } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch(...) { CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__); @@ -558,12 +525,7 @@ void CFile::Flush() if (m_pFile) m_pFile->Flush(); } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch(...) { CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__); @@ -591,12 +553,7 @@ int64_t CFile::Seek(int64_t iFilePosition, int iWhence) { return m_pFile->Seek(iFilePosition, iWhence); } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch(...) { CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__); @@ -613,12 +570,7 @@ int64_t CFile::GetLength() return m_pFile->GetLength(); return 0; } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch(...) { CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__); @@ -639,12 +591,7 @@ int64_t CFile::GetPosition() { return m_pFile->GetPosition(); } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch(...) { CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__); @@ -706,12 +653,7 @@ bool CFile::ReadString(char *szLine, int iLineLength) { return m_pFile->ReadString(szLine, iLineLength); } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch(...) { CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__); @@ -725,12 +667,7 @@ int CFile::Write(const void* lpBuf, int64_t uiBufSize) { return m_pFile->Write(lpBuf, uiBufSize); } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch(...) { CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__); @@ -754,16 +691,7 @@ bool CFile::Delete(const CStdString& strFileName) return true; } } -#ifndef _LINUX - catch (const access_violation &e) - { - e.writelog(__FUNCTION__); - } - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch(...) { CLog::Log(LOGERROR, "%s - Unhandled exception", __FUNCTION__); @@ -791,12 +719,7 @@ bool CFile::Rename(const CStdString& strFileName, const CStdString& strNewFileNa return true; } } -#ifndef _LINUX - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + XBMCCOMMONS_HANDLE_UNCHECKED catch(...) { CLog::Log(LOGERROR, "%s - Unhandled exception ", __FUNCTION__); @@ -893,19 +816,7 @@ CFileStreamBuffer::int_type CFileStreamBuffer::underflow() memmove(m_buffer, egptr()-backsize, backsize); } - unsigned int size = 0; -#ifndef _LINUX - try - { -#endif - size = m_file->Read(m_buffer+backsize, m_frontsize); -#ifndef _LINUX - } - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - } -#endif + unsigned int size = m_file->Read(m_buffer+backsize, m_frontsize); if(size == 0) return traits_type::eof(); @@ -948,24 +859,12 @@ CFileStreamBuffer::pos_type CFileStreamBuffer::seekoff( setp(0,0); int64_t position = -1; -#ifndef _LINUX - try - { -#endif - if(way == ios_base::cur) - position = m_file->Seek(offset, SEEK_CUR); - else if(way == ios_base::end) - position = m_file->Seek(offset, SEEK_END); - else - position = m_file->Seek(offset, SEEK_SET); -#ifndef _LINUX - } - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__); - return streampos(-1); - } -#endif + if(way == ios_base::cur) + position = m_file->Seek(offset, SEEK_CUR); + else if(way == ios_base::end) + position = m_file->Seek(offset, SEEK_END); + else + position = m_file->Seek(offset, SEEK_SET); if(position<0) return streampos(-1); diff --git a/xbmc/filesystem/SmbFile.cpp b/xbmc/filesystem/SmbFile.cpp index 242d482447..22d6f01fd4 100644 --- a/xbmc/filesystem/SmbFile.cpp +++ b/xbmc/filesystem/SmbFile.cpp @@ -34,6 +34,7 @@ #include "threads/SingleLock.h" #include "utils/log.h" #include "utils/TimeUtils.h" +#include "commons/Exception.h" using namespace XFILE; @@ -80,18 +81,11 @@ void CSMB::Deinit() smbc_set_context(NULL); smbc_free_context(m_context, 1); } -#ifdef TARGET_WINDOWS - catch(win32_exception e) - { - e.writelog(__FUNCTION__); - } - m_IdleTimeout = 180; -#else + XBMCCOMMONS_HANDLE_UNCHECKED catch(...) { CLog::Log(LOGERROR,"exception on CSMB::Deinit. errno: %d", errno); } -#endif m_context = NULL; } } diff --git a/xbmc/threads/Thread.cpp b/xbmc/threads/Thread.cpp index b4e1260d13..0fe8daef16 100644 --- a/xbmc/threads/Thread.cpp +++ b/xbmc/threads/Thread.cpp @@ -20,9 +20,9 @@ #include "threads/SystemClock.h" #include "Thread.h" -#include "utils/log.h" #include "threads/ThreadLocal.h" #include "threads/SingleLock.h" +#include "commons/Exception.h" #define __STDC_FORMAT_MACROS #include <inttypes.h> @@ -37,6 +37,8 @@ XbmcCommons::ILogger* CThread::logger = NULL; // Construction/Destruction ////////////////////////////////////////////////////////////////////// +#define LOG if(logger) logger->Log + CThread::CThread(const char* ThreadName) : m_StopEvent(true,true), m_TermEvent(true), m_StartEvent(true) { @@ -76,6 +78,25 @@ CThread::~CThread() StopThread(); } +void CThread::Create(bool bAutoDelete, unsigned stacksize) +{ + if (m_ThreadId != 0) + { + LOG(LOGERROR, "%s - fatal error creating thread- old thread id not null", __FUNCTION__); + exit(1); + } + m_iLastTime = XbmcThreads::SystemClockMillis() * 10000; + m_iLastUsage = 0; + m_fLastUsage = 0.0f; + m_bAutoDelete = bAutoDelete; + m_bStop = false; + m_StopEvent.Reset(); + m_TermEvent.Reset(); + m_StartEvent.Reset(); + + SpawnThread(stacksize); +} + bool CThread::IsRunning() { return m_ThreadId ? true : false; @@ -89,7 +110,7 @@ THREADFUNC CThread::staticThread(void* data) bool autodelete; if (!pThread) { - if(logger) logger->Log(LOGERROR,"%s, sanity failed. thread is NULL.",__FUNCTION__); + LOG(LOGERROR,"%s, sanity failed. thread is NULL.",__FUNCTION__); return 1; } @@ -99,7 +120,7 @@ THREADFUNC CThread::staticThread(void* data) pThread->SetThreadInfo(); - if(logger) logger->Log(LOGNOTICE,"Thread %s start, auto delete: %s", name.c_str(), (autodelete ? "true" : "false")); + LOG(LOGNOTICE,"Thread %s start, auto delete: %s", name.c_str(), (autodelete ? "true" : "false")); currentThread.set(pThread); pThread->m_StartEvent.Set(); @@ -117,12 +138,12 @@ THREADFUNC CThread::staticThread(void* data) if (autodelete) { - if(logger) logger->Log(LOGDEBUG,"Thread %s %"PRIu64" terminating (autodelete)", name.c_str(), (uint64_t)id); + LOG(LOGDEBUG,"Thread %s %"PRIu64" terminating (autodelete)", name.c_str(), (uint64_t)id); delete pThread; pThread = NULL; } else - if(logger) logger->Log(LOGDEBUG,"Thread %s %"PRIu64" terminating", name.c_str(), (uint64_t)id); + LOG(LOGDEBUG,"Thread %s %"PRIu64" terminating", name.c_str(), (uint64_t)id); return 0; } @@ -173,4 +194,50 @@ void CThread::Sleep(unsigned int milliseconds) XbmcThreads::ThreadSleep(milliseconds); } +void CThread::Action() +{ + + try + { + OnStartup(); + } + catch (const XbmcCommons::UncheckedException &e) + { + e.LogThrowMessage("OnStartup"); + if (IsAutoDelete()) + return; + } + catch (...) + { + LOG(LOGERROR, "%s - thread %s, Unhandled exception caught in thread startup, aborting. auto delete: %d", __FUNCTION__, m_ThreadName.c_str(), IsAutoDelete()); + if (IsAutoDelete()) + return; + } + + try + { + Process(); + } + catch (const XbmcCommons::UncheckedException &e) + { + e.LogThrowMessage("Process"); + } + catch (...) + { + LOG(LOGERROR, "%s - thread %s, Unhandled exception caught in thread process, aborting. auto delete: %d", __FUNCTION__, m_ThreadName.c_str(), IsAutoDelete()); + } + + try + { + OnExit(); + } + catch (const XbmcCommons::UncheckedException &e) + { + e.LogThrowMessage("OnExit"); + } + catch (...) + { + LOG(LOGERROR, "%s - thread %s, Unhandled exception caught in thread process, aborting. auto delete: %d", __FUNCTION__, m_ThreadName.c_str(), IsAutoDelete()); + } +} diff --git a/xbmc/threads/Thread.h b/xbmc/threads/Thread.h index 2f8d5f374a..c44e880a7c 100644 --- a/xbmc/threads/Thread.h +++ b/xbmc/threads/Thread.h @@ -59,30 +59,37 @@ public: CThread(IRunnable* pRunnable, const char* ThreadName); virtual ~CThread(); void Create(bool bAutoDelete = false, unsigned stacksize = 0); - bool WaitForThreadExit(unsigned int milliseconds); void Sleep(unsigned int milliseconds); - bool SetPriority(const int iPriority); - int GetPriority(void); - int GetMinPriority(void); - int GetMaxPriority(void); - int GetNormalPriority(void); int GetSchedRRPriority(void); bool SetPrioritySched_RR(int iPriority); bool IsAutoDelete() const; virtual void StopThread(bool bWait = true); + bool IsRunning(); + + // ----------------------------------------------------------------------------------- + // These are platform specific and can be found in ./platform/[platform]/ThreadImpl.cpp + // ----------------------------------------------------------------------------------- + bool IsCurrentThread() const; + int GetMinPriority(void); + int GetMaxPriority(void); + int GetNormalPriority(void); + int GetPriority(void); + bool SetPriority(const int iPriority); + bool WaitForThreadExit(unsigned int milliseconds); float GetRelativeUsage(); // returns the relative cpu usage of this thread since last call int64_t GetAbsoluteUsage(); - bool IsCurrentThread() const; - bool IsRunning(); + // ----------------------------------------------------------------------------------- static bool IsCurrentThread(const ThreadIdentifier tid); static ThreadIdentifier GetCurrentThreadId(); static CThread* GetCurrentThread(); static inline void SetLogger(XbmcCommons::ILogger* logger_) { CThread::logger = logger_; } + static inline XbmcCommons::ILogger* GetLogger() { return CThread::logger; } + + virtual void OnException(){} // signal termination handler protected: virtual void OnStartup(){}; virtual void OnExit(){}; - virtual void OnException(){} // signal termination handler virtual void Process(); volatile bool m_bStop; @@ -91,31 +98,30 @@ protected: /** * This call will wait on a CEvent in an interruptible way such that if - * stop is called on the thread the wait will return with a respone + * stop is called on the thread the wait will return with a response * indicating what happened. */ - inline WaitResponse AbortableWait(CEvent& event, int timeoutMillis) - { - XbmcThreads::CEventGroup group(&event, &m_StopEvent, NULL); - CEvent* result = group.wait(timeoutMillis); - return result == &event ? WAIT_SIGNALED : - (result == NULL ? WAIT_TIMEDOUT : WAIT_INTERRUPTED); - } - - inline WaitResponse AbortableWait(CEvent& event) + inline WaitResponse AbortableWait(CEvent& event, int timeoutMillis = -1 /* indicates wait forever*/) { XbmcThreads::CEventGroup group(&event, &m_StopEvent, NULL); - CEvent* result = group.wait(); + CEvent* result = timeoutMillis < 0 ? group.wait() : group.wait(timeoutMillis); return result == &event ? WAIT_SIGNALED : (result == NULL ? WAIT_TIMEDOUT : WAIT_INTERRUPTED); } private: static THREADFUNC staticThread(void *data); + void Action(); + + // ----------------------------------------------------------------------------------- + // These are platform specific and can be found in ./platform/[platform]/ThreadImpl.cpp + // ----------------------------------------------------------------------------------- ThreadIdentifier ThreadId() const; void SetThreadInfo(); void TermHandler(); - void Action(); + void SetSignalHandlers(); + void SpawnThread(unsigned stacksize); + // ----------------------------------------------------------------------------------- ThreadIdentifier m_ThreadId; ThreadOpaque m_ThreadOpaque; diff --git a/xbmc/threads/platform/pthreads/ThreadImpl.cpp b/xbmc/threads/platform/pthreads/ThreadImpl.cpp index 7f79db6e07..6260da7f83 100644 --- a/xbmc/threads/platform/pthreads/ThreadImpl.cpp +++ b/xbmc/threads/platform/pthreads/ThreadImpl.cpp @@ -32,22 +32,10 @@ #endif #endif -void CThread::Create(bool bAutoDelete, unsigned stacksize) -{ - if (m_ThreadId != 0) - { - if (logger) logger->Log(LOGERROR, "%s - fatal error creating thread- old thread id not null", __FUNCTION__); - exit(1); - } - m_iLastTime = XbmcThreads::SystemClockMillis() * 10000; - m_iLastUsage = 0; - m_fLastUsage = 0.0f; - m_bAutoDelete = bAutoDelete; - m_bStop = false; - m_StopEvent.Reset(); - m_TermEvent.Reset(); - m_StartEvent.Reset(); +#include <signal.h> +void CThread::SpawnThread(unsigned stacksize) +{ pthread_attr_t attr; pthread_attr_init(&attr); if (stacksize > PTHREAD_STACK_MIN) @@ -60,10 +48,7 @@ void CThread::Create(bool bAutoDelete, unsigned stacksize) pthread_attr_destroy(&attr); } -void CThread::TermHandler() -{ - -} +void CThread::TermHandler() { } void CThread::SetThreadInfo() { @@ -243,36 +228,29 @@ float CThread::GetRelativeUsage() return m_fLastUsage; } -void CThread::Action() +void term_handler (int signum) { - try - { - OnStartup(); - } - catch (...) + XbmcCommons::ILogger* logger = CThread::GetLogger(); + if (logger) + logger->Log(LOGERROR,"thread 0x%lx (%lu) got signal %d. calling OnException and terminating thread abnormally.", (long unsigned int)pthread_self(), (long unsigned int)pthread_self(), signum); + CThread* curThread = CThread::GetCurrentThread(); + if (curThread) { - CLog::Log(LOGERROR, "%s - thread %s, Unhandled exception caught in thread startup, aborting. auto delete: %d", __FUNCTION__, m_ThreadName.c_str(), IsAutoDelete()); - if (IsAutoDelete()) - return; - } - - try - { - Process(); - } - catch (...) - { - CLog::Log(LOGERROR, "%s - thread %s, Unhandled exception caught in thread process, aborting. auto delete: %d", __FUNCTION__, m_ThreadName.c_str(), IsAutoDelete()); - } - - try - { - OnExit(); - } - catch (...) - { - CLog::Log(LOGERROR, "%s - thread %s, Unhandled exception caught in thread exit, aborting. auto delete: %d", __FUNCTION__, m_ThreadName.c_str(), IsAutoDelete()); + curThread->StopThread(false); + curThread->OnException(); + if( curThread->IsAutoDelete() ) + delete curThread; } + pthread_exit(NULL); } +void CThread::SetSignalHandlers() +{ + struct sigaction action; + action.sa_handler = term_handler; + sigemptyset (&action.sa_mask); + action.sa_flags = 0; + //sigaction (SIGABRT, &action, NULL); + //sigaction (SIGSEGV, &action, NULL); +} diff --git a/xbmc/threads/platform/win/ThreadImpl.cpp b/xbmc/threads/platform/win/ThreadImpl.cpp index a2a7da520f..05252f0aaa 100644 --- a/xbmc/threads/platform/win/ThreadImpl.cpp +++ b/xbmc/threads/platform/win/ThreadImpl.cpp @@ -20,26 +20,10 @@ */ #include <windows.h> -#include "utils/Win32Exception.h" +#include "threads/platform/win/Win32Exception.h" - -void CThread::Create(bool bAutoDelete, unsigned stacksize) +void CThread::SpawnThread(unsigned stacksize) { - if (m_ThreadId != 0) - { - if (logger) logger->Log(LOGERROR, "%s - fatal error creating thread- old thread id not null", __FUNCTION__); - exit(1); - } - - m_iLastTime = XbmcThreads::SystemClockMillis() * 10000; - m_iLastUsage = 0; - m_fLastUsage = 0.0f; - m_bAutoDelete = bAutoDelete; - m_bStop = false; - m_StopEvent.Reset(); - m_TermEvent.Reset(); - m_StartEvent.Reset(); - // Create in the suspended state, so that no matter the thread priorities and scheduled order, the handle will be assigned // before the new thread exits. m_ThreadOpaque.handle = CreateThread(NULL, stacksize, (LPTHREAD_START_ROUTINE)&staticThread, this, CREATE_SUSPENDED, &m_ThreadId); @@ -203,51 +187,8 @@ float CThread::GetRelativeUsage() return m_fLastUsage; } -void CThread::Action() +void CThread::SetSignalHandlers() { // install win32 exception translator win32_exception::install_handler(); - - try - { - OnStartup(); - } - catch (const access_violation &e) - { - e.writelog(__FUNCTION__" thread startup"); - if (IsAutoDelete()) - return; - } - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__" thread startup"); - if (IsAutoDelete()) - return; - } - - try - { - Process(); - } - catch (const access_violation &e) - { - e.writelog(__FUNCTION__" thread process"); - } - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__" thread process"); - } - - try - { - OnExit(); - } - catch (const access_violation &e) - { - e.writelog(__FUNCTION__" thread exit"); - } - catch (const win32_exception &e) - { - e.writelog(__FUNCTION__" thread exit"); - } } diff --git a/xbmc/utils/Win32Exception.cpp b/xbmc/threads/platform/win/Win32Exception.cpp index fe4c59f958..7f80cba710 100644 --- a/xbmc/utils/Win32Exception.cpp +++ b/xbmc/threads/platform/win/Win32Exception.cpp @@ -20,25 +20,9 @@ */ #include "Win32Exception.h" -#ifndef _LINUX -#include "eh.h" -#endif -#include "log.h" +#include <eh.h> -#ifdef _LINUX - -void win32_exception::writelog(const char *prefix) const -{ - if( prefix ) - CLog::Log(LOGERROR, "%s : %s (code:0x%08x) at %p", - prefix, what(), (unsigned int) code(), where()); - else - CLog::Log(LOGERROR, "%s (code:0x%08x) at %p", - what(), (unsigned int) code(), where()); -} - - -#else +#define LOG if(logger) logger->Log void win32_exception::install_handler() { @@ -57,8 +41,9 @@ void win32_exception::translate(unsigned code, EXCEPTION_POINTERS* info) } } -win32_exception::win32_exception(const EXCEPTION_RECORD& info) -: mWhat("Win32 exception"), mWhere(info.ExceptionAddress), mCode(info.ExceptionCode) +win32_exception::win32_exception(const EXCEPTION_RECORD& info, const char* classname) : + XbmcCommons::Exception(classname ? classname : "win32_exception"), +mWhat("Win32 exception"), mWhere(info.ExceptionAddress), mCode(info.ExceptionCode) { switch (info.ExceptionCode) { case EXCEPTION_ACCESS_VIOLATION: @@ -71,16 +56,16 @@ win32_exception::win32_exception(const EXCEPTION_RECORD& info) } } -void win32_exception::writelog(const char *prefix) const +void win32_exception::LogThrowMessage(const char *prefix) const { if( prefix ) - CLog::Log(LOGERROR, "%s : %s (code:0x%08x) at 0x%08x", prefix, (unsigned int) what(), code(), where()); + LOG(LOGERROR, "%s : %s (code:0x%08x) at 0x%08x", prefix, (unsigned int) what(), code(), where()); else - CLog::Log(LOGERROR, "%s (code:0x%08x) at 0x%08x", what(), code(), where()); + LOG(LOGERROR, "%s (code:0x%08x) at 0x%08x", what(), code(), where()); } access_violation::access_violation(const EXCEPTION_RECORD& info) -: win32_exception(info), mAccessType(Invalid), mBadAddress(0) +: win32_exception(info,"access_voilation"), mAccessType(Invalid), mBadAddress(0) { switch(info.ExceptionInformation[0]) { @@ -97,27 +82,24 @@ access_violation::access_violation(const EXCEPTION_RECORD& info) mBadAddress = reinterpret_cast<win32_exception ::Address>(info.ExceptionInformation[1]); } -void access_violation::writelog(const char *prefix) const +void access_violation::LogThrowMessage(const char *prefix) const { if( prefix ) if( mAccessType == Write) - CLog::Log(LOGERROR, "%s : %s at 0x%08x: Writing location 0x%08x", prefix, what(), where(), address()); + LOG(LOGERROR, "%s : %s at 0x%08x: Writing location 0x%08x", prefix, what(), where(), address()); else if( mAccessType == Read) - CLog::Log(LOGERROR, "%s : %s at 0x%08x: Reading location 0x%08x", prefix, what(), where(), address()); + LOG(LOGERROR, "%s : %s at 0x%08x: Reading location 0x%08x", prefix, what(), where(), address()); else if( mAccessType == DEP) - CLog::Log(LOGERROR, "%s : %s at 0x%08x: DEP violation, location 0x%08x", prefix, what(), where(), address()); + LOG(LOGERROR, "%s : %s at 0x%08x: DEP violation, location 0x%08x", prefix, what(), where(), address()); else - CLog::Log(LOGERROR, "%s : %s at 0x%08x: unknown access type, location 0x%08x", prefix, what(), where(), address()); + LOG(LOGERROR, "%s : %s at 0x%08x: unknown access type, location 0x%08x", prefix, what(), where(), address()); else if( mAccessType == Write) - CLog::Log(LOGERROR, "%s at 0x%08x: Writing location 0x%08x", what(), where(), address()); + LOG(LOGERROR, "%s at 0x%08x: Writing location 0x%08x", what(), where(), address()); else if( mAccessType == Read) - CLog::Log(LOGERROR, "%s at 0x%08x: Reading location 0x%08x", what(), where(), address()); + LOG(LOGERROR, "%s at 0x%08x: Reading location 0x%08x", what(), where(), address()); else if( mAccessType == DEP) - CLog::Log(LOGERROR, "%s at 0x%08x: DEP violation, location 0x%08x", what(), where(), address()); + LOG(LOGERROR, "%s at 0x%08x: DEP violation, location 0x%08x", what(), where(), address()); else - CLog::Log(LOGERROR, "%s at 0x%08x: unknown access type, location 0x%08x", what(), where(), address()); - + LOG(LOGERROR, "%s at 0x%08x: unknown access type, location 0x%08x", what(), where(), address()); } - -#endif diff --git a/xbmc/utils/Win32Exception.h b/xbmc/threads/platform/win/Win32Exception.h index 25b7ada324..9b957513e9 100644 --- a/xbmc/utils/Win32Exception.h +++ b/xbmc/threads/platform/win/Win32Exception.h @@ -21,29 +21,11 @@ * */ -#ifdef _WIN32 #include <windows.h> -#endif #include <exception> +#include "commons/Exception.h" -#ifdef _LINUX - -class win32_exception: public std::exception -{ -public: - virtual const char* what() const throw() { return mWhat; }; - void* where() const { return mWhere; }; - unsigned int code() const { return mCode; }; - virtual void writelog(const char *prefix) const; -private: - const char* mWhat; - void* mWhere; - unsigned mCode; -}; - -#else - -class win32_exception: public std::exception +class win32_exception: public XbmcCommons::Exception { public: typedef const void* Address; // OK on Win32 platform @@ -52,9 +34,9 @@ public: virtual const char* what() const { return mWhat; }; Address where() const { return mWhere; }; unsigned code() const { return mCode; }; - virtual void writelog(const char *prefix) const; + virtual void LogThrowMessage(const char *prefix) const; protected: - win32_exception(const EXCEPTION_RECORD& info); + win32_exception(const EXCEPTION_RECORD& info, const char* classname = NULL); static void translate(unsigned code, EXCEPTION_POINTERS* info); private: const char* mWhat; @@ -74,7 +56,7 @@ class access_violation: public win32_exception public: Address address() const { return mBadAddress; }; - virtual void writelog(const char *prefix) const; + virtual void LogThrowMessage(const char *prefix) const; protected: friend void win32_exception::translate(unsigned code, EXCEPTION_POINTERS* info); private: @@ -82,4 +64,3 @@ private: Address mBadAddress; access_violation(const EXCEPTION_RECORD& info); }; -#endif diff --git a/xbmc/utils/Makefile b/xbmc/utils/Makefile index 79da051ef3..3d2dd5955d 100644 --- a/xbmc/utils/Makefile +++ b/xbmc/utils/Makefile @@ -57,7 +57,6 @@ SRCS=AlarmClock.cpp \ URIUtils.cpp \ Variant.cpp \ Weather.cpp \ - Win32Exception.cpp \ XBMCTinyXML.cpp \ XMLUtils.cpp \ |