PageRenderTime 396ms CodeModel.GetById 201ms app.highlight 17ms RepoModel.GetById 174ms app.codeStats 1ms

/indra/newview/llinventoryobserver.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 329 lines | 168 code | 45 blank | 116 comment | 0 complexity | 3e43fbf36be6c7726cfbda51e1b5dc77 MD5 | raw file
  1/** 
  2 * @file llinventoryobserver.h
  3 * @brief LLInventoryObserver class header file
  4 *
  5 * $LicenseInfo:firstyear=2002&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_LLINVENTORYOBSERVERS_H
 28#define LL_LLINVENTORYOBSERVERS_H
 29
 30#include "lluuid.h"
 31#include "llmd5.h"
 32#include <string>
 33#include <vector>
 34
 35class LLViewerInventoryCategory;
 36
 37//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 38// Class LLInventoryObserver
 39//
 40//   A simple abstract base class that can relay messages when the inventory 
 41//   changes.
 42//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 43class LLInventoryObserver
 44{
 45public:
 46	// This enumeration is a way to refer to what changed in a more
 47	// human readable format. You can mask the value provided by
 48	// chaged() to see if the observer is interested in the change.
 49	enum 
 50	{
 51		NONE 			= 0,
 52		LABEL 			= 1,	// Name changed
 53		INTERNAL 		= 2,	// Internal change (e.g. asset uuid different)
 54		ADD 			= 4,	// Something added
 55		REMOVE 			= 8,	// Something deleted
 56		STRUCTURE 		= 16,	// Structural change (e.g. item or folder moved)
 57		CALLING_CARD	= 32,	// Calling card change (e.g. online, grant status, cancel)
 58		GESTURE 		= 64,
 59		REBUILD 		= 128, 	// Item UI changed (e.g. item type different)
 60		SORT 			= 256, 	// Folder needs to be resorted.
 61		ALL 			= 0xffffffff
 62	};
 63	LLInventoryObserver();
 64	virtual ~LLInventoryObserver();
 65	virtual void changed(U32 mask) = 0;
 66};
 67
 68//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 69// Class LLInventoryFetchObserver
 70//
 71//   Abstract class to handle fetching items, folders, etc.
 72//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 73class LLInventoryFetchObserver : public LLInventoryObserver
 74{
 75public:
 76	LLInventoryFetchObserver(const LLUUID& id = LLUUID::null); // single item
 77	LLInventoryFetchObserver(const uuid_vec_t& ids); // multiple items
 78	void setFetchID(const LLUUID& id);
 79	void setFetchIDs(const uuid_vec_t& ids);
 80
 81	BOOL isFinished() const;
 82
 83	virtual void startFetch() = 0;
 84	virtual void changed(U32 mask) = 0;
 85	virtual void done() {};
 86protected:
 87	uuid_vec_t mComplete;
 88	uuid_vec_t mIncomplete;
 89	uuid_vec_t mIDs;
 90};
 91
 92//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 93// Class LLInventoryFetchItemsObserver
 94//
 95//   Fetches inventory items, calls done() when all inventory has arrived. 
 96//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 97class LLInventoryFetchItemsObserver : public LLInventoryFetchObserver
 98{
 99public:
100	LLInventoryFetchItemsObserver(const LLUUID& item_id = LLUUID::null); 
101	LLInventoryFetchItemsObserver(const uuid_vec_t& item_ids); 
102
103	/*virtual*/ void startFetch();
104	/*virtual*/ void changed(U32 mask);
105private:
106	LLTimer mFetchingPeriod;
107
108	/**
109	 * Period of waiting a notification when requested items get added into inventory.
110	 */
111	static const F32 FETCH_TIMER_EXPIRY;
112};
113
114//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
115// Class LLInventoryFetchDescendentsObserver
116//
117//   Fetches children of a category/folder, calls done() when all 
118//   inventory has arrived. 
119//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
120class LLInventoryFetchDescendentsObserver : public LLInventoryFetchObserver
121{
122public:
123	LLInventoryFetchDescendentsObserver(const LLUUID& cat_id = LLUUID::null);
124	LLInventoryFetchDescendentsObserver(const uuid_vec_t& cat_ids);
125
126	/*virtual*/ void startFetch();
127	/*virtual*/ void changed(U32 mask);
128protected:
129	BOOL isCategoryComplete(const LLViewerInventoryCategory* cat) const;
130};
131
132//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
133// Class LLInventoryFetchComboObserver
134//
135//   Does an appropriate combination of fetch descendents and
136//   item fetches based on completion of categories and items. This is optimized
137//   to not fetch item_ids that are descendents of any of the folder_ids.
138//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
139class LLInventoryFetchComboObserver : public LLInventoryObserver
140{
141public:
142	LLInventoryFetchComboObserver(const uuid_vec_t& folder_ids,
143								  const uuid_vec_t& item_ids);
144	~LLInventoryFetchComboObserver();
145	/*virtual*/ void changed(U32 mask);
146	void startFetch();
147
148	virtual void done() = 0;
149protected:
150	LLInventoryFetchItemsObserver *mFetchItems;
151	LLInventoryFetchDescendentsObserver *mFetchDescendents;
152};
153
154//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
155// Class LLInventoryExistenceObserver
156//
157//   Used as a base class for doing something when all the
158//   observed item ids exist in the inventory somewhere.
159//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
160class LLInventoryExistenceObserver : public LLInventoryObserver
161{
162public:
163	LLInventoryExistenceObserver() {}
164	/*virtual*/ void changed(U32 mask);
165
166	void watchItem(const LLUUID& id);
167protected:
168	virtual void done() = 0;
169	uuid_vec_t mExist;
170	uuid_vec_t mMIA;
171};
172
173//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
174// Class LLInventoryMovedObserver
175//
176// This class is used as a base class for doing something when all the
177// item for observed asset ids were added into the inventory.
178// Derive a class from this class and implement the done() method to do
179// something useful.
180//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
181
182class LLInventoryAddItemByAssetObserver : public LLInventoryObserver
183{
184public:
185	LLInventoryAddItemByAssetObserver() : mIsDirty(false) {}
186	virtual void changed(U32 mask);
187
188	void watchAsset(const LLUUID& asset_id);
189	bool isAssetWatched(const LLUUID& asset_id);
190
191protected:
192	virtual void onAssetAdded(const LLUUID& asset_id) {}
193	virtual void done() = 0;
194
195	typedef std::vector<LLUUID> item_ref_t;
196	item_ref_t mAddedItems;
197	item_ref_t mWatchedAssets;
198
199private:
200	bool mIsDirty;
201};
202
203//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
204// Class LLInventoryAddedObserver
205//
206//   Base class for doing something when a new item arrives in inventory.
207//   It does not watch for a certain UUID, rather it acts when anything is added
208//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
209class LLInventoryAddedObserver : public LLInventoryObserver
210{
211public:
212	LLInventoryAddedObserver() : mAdded() {}
213	/*virtual*/ void changed(U32 mask);
214
215protected:
216	virtual void done() = 0;
217
218	uuid_vec_t mAdded;
219};
220
221//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
222// Class LLInventoryCategoryAddedObserver
223//
224//   Base class for doing something when a new category is created in the
225//   inventory.
226//   It does not watch for a certain UUID, rather it acts when anything is added
227//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
228class LLInventoryCategoryAddedObserver : public LLInventoryObserver
229{
230public:
231	
232	typedef std::vector<LLViewerInventoryCategory*>	cat_vec_t;
233	
234	LLInventoryCategoryAddedObserver() : mAddedCategories() {}
235	/*virtual*/ void changed(U32 mask);
236	
237protected:
238	virtual void done() = 0;
239	
240	cat_vec_t	mAddedCategories;
241};
242
243//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
244// Class LLInventoryTransactionObserver
245//
246//   Base class for doing something when an inventory transaction completes.
247//   NOTE: This class is not quite complete. Avoid using unless you fix up its
248//   functionality gaps.
249//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
250class LLInventoryTransactionObserver : public LLInventoryObserver
251{
252public:
253	LLInventoryTransactionObserver(const LLTransactionID& transaction_id);
254	/*virtual*/ void changed(U32 mask);
255
256protected:
257	virtual void done(const uuid_vec_t& folders, const uuid_vec_t& items) = 0;
258
259	LLTransactionID mTransactionID;
260};
261
262//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
263// Class LLInventoryCompletionObserver
264//
265//   Base class for doing something when when all observed items are locally 
266//   complete.  Implements the changed() method of LLInventoryObserver 
267//   and declares a new method named done() which is called when all watched items 
268//   have complete information in the inventory model.
269//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
270class LLInventoryCompletionObserver : public LLInventoryObserver
271{
272public:
273	LLInventoryCompletionObserver() {}
274	/*virtual*/ void changed(U32 mask);
275
276	void watchItem(const LLUUID& id);
277
278protected:
279	virtual void done() = 0;
280
281	uuid_vec_t mComplete;
282	uuid_vec_t mIncomplete;
283};
284
285//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
286// Class LLInventoryCategoriesObserver
287//
288// This class is used for monitoring a list of inventory categories
289// and firing a callback when there are changes in any of them.
290// Categories are identified by their UUIDs.
291//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
292class LLInventoryCategoriesObserver : public LLInventoryObserver
293{
294public:
295	typedef boost::function<void()> callback_t;
296
297	LLInventoryCategoriesObserver() {};
298	virtual void changed(U32 mask);
299
300	/**
301	 * Add cat_id to the list of observed categories with a
302	 * callback fired on category being changed.
303	 *
304	 * @return "true" if category was added, "false" if it could
305	 * not be found.
306	 */
307	bool addCategory(const LLUUID& cat_id, callback_t cb);
308	void removeCategory(const LLUUID& cat_id);
309
310protected:
311	struct LLCategoryData
312	{
313		LLCategoryData(const LLUUID& cat_id, callback_t cb, S32 version, S32 num_descendents);
314
315		callback_t	mCallback;
316		S32			mVersion;
317		S32			mDescendentsCount;
318		LLMD5		mItemNameHash;
319		bool		mIsNameHashInitialized;
320		LLUUID		mCatID;
321	};
322
323	typedef	std::map<LLUUID, LLCategoryData>	category_map_t;
324	typedef category_map_t::value_type			category_map_value_t;
325
326	category_map_t				mCategoryMap;
327};
328
329#endif // LL_LLINVENTORYOBSERVERS_H