PageRenderTime 1155ms CodeModel.GetById 1141ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 21#include "threads/SystemClock.h"
 22#include "DVDMessageTracker.h"
 23#include "DVDMessage.h"
 24#include "threads/SingleLock.h"
 25
 26#ifdef DVDDEBUG_MESSAGE_TRACKER
 27
 28
 29
 30CDVDMessageTracker g_dvdMessageTracker;
 31
 32CDVDMessageTracker::CDVDMessageTracker() : CThread("DVDMsgTracker")
 33{
 34  m_bInitialized = false;
 35  InitializeCriticalSection(&m_critSection);
 36}
 37
 38CDVDMessageTracker::~CDVDMessageTracker()
 39{
 40  DeInit();
 41  DeleteCriticalSection(&m_critSection);
 42}
 43
 44void CDVDMessageTracker::Init()
 45{
 46  DeInit();
 47
 48  Create();
 49}
 50
 51void CDVDMessageTracker::DeInit()
 52{
 53  StopThread();
 54}
 55
 56void CDVDMessageTracker::Register(CDVDMsg* pMsg)
 57{
 58  if (m_bInitialized)
 59  {
 60    CSingleLock lock(m_critSection);
 61    m_messageList.push_back(new CDVDMessageTrackerItem(pMsg));
 62  }
 63}
 64
 65void CDVDMessageTracker::UnRegister(CDVDMsg* pMsg)
 66{
 67  CSingleLock lock(m_critSection);
 68
 69  std::list<CDVDMessageTrackerItem*>::iterator iter = m_messageList.begin();
 70  while (iter != m_messageList.end())
 71  {
 72    CDVDMessageTrackerItem* pItem = *iter;
 73    if (pItem->m_pMsg == pMsg)
 74    {
 75      m_messageList.remove(pItem);
 76      delete pItem;
 77      break;
 78    }
 79    ++iter;
 80  }
 81
 82}
 83
 84void CDVDMessageTracker::OnStartup()
 85{
 86  m_bInitialized = true;
 87}
 88
 89void CDVDMessageTracker::Process()
 90{
 91  while (!m_bStop)
 92  {
 93    Sleep(1000);
 94
 95    CSingleLock lock(m_critSection);
 96
 97    std::list<CDVDMessageTrackerItem*>::iterator iter = m_messageList.begin();
 98    while (!m_bStop && iter != m_messageList.end())
 99    {
100      CDVDMessageTrackerItem* pItem = *iter;
101      if ((XbmcThreads::SystemClockMillis() - pItem->m_time_created) > 60000)
102      {
103        if (!pItem->m_debug_logged)
104        {
105          CLog::Log(LOGWARNING, "CDVDMsgTracker::Process() - Msg still in system after 60 seconds.");
106          CLog::Log(LOGWARNING, "                            Type : %d", pItem->m_pMsg->GetMessageType());
107
108          pItem->m_debug_logged = true;
109        }
110      }
111      ++iter;
112    }
113
114  }
115}
116
117void CDVDMessageTracker::OnExit()
118{
119  m_bInitialized = false;
120
121  CLog::Log(LOGWARNING, "CDVDMsgTracker::Process() - nr of messages in system : %d", m_messageList.size());
122
123  m_messageList.clear();
124}
125
126#endif // DVDDEBUG_MESSAGE_TRACKER
127