Update to LLTombstone/LLHandle/LLRootHandle/LLHandleProvider.

This commit is contained in:
Shyotl
2012-11-13 17:55:52 -06:00
parent 3eebedc4c3
commit fe15371047
12 changed files with 130 additions and 69 deletions

View File

@@ -148,7 +148,6 @@ LLFloater::LLFloater() :
mResizeHandle[i] = NULL;
}
mDragHandle = NULL;
mHandle.bind(this);
mNotificationContext = new LLFloaterNotificationContext(getHandle());
}
@@ -222,7 +221,6 @@ void LLFloater::initFloater(const std::string& title,
BOOL resizable, S32 min_width, S32 min_height,
BOOL drag_on_left, BOOL minimizable, BOOL close_btn)
{
mHandle.bind(this);
mNotificationContext = new LLFloaterNotificationContext(getHandle());
// Init function can be called more than once, so clear out old data.
@@ -422,7 +420,7 @@ void LLFloater::initFloater(const std::string& title,
setVisible(FALSE);
// add self to handle->floater map
sFloaterMap[mHandle] = this;
sFloaterMap[getHandle()] = this;
if (!getParent())
{
@@ -483,7 +481,7 @@ LLFloater::~LLFloater()
// correct, non-minimized positions.
setMinimized( FALSE );
sFloaterMap.erase(mHandle);
sFloaterMap.erase(getHandle());
delete mDragHandle;
for (S32 i = 0; i < 4; i++)

View File

@@ -227,7 +227,7 @@ public:
void clearSnapTarget() { mSnappedTo.markDead(); }
LLHandle<LLFloater> getSnapTarget() const { return mSnappedTo; }
LLHandle<LLFloater> getHandle() const { return mHandle; }
LLHandle<LLFloater> getHandle() const { return getDerivedHandle<LLFloater>(); }
// Return a closeable floater, if any, given the current focus.
static LLFloater* getClosableFloaterFromFocus();
@@ -331,7 +331,6 @@ private:
S32 mPreviousMinimizedLeft;
LLFloaterNotificationContext* mNotificationContext;
LLRootHandle<LLFloater> mHandle;
};
/////////////////////////////////////////////////////////////

View File

@@ -28,38 +28,67 @@
#define LLHANDLE_H
#include "llpointer.h"
#include <boost/type_traits/is_convertible.hpp>
#include <boost/utility/enable_if.hpp>
template <typename T>
/**
* Helper object for LLHandle. Don't instantiate these directly, used
* exclusively by LLHandle.
*/
class LLTombStone : public LLRefCount
{
public:
LLTombStone(T* target = NULL) : mTarget(target) {}
LLTombStone(void* target = NULL) : mTarget(target) {}
void setTarget(T* target) { mTarget = target; }
T* getTarget() const { return mTarget; }
void setTarget(void* target) { mTarget = target; }
void* getTarget() const { return mTarget; }
private:
T* mTarget;
mutable void* mTarget;
};
// LLHandles are used to refer to objects whose lifetime you do not control or influence.
// Calling get() on a handle will return a pointer to the referenced object or NULL,
// if the object no longer exists. Note that during the lifetime of the returned pointer,
// you are assuming that the object will not be deleted by any action you perform,
// or any other thread, as normal when using pointers, so avoid using that pointer outside of
// the local code block.
//
// https://wiki.lindenlab.com/mediawiki/index.php?title=LLHandle&oldid=79669
/**
* LLHandles are used to refer to objects whose lifetime you do not control or influence.
* Calling get() on a handle will return a pointer to the referenced object or NULL,
* if the object no longer exists. Note that during the lifetime of the returned pointer,
* you are assuming that the object will not be deleted by any action you perform,
* or any other thread, as normal when using pointers, so avoid using that pointer outside of
* the local code block.
*
* https://wiki.lindenlab.com/mediawiki/index.php?title=LLHandle&oldid=79669
*
* The implementation is like some "weak pointer" implementations. When we
* can't control the lifespan of the referenced object of interest, we can
* still instantiate a proxy object whose lifespan we DO control, and store in
* the proxy object a dumb pointer to the actual target. Then we just have to
* ensure that on destruction of the target object, the proxy's dumb pointer
* is set NULL.
*
* LLTombStone is our proxy object. LLHandle contains an LLPointer to the
* LLTombStone, so every copy of an LLHandle increments the LLTombStone's ref
* count as usual.
*
* One copy of the LLHandle, specifically the LLRootHandle, must be stored in
* the referenced object. Destroying the LLRootHandle is what NULLs the
* proxy's target pointer.
*
* Minor optimization: we want LLHandle's mTombStone to always be a valid
* LLPointer, saving some conditionals in dereferencing. That's the
* getDefaultTombStone() mechanism. The default LLTombStone object's target
* pointer is always NULL, so it's semantically identical to allowing
* mTombStone to be invalid.
*/
template <typename T>
class LLHandle
{
template <typename U> friend class LLHandle;
template <typename U> friend class LLHandleProvider;
public:
LLHandle() : mTombStone(getDefaultTombStone()) {}
const LLHandle<T>& operator =(const LLHandle<T>& other)
{
mTombStone = other.mTombStone;
return *this;
}
template<typename U>
LLHandle(const LLHandle<U>& other, typename boost::enable_if< typename boost::is_convertible<U*, T*> >::type* dummy = 0)
: mTombStone(other.mTombStone)
{}
bool isDead() const
{
@@ -73,7 +102,7 @@ public:
T* get() const
{
return mTombStone->getTarget();
return reinterpret_cast<T*>(mTombStone->getTarget());
}
friend bool operator== (const LLHandle<T>& lhs, const LLHandle<T>& rhs)
@@ -94,37 +123,49 @@ public:
}
protected:
LLPointer<LLTombStone<T> > mTombStone;
LLPointer<LLTombStone> mTombStone;
private:
static LLPointer<LLTombStone<T> >& getDefaultTombStone()
typedef T* pointer_t;
static LLPointer<LLTombStone>& getDefaultTombStone()
{
static LLPointer<LLTombStone<T> > sDefaultTombStone = new LLTombStone<T>;
static LLPointer<LLTombStone> sDefaultTombStone = new LLTombStone;
return sDefaultTombStone;
}
};
/**
* LLRootHandle isa LLHandle which must be stored in the referenced object.
* You can either store it directly and explicitly bind(this), or derive from
* LLHandleProvider (q.v.) which automates that for you. The essential point
* is that destroying the LLRootHandle (as a consequence of destroying the
* referenced object) calls unbind(), setting the LLTombStone's target pointer
* NULL.
*/
template <typename T>
class LLRootHandle : public LLHandle<T>
{
public:
typedef LLRootHandle<T> self_t;
typedef LLHandle<T> base_t;
LLRootHandle(T* object) { bind(object); }
LLRootHandle() {};
~LLRootHandle() { unbind(); }
// this is redundant, since a LLRootHandle *is* an LLHandle
LLHandle<T> getHandle() { return LLHandle<T>(*this); }
// this is redundant, since an LLRootHandle *is* an LLHandle
//LLHandle<T> getHandle() { return LLHandle<T>(*this); }
void bind(T* object)
{
// unbind existing tombstone
if (LLHandle<T>::mTombStone.notNull())
{
if (LLHandle<T>::mTombStone->getTarget() == object) return;
if (LLHandle<T>::mTombStone->getTarget() == (void*)object) return;
LLHandle<T>::mTombStone->setTarget(NULL);
}
// tombstone reference counted, so no paired delete
LLHandle<T>::mTombStone = new LLTombStone<T>(object);
LLHandle<T>::mTombStone = new LLTombStone((void*)object);
}
void unbind()
@@ -137,11 +178,22 @@ private:
LLRootHandle(const LLRootHandle& other) {};
};
// Use this as a mixin for simple classes that need handles and when you don't
// want handles at multiple points of the inheritance hierarchy
/**
* Use this as a mixin for simple classes that need handles and when you don't
* want handles at multiple points of the inheritance hierarchy
*/
template <typename T>
class LLHandleProvider
{
public:
LLHandle<T> getHandle() const
{
// perform lazy binding to avoid small tombstone allocations for handle
// providers whose handles are never referenced
mHandle.bind(static_cast<T*>(const_cast<LLHandleProvider<T>* >(this)));
return mHandle;
}
protected:
typedef LLHandle<T> handle_type_t;
LLHandleProvider()
@@ -149,16 +201,17 @@ protected:
// provided here to enforce T deriving from LLHandleProvider<T>
}
LLHandle<T> getHandle()
{
// perform lazy binding to avoid small tombstone allocations for handle
// providers whose handles are never referenced
mHandle.bind(static_cast<T*>(this));
return mHandle;
template <typename U>
LLHandle<U> getDerivedHandle(typename boost::enable_if< typename boost::is_convertible<U*, T*> >::type* dummy = 0) const
{
LLHandle<U> downcast_handle;
downcast_handle.mTombStone = getHandle().mTombStone;
return downcast_handle;
}
private:
LLRootHandle<T> mHandle;
mutable LLRootHandle<T> mHandle;
};
#endif

View File

@@ -80,7 +80,6 @@ void LLPanel::init()
mDefaultBtn = NULL;
setIsChrome(FALSE); //is this a decorator to a live window or a form?
mPanelHandle.bind(this);
setTabStop(FALSE);
mVisibleSignal = NULL;
}

View File

@@ -136,7 +136,7 @@ public:
void setCtrlsEnabled(BOOL b);
LLHandle<LLPanel> getHandle() const { return mPanelHandle; }
LLHandle<LLPanel> getHandle() const { return getDerivedHandle<LLPanel>(); }
const LLCallbackMap::map_t& getFactoryMap() const { return mFactoryMap; }
@@ -246,7 +246,6 @@ private:
LLViewBorder* mBorder;
LLButton* mDefaultBtn;
std::string mLabel;
LLRootHandle<LLPanel> mPanelHandle;
typedef std::map<std::string, std::string> ui_string_map_t;
ui_string_map_t mUIStrings;

View File

@@ -132,8 +132,8 @@ public:
class LLView
: public LLMouseHandler, // handles mouse events
public LLFocusableElement, // handles keyboard events
public LLMortician // lazy deletion
//public LLHandleProvider<LLView> // passes out weak references to self
public LLMortician, // lazy deletion
public LLHandleProvider<LLView> // passes out weak references to self
{
public:
struct Follows : public LLInitParam::ChoiceBlock<Follows>
@@ -344,8 +344,6 @@ public:
void popVisible() { setVisible(mLastVisible); }
BOOL getLastVisible() const { return mLastVisible; }
LLHandle<LLView> getHandle() { mHandle.bind(this); return mHandle; }
U32 getFollows() const { return mReshapeFlags; }
BOOL followsLeft() const { return mReshapeFlags & FOLLOWS_LEFT; }
BOOL followsRight() const { return mReshapeFlags & FOLLOWS_RIGHT; }
@@ -678,7 +676,6 @@ private:
BOOL mIsFocusRoot;
BOOL mUseBoundingRect; // hit test against bounding rectangle that includes all child elements
LLRootHandle<LLView> mHandle;
BOOL mLastVisible;
S32 mNextInsertionOrdinal;

View File

@@ -971,7 +971,7 @@ void LLFastTimerView::draw()
gGL.color4f(col[0], col[1], col[2], alpha);
gGL.begin(LLRender::TRIANGLE_STRIP);
for (U32 j = llmax(0, LLFastTimer::NamedTimer::HISTORY_NUM - LLFastTimer::getLastFrameIndex());
j < LLFastTimer::NamedTimer::HISTORY_NUM;
j < (U32)LLFastTimer::NamedTimer::HISTORY_NUM;
j++)
{
U64 ticks = idp->getHistoricalCount(j);

View File

@@ -263,7 +263,7 @@ LLInvFVBridge::LLInvFVBridge(LLInventoryPanel* inventory,
mInvType(LLInventoryType::IT_NONE),
mIsLink(FALSE)
{
mInventoryPanel = inventory->getHandle();
mInventoryPanel = inventory->getInventoryPanelHandle();
const LLInventoryObject* obj = getInventoryObject();
mIsLink = obj && obj->getIsLinkType();
}
@@ -973,7 +973,7 @@ LLInventoryObject* LLInvFVBridge::getInventoryObject() const
LLInventoryModel* LLInvFVBridge::getInventoryModel() const
{
LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(mInventoryPanel.get());
LLInventoryPanel* panel = mInventoryPanel.get();
return panel ? panel->getModel() : NULL;
}
@@ -1937,7 +1937,7 @@ BOOL LLFolderBridge::isItemRemovable() const
return FALSE;
}
LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(mInventoryPanel.get());
LLInventoryPanel* panel = mInventoryPanel.get();
LLFolderViewFolder* folderp = dynamic_cast<LLFolderViewFolder*>(panel ? panel->getRootFolder()->getItemByID(mUUID) : NULL);
if (folderp)
{
@@ -3200,7 +3200,7 @@ void LLFolderBridge::buildContextMenuBaseOptions(U32 flags)
// Not sure what the right thing is to do here.
if (!isCOFFolder() && cat && (cat->getPreferredType() != LLFolderType::FT_OUTFIT))
{
LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(mInventoryPanel.get());
LLInventoryPanel* panel = mInventoryPanel.get();
if(panel && !panel->getFilterWorn())
if (!isInboxFolder() && !isOutboxFolder()) // don't allow creation in inbox or outbox
{
@@ -3481,7 +3481,7 @@ void LLFolderBridge::createNewCategory(void* user_data)
{
LLFolderBridge* bridge = (LLFolderBridge*)user_data;
if(!bridge) return;
LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(bridge->mInventoryPanel.get());
LLInventoryPanel* panel = bridge->mInventoryPanel.get();
if (!panel) return;
LLInventoryModel* model = panel->getModel();
if(!model) return;
@@ -3675,7 +3675,7 @@ void LLFolderBridge::dropToFavorites(LLInventoryItem* inv_item)
// use callback to rearrange favorite landmarks after adding
// to have new one placed before target (on which it was dropped). See EXT-4312.
LLPointer<AddFavoriteLandmarkCallback> cb = new AddFavoriteLandmarkCallback();
LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(mInventoryPanel.get());
LLInventoryPanel* panel = mInventoryPanel.get();
LLFolderViewItem* drag_over_item = panel ? panel->getRootFolder()->getDraggingOverItem() : NULL;
if (drag_over_item && drag_over_item->getListener())
{
@@ -3724,6 +3724,9 @@ BOOL LLFolderBridge::dragItemIntoFolder(LLInventoryItem* inv_item,
if(!isAgentInventory()) return FALSE; // cannot drag into library
if (!isAgentAvatarValid()) return FALSE;
LLInventoryPanel* destination_panel = mInventoryPanel.get();
if (!destination_panel) return false;
const LLUUID &current_outfit_id = model->findCategoryUUIDForType(LLFolderType::FT_CURRENT_OUTFIT, false);
const LLUUID &favorites_id = model->findCategoryUUIDForType(LLFolderType::FT_FAVORITE, false);
const LLUUID &landmarks_id = model->findCategoryUUIDForType(LLFolderType::FT_LANDMARK, false);
@@ -3855,6 +3858,15 @@ BOOL LLFolderBridge::dragItemIntoFolder(LLInventoryItem* inv_item,
}
}
LLInventoryPanel* active_panel = LLInventoryPanel::getActiveInventoryPanel(FALSE);
// Check whether the item being dragged from active inventory panel
if (accept && active_panel)
{
LLFolderView* active_folder_view = active_panel->getRootFolder();
if (!active_folder_view) return false;
}
if(accept && drop)
{
if (inv_item->getType() == LLAssetType::AT_GESTURE
@@ -3864,14 +3876,9 @@ BOOL LLFolderBridge::dragItemIntoFolder(LLInventoryItem* inv_item,
}
// If an item is being dragged between windows, unselect everything in the active window
// so that we don't follow the selection to its new location (which is very annoying).
LLInventoryPanel *active_panel = LLInventoryPanel::getActiveInventoryPanel(FALSE);
if (active_panel)
if (active_panel && (destination_panel != active_panel))
{
LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(mInventoryPanel.get());
if (active_panel && (panel != active_panel))
{
active_panel->unSelectAll();
}
}
// FAVORITES folder
@@ -4034,6 +4041,15 @@ BOOL LLFolderBridge::dragItemIntoFolder(LLInventoryItem* inv_item,
accept = can_move_to_landmarks(inv_item);
}
LLInventoryPanel* active_panel = LLInventoryPanel::getActiveInventoryPanel(FALSE);
// Check whether the item being dragged from the library
if (accept && active_panel)
{
LLFolderView* active_folder_view = active_panel->getRootFolder();
if (!active_folder_view) return false;
}
if (accept && drop)
{
// FAVORITES folder
@@ -4436,7 +4452,7 @@ LLCallingCardBridge::~LLCallingCardBridge()
void LLCallingCardBridge::refreshFolderViewItem()
{
LLInventoryPanel* panel = dynamic_cast<LLInventoryPanel*>(mInventoryPanel.get());
LLInventoryPanel* panel = mInventoryPanel.get();
LLFolderViewItem* itemp = panel ? panel->getRootFolder()->getItemByID(mUUID) : NULL;
if (itemp)
{

View File

@@ -160,7 +160,7 @@ protected:
BOOL restamp);
void removeBatchNoCheck(LLDynamicArray<LLFolderViewEventListener*>& batch);
protected:
LLHandle<LLPanel> mInventoryPanel;
LLHandle<LLInventoryPanel> mInventoryPanel;
LLFolderView* mRoot;
const LLUUID mUUID; // item id
LLInventoryType::EType mInvType;

View File

@@ -129,6 +129,8 @@ public:
LLScrollableContainerView* getScrollableContainer() { return mScroller; }
void onSelectionChange(const std::deque<LLFolderViewItem*> &items, BOOL user_action);
LLHandle<LLInventoryPanel> getInventoryPanelHandle() const { return getDerivedHandle<LLInventoryPanel>(); }
// DEBUG ONLY:
static void dumpSelectionInformation(void* user_data);

View File

@@ -78,8 +78,6 @@ LLPanelMediaHUD::LLPanelMediaHUD(viewer_media_t media_impl)
mFadeTimer.stop();
mCurrentZoom = ZOOM_NONE;
mScrollState = SCROLL_NONE;
mPanelHandle.bind(this);
}
LLPanelMediaHUD::~LLPanelMediaHUD()
{

View File

@@ -55,7 +55,8 @@ public:
void nextZoomLevel();
void resetZoomLevel() { mCurrentZoom = ZOOM_NONE; }
LLHandle<LLPanelMediaHUD> getHandle() const { return mPanelHandle; }
LLHandle<LLPanelMediaHUD> getHandle() const { return getDerivedHandle<LLPanelMediaHUD>(); }
void setMediaImpl(viewer_media_t media_impl) { mMediaImpl = media_impl; }
@@ -105,7 +106,6 @@ private:
F32 mMouseInactiveTime;
F32 mControlFadeTime;
viewer_media_t mMediaImpl;
LLRootHandle<LLPanelMediaHUD> mPanelHandle;
};
#endif // LL_PANELMEDIAHUD_H