From 3fd2ea61ceadc1ca503d80b5d5b722d643a0b255 Mon Sep 17 00:00:00 2001 From: Alexandre Deckner Date: Sun, 8 Mar 2009 16:08:03 +0000 Subject: [PATCH] * Update ref count later in _AddReplicant and add one check to be sure we checked all possible errors. * Moved new statics to the cpp file as it seems we don't usually expose such internals in our public headers git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29443 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- headers/os/interface/Shelf.h | 8 ------- src/kits/interface/Shelf.cpp | 46 +++++++++++++++++++++--------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/headers/os/interface/Shelf.h b/headers/os/interface/Shelf.h index ad3d288db4..6183f90b38 100644 --- a/headers/os/interface/Shelf.h +++ b/headers/os/interface/Shelf.h @@ -9,10 +9,6 @@ #include #include #include -#include - -#include -#include class BDataIO; class BPoint; @@ -127,10 +123,6 @@ class BShelf : public BHandler { bool fAllowZombies; bool fTypeEnforced; - typedef std::map > LoadedImageMap; - static LoadedImageMap sLoadedImages; - static BLocker sLoadedImageMapLocker; - uint32 _reserved[8]; }; diff --git a/src/kits/interface/Shelf.cpp b/src/kits/interface/Shelf.cpp index 02537a2272..62f9ff3ec1 100644 --- a/src/kits/interface/Shelf.cpp +++ b/src/kits/interface/Shelf.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -34,6 +35,13 @@ #include #include +#include +#include + + +typedef std::map > LoadedImageMap; +static LoadedImageMap sLoadedImages; +static BLocker sLoadedImageMapLocker("BShelf loaded image map"); static property_info sShelfPropertyList[] = { { @@ -455,9 +463,6 @@ ReplicantViewFilter::Filter(BMessage *message, BHandler **handler) // #pragma mark - -BShelf::LoadedImageMap BShelf::sLoadedImages; -BLocker BShelf::sLoadedImageMapLocker("BShelf loaded image map"); - BShelf::BShelf(BView *view, bool allowDrags, const char *shelfType) : BHandler(shelfType) @@ -1167,7 +1172,7 @@ BShelf::_DeleteReplicant(replicant_data* item) LoadedImageMap::iterator it = sLoadedImages.find(BString(signature)); if (it != sLoadedImages.end()) { - (*it).second.second -= 1; + (*it).second.second--; if ((*it).second.second <= 0) { unload_add_on((*it).second.first); sLoadedImages.erase(it); @@ -1229,23 +1234,11 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID) image_id image = -1; BArchivable *archivable = _InstantiateObject(data, &image); - // Update use count for image - const char* signature = NULL; - if (data->FindString("add_on", &signature) == B_OK && signature != NULL) { - AutoLock lock(sLoadedImageMapLocker); - if (lock.IsLocked()) { - LoadedImageMap::iterator it = sLoadedImages.find(BString(signature)); - - if (it == sLoadedImages.end()) - sLoadedImages.insert(LoadedImageMap::value_type( - BString(signature), std::pair(image, 1))); - else - (*it).second.second += 1; - } - } + if (archivable == NULL) + return send_reply(data, B_ERROR, uniqueID); BView *view = dynamic_cast(archivable); - if (archivable != NULL && view == NULL) { + if (view == NULL) { printf("Replicant was rejected: it's not a view!"); return send_reply(data, B_ERROR, uniqueID); } @@ -1268,6 +1261,21 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID) return send_reply(data, B_ERROR, uniqueID); } + // Update use count for image + const char* signature = NULL; + if (data->FindString("add_on", &signature) == B_OK && signature != NULL) { + AutoLock lock(sLoadedImageMapLocker); + if (lock.IsLocked()) { + LoadedImageMap::iterator it = sLoadedImages.find(BString(signature)); + + if (it == sLoadedImages.end()) + sLoadedImages.insert(LoadedImageMap::value_type( + BString(signature), std::pair(image, 1))); + else + (*it).second.second++; + } + } + data->RemoveName("_drop_point_"); data->RemoveName("_drop_offset_");