PageRenderTime 23ms CodeModel.GetById 12ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/llcallbacklist.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 66 lines | 26 code | 12 blank | 28 comment | 0 complexity | c41a1c62692bfdac51fae4c63162a648 MD5 | raw file
 1/** 
 2 * @file llcallbacklist.h
 3 * @brief A simple list of callback functions to call.
 4 *
 5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 */
26
27#ifndef LL_LLCALLBACKLIST_H
28#define LL_LLCALLBACKLIST_H
29
30#include "llstl.h"
31
32class LLCallbackList
33{
34public:
35	typedef void (*callback_t)(void*);
36	
37	LLCallbackList();
38	~LLCallbackList();
39
40	void addFunction( callback_t func, void *data = NULL );		// register a callback, which will be called as func(data)
41	BOOL containsFunction( callback_t func, void *data = NULL );	// true if list already contains the function/data pair
42	BOOL deleteFunction( callback_t func, void *data = NULL );		// removes the first instance of this function/data pair from the list, false if not found
43	void callFunctions();												// calls all functions
44	void deleteAllFunctions();
45
46	static void test();
47
48protected:
49	// Use a list so that the callbacks are ordered in case that matters
50	typedef std::pair<callback_t,void*> callback_pair_t;
51	typedef std::list<callback_pair_t > callback_list_t;
52	callback_list_t	mCallbackList;
53};
54
55typedef boost::function<void ()> nullary_func_t;
56typedef boost::function<bool ()> bool_func_t;
57
58// Call a given callable once in idle loop.
59void doOnIdleOneTime(nullary_func_t callable);
60
61// Repeatedly call a callable in idle loop until it returns true.
62void doOnIdleRepeating(bool_func_t callable);
63
64extern LLCallbackList gIdleCallbacks;
65
66#endif