llaisapi.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /**
  2. * @file llaisapi.h
  3. * @brief classes and functions definitions for interfacing with the v3+ ais
  4. * inventory service.
  5. *
  6. * $LicenseInfo:firstyear=2000&license=viewergpl$
  7. *
  8. * Copyright (c) 2000-2009, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #ifndef LL_LLAISAPI_H
  34. #define LL_LLAISAPI_H
  35. #include "llcoproceduremanager.h"
  36. #include "llcorehttputil.h"
  37. #include "hbfastmap.h"
  38. #include "llhttpretrypolicy.h"
  39. #include "llviewerinventory.h"
  40. // Purely static class
  41. class AISAPI
  42. {
  43. AISAPI() = delete;
  44. ~AISAPI() = delete;
  45. protected:
  46. LOG_CLASS(AISAPI);
  47. public:
  48. typedef enum : U32
  49. {
  50. COPYINVENTORY,
  51. SLAMFOLDER,
  52. REMOVECATEGORY,
  53. REMOVEITEM,
  54. PURGEDESCENDENTS,
  55. UPDATECATEGORY,
  56. UPDATEITEM,
  57. COPYLIBRARYCATEGORY,
  58. CREATEINVENTORY,
  59. // Note: keep all fetch types >= FETCHITEM or change AISUpdate(). HB
  60. FETCHITEM,
  61. FETCHCATEGORYCHILDREN,
  62. FETCHCATEGORYCATEGORIES,
  63. FETCHCATEGORYSUBSET,
  64. FETCHCOF,
  65. FETCHORPHANS,
  66. FETCHCATEGORYLINKS
  67. } ECommandType;
  68. typedef boost::function<void(const LLUUID& item_id)> completion_t;
  69. static bool isAvailable(bool override_setting = false);
  70. static void createInventory(const LLUUID& parent_id,
  71. const LLSD& new_inventory,
  72. completion_t callback = completion_t());
  73. static void slamFolder(const LLUUID& folder_id, const LLSD& new_inventory,
  74. completion_t callback = completion_t());
  75. static void removeCategory(const LLUUID& cat_id,
  76. completion_t callback = completion_t());
  77. static void removeItem(const LLUUID& item_id,
  78. completion_t callback = completion_t());
  79. static void purgeDescendents(const LLUUID& cat_id,
  80. completion_t callback = completion_t());
  81. static void updateCategory(const LLUUID& cat_id, const LLSD& updates,
  82. completion_t callback = completion_t());
  83. static void updateItem(const LLUUID& item_id, const LLSD& updates,
  84. completion_t callback = completion_t());
  85. static void fetchItem(const LLUUID& item_id, bool library = false,
  86. completion_t callback = completion_t());
  87. static void fetchCategoryChildren(const LLUUID& cat_id,
  88. bool library = false,
  89. bool recursive = false,
  90. completion_t callback = completion_t(),
  91. U32 depth = 0);
  92. static void fetchCategoryCategories(const LLUUID& cat_id,
  93. bool library = false,
  94. bool recursive = false,
  95. completion_t callback = completion_t(),
  96. U32 depth = 0);
  97. static void fetchCategorySubset(const LLUUID& cat_id,
  98. const uuid_vec_t& children,
  99. bool library = false,
  100. bool recursive = false,
  101. completion_t callback = completion_t(),
  102. U32 depth = 0);
  103. static void fetchCategoryLinks(const LLUUID& cat_id,
  104. completion_t callback);
  105. static void fetchCOF(completion_t callback = completion_t());
  106. static void fetchOrphans(completion_t callback = completion_t());
  107. static void copyLibraryCategory(const LLUUID& source_id,
  108. const LLUUID& dest_id,
  109. bool copy_subfolders,
  110. completion_t callback = completion_t());
  111. private:
  112. typedef boost::function<LLSD(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t,
  113. const std::string, LLSD,
  114. LLCore::HttpOptions::ptr_t,
  115. LLCore::HttpHeaders::ptr_t)> invokationFn_t;
  116. static void enqueueAISCommand(const std::string& proc_name,
  117. LLCoprocedureManager::coprocedure_t proc);
  118. static void onIdle(void*);
  119. static bool getInvCap(std::string& cap);
  120. static bool getLibCap(std::string& cap);
  121. static void invokeAISCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t adapter,
  122. invokationFn_t invoke, std::string url,
  123. LLUUID target_id, LLSD body,
  124. completion_t callback, U32 type);
  125. private:
  126. typedef std::pair<std::string,
  127. LLCoprocedureManager::coprocedure_t> ais_query_item_t;
  128. static std::list<ais_query_item_t> sPostponedQuery;
  129. };
  130. class AISUpdate
  131. {
  132. protected:
  133. LOG_CLASS(AISUpdate);
  134. public:
  135. AISUpdate(const LLSD& update, U32 command_type, const LLSD& request_body);
  136. void parseUpdate(const LLSD& update);
  137. void parseMeta(const LLSD& update);
  138. void parseContent(const LLSD& update);
  139. void parseUUIDArray(const LLSD& content, const std::string& name,
  140. uuid_list_t& ids);
  141. void parseLink(const LLSD& link_map, U32 depth);
  142. void parseItem(const LLSD& link_map);
  143. void parseCategory(const LLSD& link_map, U32 depth);
  144. void parseDescendentCount(const LLUUID& cat_id, bool links_only,
  145. const LLSD& embedded);
  146. void parseEmbedded(const LLSD& embedded, U32 depth);
  147. void parseEmbeddedLinks(const LLSD& links, U32 depth);
  148. void parseEmbeddedItems(const LLSD& links);
  149. void parseEmbeddedCategories(const LLSD& links, U32 depth);
  150. void parseEmbeddedItem(const LLSD& item);
  151. void parseEmbeddedCategory(const LLSD& category, U32 depth);
  152. void doUpdate();
  153. private:
  154. void checkTimeout();
  155. void clearParseResults();
  156. private:
  157. typedef fast_hmap<LLUUID, S32> uuid_int_map_t;
  158. uuid_int_map_t mCatDescendentDeltas;
  159. uuid_int_map_t mCatDescendentsKnown;
  160. uuid_int_map_t mCatVersionsUpdated;
  161. typedef fast_hmap<LLUUID, LLPointer<LLViewerInventoryItem> >
  162. deferred_item_map_t;
  163. deferred_item_map_t mItemsCreated;
  164. deferred_item_map_t mItemsUpdated;
  165. deferred_item_map_t mItemsLost;
  166. typedef fast_hmap<LLUUID, LLPointer<LLViewerInventoryCategory> >
  167. deferred_category_map_t;
  168. deferred_category_map_t mCategoriesCreated;
  169. deferred_category_map_t mCategoriesUpdated;
  170. // These keep track of UUIDs mentioned in meta values. Useful for filtering
  171. // out which content we are interested in.
  172. uuid_list_t mObjectsDeletedIds;
  173. uuid_list_t mItemIds;
  174. uuid_list_t mCategoryIds;
  175. LLTimer mTimer;
  176. U32 mFetchDepth;
  177. U32 mType;
  178. bool mFetch;
  179. };
  180. #endif // LL_LLAISAPI_H