Adds back signal handling and windows translated exception handling in a less platfor...
authorFernetMenta <fernetmenta@online.de>
Wed, 2 May 2012 10:44:32 +0000 (12:44 +0200)
committerJim Carroll <thecarrolls@jiminger.com>
Sat, 12 May 2012 15:08:52 +0000 (11:08 -0400)
28 files changed:
Makefile.in
project/VS2010Express/XBMC.vcxproj
project/VS2010Express/XBMC.vcxproj.filters
project/VS2010Express/XbmcCommons.vcxproj
project/VS2010Express/XbmcCommons.vcxproj.filters
project/VS2010Express/XbmcThreads.vcxproj
project/VS2010Express/XbmcThreads.vcxproj.filters
xbmc/Application.cpp
xbmc/XbmcContext.cpp
xbmc/commons/Exception.cpp [new file with mode: 0644]
xbmc/commons/Exception.h [new file with mode: 0644]
xbmc/commons/Makefile
xbmc/cores/DllLoader/DllLoader.cpp
xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecFFmpeg.cpp
xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp
xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
xbmc/filesystem/Directory.cpp
xbmc/filesystem/File.cpp
xbmc/filesystem/SmbFile.cpp
xbmc/threads/Thread.cpp
xbmc/threads/Thread.h
xbmc/threads/platform/pthreads/ThreadImpl.cpp
xbmc/threads/platform/win/ThreadImpl.cpp
xbmc/threads/platform/win/Win32Exception.cpp [new file with mode: 0644]
xbmc/threads/platform/win/Win32Exception.h [new file with mode: 0644]
xbmc/utils/Makefile
xbmc/utils/Win32Exception.cpp [deleted file]
xbmc/utils/Win32Exception.h [deleted file]

index 4500b2c..f12cc57 100755 (executable)
@@ -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
index 64d865b..58ff836 100644 (file)
     <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" />
     <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" />
     </VisualStudio>
   </ProjectExtensions>
   <Import Project="$(SolutionDir)\$(ProjectFileName).targets.user" Condition="Exists('$(SolutionDir)\$(ProjectFileName).targets.user')" />
-</Project>
+</Project>
\ No newline at end of file
index 3de0c6a..338eb5e 100644 (file)
     <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>
     <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>
       <Filter>win32</Filter>
     </CustomBuild>
   </ItemGroup>
-</Project>
+</Project>
\ No newline at end of file
index 4e06597..988468c 100644 (file)
     </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">
index 7d6142a..7a3faa5 100644 (file)
@@ -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
index b891593..0ed3b80 100644 (file)
@@ -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" />
index 14353ed..84cde3b 100644 (file)
@@ -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">
index b7e43d9..04745e1 100644 (file)
 #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"
index 72b14ae..109474f 100644 (file)
@@ -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 (file)
index 0000000..867d1dc
--- /dev/null
@@ -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 (file)
index 0000000..810c1b0
--- /dev/null
@@ -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; }
+
+}
+
index 97fdc2f..b6403f4 100644 (file)
@@ -1,7 +1,7 @@
 SRCS= \
+       Exception.cpp \
        ilog.cpp
 
-
 LIB=commons.a
 
 include ../../Makefile.include
index b7b23e1..1500d49 100644 (file)
@@ -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__);
index 238c855..2d87cd2 100644 (file)
@@ -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()
index f70ecef..e9b9c8c 100644 (file)
@@ -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
index d1b51af..73dd846 100644 (file)
@@ -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))
index ecf5b50..4f78092 100644 (file)
@@ -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__);
index 29a8093..78c96ea 100644 (file)
 #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);
index 242d482..22d6f01 100644 (file)
@@ -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;
   }
 }
index b4e1260..0fe8dae 100644 (file)
@@ -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());
+  }
+}
 
index 2f8d5f3..c44e880 100644 (file)
@@ -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;
index 7f79db6..6260da7 100644 (file)
 #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);
+}
 
index a2a7da5..05252f0 100644 (file)
  */
 
 #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/threads/platform/win/Win32Exception.cpp b/xbmc/threads/platform/win/Win32Exception.cpp
