Improved docs of TIMER_HNDL_CLOSE (bug 3641, r=dvander).

This commit is contained in:
Fyren 2009-03-01 16:48:55 -05:00
parent 98c1a18e57
commit e6ea726b69
2 changed files with 23 additions and 20 deletions

View File

@ -35,6 +35,7 @@
#include "Logger.h" #include "Logger.h"
#include "DebugReporter.h" #include "DebugReporter.h"
#define TIMER_DATA_HNDL_CLOSE (1<<9)
#define TIMER_HNDL_CLOSE (1<<9) #define TIMER_HNDL_CLOSE (1<<9)
HandleType_t g_TimerType; HandleType_t g_TimerType;
@ -147,14 +148,14 @@ void TimerNatives::OnTimerEnd(ITimer *pTimer, void *pData)
sec.pOwner = pInfo->pContext->GetIdentity(); sec.pOwner = pInfo->pContext->GetIdentity();
sec.pIdentity = g_pCoreIdent; sec.pIdentity = g_pCoreIdent;
if (pInfo->Flags & TIMER_HNDL_CLOSE) if (pInfo->Flags & TIMER_DATA_HNDL_CLOSE)
{ {
if ((herr=g_HandleSys.FreeHandle(usrhndl, &sec)) != HandleError_None) if ((herr=g_HandleSys.FreeHandle(usrhndl, &sec)) != HandleError_None)
{ {
g_DbgReporter.GenerateError(pInfo->pContext, g_DbgReporter.GenerateError(pInfo->pContext,
pInfo->Hook->GetFunctionID(), pInfo->Hook->GetFunctionID(),
SP_ERROR_NATIVE, SP_ERROR_NATIVE,
"Invalid data handle %x (error %d) passed during timer end", "Invalid data handle %x (error %d) passed during timer end with TIMER_DATA_HNDL_CLOSE",
usrhndl, usrhndl,
herr); herr);
} }
@ -215,7 +216,7 @@ static cell_t smn_CreateTimer(IPluginContext *pCtx, const cell_t *params)
if (hndl == BAD_HANDLE) if (hndl == BAD_HANDLE)
{ {
/* Free this for completeness. */ /* Free this for completeness. */
if (flags & TIMER_HNDL_CLOSE) if (flags & TIMER_DATA_HNDL_CLOSE)
{ {
HandleSecurity sec(pCtx->GetIdentity(), g_pCoreIdent); HandleSecurity sec(pCtx->GetIdentity(), g_pCoreIdent);
g_HandleSys.FreeHandle(params[3], &sec); g_HandleSys.FreeHandle(params[3], &sec);
@ -255,14 +256,14 @@ static cell_t smn_KillTimer(IPluginContext *pCtx, const cell_t *params)
g_Timers.KillTimer(pInfo->Timer); g_Timers.KillTimer(pInfo->Timer);
if (params[2] && !(pInfo->Flags & TIMER_HNDL_CLOSE)) if (params[2] && !(pInfo->Flags & TIMER_DATA_HNDL_CLOSE))
{ {
sec.pOwner = pInfo->pContext->GetIdentity(); sec.pOwner = pInfo->pContext->GetIdentity();
sec.pIdentity = g_pCoreIdent; sec.pIdentity = g_pCoreIdent;
if ((herr=g_HandleSys.FreeHandle(static_cast<Handle_t>(pInfo->UserData), &sec)) != HandleError_None) if ((herr=g_HandleSys.FreeHandle(static_cast<Handle_t>(pInfo->UserData), &sec)) != HandleError_None)
{ {
return pCtx->ThrowNativeError("Invalid data handle %x (error %d)", hndl, herr); return pCtx->ThrowNativeError("Invalid data handle %x (error %d) on timer kill with TIMER_DATA_HNDL_CLOSE", hndl, herr);
} }
} }

View File

@ -39,7 +39,8 @@
#define TIMER_REPEAT (1<<0) /**< Timer will repeat until it returns Plugin_Stop */ #define TIMER_REPEAT (1<<0) /**< Timer will repeat until it returns Plugin_Stop */
#define TIMER_FLAG_NO_MAPCHANGE (1<<1) /**< Timer will not carry over mapchanges */ #define TIMER_FLAG_NO_MAPCHANGE (1<<1) /**< Timer will not carry over mapchanges */
#define TIMER_HNDL_CLOSE (1<<9) /**< Timer will automatically call CloseHandle() on its value when finished */ #define TIMER_HNDL_CLOSE (1<<9) /**< Deprecated define, replaced by below */
#define TIMER_DATA_HNDL_CLOSE (1<<9) /**< Timer will automatically call CloseHandle() on its data when finished */
/** /**
* Any of the following prototypes will work for a timed function. * Any of the following prototypes will work for a timed function.
@ -50,7 +51,7 @@ funcenum Timer
* Called when the timer interval has elapsed. * Called when the timer interval has elapsed.
* *
* @param timer Handle to the timer object. * @param timer Handle to the timer object.
* @param hndl Handle passed when the timer was created. * @param hndl Handle passed to CreateTimer() when timer was created.
* @return Plugin_Stop to stop a repeating timer, any other value for * @return Plugin_Stop to stop a repeating timer, any other value for
* default behavior. * default behavior.
*/ */
@ -60,11 +61,11 @@ funcenum Timer
* Called when the timer interval has elapsed. * Called when the timer interval has elapsed.
* *
* @param timer Handle to the timer object. * @param timer Handle to the timer object.
* @param value Value passed when the timer was created. * @param data Data passed to CreateTimer() when timer was created.
* @return Plugin_Stop to stop a repeating timer, any other value for * @return Plugin_Stop to stop a repeating timer, any other value for
* default behavior. * default behavior.
*/ */
Action:public(Handle:timer, any:value), Action:public(Handle:timer, any:data),
/** /**
* Called when the timer interval has elapsed. * Called when the timer interval has elapsed.
@ -81,18 +82,18 @@ funcenum Timer
* *
* @param interval Interval from the current game time to execute the given function. * @param interval Interval from the current game time to execute the given function.
* @param func Function to execute once the given interval has elapsed. * @param func Function to execute once the given interval has elapsed.
* @param value Handle or value to give to the timer function. * @param data Handle or value to pass through to the timer callback function.
* @param flags Flags to set (such as repeatability or auto-Handle closing). * @param flags Flags to set (such as repeatability or auto-Handle closing).
* @return Handle to the timer object. You do not need to call CloseHandle(). * @return Handle to the timer object. You do not need to call CloseHandle().
* If the timer could not be created, INVALID_HANDLE will be returned. * If the timer could not be created, INVALID_HANDLE will be returned.
*/ */
native Handle:CreateTimer(Float:interval, Timer:func, any:value=INVALID_HANDLE, flags=0); native Handle:CreateTimer(Float:interval, Timer:func, any:data=INVALID_HANDLE, flags=0);
/** /**
* Kills a timer. Use this instead of CloseHandle() if you need more options. * Kills a timer. Use this instead of CloseHandle() if you need more options.
* *
* @param autoClose If autoClose is true, the timer's value will be * @param autoClose If autoClose is true, the data that was passed to CreateTimer() will
* closed as a handle if TIMER_HNDL_CLOSE was not specified. * be closed as a handle if TIMER_DATA_HNDL_CLOSE was not specified.
* @noreturn * @noreturn
*/ */
native KillTimer(Handle:timer, bool:autoClose=false); native KillTimer(Handle:timer, bool:autoClose=false);
@ -195,14 +196,15 @@ native bool:IsServerProcessing();
* *
* @param interval Interval from the current game time to execute the given function. * @param interval Interval from the current game time to execute the given function.
* @param func Function to execute once the given interval has elapsed. * @param func Function to execute once the given interval has elapsed.
* @param data The newly created datapack is passed though this by-reference parameter. * @param datapack The newly created datapack is passed though this by-reference
* parameter to the timer callback function.
* @param flags Timer flags. * @param flags Timer flags.
* @return Handle to the timer object. You do not need to call CloseHandle(). * @return Handle to the timer object. You do not need to call CloseHandle().
*/ */
stock Handle:CreateDataTimer(Float:interval, Timer:func, &Handle:data, flags=0) stock Handle:CreateDataTimer(Float:interval, Timer:func, &Handle:datapack, flags=0)
{ {
data = CreateDataPack(); datapack = CreateDataPack();
flags |= TIMER_HNDL_CLOSE; flags |= TIMER_DATA_HNDL_CLOSE;
return CreateTimer(interval, func, data, flags); return CreateTimer(interval, func, datapack, flags);
} }