initial import of sharesystem (unfinished)
final revision of handle system (I hope!) initial import of plugin handles --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40234
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
#define SMINTERFACE_HANDLESYSTEM_NAME "IHandleSys"
|
||||
#define SMINTERFACE_HANDLESYSTEM_VERSION 1
|
||||
|
||||
#define DEFAULT_IDENTITY NULL
|
||||
|
||||
namespace SourceMod
|
||||
{
|
||||
/**
|
||||
@@ -37,6 +39,7 @@ namespace SourceMod
|
||||
HandleError_Index, /* generic internal indexing error */
|
||||
HandleError_Access, /* No access permitted to free this handle */
|
||||
HandleError_Limit, /* The limited number of handles has been reached */
|
||||
HandleError_Identity, /* The identity token was not usable */
|
||||
};
|
||||
|
||||
enum HandleAccessRight
|
||||
@@ -54,14 +57,14 @@ namespace SourceMod
|
||||
{
|
||||
HandleSecurity()
|
||||
{
|
||||
owner = 0;
|
||||
owner = NULL;
|
||||
access[HandleAccess_Create] = true;
|
||||
access[HandleAccess_Read] = true;
|
||||
access[HandleAccess_Delete] = true;
|
||||
access[HandleAccess_Inherit] = true;
|
||||
access[HandleAccess_Clone] = true;
|
||||
}
|
||||
IdentityToken_t owner; /* Owner of the handle */
|
||||
IdentityToken_t *owner; /* Owner of the handle */
|
||||
bool access[HandleAccess_TOTAL]; /* World access rights */
|
||||
};
|
||||
|
||||
@@ -112,12 +115,14 @@ namespace SourceMod
|
||||
* @param parent Parent handle to inherit from, 0 for none.
|
||||
* @param security Pointer to a temporary HandleSecurity object, NULL to use default
|
||||
* or inherited permissions.
|
||||
* @param ident Security token for any permissions.
|
||||
* @return A new HandleType_t unique ID.
|
||||
*/
|
||||
virtual HandleType_t CreateTypeEx(const char *name,
|
||||
IHandleTypeDispatch *dispatch,
|
||||
HandleType_t parent,
|
||||
const HandleSecurity *security) =0;
|
||||
const HandleSecurity *security,
|
||||
IdentityToken_t *ident) =0;
|
||||
|
||||
|
||||
/**
|
||||
@@ -143,7 +148,7 @@ namespace SourceMod
|
||||
* @param type Type chain to remove.
|
||||
* @return True on success, false on failure.
|
||||
*/
|
||||
virtual bool RemoveType(HandleType_t type, IdentityToken_t ident) =0;
|
||||
virtual bool RemoveType(HandleType_t type, IdentityToken_t *ident) =0;
|
||||
|
||||
/**
|
||||
* @brief Finds a handle type by name.
|
||||
@@ -159,14 +164,14 @@ namespace SourceMod
|
||||
*
|
||||
* @param type Type to use on the handle.
|
||||
* @param object Object to bind to the handle.
|
||||
* @param source Identity token for object using this handle (for example, a script).
|
||||
* @param owner Owner for the handle.
|
||||
* @param ident Identity token if any security rights are needed.
|
||||
* @return A new Handle_t, or 0 on failure.
|
||||
*/
|
||||
virtual Handle_t CreateHandle(HandleType_t type,
|
||||
void *object,
|
||||
IdentityToken_t source,
|
||||
IdentityToken_t ident) =0;
|
||||
IdentityToken_t *owner,
|
||||
IdentityToken_t *ident) =0;
|
||||
|
||||
/**
|
||||
* @brief Creates a new handle.
|
||||
@@ -181,7 +186,7 @@ namespace SourceMod
|
||||
virtual Handle_t CreateScriptHandle(HandleType_t type,
|
||||
void *object,
|
||||
sp_context_t *ctx,
|
||||
IdentityToken_t ident) =0;
|
||||
IdentityToken_t *ident) =0;
|
||||
|
||||
/**
|
||||
* @brief Frees the memory associated with a handle and calls any destructors.
|
||||
@@ -192,7 +197,7 @@ namespace SourceMod
|
||||
* @param ident Identity token, for destroying secure handles (0 for none).
|
||||
* @return A HandleError error code.
|
||||
*/
|
||||
virtual HandleError FreeHandle(Handle_t handle, IdentityToken_t ident) =0;
|
||||
virtual HandleError FreeHandle(Handle_t handle, IdentityToken_t *ident) =0;
|
||||
|
||||
/**
|
||||
* @brief Clones a handle by adding to its internal reference count. Its data,
|
||||
@@ -200,11 +205,11 @@ namespace SourceMod
|
||||
*
|
||||
* @param handle Handle to duplicate. Any non-free handle target is valid.
|
||||
* @param newhandle If non-NULL, stores the duplicated handle in the pointer.
|
||||
* @param source New source of cloned handle.
|
||||
* @param owner New owner of cloned handle.
|
||||
* @param ident Security token, if needed.
|
||||
* @return A HandleError error code.
|
||||
*/
|
||||
virtual HandleError CloneHandle(Handle_t handle, Handle_t *newhandle, IdentityToken_t source, IdentityToken_t ident) =0;
|
||||
virtual HandleError CloneHandle(Handle_t handle, Handle_t *newhandle, IdentityToken_t *owner, IdentityToken_t *ident) =0;
|
||||
|
||||
/**
|
||||
* @brief Retrieves the contents of a handle.
|
||||
@@ -215,7 +220,7 @@ namespace SourceMod
|
||||
* @param object Address to store object in.
|
||||
* @return HandleError error code.
|
||||
*/
|
||||
virtual HandleError ReadHandle(Handle_t handle, HandleType_t type, IdentityToken_t ident, void **object) =0;
|
||||
virtual HandleError ReadHandle(Handle_t handle, HandleType_t type, IdentityToken_t *ident, void **object) =0;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ namespace SourceMod
|
||||
/**
|
||||
* @brief Returns a plugin's identity token.
|
||||
*/
|
||||
virtual IdentityToken_t GetIdentity() =0;
|
||||
virtual IdentityToken_t *GetIdentity() =0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -3,11 +3,13 @@
|
||||
|
||||
#include <sp_vm_types.h>
|
||||
|
||||
#define DEFAULT_IDENTITY 0
|
||||
#define NO_IDENTITY 0
|
||||
|
||||
namespace SourceMod
|
||||
{
|
||||
typedef unsigned int IdentityToken_t;
|
||||
struct IdentityToken_t;
|
||||
typedef unsigned int HandleType_t;
|
||||
typedef HandleType_t IdentityType_t;
|
||||
/**
|
||||
* @brief Defines the base functionality required by a shared interface.
|
||||
*/
|
||||
@@ -49,12 +51,13 @@ namespace SourceMod
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Adds an interface to the global interface system
|
||||
* @brief Adds an interface to the global interface system.
|
||||
*
|
||||
* @param iface Interface pointer (must be unique).
|
||||
* @param token Parent token of the module/interface.
|
||||
* @return True on success, false otherwise.
|
||||
*/
|
||||
virtual bool AddInterface(SMInterface *iface, IdentityToken_t token) =0;
|
||||
virtual bool AddInterface(SMInterface *iface, IdentityToken_t *token) =0;
|
||||
|
||||
/**
|
||||
* @brief Requests an interface from the global interface system.
|
||||
@@ -67,8 +70,8 @@ namespace SourceMod
|
||||
*/
|
||||
virtual bool RequestInterface(const char *iface_name,
|
||||
unsigned int iface_vers,
|
||||
IdentityToken_t token,
|
||||
void **pIface) =0;
|
||||
IdentityToken_t *token,
|
||||
SMInterface **pIface) =0;
|
||||
|
||||
/**
|
||||
* @brief Adds a list of natives to the global native pool.
|
||||
@@ -76,7 +79,54 @@ namespace SourceMod
|
||||
* @param token Identity token of parent object.
|
||||
* @param natives Array of natives to add, NULL terminated.
|
||||
*/
|
||||
virtual void AddNatives(IdentityToken_t token, const sp_nativeinfo_t *natives[]) =0;
|
||||
virtual void AddNatives(IdentityToken_t *token, const sp_nativeinfo_t *natives[]) =0;
|
||||
|
||||
/**
|
||||
* @brief Creates a new identity type.
|
||||
* NOTE: Module authors should never need to use this. Due to the current implementation,
|
||||
* there is a hardcoded limit of 15 types. Core uses up a few, so think carefully!
|
||||
*
|
||||
* @param name String containing type name. Must not be empty or NULL.
|
||||
* @return A new HandleType_t identifier, or 0 on failure.
|
||||
*/
|
||||
virtual IdentityType_t CreateIdentType(const char *name) =0;
|
||||
|
||||
/**
|
||||
* @brief Finds an identity type by name.
|
||||
* DEFAULT IDENTITY TYPES:
|
||||
* "PLUGIN" - An IPlugin object.
|
||||
* "MODULE" - An IModule object.
|
||||
* "CORE" - An SMGlobalClass or other singleton.
|
||||
*
|
||||
* @param name String containing type name to search for.
|
||||
* @return A HandleType_t identifier if found, 0 otherwise.
|
||||
*/
|
||||
virtual IdentityType_t FindIdentType(const char *name) =0;
|
||||
|
||||
/**
|
||||
* @brief Creates a new identity token. This token is guaranteed to be unique
|
||||
* amongst all other open identities.
|
||||
*
|
||||
* @param type Identity type.
|
||||
* @return A new IdentityToken_t identifier.
|
||||
*/
|
||||
virtual IdentityToken_t *CreateIdentity(IdentityType_t type) =0;
|
||||
|
||||
/**
|
||||
* @brief Destroys an identity type. Note that this will delete any identities
|
||||
* that are under this type.
|
||||
*
|
||||
* @param type Identity type.
|
||||
*/
|
||||
virtual void DestroyIdentType(IdentityType_t type) =0;
|
||||
|
||||
/**
|
||||
* @brief Destroys an identity token. Any handles being owned by this token, or
|
||||
* any handles being
|
||||
*
|
||||
* @param identity Identity to remove.
|
||||
*/
|
||||
virtual void DestroyIdentity(IdentityToken_t *identity) =0;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user