Initial Import of beta structs extension.
1 #include "NativeOwner.h"
5 void CNativeOwner::SetMarkSerial(unsigned int serial)
7 m_nMarkSerial = serial;
10 unsigned int CNativeOwner::GetMarkSerial()
15 void CNativeOwner::AddDependent(CPlugin *pPlugin)
17 m_Dependents.push_back(pPlugin);
20 void CNativeOwner::AddWeakRef(const WeakNative & ref)
22 m_WeakRefs.push_back(ref);
25 void CNativeOwner::AddNatives(const sp_nativeinfo_t *natives)
29 for (unsigned int i = 0; natives[i].func != NULL && natives[i].name != NULL; i++)
31 if ((pEntry = g_ShareSys.AddNativeToCache(this, &natives[i])) == NULL)
36 m_Natives.push_back(pEntry);
40 void CNativeOwner::PropogateMarkSerial(unsigned int serial)
43 List<CPlugin *>::iterator iter;
45 for (iter = m_Dependents.begin();
46 iter != m_Dependents.end();
50 pOwner->SetMarkSerial(serial);
54 void CNativeOwner::UnbindWeakRef(const WeakNative & ref)
57 IPluginContext *pContext;
59 pContext = ref.pl->GetBaseContext();
60 if ((pContext->GetNativeByIndex(ref.idx, &native)) == SP_ERROR_NONE)
62 /* If there is no reference, the native must be unbound */
63 if (ref.entry == NULL)
65 native->status = SP_NATIVE_UNBOUND;
68 /* If we've cached a reference, it's a core native we can
69 * rebind back to its original (this was a replacement).
73 native->pfn = ref.entry->func;
78 void CNativeOwner::DropEverything()
81 List<WeakNative>::iterator iter;
82 List<NativeEntry *>::iterator ntv_iter;
84 /* Unbind and remove all weak references to us */
85 iter = m_WeakRefs.begin();
86 while (iter != m_WeakRefs.end())
88 UnbindWeakRef((*iter));
89 iter = m_WeakRefs.erase(iter);
92 /* Unmark our replacement natives */
93 ntv_iter = m_ReplacedNatives.begin();
94 while (ntv_iter != m_ReplacedNatives.end())
97 pEntry->replacement.func = NULL;
98 pEntry->replacement.owner = NULL;
99 ntv_iter = m_ReplacedNatives.erase(ntv_iter);
102 /* Strip all of our natives from the cache */
103 ntv_iter = m_Natives.begin();
104 while (ntv_iter != m_Natives.end())
106 g_ShareSys.ClearNativeFromCache(this, (*ntv_iter)->name);
107 ntv_iter = m_Natives.erase(ntv_iter);
111 void CNativeOwner::DropWeakRefsTo(CPlugin *pPlugin)
113 List<WeakNative>::iterator iter;
115 iter = m_WeakRefs.begin();
116 while (iter != m_WeakRefs.end())
118 WeakNative & ref = (*iter);
120 if (ref.pl == pPlugin)
122 iter = m_WeakRefs.erase(iter);
131 void CNativeOwner::DropRefsTo(CPlugin *pPlugin)
133 m_Dependents.remove(pPlugin);
134 DropWeakRefsTo(pPlugin);
137 void CNativeOwner::AddReplacedNative(NativeEntry *pEntry)
139 m_ReplacedNatives.push_back(pEntry);