Fix keymap.
[vuplus_xbmc] / xbmc / SectionLoader.cpp
index 51dcca5..a4970f5 100644 (file)
@@ -1,6 +1,6 @@
 /*
- *      Copyright (C) 2005-2008 Team XBMC
- *      http://www.xbmc.org
+ *      Copyright (C) 2005-2013 Team XBMC
+ *      http://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
  *  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
+ *  along with XBMC; see the file COPYING.  If not, see
+ *  <http://www.gnu.org/licenses/>.
  *
  */
 
+#include "threads/SystemClock.h"
 #include "system.h"
 #include "SectionLoader.h"
 #include "cores/DllLoader/DllLoaderContainer.h"
 
 using namespace std;
 
-// explicit template instantiation
-template class xbmcutil::Singleton<CSectionLoader>;
-
-#define g_sectionLoader (*(xbmcutil::Singleton<CSectionLoader>::getInstance()))
+#define g_sectionLoader XBMC_GLOBAL_USE(CSectionLoader)
 
 //  delay for unloading dll's
 #define UNLOAD_DELAY 30*1000 // 30 sec.
@@ -43,81 +40,8 @@ CSectionLoader::CSectionLoader(void)
 {}
 
 CSectionLoader::~CSectionLoader(void)
-{}
-
-bool CSectionLoader::IsLoaded(const CStdString& strSection)
-{
-  CSingleLock lock(g_sectionLoader.m_critSection);
-
-  for (int i = 0; i < (int)g_sectionLoader.m_vecLoadedSections.size(); ++i)
-  {
-    CSection& section = g_sectionLoader.m_vecLoadedSections[i];
-    if (section.m_strSectionName == strSection && section.m_lReferenceCount > 0) return true;
-  }
-  return false;
-}
-
-bool CSectionLoader::Load(const CStdString& strSection)
-{
-  CSingleLock lock(g_sectionLoader.m_critSection);
-
-  for (int i = 0; i < (int)g_sectionLoader.m_vecLoadedSections.size(); ++i)
-  {
-    CSection& section = g_sectionLoader.m_vecLoadedSections[i];
-    if (section.m_strSectionName == strSection)
-    {
-
-#ifdef LOGALL
-      CLog::Log(LOGDEBUG,"SECTION:LoadSection(%s) count:%i\n", strSection.c_str(), section.m_lReferenceCount);
-#endif
-
-      section.m_lReferenceCount++;
-      return true;
-    }
-  }
-
-#ifdef HAS_SECTIONS
-  if ( NULL == XLoadSection(strSection.c_str() ) )
-  {
-    CLog::Log(LOGDEBUG,"SECTION:LoadSection(%s) load failed!!\n", strSection.c_str());
-    return false;
-  }
-  HANDLE hHandle = XGetSectionHandle(strSection.c_str());
-
-  CLog::Log(LOGDEBUG,"SECTION:Section %s loaded count:1 size:%i\n", strSection.c_str(), XGetSectionSize(hHandle) );
-#endif
-
-  CSection newSection;
-  newSection.m_strSectionName = strSection;
-  newSection.m_lReferenceCount = 1;
-  g_sectionLoader.m_vecLoadedSections.push_back(newSection);
-  return true;
-}
-
-void CSectionLoader::Unload(const CStdString& strSection)
 {
-  CSingleLock lock(g_sectionLoader.m_critSection);
-  if (!CSectionLoader::IsLoaded(strSection)) return ;
-
-  ivecLoadedSections i;
-  i = g_sectionLoader.m_vecLoadedSections.begin();
-  while (i != g_sectionLoader.m_vecLoadedSections.end())
-  {
-    CSection& section = *i;
-    if (section.m_strSectionName == strSection)
-    {
-#ifdef LOGALL
-      CLog::Log(LOGDEBUG,"SECTION:FreeSection(%s) count:%i\n", strSection.c_str(), section.m_lReferenceCount);
-#endif
-      section.m_lReferenceCount--;
-      if ( 0 == section.m_lReferenceCount)
-      {
-        section.m_unloadDelayStartTick = CTimeUtils::GetTimeMS();
-        return ;
-      }
-    }
-    ++i;
-  }
+  UnloadAll();
 }
 
 LibraryLoader *CSectionLoader::LoadDLL(const CStdString &dllname, bool bDelayUnload /*=true*/, bool bLoadSymbols /*=false*/)
@@ -167,7 +91,7 @@ void CSectionLoader::UnloadDLL(const CStdString &dllname)
       if (0 == dll.m_lReferenceCount)
       {
         if (dll.m_bDelayUnload)
-          dll.m_unloadDelayStartTick = CTimeUtils::GetTimeMS();
+          dll.m_unloadDelayStartTick = XbmcThreads::SystemClockMillis();
         else
         {
           CLog::Log(LOGDEBUG,"SECTION:UnloadDll(%s)", dllname.c_str());
@@ -186,27 +110,11 @@ void CSectionLoader::UnloadDelayed()
 {
   CSingleLock lock(g_sectionLoader.m_critSection);
 
-  ivecLoadedSections i = g_sectionLoader.m_vecLoadedSections.begin();
-  while( i != g_sectionLoader.m_vecLoadedSections.end() )
-  {
-    CSection& section = *i;
-    if( section.m_lReferenceCount == 0 && CTimeUtils::GetTimeMS() - section.m_unloadDelayStartTick > UNLOAD_DELAY)
-    {
-      CLog::Log(LOGDEBUG,"SECTION:UnloadDelayed(SECTION: %s)", section.m_strSectionName.c_str());
-#ifdef HAS_SECTIONS
-      XFreeSection(section.m_strSectionName.c_str());
-#endif
-      i = g_sectionLoader.m_vecLoadedSections.erase(i);
-      continue;
-    }
-    i++;
-  }
-
   // check if we can unload any unreferenced dlls
   for (int i = 0; i < (int)g_sectionLoader.m_vecLoadedDLLs.size(); ++i)
   {
     CDll& dll = g_sectionLoader.m_vecLoadedDLLs[i];
-    if (dll.m_lReferenceCount == 0 && CTimeUtils::GetTimeMS() - dll.m_unloadDelayStartTick > UNLOAD_DELAY)
+    if (dll.m_lReferenceCount == 0 && XbmcThreads::SystemClockMillis() - dll.m_unloadDelayStartTick > UNLOAD_DELAY)
     {
       CLog::Log(LOGDEBUG,"SECTION:UnloadDelayed(DLL: %s)", dll.m_strDllName.c_str());
 
@@ -220,19 +128,6 @@ void CSectionLoader::UnloadDelayed()
 
 void CSectionLoader::UnloadAll()
 {
-  ivecLoadedSections i;
-  i = g_sectionLoader.m_vecLoadedSections.begin();
-  while (i != g_sectionLoader.m_vecLoadedSections.end())
-  {
-    CSection& section = *i;
-    //g_sectionLoader.m_vecLoadedSections.erase(i);
-    CLog::Log(LOGDEBUG,"SECTION:UnloadAll(SECTION: %s)", section.m_strSectionName.c_str());
-#ifdef HAS_SECTIONS
-    XFreeSection(section.m_strSectionName.c_str());
-#endif
-    i = g_sectionLoader.m_vecLoadedSections.erase(i);
-  }
-
   // delete the dll's
   CSingleLock lock(g_sectionLoader.m_critSection);
   vector<CDll>::iterator it = g_sectionLoader.m_vecLoadedDLLs.begin();