diff options
Diffstat (limited to 'indra/newview/llcallbacklist.cpp')
-rwxr-xr-x[-rw-r--r--] | indra/newview/llcallbacklist.cpp | 79 |
1 files changed, 64 insertions, 15 deletions
diff --git a/indra/newview/llcallbacklist.cpp b/indra/newview/llcallbacklist.cpp index 357a6582d1..59ecbdd0ea 100644..100755 --- a/indra/newview/llcallbacklist.cpp +++ b/indra/newview/llcallbacklist.cpp @@ -27,6 +27,7 @@ #include "llviewerprecompiledheaders.h" #include "llcallbacklist.h" +#include "lleventtimer.h" // Library includes #include "llerror.h" @@ -55,7 +56,7 @@ void LLCallbackList::addFunction( callback_t func, void *data) { if (!func) { - llerrs << "LLCallbackList::addFunction - function is NULL" << llendl; + LL_ERRS() << "LLCallbackList::addFunction - function is NULL" << LL_ENDL; return; } @@ -180,19 +181,67 @@ void doOnIdleRepeating(bool_func_t callable) gIdleCallbacks.addFunction(&OnIdleCallbackRepeating::onIdle,cb_functor); } +class NullaryFuncEventTimer: public LLEventTimer +{ +public: + NullaryFuncEventTimer(nullary_func_t callable, F32 seconds): + LLEventTimer(seconds), + mCallable(callable) + { + } + +private: + BOOL tick() + { + mCallable(); + return TRUE; + } + + nullary_func_t mCallable; +}; + +// Call a given callable once after specified interval. +void doAfterInterval(nullary_func_t callable, F32 seconds) +{ + new NullaryFuncEventTimer(callable, seconds); +} + +class BoolFuncEventTimer: public LLEventTimer +{ +public: + BoolFuncEventTimer(bool_func_t callable, F32 seconds): + LLEventTimer(seconds), + mCallable(callable) + { + } +private: + BOOL tick() + { + return mCallable(); + } + + bool_func_t mCallable; +}; + +// Call a given callable every specified number of seconds, until it returns true. +void doPeriodically(bool_func_t callable, F32 seconds) +{ + new BoolFuncEventTimer(callable, seconds); +} + #ifdef _DEBUG void test1(void *data) { S32 *s32_data = (S32 *)data; - llinfos << "testfunc1 " << *s32_data << llendl; + LL_INFOS() << "testfunc1 " << *s32_data << LL_ENDL; } void test2(void *data) { S32 *s32_data = (S32 *)data; - llinfos << "testfunc2 " << *s32_data << llendl; + LL_INFOS() << "testfunc2 " << *s32_data << LL_ENDL; } @@ -203,54 +252,54 @@ LLCallbackList::test() S32 b = 2; LLCallbackList *list = new LLCallbackList; - llinfos << "Testing LLCallbackList" << llendl; + LL_INFOS() << "Testing LLCallbackList" << LL_ENDL; if (!list->deleteFunction(NULL)) { - llinfos << "passed 1" << llendl; + LL_INFOS() << "passed 1" << LL_ENDL; } else { - llinfos << "error, removed function from empty list" << llendl; + LL_INFOS() << "error, removed function from empty list" << LL_ENDL; } - // llinfos << "This should crash" << llendl; + // LL_INFOS() << "This should crash" << LL_ENDL; // list->addFunction(NULL); list->addFunction(&test1, &a); list->addFunction(&test1, &a); - llinfos << "Expect: test1 1, test1 1" << llendl; + LL_INFOS() << "Expect: test1 1, test1 1" << LL_ENDL; list->callFunctions(); list->addFunction(&test1, &b); list->addFunction(&test2, &b); - llinfos << "Expect: test1 1, test1 1, test1 2, test2 2" << llendl; + LL_INFOS() << "Expect: test1 1, test1 1, test1 2, test2 2" << LL_ENDL; list->callFunctions(); if (list->deleteFunction(&test1, &b)) { - llinfos << "passed 3" << llendl; + LL_INFOS() << "passed 3" << LL_ENDL; } else { - llinfos << "error removing function" << llendl; + LL_INFOS() << "error removing function" << LL_ENDL; } - llinfos << "Expect: test1 1, test1 1, test2 2" << llendl; + LL_INFOS() << "Expect: test1 1, test1 1, test2 2" << LL_ENDL; list->callFunctions(); list->deleteAllFunctions(); - llinfos << "Expect nothing" << llendl; + LL_INFOS() << "Expect nothing" << LL_ENDL; list->callFunctions(); - llinfos << "nothing :-)" << llendl; + LL_INFOS() << "nothing :-)" << LL_ENDL; delete list; - llinfos << "test complete" << llendl; + LL_INFOS() << "test complete" << LL_ENDL; } #endif // _DEBUG |