1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-18 19:47:15 +01:00

Further fixes of unreleased objects.

This commit is contained in:
Sandu Liviu Catalin 2020-05-11 17:51:39 +03:00
parent 59e4b9ad7c
commit f795981dd9
3 changed files with 98 additions and 0 deletions

View File

@ -42,6 +42,7 @@ extern void InitializeTasks();
extern void InitializeRoutines(); extern void InitializeRoutines();
extern void TerminateAreas(); extern void TerminateAreas();
extern void TerminateTasks(); extern void TerminateTasks();
extern void TerminatePrivileges();
extern void TerminateRoutines(); extern void TerminateRoutines();
extern void TerminateCommands(); extern void TerminateCommands();
extern void TerminateSignals(); extern void TerminateSignals();
@ -493,6 +494,8 @@ void Core::Terminate(bool shutdown)
TerminateSignals(); TerminateSignals();
// Release all managed areas // Release all managed areas
TerminateAreas(); TerminateAreas();
// Release privilege managers
TerminatePrivileges();
// In case there's a payload for reload // In case there's a payload for reload
m_ReloadPayload.Release(); m_ReloadPayload.Release();
// Release null objects in case any reference to valid objects is stored in them // Release null objects in case any reference to valid objects is stored in them

View File

@ -14,6 +14,9 @@ SQMODE_DECL_TYPENAME(ManagerTn, _SC("SqPrivilegeManager"))
// Helper value used to identify an index that doesn't exist. // Helper value used to identify an index that doesn't exist.
static constexpr size_t BAD_POS = ~static_cast< size_t >(0); static constexpr size_t BAD_POS = ~static_cast< size_t >(0);
// ------------------------------------------------------------------------------------------------
PvManagers PvManager::s_Managers;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
PvManager & PvUnit::GetManager() const PvManager & PvUnit::GetManager() const
{ {
@ -319,6 +322,10 @@ std::pair< PvUnit *, LightObj > PvManager::CreateUnitImpl(SQInteger id, PvClass
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
void TerminatePrivileges()
{
PvManager::Terminate();
}
// ================================================================================================ // ================================================================================================
void Register_Privilege(HSQUIRRELVM vm) void Register_Privilege(HSQUIRRELVM vm)

View File

@ -39,6 +39,8 @@ typedef std::vector< std::pair< SQInteger, PvUnit * > > PvUnitList;
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
typedef std::vector< std::pair< SQInteger, SQInteger > > PvStatusList; typedef std::vector< std::pair< SQInteger, SQInteger > > PvStatusList;
// ------------------------------------------------------------------------------------------------
typedef std::vector< PvManager * > PvManagers;
/* ------------------------------------------------------------------------------------------------ /* ------------------------------------------------------------------------------------------------
* An individual unit/entity that inherits the privileges of a class/group and can * An individual unit/entity that inherits the privileges of a class/group and can
@ -154,6 +156,18 @@ public:
bool operator <= (const PvUnit & o) const { return m_ID <= o.m_ID; } bool operator <= (const PvUnit & o) const { return m_ID <= o.m_ID; }
bool operator >= (const PvUnit & o) const { return m_ID >= o.m_ID; } bool operator >= (const PvUnit & o) const { return m_ID >= o.m_ID; }
/* --------------------------------------------------------------------------------------------
* Release all script resources. Recursively forward request.
*/
void Release()
{
m_OnQuery.Release();
m_OnGained.Release();
m_OnLost.Release();
m_Tag.Release();
m_Data.Release();
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the identifier associated with this unit. * Retrieve the identifier associated with this unit.
*/ */
@ -439,6 +453,18 @@ public:
bool operator <= (const PvClass & o) const { return m_ID <= o.m_ID; } bool operator <= (const PvClass & o) const { return m_ID <= o.m_ID; }
bool operator >= (const PvClass & o) const { return m_ID >= o.m_ID; } bool operator >= (const PvClass & o) const { return m_ID >= o.m_ID; }
/* --------------------------------------------------------------------------------------------
* Release all script resources. Recursively forward request.
*/
void Release()
{
m_OnQuery.Release();
m_OnGained.Release();
m_OnLost.Release();
m_Tag.Release();
m_Data.Release();
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the identifier associated with this manager. * Retrieve the identifier associated with this manager.
*/ */
@ -745,6 +771,20 @@ public:
bool operator <= (const PvEntry & o) const { return m_ID <= o.m_ID; } bool operator <= (const PvEntry & o) const { return m_ID <= o.m_ID; }
bool operator >= (const PvEntry & o) const { return m_ID >= o.m_ID; } bool operator >= (const PvEntry & o) const { return m_ID >= o.m_ID; }
/* --------------------------------------------------------------------------------------------
* Release all script resources. Recursively forward request.
*/
void Release()
{
m_Tag.Release();
m_OnQuery.Release();
m_OnGained.Release();
m_OnLost.Release();
m_Data.Release();
m_Brief.Release();
m_Info.Release();
}
/* -------------------------------------------------------------------------------------------- /* --------------------------------------------------------------------------------------------
* Retrieve the manager associated with this unit. * Retrieve the manager associated with this unit.
*/ */
@ -980,6 +1020,11 @@ private:
*/ */
LightObj m_Data; LightObj m_Data;
/* --------------------------------------------------------------------------------------------
* List of active privilege managers.
*/
static PvManagers s_Managers;
public: public:
/* ------------------------------------------------------------------------------------------- /* -------------------------------------------------------------------------------------------
@ -990,6 +1035,7 @@ public:
, m_OnQuery(), m_OnGained(), m_OnLost() , m_OnQuery(), m_OnGained(), m_OnLost()
, m_Tag(), m_Data() , m_Tag(), m_Data()
{ {
s_Managers.push_back(this);
} }
/* ------------------------------------------------------------------------------------------- /* -------------------------------------------------------------------------------------------
@ -1000,6 +1046,7 @@ public:
, m_OnQuery(), m_OnGained(), m_OnLost() , m_OnQuery(), m_OnGained(), m_OnLost()
, m_Tag(std::move(tag)), m_Data() , m_Tag(std::move(tag)), m_Data()
{ {
s_Managers.push_back(this);
} }
/* ------------------------------------------------------------------------------------------- /* -------------------------------------------------------------------------------------------
@ -1017,6 +1064,7 @@ public:
*/ */
~PvManager() ~PvManager()
{ {
s_Managers.erase(std::remove(s_Managers.begin(), s_Managers.end(), this), s_Managers.end());
} }
/* ------------------------------------------------------------------------------------------- /* -------------------------------------------------------------------------------------------
@ -1231,6 +1279,46 @@ public:
{ {
return m_OnGained; return m_OnGained;
} }
/* --------------------------------------------------------------------------------------------
* Release all script resources. Recursively forward request to all classes, units and entries.
*/
void Release()
{
// Release objects from entries
for (auto & pve : m_Entries)
{
pve.second->Release();
}
// Release objects from classes
for (auto & pvc : m_Classes)
{
pvc.second->Release();
}
// Release objects from units
for (auto & pvu : m_Units)
{
pvu.second->Release();
}
// Release objects from this instance
m_OnQuery.Release();
m_OnGained.Release();
m_OnLost.Release();
m_Tag.Release();
m_Data.Release();
}
/* --------------------------------------------------------------------------------------------
* Terminate the all managers by releasing their classes and units and callbacks.
*/
static void Terminate()
{
for (auto & pvm : s_Managers)
{
pvm->Release();
}
}
}; };
} // Namespace:: SqMod } // Namespace:: SqMod