forked from xbmc/xbmc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
AddonClass.cpp
113 lines (94 loc) · 3.31 KB
/
AddonClass.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
* Copyright (C) 2005-2012 Team XBMC
* http://www.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
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* 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
*
*/
#include "AddonClass.h"
#include "utils/log.h"
#include "LanguageHook.h"
#include "AddonUtils.h"
using namespace XBMCAddonUtils;
namespace XBMCAddon
{
// need a place to put the vtab
AddonClass::~AddonClass()
{
m_isDeallocating= true;
if (languageHook != NULL)
languageHook->Release();
#ifdef ENABLE_TRACE_API
TraceGuard tg_;
CLog::Log(LOGDEBUG, "%sNEWADDON destroying %s 0x%lx", tg_.getSpaces(), classname.c_str(), (long)(((void*)this)));
#endif
#ifdef XBMC_ADDON_DEBUG_MEMORY
isDeleted = false;
#endif
}
AddonClass::AddonClass(const char* cname) : refs(0L), classname(cname), m_isDeallocating(false),
languageHook(NULL)
{
#ifdef ENABLE_TRACE_API
TraceGuard tg_;
CLog::Log(LOGDEBUG, "%sNEWADDON constructing %s 0x%lx", tg_.getSpaces(), classname.c_str(), (long)(((void*)this)));
#endif
#ifdef XBMC_ADDON_DEBUG_MEMORY
isDeleted = false;
#endif
// check to see if we have a language hook that was prepared for this instantiation
languageHook = LanguageHook::GetLanguageHook();
if (languageHook != NULL)
{
languageHook->Acquire();
// here we assume the language hook was set for the single instantiation of
// this AddonClass (actually - its subclass - but whatever). So we
// will now reset the Tls. This avoids issues if the constructor of the
// subclass throws an exception.
LanguageHook::ClearLanguageHook();
}
}
#ifdef XBMC_ADDON_DEBUG_MEMORY
void AddonClass::Release() const
{
if (isDeleted)
CLog::Log(LOGERROR,"NEWADDON REFCNT Releasing dead class %s 0x%lx",
classname.c_str(), (long)(((void*)this)));
long ct = AtomicDecrement((long*)&refs);
#ifdef LOG_LIFECYCLE_EVENTS
CLog::Log(LOGDEBUG,"NEWADDON REFCNT decrementing to %ld on %s 0x%lx", ct,classname.c_str(), (long)(((void*)this)));
#endif
if(ct == 0)
{
((AddonClass*)this)->isDeleted = true;
// we're faking a delete but not doing it so call the destructor explicitly
this->~AddonClass();
}
}
void AddonClass::Acquire() const
{
if (isDeleted)
CLog::Log(LOGERROR,"NEWADDON REFCNT Acquiring dead class %s 0x%lx",
classname.c_str(), (long)(((void*)this)));
#ifdef LOG_LIFECYCLE_EVENTS
CLog::Log(LOGDEBUG,"NEWADDON REFCNT incrementing to %ld on %s 0x%lx",
AtomicIncrement((long*)&refs),classname.c_str(), (long)(((void*)this)));
#else
AtomicIncrement((long*)&refs);
#endif
}
#endif
}