* 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
This commit is contained in:
@@ -9,10 +9,6 @@
|
|||||||
#include <Handler.h>
|
#include <Handler.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
#include <Locker.h>
|
#include <Locker.h>
|
||||||
#include <String.h>
|
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <utility>
|
|
||||||
|
|
||||||
class BDataIO;
|
class BDataIO;
|
||||||
class BPoint;
|
class BPoint;
|
||||||
@@ -127,10 +123,6 @@ class BShelf : public BHandler {
|
|||||||
bool fAllowZombies;
|
bool fAllowZombies;
|
||||||
bool fTypeEnforced;
|
bool fTypeEnforced;
|
||||||
|
|
||||||
typedef std::map<BString, std::pair<image_id, int32> > LoadedImageMap;
|
|
||||||
static LoadedImageMap sLoadedImages;
|
|
||||||
static BLocker sLoadedImageMapLocker;
|
|
||||||
|
|
||||||
uint32 _reserved[8];
|
uint32 _reserved[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include <PropertyInfo.h>
|
#include <PropertyInfo.h>
|
||||||
#include <Rect.h>
|
#include <Rect.h>
|
||||||
#include <Shelf.h>
|
#include <Shelf.h>
|
||||||
|
#include <String.h>
|
||||||
#include <View.h>
|
#include <View.h>
|
||||||
|
|
||||||
#include <ViewPrivate.h>
|
#include <ViewPrivate.h>
|
||||||
@@ -34,6 +35,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
|
||||||
|
typedef std::map<BString, std::pair<image_id, int32> > LoadedImageMap;
|
||||||
|
static LoadedImageMap sLoadedImages;
|
||||||
|
static BLocker sLoadedImageMapLocker("BShelf loaded image map");
|
||||||
|
|
||||||
static property_info sShelfPropertyList[] = {
|
static property_info sShelfPropertyList[] = {
|
||||||
{
|
{
|
||||||
@@ -455,9 +463,6 @@ ReplicantViewFilter::Filter(BMessage *message, BHandler **handler)
|
|||||||
|
|
||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
BShelf::LoadedImageMap BShelf::sLoadedImages;
|
|
||||||
BLocker BShelf::sLoadedImageMapLocker("BShelf loaded image map");
|
|
||||||
|
|
||||||
|
|
||||||
BShelf::BShelf(BView *view, bool allowDrags, const char *shelfType)
|
BShelf::BShelf(BView *view, bool allowDrags, const char *shelfType)
|
||||||
: BHandler(shelfType)
|
: BHandler(shelfType)
|
||||||
@@ -1167,7 +1172,7 @@ BShelf::_DeleteReplicant(replicant_data* item)
|
|||||||
LoadedImageMap::iterator it = sLoadedImages.find(BString(signature));
|
LoadedImageMap::iterator it = sLoadedImages.find(BString(signature));
|
||||||
|
|
||||||
if (it != sLoadedImages.end()) {
|
if (it != sLoadedImages.end()) {
|
||||||
(*it).second.second -= 1;
|
(*it).second.second--;
|
||||||
if ((*it).second.second <= 0) {
|
if ((*it).second.second <= 0) {
|
||||||
unload_add_on((*it).second.first);
|
unload_add_on((*it).second.first);
|
||||||
sLoadedImages.erase(it);
|
sLoadedImages.erase(it);
|
||||||
@@ -1229,23 +1234,11 @@ BShelf::_AddReplicant(BMessage *data, BPoint *location, uint32 uniqueID)
|
|||||||
image_id image = -1;
|
image_id image = -1;
|
||||||
BArchivable *archivable = _InstantiateObject(data, &image);
|
BArchivable *archivable = _InstantiateObject(data, &image);
|
||||||
|
|
||||||
// Update use count for image
|
if (archivable == NULL)
|
||||||
const char* signature = NULL;
|
return send_reply(data, B_ERROR, uniqueID);
|
||||||
if (data->FindString("add_on", &signature) == B_OK && signature != NULL) {
|
|
||||||
AutoLock<BLocker> 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_id, int>(image, 1)));
|
|
||||||
else
|
|
||||||
(*it).second.second += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BView *view = dynamic_cast<BView*>(archivable);
|
BView *view = dynamic_cast<BView*>(archivable);
|
||||||
if (archivable != NULL && view == NULL) {
|
if (view == NULL) {
|
||||||
printf("Replicant was rejected: it's not a view!");
|
printf("Replicant was rejected: it's not a view!");
|
||||||
return send_reply(data, B_ERROR, uniqueID);
|
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);
|
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<BLocker> 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_id, int>(image, 1)));
|
||||||
|
else
|
||||||
|
(*it).second.second++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
data->RemoveName("_drop_point_");
|
data->RemoveName("_drop_point_");
|
||||||
data->RemoveName("_drop_offset_");
|
data->RemoveName("_drop_offset_");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user