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, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 #include "AddonClass.h"
24 #include "utils/log.h"
26 #include "LanguageHook.h"
27 #include "AddonUtils.h"
29 using namespace XBMCAddonUtils;
33 // need a place to put the vtab
34 AddonClass::~AddonClass()
36 m_isDeallocating= true;
38 if (languageHook != NULL)
39 languageHook->Release();
41 #ifdef ENABLE_TRACE_API
43 CLog::Log(LOGDEBUG, "%sNEWADDON destroying %s 0x%lx", tg_.getSpaces(), classname.c_str(), (long)(((void*)this)));
46 #ifdef XBMC_ADDON_DEBUG_MEMORY
51 AddonClass::AddonClass(const char* cname) : refs(0L), classname(cname), m_isDeallocating(false),
54 #ifdef ENABLE_TRACE_API
56 CLog::Log(LOGDEBUG, "%sNEWADDON constructing %s 0x%lx", tg_.getSpaces(), classname.c_str(), (long)(((void*)this)));
59 #ifdef XBMC_ADDON_DEBUG_MEMORY
63 // check to see if we have a language hook that was prepared for this instantiation
64 languageHook = LanguageHook::GetLanguageHook();
65 if (languageHook != NULL)
67 languageHook->Acquire();
69 // here we assume the language hook was set for the single instantiation of
70 // this AddonClass (actually - its subclass - but whatever). So we
71 // will now reset the Tls. This avoids issues if the constructor of the
72 // subclass throws an exception.
73 LanguageHook::ClearLanguageHook();
77 #ifdef XBMC_ADDON_DEBUG_MEMORY
78 void AddonClass::Release() const
81 CLog::Log(LOGERROR,"NEWADDON REFCNT Releasing dead class %s 0x%lx",
82 classname.c_str(), (long)(((void*)this)));
84 long ct = AtomicDecrement((long*)&refs);
85 #ifdef LOG_LIFECYCLE_EVENTS
86 CLog::Log(LOGDEBUG,"NEWADDON REFCNT decrementing to %ld on %s 0x%lx", ct,classname.c_str(), (long)(((void*)this)));
90 ((AddonClass*)this)->isDeleted = true;
91 // we're faking a delete but not doing it so call the destructor explicitly
96 void AddonClass::Acquire() const
99 CLog::Log(LOGERROR,"NEWADDON REFCNT Acquiring dead class %s 0x%lx",
100 classname.c_str(), (long)(((void*)this)));
102 #ifdef LOG_LIFECYCLE_EVENTS
103 CLog::Log(LOGDEBUG,"NEWADDON REFCNT incrementing to %ld on %s 0x%lx",
104 AtomicIncrement((long*)&refs),classname.c_str(), (long)(((void*)this)));
106 AtomicIncrement((long*)&refs);