- Interface dropping semantics are now changed, any pointer can be piped through.

- IDBDriver lets you bind driver dependencies and cleanly shutdown now

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%402315
This commit is contained in:
David Anderson 2008-07-01 06:12:16 +00:00
parent 4106620928
commit 968045ae62
6 changed files with 47 additions and 7 deletions

View File

@ -717,3 +717,9 @@ const char *DBManager::GetDefaultDriverName()
{ {
return m_DefDriver.c_str(); return m_DefDriver.c_str();
} }
void DBManager::AddDependency(IExtension *myself, IDBDriver *driver)
{
g_Extensions.AddRawDependency(myself, driver->GetIdentity(), driver);
}

View File

@ -92,6 +92,7 @@ public: //IDBManager
Handle_t CreateHandle(DBHandleType type, void *ptr, IdentityToken_t *pToken); Handle_t CreateHandle(DBHandleType type, void *ptr, IdentityToken_t *pToken);
HandleError ReadHandle(Handle_t hndl, DBHandleType type, void **ptr); HandleError ReadHandle(Handle_t hndl, DBHandleType type, void **ptr);
HandleError ReleaseHandle(Handle_t hndl, DBHandleType type, IdentityToken_t *token); HandleError ReleaseHandle(Handle_t hndl, DBHandleType type, IdentityToken_t *token);
void AddDependency(IExtension *myself, IDBDriver *driver);
public: //ITextListener_SMC public: //ITextListener_SMC
void ReadSMC_ParseStart(); void ReadSMC_ParseStart();
SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name); SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);

View File

@ -305,7 +305,7 @@ bool CLocalExtension::IsLoaded()
return (m_pLib != NULL); return (m_pLib != NULL);
} }
void CExtension::AddDependency(IfaceInfo *pInfo) void CExtension::AddDependency(const IfaceInfo *pInfo)
{ {
if (m_Deps.find(*pInfo) == m_Deps.end()) if (m_Deps.find(*pInfo) == m_Deps.end())
{ {
@ -633,6 +633,20 @@ void CExtensionManager::BindDependency(IExtension *pRequester, IfaceInfo *pInfo)
} }
} }
void CExtensionManager::AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface)
{
CExtension *pExt = (CExtension *)ext;
CExtension *pOwner = GetExtensionFromIdent(other);
IfaceInfo info;
info.iface = (SMInterface *)iface;
info.owner = pOwner;
pExt->AddDependency(&info);
pOwner->AddChildDependent(pExt, (SMInterface *)iface);
}
void CExtensionManager::AddInterface(IExtension *pOwner, SMInterface *pInterface) void CExtensionManager::AddInterface(IExtension *pOwner, SMInterface *pInterface)
{ {
CExtension *pExt = (CExtension *)pOwner; CExtension *pExt = (CExtension *)pOwner;

View File

@ -73,7 +73,7 @@ public: //IExtension
bool IsRunning(char *error, size_t maxlength); bool IsRunning(char *error, size_t maxlength);
public: public:
void SetError(const char *error); void SetError(const char *error);
void AddDependency(IfaceInfo *pInfo); void AddDependency(const IfaceInfo *pInfo);
void AddChildDependent(CExtension *pOther, SMInterface *iface); void AddChildDependent(CExtension *pOther, SMInterface *iface);
void AddInterface(SMInterface *pInterface); void AddInterface(SMInterface *pInterface);
void AddPlugin(CPlugin *pPlugin); void AddPlugin(CPlugin *pPlugin);
@ -166,6 +166,7 @@ public:
void AddLibrary(IExtension *pSource, const char *library); void AddLibrary(IExtension *pSource, const char *library);
bool LibraryExists(const char *library); bool LibraryExists(const char *library);
void CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax); void CallOnCoreMapStart(edict_t *pEdictList, int edictCount, int clientMax);
void AddRawDependency(IExtension *ext, IdentityToken_t *other, void *iface);
public: public:
CExtension *GetExtensionFromIdent(IdentityToken_t *ptr); CExtension *GetExtensionFromIdent(IdentityToken_t *ptr);
void Shutdown(); void Shutdown();

View File

@ -42,7 +42,7 @@
*/ */
#define SMINTERFACE_DBI_NAME "IDBI" #define SMINTERFACE_DBI_NAME "IDBI"
#define SMINTERFACE_DBI_VERSION 6 #define SMINTERFACE_DBI_VERSION 7
namespace SourceMod namespace SourceMod
{ {
@ -867,7 +867,16 @@ namespace SourceMod
* @return True on success, false on failure. * @return True on success, false on failure.
*/ */
virtual bool AddToThreadQueue(IDBThreadOperation *op, PrioQueueLevel prio) =0; virtual bool AddToThreadQueue(IDBThreadOperation *op, PrioQueueLevel prio) =0;
/**
* @brief Adds a dependency from one extension to the owner of a driver.
*
* @param myself Extension that is using the IDBDriver.
* @param driver Driver that is being used.
*/
virtual void AddDependency(IExtension *myself, IDBDriver *driver) =0;
}; };
} }
#endif //_INCLUDE_SOURCEMOD_INTERFACE_DBDRIVER_H_ #endif //_INCLUDE_SOURCEMOD_INTERFACE_DBDRIVER_H_

View File

@ -186,10 +186,16 @@ namespace SourceMod
* interface it's using. If it's not safe, return false, and the * interface it's using. If it's not safe, return false, and the
* extension will be unloaded afterwards. * extension will be unloaded afterwards.
* *
* NOTE: It is important to also hook NotifyInterfaceDrop() in order to clean up resources. * NOTE: It is important to also hook NotifyInterfaceDrop() in order to clean
* up resources.
* *
* @param pInterface Pointer to interface being dropped. * @param pInterface Pointer to interface being dropped. This
* @return True to continue, false to unload this extension afterwards. * pointer may be opaque, and it should not
* be queried using SMInterface functions unless
* it can be verified to match an existing
* pointer of known type.
* @return True to continue, false to unload this
* extension afterwards.
*/ */
virtual bool QueryInterfaceDrop(SMInterface *pInterface) virtual bool QueryInterfaceDrop(SMInterface *pInterface)
{ {
@ -199,7 +205,10 @@ namespace SourceMod
/** /**
* @brief Notifies the extension that an external interface it uses is being removed. * @brief Notifies the extension that an external interface it uses is being removed.
* *
* @param pInterface Pointer to interface being dropped. * @param pInterface Pointer to interface being dropped. This
* pointer may be opaque, and it should not
* be queried using SMInterface functions unless
* it can be verified to match an existing
*/ */
virtual void NotifyInterfaceDrop(SMInterface *pInterface) virtual void NotifyInterfaceDrop(SMInterface *pInterface)
{ {