Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Adds back signal handling and windows translated exception handling #961

Merged
merged 1 commit into from

5 participants

@jimfcarroll
Collaborator

Adds back signal handling and windows translated exception handling in a less platform specific manner while preserving the library dependency hierarchy.

@FernetMenta FernetMenta Adds back signal handling and windows translated exception handling i…
…n a less platform specific manner while preserving the library dependency hierarchy.
cf3383a
@jimfcarroll
Collaborator

@CrystalP , can you try this out. I got it working on Windows. For some reason on Windows I have no sound but I don't think it's related to anything in this PR.

@jimfcarroll
Collaborator

Hey, @CrystalP . I was hoping to get this in for June but I want to make sure it gives you what you want. What do you think?

@ghost

it's certainly better than nothing, and can be refined if crystalp has objections when he pops by again. no sense delaying another window imo.

@jimfcarroll
Collaborator

Ok. I'll do it in the next day or so.

@jimfcarroll
Collaborator

I'm going to merge this, tomorrow, the 9th. If anyone has any issues please let me know.

@Memphiz
Owner

If anybody reads - this needs xcode sync (remove utils/win32exception.cpp/.h and add commons/exception.cpp/.h). Tested on ios (compile only) and osx with these changes and didn't see anything obvious during runtime. I think we sync xcode after its merged for preventing any merge conflicts...

I did a pr to you with the sync nevertheless if you merge it and the button is still green then its fine - if not just remove the commit again from the commit range and we will fix after merging.

@jimfcarroll jimfcarroll merged commit afe8422 into from
@jimfcarroll
Collaborator

