summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
authorLoren Shih <seraph@lindenlab.com>2010-04-07 13:30:21 -0400
committerLoren Shih <seraph@lindenlab.com>2010-04-07 13:30:21 -0400
commit5d3de2ea03ff500690acec13fd4b403dc8a72088 (patch)
treec16bcbe34d65de983e58f94a5837f603e616d17e /indra/newview
parente9f06764412af37023f45c4d83b2b97c48d2a13e (diff)
EXT-6745 : Refactor LLFetchComboObserver to use LLFetchItems and LLFetchDescedents instead of code duplication
Took out a bunch of code duplication from the FetchComboObserver and am using the LLFetchItems/DescendentsObservers instead. Also added some comments and made some minor superficial cleanup to LLInventoryObserver done().
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/llinventoryobserver.cpp135
-rw-r--r--indra/newview/llinventoryobserver.h23
-rw-r--r--indra/newview/lltooldraganddrop.cpp8
3 files changed, 44 insertions, 122 deletions
diff --git a/indra/newview/llinventoryobserver.cpp b/indra/newview/llinventoryobserver.cpp
index 35bd06125f..26fe1904fb 100644
--- a/indra/newview/llinventoryobserver.cpp
+++ b/indra/newview/llinventoryobserver.cpp
@@ -205,10 +205,6 @@ void LLInventoryFetchItemsObserver::changed(U32 mask)
//llinfos << "LLInventoryFetchItemsObserver::changed() mIncomplete size " << mIncomplete.size() << llendl;
}
-void LLInventoryFetchItemsObserver::done()
-{
-}
-
void fetch_items_from_llsd(const LLSD& items_llsd)
{
if (!items_llsd.size()) return;
@@ -406,119 +402,50 @@ BOOL LLInventoryFetchDescendentsObserver::isCategoryComplete(const LLViewerInven
}
LLInventoryFetchComboObserver::LLInventoryFetchComboObserver(const uuid_vec_t& folder_ids,
- const uuid_vec_t& item_ids) :
- mFolderIDs(folder_ids),
- mItemIDs(item_ids),
- mDone(FALSE)
+ const uuid_vec_t& item_ids)
{
-}
+ mFetchDescendents = new LLInventoryFetchDescendentsObserver(folder_ids);
-void LLInventoryFetchComboObserver::changed(U32 mask)
-{
- if (!mIncompleteItems.empty())
- {
- for (uuid_vec_t::iterator it = mIncompleteItems.begin(); it < mIncompleteItems.end(); )
- {
- LLViewerInventoryItem* item = gInventory.getItem(*it);
- if (!item)
- {
- it = mIncompleteItems.erase(it);
- continue;
- }
- if (item->isFinished())
- {
- mCompleteItems.push_back(*it);
- it = mIncompleteItems.erase(it);
- continue;
- }
- ++it;
- }
- }
- if (!mIncompleteFolders.empty())
+ uuid_vec_t pruned_item_ids;
+ for (uuid_vec_t::const_iterator item_iter = item_ids.begin();
+ item_iter != item_ids.end();
+ ++item_iter)
{
- for (uuid_vec_t::iterator it = mIncompleteFolders.begin(); it < mIncompleteFolders.end();)
+ const LLUUID& item_id = (*item_iter);
+ const LLViewerInventoryItem* item = gInventory.getItem(item_id);
+ if (item && std::find(folder_ids.begin(), folder_ids.end(), item->getParentUUID()) == folder_ids.end())
{
- LLViewerInventoryCategory* cat = gInventory.getCategory(*it);
- if (!cat)
- {
- it = mIncompleteFolders.erase(it);
- continue;
- }
- if (gInventory.isCategoryComplete(*it))
- {
- mCompleteFolders.push_back(*it);
- it = mIncompleteFolders.erase(it);
- continue;
- }
- ++it;
+ continue;
}
+ pruned_item_ids.push_back(item_id);
}
- if (!mDone && mIncompleteItems.empty() && mIncompleteFolders.empty())
+
+ mFetchItems = new LLInventoryFetchItemsObserver(pruned_item_ids);
+ mFetchDescendents = new LLInventoryFetchDescendentsObserver(folder_ids);
+}
+
+LLInventoryFetchComboObserver::~LLInventoryFetchComboObserver()
+{
+ mFetchItems->done();
+ mFetchDescendents->done();
+ delete mFetchItems;
+ delete mFetchDescendents;
+}
+
+void LLInventoryFetchComboObserver::changed(U32 mask)
+{
+ mFetchItems->changed(mask);
+ mFetchDescendents->changed(mask);
+ if (mFetchItems->isFinished() && mFetchDescendents->isFinished())
{
- mDone = TRUE;
done();
}
}
void LLInventoryFetchComboObserver::startFetch()
{
- lldebugs << "LLInventoryFetchComboObserver::startFetch()" << llendl;
- for (uuid_vec_t::const_iterator fit = mFolderIDs.begin(); fit != mFolderIDs.end(); ++fit)
- {
- LLViewerInventoryCategory* cat = gInventory.getCategory(*fit);
- if (!cat) continue;
- if (!gInventory.isCategoryComplete(*fit))
- {
- cat->fetch();
- lldebugs << "fetching folder " << *fit <<llendl;
- mIncompleteFolders.push_back(*fit);
- }
- else
- {
- mCompleteFolders.push_back(*fit);
- lldebugs << "completing folder " << *fit <<llendl;
- }
- }
-
- // Now for the items - we fetch everything which is not a direct
- // descendent of an incomplete folder because the item will show
- // up in an inventory descendents message soon enough so we do not
- // have to fetch it individually.
- LLSD items_llsd;
- LLUUID owner_id;
- for (uuid_vec_t::const_iterator iit = mItemIDs.begin(); iit != mItemIDs.end(); ++iit)
- {
- const LLViewerInventoryItem* item = gInventory.getItem(*iit);
- if (!item)
- {
- lldebugs << "uanble to find item " << *iit << llendl;
- continue;
- }
- if (item->isFinished())
- {
- // It's complete, so put it on the complete container.
- mCompleteItems.push_back(*iit);
- lldebugs << "completing item " << *iit << llendl;
- continue;
- }
- else
- {
- mIncompleteItems.push_back(*iit);
- owner_id = item->getPermissions().getOwner();
- }
- if (std::find(mIncompleteFolders.begin(), mIncompleteFolders.end(), item->getParentUUID()) == mIncompleteFolders.end())
- {
- LLSD item_entry;
- item_entry["owner_id"] = owner_id;
- item_entry["item_id"] = (*iit);
- items_llsd.append(item_entry);
- }
- else
- {
- lldebugs << "not worrying about " << *iit << llendl;
- }
- }
- fetch_items_from_llsd(items_llsd);
+ mFetchItems->startFetch();
+ mFetchDescendents->startFetch();
}
void LLInventoryExistenceObserver::watchItem(const LLUUID& id)
diff --git a/indra/newview/llinventoryobserver.h b/indra/newview/llinventoryobserver.h
index e4ae9097bd..7b4d3dfe7b 100644
--- a/indra/newview/llinventoryobserver.h
+++ b/indra/newview/llinventoryobserver.h
@@ -45,7 +45,6 @@ class LLViewerInventoryCategory;
// A simple abstract base class that can relay messages when the inventory
// changes.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
class LLInventoryObserver
{
public:
@@ -60,7 +59,7 @@ public:
ADD = 4, // Something added
REMOVE = 8, // Something deleted
STRUCTURE = 16, // Structural change (e.g. item or folder moved)
- CALLING_CARD = 32, // Calling card change (e.g. online, grant status, cancel)
+ CALLING_CARD = 32, // Calling card change (e.g. online, grant status, cancel)
GESTURE = 64,
REBUILD = 128, // Item UI changed (e.g. item type different)
SORT = 256, // Folder needs to be resorted.
@@ -88,9 +87,8 @@ public:
BOOL isFinished() const;
virtual void startFetch() = 0;
- virtual void done() = 0;
virtual void changed(U32 mask) = 0;
-
+ virtual void done() {};
protected:
uuid_vec_t mComplete;
uuid_vec_t mIncomplete;
@@ -112,8 +110,6 @@ public:
/*virtual*/ void startFetch();
/*virtual*/ void changed(U32 mask);
- /*virtual*/ void done();
-
protected:
BOOL mRetryIfMissing;
};
@@ -140,28 +136,23 @@ protected:
// Class LLInventoryFetchComboObserver
//
// Does an appropriate combination of fetch descendents and
-// item fetches based on completion of categories and items. Much like
-// the fetch and fetch descendents, this will call done() when everything
-// has arrived.
+// item fetches based on completion of categories and items. This is optimized
+// to not fetch item_ids that are descendents of any of the folder_ids.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class LLInventoryFetchComboObserver : public LLInventoryObserver
{
public:
LLInventoryFetchComboObserver(const uuid_vec_t& folder_ids,
const uuid_vec_t& item_ids);
+ ~LLInventoryFetchComboObserver();
/*virtual*/ void changed(U32 mask);
void startFetch();
virtual void done() = 0;
protected:
BOOL mDone;
- uuid_vec_t mCompleteFolders;
- uuid_vec_t mIncompleteFolders;
- uuid_vec_t mCompleteItems;
- uuid_vec_t mIncompleteItems;
-
- uuid_vec_t mItemIDs;
- uuid_vec_t mFolderIDs;
+ LLInventoryFetchItemsObserver *mFetchItems;
+ LLInventoryFetchDescendentsObserver *mFetchDescendents;
};
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/indra/newview/lltooldraganddrop.cpp b/indra/newview/lltooldraganddrop.cpp
index a67067d29c..774626f19d 100644
--- a/indra/newview/lltooldraganddrop.cpp
+++ b/indra/newview/lltooldraganddrop.cpp
@@ -232,6 +232,9 @@ bool LLGiveable::operator()(LLInventoryCategory* cat, LLInventoryItem* item)
return allowed;
}
+// Starts a fetch on folders and items. This is really not used
+// as an observer in the traditional sense; we're just using it to
+// request a fetch and we don't care about when/if the response arrives.
class LLCategoryFireAndForget : public LLInventoryFetchComboObserver
{
public:
@@ -485,8 +488,9 @@ void LLToolDragAndDrop::beginDrag(EDragAndDropType type,
}
if (!folder_ids.empty() || !item_ids.empty())
{
- LLCategoryFireAndForget fetcher(folder_ids, item_ids);
- fetcher.startFetch();
+ LLCategoryFireAndForget *fetcher = new LLCategoryFireAndForget(folder_ids, item_ids);
+ fetcher->startFetch();
+ delete fetcher;
}
}
}