aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llcallbacklist.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llcallbacklist.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/newview/llcallbacklist.cpp')
-rw-r--r--linden/indra/newview/llcallbacklist.cpp192
1 files changed, 192 insertions, 0 deletions
diff --git a/linden/indra/newview/llcallbacklist.cpp b/linden/indra/newview/llcallbacklist.cpp
new file mode 100644
index 0000000..3931371
--- /dev/null
+++ b/linden/indra/newview/llcallbacklist.cpp
@@ -0,0 +1,192 @@
1/**
2 * @file llcallbacklist.cpp
3 * @brief A simple list of callback functions to call.
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include "llcallbacklist.h"
31
32// Library includes
33#include "llerror.h"
34
35
36//
37// Globals
38//
39LLCallbackList gIdleCallbacks;
40
41//
42// Member functions
43//
44
45LLCallbackList::LLCallbackList()
46{
47 // nothing
48}
49
50LLCallbackList::~LLCallbackList()
51{
52}
53
54
55void LLCallbackList::addFunction( callback_t func, void *data)
56{
57 if (!func)
58 {
59 llerrs << "LLCallbackList::addFunction - function is NULL" << llendl;
60 return;
61 }
62
63 // only add one callback per func/data pair
64 callback_pair_t t(func, data);
65 callback_list_t::iterator iter = std::find(mCallbackList.begin(), mCallbackList.end(), t);
66 if (iter == mCallbackList.end())
67 {
68 mCallbackList.push_back(t);
69 }
70}
71
72
73BOOL LLCallbackList::containsFunction( callback_t func, void *data)
74{
75 callback_pair_t t(func, data);
76 callback_list_t::iterator iter = std::find(mCallbackList.begin(), mCallbackList.end(), t);
77 if (iter != mCallbackList.end())
78 {
79 return TRUE;
80 }
81 else
82 {
83 return FALSE;
84 }
85}
86
87
88BOOL LLCallbackList::deleteFunction( callback_t func, void *data)
89{
90 callback_pair_t t(func, data);
91 callback_list_t::iterator iter = std::find(mCallbackList.begin(), mCallbackList.end(), t);
92 if (iter != mCallbackList.end())
93 {
94 mCallbackList.erase(iter);
95 return TRUE;
96 }
97 else
98 {
99 return FALSE;
100 }
101}
102
103
104void LLCallbackList::deleteAllFunctions()
105{
106 mCallbackList.clear();
107}
108
109
110void LLCallbackList::callFunctions()
111{
112 for (callback_list_t::iterator iter = mCallbackList.begin(); iter != mCallbackList.end(); )
113 {
114 callback_list_t::iterator curiter = iter++;
115 curiter->first(curiter->second);
116 }
117}
118
119#ifdef _DEBUG
120
121void test1(void *data)
122{
123 S32 *s32_data = (S32 *)data;
124 llinfos << "testfunc1 " << *s32_data << llendl;
125}
126
127
128void test2(void *data)
129{
130 S32 *s32_data = (S32 *)data;
131 llinfos << "testfunc2 " << *s32_data << llendl;
132}
133
134
135void
136LLCallbackList::test()
137{
138 S32 a = 1;
139 S32 b = 2;
140 LLCallbackList *list = new LLCallbackList;
141
142 llinfos << "Testing LLCallbackList" << llendl;
143
144 if (!list->deleteFunction(NULL))
145 {
146 llinfos << "passed 1" << llendl;
147 }
148 else
149 {
150 llinfos << "error, removed function from empty list" << llendl;
151 }
152
153 // llinfos << "This should crash" << llendl;
154 // list->addFunction(NULL);
155
156 list->addFunction(&test1, &a);
157 list->addFunction(&test1, &a);
158
159 llinfos << "Expect: test1 1, test1 1" << llendl;
160 list->callFunctions();
161
162 list->addFunction(&test1, &b);
163 list->addFunction(&test2, &b);
164
165 llinfos << "Expect: test1 1, test1 1, test1 2, test2 2" << llendl;
166 list->callFunctions();
167
168 if (list->deleteFunction(&test1, &b))
169 {
170 llinfos << "passed 3" << llendl;
171 }
172 else
173 {
174 llinfos << "error removing function" << llendl;
175 }
176
177 llinfos << "Expect: test1 1, test1 1, test2 2" << llendl;
178 list->callFunctions();
179
180 list->deleteAllFunctions();
181
182 llinfos << "Expect nothing" << llendl;
183 list->callFunctions();
184
185 llinfos << "nothing :-)" << llendl;
186
187 delete list;
188
189 llinfos << "test complete" << llendl;
190}
191
192#endif // _DEBUG