new file mode 100644 (file)
index 0000000..7f80cba
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ *      Copyright (C) 2005-2008 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 "Win32Exception.h"
+#include <eh.h>
+
+#define LOG if(logger) logger->Log
+
+void win32_exception::install_handler()
+{
+    _set_se_translator(win32_exception::translate);
+}
+
+void win32_exception::translate(unsigned code, EXCEPTION_POINTERS* info)
+{
+    // Windows guarantees that *(info->ExceptionRecord) is valid
+    switch (code) {
+    case EXCEPTION_ACCESS_VIOLATION:
+        throw access_violation(*(info->ExceptionRecord));
+        break;
+    default:
+        throw win32_exception(*(info->ExceptionRecord));
+    }
+}
+
+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:
+        mWhat = "Access violation";
+        break;
+    case EXCEPTION_FLT_DIVIDE_BY_ZERO:
+    case EXCEPTION_INT_DIVIDE_BY_ZERO:
+        mWhat = "Division by zero";
+        break;
+    }
+}
+
+void win32_exception::LogThrowMessage(const char *prefix)  const
+{
+  if( prefix )
+    LOG(LOGERROR, "%s : %s (code:0x%08x) at 0x%08x", prefix, (unsigned int) what(), code(), where());
+  else
+    LOG(LOGERROR, "%s (code:0x%08x) at 0x%08x", what(), code(), where());
+}
+
+access_violation::access_violation(const EXCEPTION_RECORD& info)
+: win32_exception(info,"access_voilation"), mAccessType(Invalid), mBadAddress(0)
+{
+    switch(info.ExceptionInformation[0])
+    {
+    case 0:
+      mAccessType = Read;
+      break;
+    case 1:
+      mAccessType = Write;
+      break;
+    case 8:
+      mAccessType = DEP;
+      break;
+    }
+    mBadAddress = reinterpret_cast<win32_exception ::Address>(info.ExceptionInformation[1]);
+}
+
+void access_violation::LogThrowMessage(const char *prefix) const
+{
+  if( prefix )
+    if( mAccessType == Write)
+      LOG(LOGERROR, "%s : %s at 0x%08x: Writing location 0x%08x", prefix, what(), where(), address());
+    else if( mAccessType == Read)
+      LOG(LOGERROR, "%s : %s at 0x%08x: Reading location 0x%08x", prefix, what(), where(), address());
+    else if( mAccessType == DEP)
+      LOG(LOGERROR, "%s : %s at 0x%08x: DEP violation, location 0x%08x", prefix, what(), where(), address());
+    else
+      LOG(LOGERROR, "%s : %s at 0x%08x: unknown access type, location 0x%08x", prefix, what(), where(), address());
+  else
+    if( mAccessType == Write)
+      LOG(LOGERROR, "%s at 0x%08x: Writing location 0x%08x", what(), where(), address());
+    else if( mAccessType == Read)
+      LOG(LOGERROR, "%s at 0x%08x: Reading location 0x%08x", what(), where(), address());
+    else if( mAccessType == DEP)
+      LOG(LOGERROR, "%s at 0x%08x: DEP violation, location 0x%08x", what(), where(), address());
+    else
+      LOG(LOGERROR, "%s at 0x%08x: unknown access type, location 0x%08x", what(), where(), address());
+}
diff --git a/xbmc/threads/platform/win/Win32Exception.h b/xbmc/threads/platform/win/Win32Exception.h
new file mode 100644 (file)
index 0000000..9b95751
--- /dev/null
@@ -0,0 +1,66 @@
+#pragma once
+
+/*
+ *      Copyright (C) 2005-2008 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 <windows.h>
+#include <exception>
+#include "commons/Exception.h"
+
+class win32_exception: public XbmcCommons::Exception
+{
+public:
+    typedef const void* Address; // OK on Win32 platform
+
+    static void install_handler();
+    virtual const char* what() const { return mWhat; };
+    Address where() const { return mWhere; };
+    unsigned code() const { return mCode; };
+    virtual void LogThrowMessage(const char *prefix) const;
+protected:
+    win32_exception(const EXCEPTION_RECORD& info, const char* classname = NULL);
+    static void translate(unsigned code, EXCEPTION_POINTERS* info);
+private:
+    const char* mWhat;
+    Address mWhere;
+    unsigned mCode;
+};
+
+class access_violation: public win32_exception
+{
+  enum access_type
+  {
+    Invalid,
+    Read,
+    Write,
+    DEP
+  };
+
+public:
+    Address address() const { return mBadAddress; };
+    virtual void LogThrowMessage(const char *prefix) const;
+protected:
+    friend void win32_exception::translate(unsigned code, EXCEPTION_POINTERS* info);
+private:
+    access_type mAccessType;
+    Address mBadAddress;
+    access_violation(const EXCEPTION_RECORD& info);
+};
index 79da051..3d2dd59 100644 (file)
@@ -57,7 +57,6 @@ SRCS=AlarmClock.cpp \
      URIUtils.cpp \
      Variant.cpp \
      Weather.cpp \
-     Win32Exception.cpp \
      XBMCTinyXML.cpp \
      XMLUtils.cpp \
 
diff --git a/xbmc/utils/Win32Exception.cpp b/xbmc/utils/Win32Exception.cpp
deleted file mode 100644 (file)
index fe4c59f..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- *      Copyright (C) 2005-2008 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 "Win32Exception.h"
-#ifndef _LINUX
-#include "eh.h"
-#endif
-#include "log.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
-
-void win32_exception::install_handler()
-{
-    _set_se_translator(win32_exception::translate);
-}
-
-void win32_exception::translate(unsigned code, EXCEPTION_POINTERS* info)
-{
-    // Windows guarantees that *(info->ExceptionRecord) is valid
-    switch (code) {
-    case EXCEPTION_ACCESS_VIOLATION:
-        throw access_violation(*(info->ExceptionRecord));
-        break;
-    default:
-        throw win32_exception(*(info->ExceptionRecord));
-    }
-}
-
-win32_exception::win32_exception(const EXCEPTION_RECORD& info)
-: mWhat("Win32 exception"), mWhere(info.ExceptionAddress), mCode(info.ExceptionCode)
-{
-    switch (info.ExceptionCode) {
-    case EXCEPTION_ACCESS_VIOLATION:
-        mWhat = "Access violation";
-        break;
-    case EXCEPTION_FLT_DIVIDE_BY_ZERO:
-    case EXCEPTION_INT_DIVIDE_BY_ZERO:
-        mWhat = "Division by zero";
-        break;
-    }
-}
-
-void win32_exception::writelog(const char *prefix)  const
-{
-  if( prefix )
-    CLog::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());
-}
-
-access_violation::access_violation(const EXCEPTION_RECORD& info)
-: win32_exception(info), mAccessType(Invalid), mBadAddress(0)
-{
-    switch(info.ExceptionInformation[0])
-    {
-    case 0:
-      mAccessType = Read;
-      break;
-    case 1:
-      mAccessType = Write;
-      break;
-    case 8:
-      mAccessType = DEP;
-      break;
-    }
-    mBadAddress = reinterpret_cast<win32_exception ::Address>(info.ExceptionInformation[1]);
-}
-
-void access_violation::writelog(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());
-    else if( mAccessType == Read)
-      CLog::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());
-    else
-      CLog::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());
-    else if( mAccessType == Read)
-      CLog::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());
-    else
-      CLog::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/utils/Win32Exception.h
deleted file mode 100644 (file)
index 25b7ada..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-#pragma once
-
-/*
- *      Copyright (C) 2005-2008 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
- *
- */
-
-#ifdef _WIN32
-#include <windows.h>
-#endif
-#include <exception>
-
-#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
-{
-public:
-    typedef const void* Address; // OK on Win32 platform
-
-    static void install_handler();
-    virtual const char* what() const { return mWhat; };
-    Address where() const { return mWhere; };
-    unsigned code() const { return mCode; };
-    virtual void writelog(const char *prefix) const;
-protected:
-    win32_exception(const EXCEPTION_RECORD& info);
-    static void translate(unsigned code, EXCEPTION_POINTERS* info);
-private:
-    const char* mWhat;
-    Address mWhere;
-    unsigned mCode;
-};
-
-class access_violation: public win32_exception
-{
-  enum access_type
-  {
-    Invalid,
-    Read,
-    Write,
-    DEP
-  };
-
-public:
-    Address address() const { return mBadAddress; };
-    virtual void writelog(const char *prefix) const;
-protected:
-    friend void win32_exception::translate(unsigned code, EXCEPTION_POINTERS* info);
-private:
-    access_type mAccessType;
-    Address mBadAddress;
-    access_violation(const EXCEPTION_RECORD& info);
-};
-#endif