2013-03-29 19:37:29 +01:00
|
|
|
/**
|
2013-08-30 19:12:44 +02:00
|
|
|
* vim: set ts=4 sw=4 tw=99 noet :
|
2013-03-29 19:37:29 +01:00
|
|
|
* =============================================================================
|
|
|
|
* SourcePawn
|
|
|
|
* Copyright (C) 2004-2009 AlliedModders LLC. All rights reserved.
|
|
|
|
* =============================================================================
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU General Public License, version 3.0, as published by the
|
|
|
|
* Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* As a special exception, AlliedModders LLC gives you permission to link the
|
|
|
|
* code of this program (as well as its derivative works) to "Half-Life 2," the
|
|
|
|
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
|
|
|
|
* by the Valve Corporation. You must obey the GNU General Public License in
|
|
|
|
* all respects for all other code used. Additionally, AlliedModders LLC grants
|
|
|
|
* this exception to all derivative works. AlliedModders LLC defines further
|
|
|
|
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
|
|
|
|
* or <http://www.sourcemod.net/license.php>.
|
|
|
|
*
|
|
|
|
* Version: $Id$
|
|
|
|
*/
|
2008-05-26 09:52:27 +02:00
|
|
|
#include "NativeOwner.h"
|
|
|
|
#include "ShareSys.h"
|
|
|
|
#include "PluginSys.h"
|
|
|
|
|
2008-08-15 07:22:26 +02:00
|
|
|
CNativeOwner::CNativeOwner() : m_nMarkSerial(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-05-26 09:52:27 +02:00
|
|
|
void CNativeOwner::SetMarkSerial(unsigned int serial)
|
|
|
|
{
|
|
|
|
m_nMarkSerial = serial;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int CNativeOwner::GetMarkSerial()
|
|
|
|
{
|
|
|
|
return m_nMarkSerial;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CNativeOwner::AddDependent(CPlugin *pPlugin)
|
|
|
|
{
|
|
|
|
m_Dependents.push_back(pPlugin);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CNativeOwner::AddWeakRef(const WeakNative & ref)
|
|
|
|
{
|
|
|
|
m_WeakRefs.push_back(ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CNativeOwner::AddNatives(const sp_nativeinfo_t *natives)
|
|
|
|
{
|
2013-08-30 19:12:44 +02:00
|
|
|
for (const sp_nativeinfo_t *native = natives; native->func && native->name; native++)
|
|
|
|
g_ShareSys.AddNativeToCache(this, native);
|
2008-05-26 09:52:27 +02:00
|
|
|
|
2013-08-30 19:12:44 +02:00
|
|
|
m_natives.append(natives);
|
2008-05-26 09:52:27 +02:00
|
|
|
}
|
|
|
|
|
2013-03-29 19:37:29 +01:00
|
|
|
void CNativeOwner::PropagateMarkSerial(unsigned int serial)
|
2008-05-26 09:52:27 +02:00
|
|
|
{
|
|
|
|
CNativeOwner *pOwner;
|
|
|
|
List<CPlugin *>::iterator iter;
|
|
|
|
|
|
|
|
for (iter = m_Dependents.begin();
|
|
|
|
iter != m_Dependents.end();
|
|
|
|
iter++)
|
|
|
|
{
|
|
|
|
pOwner = (*iter);
|
|
|
|
pOwner->SetMarkSerial(serial);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-30 19:16:28 +02:00
|
|
|
void CNativeOwner::UnbindWeakRef(const WeakNative &ref)
|
2008-05-26 09:52:27 +02:00
|
|
|
{
|
|
|
|
sp_native_t *native;
|
|
|
|
IPluginContext *pContext;
|
|
|
|
|
|
|
|
pContext = ref.pl->GetBaseContext();
|
2015-02-25 07:58:31 +01:00
|
|
|
pContext->GetRuntime()->UpdateNativeBinding(
|
|
|
|
ref.idx,
|
|
|
|
nullptr,
|
|
|
|
0,
|
|
|
|
nullptr);
|
2008-05-26 09:52:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CNativeOwner::DropEverything()
|
|
|
|
{
|
|
|
|
List<WeakNative>::iterator iter;
|
|
|
|
|
|
|
|
/* Unbind and remove all weak references to us */
|
|
|
|
iter = m_WeakRefs.begin();
|
|
|
|
while (iter != m_WeakRefs.end())
|
|
|
|
{
|
|
|
|
UnbindWeakRef((*iter));
|
|
|
|
iter = m_WeakRefs.erase(iter);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Strip all of our natives from the cache */
|
2013-08-30 19:12:44 +02:00
|
|
|
for (size_t i = 0; i < m_natives.length(); i++) {
|
|
|
|
const sp_nativeinfo_t *natives = m_natives[i];
|
|
|
|
for (const sp_nativeinfo_t *native = natives; native->func && native->name; native++)
|
|
|
|
g_ShareSys.ClearNativeFromCache(this, native->name);
|
|
|
|
}
|
2013-08-30 19:16:28 +02:00
|
|
|
m_natives.clear();
|
2013-08-30 19:12:44 +02:00
|
|
|
|
2013-08-30 19:16:28 +02:00
|
|
|
for (size_t i = 0; i < m_fakes.length(); i++)
|
|
|
|
g_ShareSys.ClearNativeFromCache(this, m_fakes[i]->name());
|
|
|
|
m_fakes.clear();
|
2008-05-26 09:52:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void CNativeOwner::DropWeakRefsTo(CPlugin *pPlugin)
|
|
|
|
{
|
|
|
|
List<WeakNative>::iterator iter;
|
|
|
|
|
|
|
|
iter = m_WeakRefs.begin();
|
|
|
|
while (iter != m_WeakRefs.end())
|
|
|
|
{
|
|
|
|
WeakNative & ref = (*iter);
|
|
|
|
|
|
|
|
if (ref.pl == pPlugin)
|
|
|
|
{
|
|
|
|
iter = m_WeakRefs.erase(iter);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
iter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CNativeOwner::DropRefsTo(CPlugin *pPlugin)
|
|
|
|
{
|
|
|
|
m_Dependents.remove(pPlugin);
|
|
|
|
DropWeakRefsTo(pPlugin);
|
|
|
|
}
|