/xbmc/cores/dvdplayer/DVDMessageTracker.cpp

http://github.com/xbmc/xbmc · C++ · 127 lines · 83 code · 25 blank · 19 comment · 11 complexity · 4f108c1c374a98e37111a649c9c4bf89 MD5 · raw file

  1. /*
  2. * Copyright (C) 2005-2013 Team XBMC
  3. * http://xbmc.org
  4. *
  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)
  8. * any later version.
  9. *
  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.
  14. *
  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/>.
  18. *
  19. */
  20. #include "threads/SystemClock.h"
  21. #include "DVDMessageTracker.h"
  22. #include "DVDMessage.h"
  23. #include "threads/SingleLock.h"
  24. #ifdef DVDDEBUG_MESSAGE_TRACKER
  25. CDVDMessageTracker g_dvdMessageTracker;
  26. CDVDMessageTracker::CDVDMessageTracker() : CThread("DVDMsgTracker")
  27. {
  28. m_bInitialized = false;
  29. InitializeCriticalSection(&m_critSection);
  30. }
  31. CDVDMessageTracker::~CDVDMessageTracker()
  32. {
  33. DeInit();
  34. DeleteCriticalSection(&m_critSection);
  35. }
  36. void CDVDMessageTracker::Init()
  37. {
  38. DeInit();
  39. Create();
  40. }
  41. void CDVDMessageTracker::DeInit()
  42. {
  43. StopThread();
  44. }
  45. void CDVDMessageTracker::Register(CDVDMsg* pMsg)
  46. {
  47. if (m_bInitialized)
  48. {
  49. CSingleLock lock(m_critSection);
  50. m_messageList.push_back(new CDVDMessageTrackerItem(pMsg));
  51. }
  52. }
  53. void CDVDMessageTracker::UnRegister(CDVDMsg* pMsg)
  54. {
  55. CSingleLock lock(m_critSection);
  56. std::list<CDVDMessageTrackerItem*>::iterator iter = m_messageList.begin();
  57. while (iter != m_messageList.end())
  58. {
  59. CDVDMessageTrackerItem* pItem = *iter;
  60. if (pItem->m_pMsg == pMsg)
  61. {
  62. m_messageList.remove(pItem);
  63. delete pItem;
  64. break;
  65. }
  66. ++iter;
  67. }
  68. }
  69. void CDVDMessageTracker::OnStartup()
  70. {
  71. m_bInitialized = true;
  72. }
  73. void CDVDMessageTracker::Process()
  74. {
  75. while (!m_bStop)
  76. {
  77. Sleep(1000);
  78. CSingleLock lock(m_critSection);
  79. std::list<CDVDMessageTrackerItem*>::iterator iter = m_messageList.begin();
  80. while (!m_bStop && iter != m_messageList.end())
  81. {
  82. CDVDMessageTrackerItem* pItem = *iter;
  83. if ((XbmcThreads::SystemClockMillis() - pItem->m_time_created) > 60000)
  84. {
  85. if (!pItem->m_debug_logged)
  86. {
  87. CLog::Log(LOGWARNING, "CDVDMsgTracker::Process() - Msg still in system after 60 seconds.");
  88. CLog::Log(LOGWARNING, " Type : %d", pItem->m_pMsg->GetMessageType());
  89. pItem->m_debug_logged = true;
  90. }
  91. }
  92. ++iter;
  93. }
  94. }
  95. }
  96. void CDVDMessageTracker::OnExit()
  97. {
  98. m_bInitialized = false;
  99. CLog::Log(LOGWARNING, "CDVDMsgTracker::Process() - nr of messages in system : %d", m_messageList.size());
  100. m_messageList.clear();
  101. }
  102. #endif // DVDDEBUG_MESSAGE_TRACKER