plugins/include/handles.inc
changeset 1952 b7aa2b626807
child 2289 44045ead61cd
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plugins/include/handles.inc	Sun Mar 30 07:00:22 2008 +0000
     1.3 @@ -0,0 +1,96 @@
     1.4 +/**
     1.5 + * vim: set ts=4 :
     1.6 + * =============================================================================
     1.7 + * SourceMod (C)2004-2008 AlliedModders LLC.  All rights reserved.
     1.8 + * =============================================================================
     1.9 + *
    1.10 + * This file is part of the SourceMod/SourcePawn SDK.
    1.11 + *
    1.12 + * This program is free software; you can redistribute it and/or modify it under
    1.13 + * the terms of the GNU General Public License, version 3.0, as published by the
    1.14 + * Free Software Foundation.
    1.15 + * 
    1.16 + * This program is distributed in the hope that it will be useful, but WITHOUT
    1.17 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    1.18 + * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    1.19 + * details.
    1.20 + *
    1.21 + * You should have received a copy of the GNU General Public License along with
    1.22 + * this program.  If not, see <http://www.gnu.org/licenses/>.
    1.23 + *
    1.24 + * As a special exception, AlliedModders LLC gives you permission to link the
    1.25 + * code of this program (as well as its derivative works) to "Half-Life 2," the
    1.26 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    1.27 + * by the Valve Corporation.  You must obey the GNU General Public License in
    1.28 + * all respects for all other code used.  Additionally, AlliedModders LLC grants
    1.29 + * this exception to all derivative works.  AlliedModders LLC defines further
    1.30 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    1.31 + * or <http://www.sourcemod.net/license.php>.
    1.32 + *
    1.33 + * Version: $Id$
    1.34 + */
    1.35 +
    1.36 +#if defined _handles_included
    1.37 + #endinput
    1.38 +#endif
    1.39 +#define _handles_included
    1.40 +
    1.41 +/**
    1.42 + * Handle helper macros.
    1.43 + */
    1.44 +enum Handle
    1.45 +{
    1.46 +	INVALID_HANDLE = 0,
    1.47 +};
    1.48 +
    1.49 +
    1.50 +/**
    1.51 + * Closes a Handle.  If the handle has multiple copies open, 
    1.52 + * it is not destroyed unless all copies are closed.
    1.53 + * 
    1.54 + * @note Closing a Handle has a different meaning for each Handle type.  Make
    1.55 + *       sure you read the documentation on whatever provided the Handle.
    1.56 + *
    1.57 + * @param hndl		Handle to close.
    1.58 + * @return			True if successful, false if not closeable.
    1.59 + * @error			Invalid handles will cause a run time error.
    1.60 + */
    1.61 +native bool:CloseHandle(Handle:hndl);
    1.62 +
    1.63 +/**
    1.64 + * Clones a Handle.  When passing handles in between plugins, caching handles
    1.65 + * can result in accidental invalidation when one plugin releases the Handle, or is its owner
    1.66 + * is unloaded from memory.  To prevent this, the Handle may be "cloned" with a new owner.
    1.67 + * 
    1.68 + * @note Usually, you will be cloning Handles for other plugins.  This means that if you clone
    1.69 + * the Handle without specifying the new owner, it will assume the identity of your original calling
    1.70 + * plugin, which is not very useful.  You should either specify that the receiving plugin should
    1.71 + * clone the handle on its own, or you should explicitly clone the Handle using the receiving plugin's
    1.72 + * identity Handle.
    1.73 + *
    1.74 + * @param hndl		Handle to clone/duplicate.
    1.75 + * @param plugin	Optional Handle to another plugin to mark as the new owner.
    1.76 + *					If no owner is passed, the owner becomes the calling plugin.
    1.77 + * @return			Handle on success, INVALID_HANDLE if not cloneable.
    1.78 + * @error			Invalid handles will cause a run time error.
    1.79 + */
    1.80 +native Handle:CloneHandle(Handle:hndl, Handle:plugin=INVALID_HANDLE);
    1.81 +
    1.82 +/**
    1.83 + * Do not use this function.  Returns if a Handle and its contents 
    1.84 + * are readable, whereas INVALID_HANDLE only checks for the absence 
    1.85 + * of a Handle.
    1.86 + *
    1.87 + * This function is intended only for tests where the validity of a 
    1.88 + * Handle can absolutely not be known. 
    1.89 + *
    1.90 + * Do not use this to check the return values of functions, or to 
    1.91 + * check if timers should be closed (except in very rare cases).  
    1.92 + * This function is for very specific usage and using it for general 
    1.93 + * purpose routines can and will hide very subtle bugs.
    1.94 + *
    1.95 + * @param hndl		Handle to test for validity.
    1.96 + * @return			True if handle is valid, false otherwise.
    1.97 + */
    1.98 +#pragma deprecated Do not use this function.
    1.99 +native bool:IsValidHandle(Handle:hndl);