Ok @Memphiz, I didn't realize your PR was against my repository until after I merged this. So I hand merged the project files and pushed them to the main repository. Please let me know if there's any issues (since I didn't build them myself).

@Uxorious

I'm getting this on Linux:
LD xbmc.bin
xbmc/cores/DllLoader/dllloader.a(DllLoader.o):(.data.rel.ro._ZTIN11XbmcCommons18UncheckedExceptionE[typeinfo for XbmcCommons::UncheckedException]+0x8): undefined reference to typeinfo for XbmcCommons::Exception'
xbmc/xbmc.a(XbmcContext.o): In function
XbmcCommons::Exception::SetLogger(XbmcCommons::ILogger)':
/home/Uxorious/Development/xbmc/xbmc/commons/Exception.h:93: undefined reference to XbmcCommons::Exception::logger'
xbmc/threads/threads.a(Thread.o): In function
CThread::Create(bool, unsigned int)':
/home/Uxorious/Development/xbmc/xbmc/threads/platform/pthreads/ThreadImpl.cpp:58: undefined reference to `XbmcCommons::ILogger::Log(int, char const
, ...)'
/home/Uxorious/Development/xbmc/xbmc/threads/platform/pthreads/ThreadImpl.cpp:39: undefined reference to XbmcCommons::ILogger::Log(int, char const*, ...)'
xbmc/threads/threads.a(Thread.o): In function
CThread::SetThreadInfo()':
/home/Uxorious/Development/xbmc/xbmc/threads/platform/pthreads/ThreadImpl.cpp:85: undefined reference to XbmcCommons::ILogger::Log(int, char const*, ...)'
xbmc/threads/threads.a(Thread.o): In function
CThread::SetPriority(int)':
/home/Uxorious/Development/xbmc/xbmc/threads/platform/pthreads/ThreadImpl.cpp:160: undefined reference to XbmcCommons::ILogger::Log(int, char const*, ...)'
xbmc/threads/threads.a(Thread.o): In function
CThread::staticThread(void)':
/home/Uxorious/Development/xbmc/xbmc/threads/Thread.cpp:102: undefined reference to `XbmcCommons::ILogger::Log(int, char const
, ...)'
xbmc/threads/threads.a(Thread.o):/home/Uxorious/Development/xbmc/xbmc/threads/Thread.cpp:125: more undefined references to `XbmcCommons::ILogger::Log(int, char const, ...)' follow
collect2: ld returned 1 exit status
make: *
* [xbmc.bin] Error 1

@jimfcarroll
Collaborator

Ok. Checking this now. Maybe there was an indirect conflict.

@Memphiz
Owner

xcode sync looks good ... can't compile atm - only on battery ;)

@jimfcarroll
Collaborator

The Makefile is broken. Fixing it now.

@jimfcarroll
Collaborator

Ok. This commit should have fixed it:

3277107

Let me know if there are more issues.

@Uxorious

It at least compiles now.
Thanks!

@Montellese
Owner

Visual Studio throws a warning at me concerning the call to _set_se_translator in win32_exception::install_handler because the XbmcThreads project uses the /EHsc switch instead of the /EHa switch for exception handling (the xbmc project uses /EHa).

@jimfcarroll
Collaborator

If you're in there (since I only load up the windows project to double check it) can you fix it and check it in? If not, let me know and I'll take care of it. I don't think this warrants a PR since it's a minor fix.

Thanks for taking a look.

@Montellese
Owner

I can do it. Just wanted to check back first if this was unintended ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 12, 2012
  1. @FernetMenta

    Adds back signal handling and windows translated exception handling i…

    FernetMenta authored Jim Carroll committed
    …n a less platform specific manner while preserving the library dependency hierarchy.
This page is out of date. Refresh to see the latest.
Showing with 360 additions and 403 deletions.
  1. +6 −4 Makefile.in
  2. +1 −3 project/VS2010Express/XBMC.vcxproj
  3. +1 −7 project/VS2010Express/XBMC.vcxproj.filters
  4. +2 −0  project/VS2010Express/XbmcCommons.vcxproj
  5. +2 −0  project/VS2010Express/XbmcCommons.vcxproj.filters
  6. +2 −0  project/VS2010Express/XbmcThreads.vcxproj
  7. +6 −0 project/VS2010Express/XbmcThreads.vcxproj.filters
  8. +1 −1  xbmc/Application.cpp
  9. +2 −0  xbmc/XbmcContext.cpp
  10. +30 −0 xbmc/commons/Exception.cpp
  11. +123 −0 xbmc/commons/Exception.h
  12. +1 −1  xbmc/commons/Makefile
  13. +2 −6 xbmc/cores/DllLoader/DllLoader.cpp
  14. +1 −16 xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecFFmpeg.cpp
  15. +0 −1  xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp
  16. +2 −11 xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp
  17. +5 −27 xbmc/filesystem/Directory.cpp
  18. +22 −123 xbmc/filesystem/File.cpp
  19. +2 −8 xbmc/filesystem/SmbFile.cpp
  20. +72 −5 xbmc/threads/Thread.cpp
  21. +27 −21 xbmc/threads/Thread.h
  22. +24 −46 xbmc/threads/platform/pthreads/ThreadImpl.cpp
  23. +3 −62 xbmc/threads/platform/win/ThreadImpl.cpp
  24. +18 −36 xbmc/{utils → threads/platform/win}/Win32Exception.cpp
  25. +5 −24 xbmc/{utils → threads/platform/win}/Win32Exception.h
  26. +0 −1  xbmc/utils/Makefile
View
10 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
View
4 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>
View
8 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>
View
2  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">
View
2  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>
View
2  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" />
View
6 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">
View
2  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"
View
2  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);
}
View
30 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() {}
+}
+
View
123 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; }
+
+}
+
View
2  xbmc/commons/Makefile
@@ -1,7 +1,7 @@
SRCS= \
+ Exception.cpp \
ilog.cpp
-
LIB=commons.a
include ../../Makefile.include
View
8 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__);
View
17 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()
View
1  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
View
13 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))
View
32 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__);
View
145 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);
View
10 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;
}
}
View
77 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());
+ }
+}
View
48 xbmc/threads/Thread.h
@@ -59,30 +59,37 @@ class CThread
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 @@ class CThread
/**
* 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;
View
70 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);
+}
View
65 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");
- }
}
View
54 xbmc/utils/Win32Exception.cpp → 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
View
29 xbmc/utils/Win32Exception.h → 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 @@ class win32_exception: public std::exception
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 @@ class access_violation: public win32_exception
Address mBadAddress;
access_violation(const EXCEPTION_RECORD& info);
};
-#endif
View
1  xbmc/utils/Makefile
@@ -57,7 +57,6 @@ SRCS=AlarmClock.cpp \
URIUtils.cpp \
Variant.cpp \
Weather.cpp \
- Win32Exception.cpp \
XBMCTinyXML.cpp \
XMLUtils.cpp \
Something went wrong with that request. Please try again.