/addons/sourcemod/scripting/include/handles.inc
Pascal | 96 lines | 89 code | 5 blank | 2 comment | 7 complexity | 8a7baf417b9bca05c9c8e5af46099195 MD5 | raw file
1/**
2 * vim: set ts=4 :
3 * =============================================================================
4 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
5 * =============================================================================
6 *
7 * This file is part of the SourceMod/SourcePawn SDK.
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, version 3.0, as published by the
11 * Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * As a special exception, AlliedModders LLC gives you permission to link the
22 * code of this program (as well as its derivative works) to "Half-Life 2," the
23 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
24 * by the Valve Corporation. You must obey the GNU General Public License in
25 * all respects for all other code used. Additionally, AlliedModders LLC grants
26 * this exception to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
28 * or <http://www.sourcemod.net/license.php>.
29 *
30 * Version: $Id$
31 */
32
33#if defined _handles_included
34 #endinput
35#endif
36#define _handles_included
37
38/**
39 * Handle helper macros.
40 */
41enum Handle
42{
43 INVALID_HANDLE = 0,
44};
45
46
47/**
48 * Closes a Handle. If the handle has multiple copies open,
49 * it is not destroyed unless all copies are closed.
50 *
51 * @note Closing a Handle has a different meaning for each Handle type. Make
52 * sure you read the documentation on whatever provided the Handle.
53 *
54 * @param hndl Handle to close.
55 * @return True if successful, false if not closeable.
56 * @error Invalid handles will cause a run time error.
57 */
58native bool:CloseHandle(Handle:hndl);
59
60/**
61 * Clones a Handle. When passing handles in between plugins, caching handles
62 * can result in accidental invalidation when one plugin releases the Handle, or is its owner
63 * is unloaded from memory. To prevent this, the Handle may be "cloned" with a new owner.
64 *
65 * @note Usually, you will be cloning Handles for other plugins. This means that if you clone
66 * the Handle without specifying the new owner, it will assume the identity of your original calling
67 * plugin, which is not very useful. You should either specify that the receiving plugin should
68 * clone the handle on its own, or you should explicitly clone the Handle using the receiving plugin's
69 * identity Handle.
70 *
71 * @param hndl Handle to clone/duplicate.
72 * @param plugin Optional Handle to another plugin to mark as the new owner.
73 * If no owner is passed, the owner becomes the calling plugin.
74 * @return Handle on success, INVALID_HANDLE if not cloneable.
75 * @error Invalid handles will cause a run time error.
76 */
77native Handle:CloneHandle(Handle:hndl, Handle:plugin=INVALID_HANDLE);
78
79/**
80 * Do not use this function. Returns if a Handle and its contents
81 * are readable, whereas INVALID_HANDLE only checks for the absence
82 * of a Handle.
83 *
84 * This function is intended only for tests where the validity of a
85 * Handle can absolutely not be known.
86 *
87 * Do not use this to check the return values of functions, or to
88 * check if timers should be closed (except in very rare cases).
89 * This function is for very specific usage and using it for general
90 * purpose routines can and will hide very subtle bugs.
91 *
92 * @param hndl Handle to test for validity.
93 * @return True if handle is valid, false otherwise.
94 */
95#pragma deprecated Do not use this function.
96native bool:IsValidHandle(Handle:hndl);