1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core/NativeOwner.cpp Sun Jul 06 04:49:55 2008 +0000
1.3 @@ -0,0 +1,140 @@
1.4 +#include "NativeOwner.h"
1.5 +#include "ShareSys.h"
1.6 +#include "PluginSys.h"
1.7 +
1.8 +void CNativeOwner::SetMarkSerial(unsigned int serial)
1.9 +{
1.10 + m_nMarkSerial = serial;
1.11 +}
1.12 +
1.13 +unsigned int CNativeOwner::GetMarkSerial()
1.14 +{
1.15 + return m_nMarkSerial;
1.16 +}
1.17 +
1.18 +void CNativeOwner::AddDependent(CPlugin *pPlugin)
1.19 +{
1.20 + m_Dependents.push_back(pPlugin);
1.21 +}
1.22 +
1.23 +void CNativeOwner::AddWeakRef(const WeakNative & ref)
1.24 +{
1.25 + m_WeakRefs.push_back(ref);
1.26 +}
1.27 +
1.28 +void CNativeOwner::AddNatives(const sp_nativeinfo_t *natives)
1.29 +{
1.30 + NativeEntry *pEntry;
1.31 +
1.32 + for (unsigned int i = 0; natives[i].func != NULL && natives[i].name != NULL; i++)
1.33 + {
1.34 + if ((pEntry = g_ShareSys.AddNativeToCache(this, &natives[i])) == NULL)
1.35 + {
1.36 + continue;
1.37 + }
1.38 +
1.39 + m_Natives.push_back(pEntry);
1.40 + }
1.41 +}
1.42 +
1.43 +void CNativeOwner::PropogateMarkSerial(unsigned int serial)
1.44 +{
1.45 + CNativeOwner *pOwner;
1.46 + List<CPlugin *>::iterator iter;
1.47 +
1.48 + for (iter = m_Dependents.begin();
1.49 + iter != m_Dependents.end();
1.50 + iter++)
1.51 + {
1.52 + pOwner = (*iter);
1.53 + pOwner->SetMarkSerial(serial);
1.54 + }
1.55 +}
1.56 +
1.57 +void CNativeOwner::UnbindWeakRef(const WeakNative & ref)
1.58 +{
1.59 + sp_native_t *native;
1.60 + IPluginContext *pContext;
1.61 +
1.62 + pContext = ref.pl->GetBaseContext();
1.63 + if ((pContext->GetNativeByIndex(ref.idx, &native)) == SP_ERROR_NONE)
1.64 + {
1.65 + /* If there is no reference, the native must be unbound */
1.66 + if (ref.entry == NULL)
1.67 + {
1.68 + native->status = SP_NATIVE_UNBOUND;
1.69 + native->pfn = NULL;
1.70 + }
1.71 + /* If we've cached a reference, it's a core native we can
1.72 + * rebind back to its original (this was a replacement).
1.73 + */
1.74 + else
1.75 + {
1.76 + native->pfn = ref.entry->func;
1.77 + }
1.78 + }
1.79 +}
1.80 +
1.81 +void CNativeOwner::DropEverything()
1.82 +{
1.83 + NativeEntry *pEntry;
1.84 + List<WeakNative>::iterator iter;
1.85 + List<NativeEntry *>::iterator ntv_iter;
1.86 +
1.87 + /* Unbind and remove all weak references to us */
1.88 + iter = m_WeakRefs.begin();
1.89 + while (iter != m_WeakRefs.end())
1.90 + {
1.91 + UnbindWeakRef((*iter));
1.92 + iter = m_WeakRefs.erase(iter);
1.93 + }
1.94 +
1.95 + /* Unmark our replacement natives */
1.96 + ntv_iter = m_ReplacedNatives.begin();
1.97 + while (ntv_iter != m_ReplacedNatives.end())
1.98 + {
1.99 + pEntry = (*ntv_iter);
1.100 + pEntry->replacement.func = NULL;
1.101 + pEntry->replacement.owner = NULL;
1.102 + ntv_iter = m_ReplacedNatives.erase(ntv_iter);
1.103 + }
1.104 +
1.105 + /* Strip all of our natives from the cache */
1.106 + ntv_iter = m_Natives.begin();
1.107 + while (ntv_iter != m_Natives.end())
1.108 + {
1.109 + g_ShareSys.ClearNativeFromCache(this, (*ntv_iter)->name);
1.110 + ntv_iter = m_Natives.erase(ntv_iter);
1.111 + }
1.112 +}
1.113 +
1.114 +void CNativeOwner::DropWeakRefsTo(CPlugin *pPlugin)
1.115 +{
1.116 + List<WeakNative>::iterator iter;
1.117 +
1.118 + iter = m_WeakRefs.begin();
1.119 + while (iter != m_WeakRefs.end())
1.120 + {
1.121 + WeakNative & ref = (*iter);
1.122 +
1.123 + if (ref.pl == pPlugin)
1.124 + {
1.125 + iter = m_WeakRefs.erase(iter);
1.126 + }
1.127 + else
1.128 + {
1.129 + iter++;
1.130 + }
1.131 + }
1.132 +}
1.133 +
1.134 +void CNativeOwner::DropRefsTo(CPlugin *pPlugin)
1.135 +{
1.136 + m_Dependents.remove(pPlugin);
1.137 + DropWeakRefsTo(pPlugin);
1.138 +}
1.139 +
1.140 +void CNativeOwner::AddReplacedNative(NativeEntry *pEntry)
1.141 +{
1.142 + m_ReplacedNatives.push_back(pEntry);
1.143 +}