2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
22 #include "XBApplicationEx.h"
23 #include "utils/log.h"
24 #include "threads/SystemClock.h"
25 #ifdef HAS_PERFORMANCE_SAMPLE
26 #include "utils/PerformanceSample.h"
28 #define MEASURE_FUNCTION
30 #include "commons/Exception.h"
32 // Put this here for easy enable and disable
34 #define XBMC_TRACK_EXCEPTIONS
37 CXBApplicationEx::CXBApplicationEx()
39 // Variables to perform app timing
42 m_ExitCode = EXITCODE_QUIT;
46 CXBApplicationEx::~CXBApplicationEx()
51 bool CXBApplicationEx::Create()
53 // Variables to perform app timing
56 m_ExitCode = EXITCODE_QUIT;
58 // Initialize the app's device-dependent objects
61 CLog::Log(LOGERROR, "XBAppEx: Call to Initialize() failed!" );
69 VOID CXBApplicationEx::Destroy()
71 CLog::Log(LOGNOTICE, "destroy");
72 // Perform app-specific cleanup
76 /* Function that runs the application */
77 INT CXBApplicationEx::Run()
79 CLog::Log(LOGNOTICE, "Running the application..." );
81 unsigned int lastFrameTime = 0;
82 unsigned int frameTime = 0;
83 const unsigned int noRenderFrameTime = 15; // Simulates ~66fps
85 #ifdef XBMC_TRACK_EXCEPTIONS
86 BYTE processExceptionCount = 0;
87 BYTE frameMoveExceptionCount = 0;
88 BYTE renderExceptionCount = 0;
89 const BYTE MAX_EXCEPTION_COUNT = 10;
95 #ifdef HAS_PERFORMANCE_SAMPLE
96 CPerformanceSample sampleLoop("XBApplicationEx-loop");
98 //-----------------------------------------
99 // Animate and render a frame
100 //-----------------------------------------
101 #ifdef XBMC_TRACK_EXCEPTIONS
105 lastFrameTime = XbmcThreads::SystemClockMillis();
107 //reset exception count
108 #ifdef XBMC_TRACK_EXCEPTIONS
109 processExceptionCount = 0;
112 catch (const XbmcCommons::UncheckedException &e)
114 e.LogThrowMessage("CApplication::Process()");
115 processExceptionCount++;
116 //MAX_EXCEPTION_COUNT exceptions in a row? -> bail out
117 if (processExceptionCount > MAX_EXCEPTION_COUNT)
119 CLog::Log(LOGERROR, "CApplication::Process(), too many exceptions");
125 CLog::Log(LOGERROR, "exception in CApplication::Process()");
126 processExceptionCount++;
127 //MAX_EXCEPTION_COUNT exceptions in a row? -> bail out
128 if (processExceptionCount > MAX_EXCEPTION_COUNT)
130 CLog::Log(LOGERROR, "CApplication::Process(), too many exceptions");
135 // Frame move the scene
136 #ifdef XBMC_TRACK_EXCEPTIONS
140 if (!m_bStop) FrameMove(true, m_renderGUI);
141 //reset exception count
142 #ifdef XBMC_TRACK_EXCEPTIONS
143 frameMoveExceptionCount = 0;
146 catch (const XbmcCommons::UncheckedException &e)
148 e.LogThrowMessage("CApplication::FrameMove()");
149 frameMoveExceptionCount++;
150 //MAX_EXCEPTION_COUNT exceptions in a row? -> bail out
151 if (frameMoveExceptionCount > MAX_EXCEPTION_COUNT)
153 CLog::Log(LOGERROR, "CApplication::FrameMove(), too many exceptions");
159 CLog::Log(LOGERROR, "exception in CApplication::FrameMove()");
160 frameMoveExceptionCount++;
161 //MAX_EXCEPTION_COUNT exceptions in a row? -> bail out
162 if (frameMoveExceptionCount > MAX_EXCEPTION_COUNT)
164 CLog::Log(LOGERROR, "CApplication::FrameMove(), too many exceptions");
171 #ifdef XBMC_TRACK_EXCEPTIONS
175 if (m_renderGUI && !m_bStop) Render();
176 else if (!m_renderGUI)
178 frameTime = XbmcThreads::SystemClockMillis() - lastFrameTime;
179 if(frameTime < noRenderFrameTime)
180 Sleep(noRenderFrameTime - frameTime);
182 #ifdef XBMC_TRACK_EXCEPTIONS
183 //reset exception count
184 renderExceptionCount = 0;
187 catch (const XbmcCommons::UncheckedException &e)
189 e.LogThrowMessage("CApplication::Render()");
190 renderExceptionCount++;
191 //MAX_EXCEPTION_COUNT exceptions in a row? -> bail out
192 if (renderExceptionCount > MAX_EXCEPTION_COUNT)
194 CLog::Log(LOGERROR, "CApplication::Render(), too many exceptions");
200 CLog::Log(LOGERROR, "exception in CApplication::Render()");
201 renderExceptionCount++;
202 //MAX_EXCEPTION_COUNT exceptions in a row? -> bail out
203 if (renderExceptionCount > MAX_EXCEPTION_COUNT)
205 CLog::Log(LOGERROR, "CApplication::Render(), too many exceptions");
210 } // while (!m_bStop)
213 #ifdef TARGET_DVBBOX // oskwon
214 system("xbmc.helper --stop");
215 #endif /*TARGET_DVBBOX*/
217 CLog::Log(LOGNOTICE, "application stopped..." );