plugins/include/handles.h
author David Anderson <dvander@alliedmods.net>
Mon Jan 01 10:33:51 2007 +0000 (2007-01-01)
changeset 247 c110039da326
permissions -rw-r--r--
initial import of handle natives and a few minor API changes
dvander@247
     1
/**
dvander@247
     2
 * :TODO: license info
dvander@247
     3
 */
dvander@247
     4
dvander@247
     5
dvander@247
     6
#if defined _handles_included
dvander@247
     7
 #endinput
dvander@247
     8
#endif
dvander@247
     9
#define _handles_included
dvander@247
    10
dvander@247
    11
enum Handle
dvander@247
    12
{
dvander@247
    13
	INVALID_HANDLE = 0,
dvander@247
    14
};
dvander@247
    15
dvander@247
    16
/**
dvander@247
    17
 * @brief Returns if a handle is valid or not.
dvander@247
    18
 * @note It is not a good idea to call this on every Handle.  If you code properly,
dvander@247
    19
 *       all of your Handles will either be valid or will expose important bugs to fix.
dvander@247
    20
 *       This is provided for situations only where testing for handle validity is needed.
dvander@247
    21
 *
dvander@247
    22
 * @param hndl		Handle to test for validity.
dvander@247
    23
 * @return		True if handle is valid, false otherwise.
dvander@247
    24
 */
dvander@247
    25
native bool:IsValidHandle(Handle:hndl);
dvander@247
    26
dvander@247
    27
/**
dvander@247
    28
 * @brief Closes a Handle.  If the handle has multiple copies open, 
dvander@247
    29
 * it is not destroyed unless all copies are closed.
dvander@247
    30
 * 
dvander@247
    31
 * @note Closing a Handle has a different meaning for each Handle type.  Make
dvander@247
    32
 *       sure you read the documentation on whatever provided the Handle.
dvander@247
    33
 *
dvander@247
    34
 * @param hndl		Handle to close.
dvander@247
    35
 * @return		True if successful, false if not closeable.
dvander@247
    36
 * @error			Invalid handles will cause a run time error.
dvander@247
    37
 */
dvander@247
    38
native bool:CloseHandle(Handle:hndl);
dvander@247
    39
dvander@247
    40
/**
dvander@247
    41
 * @brief Clones a Handle.  When passing handles in between plugins, caching handles
dvander@247
    42
 * can result in accidental invalidation when one plugin releases the Handle, or is its owner
dvander@247
    43
 * is unloaded from memory.  To prevent this, the Handle may be "cloned" with a new owner.
dvander@247
    44
 * 
dvander@247
    45
 * @note Usually, you will be cloning Handles for other plugins.  This means that if you clone
dvander@247
    46
 * the Handle without specifying the new owner, it will assume the identity of your original calling
dvander@247
    47
 * plugin, which is not very useful.  You should either specify that the receiving plugin should
dvander@247
    48
 * clone the handle on its own, or you should explicitly clone the Handle using the receiving plugin's
dvander@247
    49
 * identity Handle.
dvander@247
    50
 *
dvander@247
    51
 * @param hndl		Handle to clone/duplicate.
dvander@247
    52
 * @param plugin	Optional Handle to another plugin to mark as the new owner.
dvander@247
    53
 *				If no owner is passed, the owner becomes the calling plugin.
dvander@247
    54
 * @return		Handle on success, INVALID_HANDLE if not cloneable.
dvander@247
    55
 * @error			Invalid handles will cause a run time error.
dvander@247
    56
 */
dvander@247
    57
native Handle:CloneHandle(Handle:hndl, Handle:plugin=INVALID_HANDLE);
dvander@247
    58