PageRenderTime 130ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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