Renamed some BPicture private functions, small cleanups.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21927 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini
2007-08-13 15:28:31 +00:00
parent 38daa5cd6e
commit 4d47fee5cd
3 changed files with 116 additions and 88 deletions
+15 -10
View File
@@ -78,24 +78,29 @@ virtual void _ReservedPicture3();
BPicture &operator=(const BPicture &); BPicture &operator=(const BPicture &);
void init_data(); void _InitData();
void import_data(const void *data, int32 size, BPicture **subs, int32 subCount); void _DisposeData();
void import_old_data(const void *data, int32 size);
void set_token(int32 token); void _ImportData(const void *data, int32 size, BPicture **subs, int32 subCount);
bool assert_local_copy(); void _ImportOldData(const void *data, int32 size);
bool assert_old_local_copy(); void SetToken(int32 token);
bool assert_server_copy(); bool _AssertLocalCopy();
bool _AssertOldLocalCopy();
bool _AssertServerCopy();
status_t _Upload();
status_t _Download();
/**Deprecated API**/ /**Deprecated API**/
BPicture(const void *data, int32 size); BPicture(const void *data, int32 size);
const void *Data() const; const void *Data() const;
int32 DataSize() const; int32 DataSize() const;
void usurp(BPicture *lameDuck); void Usurp(BPicture *lameDuck);
BPicture *step_down(); BPicture *StepDown();
int32 token; int32 token;
_BPictureExtent_ *extent; _BPictureExtent_ *extent;
BPicture *usurped; BPicture *usurped;
uint32 _reserved[3]; uint32 _reserved[3];
}; };
+97 -74
View File
@@ -13,6 +13,8 @@
#include <PicturePlayer.h> #include <PicturePlayer.h>
#include <ServerProtocol.h> #include <ServerProtocol.h>
//#define DEBUG 1
#include <Debug.h>
#include <ByteOrder.h> #include <ByteOrder.h>
#include <List.h> #include <List.h>
#include <Message.h> #include <Message.h>
@@ -64,7 +66,7 @@ BPicture::BPicture()
extent(NULL), extent(NULL),
usurped(NULL) usurped(NULL)
{ {
init_data(); _InitData();
} }
@@ -74,7 +76,7 @@ BPicture::BPicture(const BPicture &otherPicture)
extent(NULL), extent(NULL),
usurped(NULL) usurped(NULL)
{ {
init_data(); _InitData();
if (otherPicture.token != -1) { if (otherPicture.token != -1) {
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
@@ -106,7 +108,7 @@ BPicture::BPicture(BMessage *archive)
extent(NULL), extent(NULL),
usurped(NULL) usurped(NULL)
{ {
init_data(); _InitData();
int32 version; int32 version;
if (archive->FindInt32("_ver", &version) != B_OK) if (archive->FindInt32("_ver", &version) != B_OK)
@@ -138,7 +140,7 @@ BPicture::BPicture(BMessage *archive)
// swap_data(extent->fNewData, extent->fNewSize); // swap_data(extent->fNewData, extent->fNewSize);
if (extent->Size() > 0) if (extent->Size() > 0)
assert_server_copy(); _AssertServerCopy();
} }
// Do we just free the data now? // Do we just free the data now?
@@ -153,14 +155,14 @@ BPicture::BPicture(BMessage *archive)
BPicture::BPicture(const void *data, int32 size) BPicture::BPicture(const void *data, int32 size)
{ {
init_data(); _InitData();
// TODO: For now. We'll see if it's worth to support old style data // TODO: For now. We'll see if it's worth to support old style data
debugger("old style BPicture data is not supported"); debugger("old style BPicture data is not supported");
} }
void void
BPicture::init_data() BPicture::_InitData()
{ {
token = -1; token = -1;
usurped = NULL; usurped = NULL;
@@ -170,6 +172,13 @@ BPicture::init_data()
BPicture::~BPicture() BPicture::~BPicture()
{
_DisposeData();
}
void
BPicture::_DisposeData()
{ {
if (token != -1) { if (token != -1) {
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
@@ -177,9 +186,11 @@ BPicture::~BPicture()
link.StartMessage(AS_DELETE_PICTURE); link.StartMessage(AS_DELETE_PICTURE);
link.Attach<int32>(token); link.Attach<int32>(token);
link.Flush(); link.Flush();
SetToken(-1);
} }
delete extent; delete extent;
extent = NULL;
} }
@@ -196,7 +207,7 @@ BPicture::Instantiate(BMessage *archive)
status_t status_t
BPicture::Archive(BMessage *archive, bool deep) const BPicture::Archive(BMessage *archive, bool deep) const
{ {
if (!const_cast<BPicture*>(this)->assert_local_copy()) if (!const_cast<BPicture*>(this)->_AssertLocalCopy())
return B_ERROR; return B_ERROR;
status_t err = BArchivable::Archive(archive, deep); status_t err = BArchivable::Archive(archive, deep);
@@ -238,7 +249,7 @@ BPicture::Perform(perform_code d, void *arg)
status_t status_t
BPicture::Play(void **callBackTable, int32 tableEntries, void *user) BPicture::Play(void **callBackTable, int32 tableEntries, void *user)
{ {
if (!assert_local_copy()) if (!_AssertLocalCopy())
return B_ERROR; return B_ERROR;
PicturePlayer player(extent->Data(), extent->Size(), extent->Pictures()); PicturePlayer player(extent->Data(), extent->Size(), extent->Pictures());
@@ -252,7 +263,7 @@ BPicture::Flatten(BDataIO *stream)
{ {
// TODO: what about endianess? // TODO: what about endianess?
if (!assert_local_copy()) if (!_AssertLocalCopy())
return B_ERROR; return B_ERROR;
const picture_header header = { 2, 0 }; const picture_header header = { 2, 0 };
@@ -327,7 +338,7 @@ BPicture::Unflatten(BDataIO *stream)
// swap_data(extent->fNewData, extent->fNewSize); // swap_data(extent->fNewData, extent->fNewSize);
if (!assert_server_copy()) if (!_AssertServerCopy())
return B_ERROR; return B_ERROR;
// Data is now kept server side, remove the local copy // Data is now kept server side, remove the local copy
@@ -340,7 +351,7 @@ BPicture::Unflatten(BDataIO *stream)
void void
BPicture::import_data(const void *data, int32 size, BPicture **subs, BPicture::_ImportData(const void *data, int32 size, BPicture **subs,
int32 subCount) int32 subCount)
{ {
/* /*
@@ -366,21 +377,21 @@ BPicture::import_data(const void *data, int32 size, BPicture **subs,
void void
BPicture::import_old_data(const void *data, int32 size) BPicture::_ImportOldData(const void *data, int32 size)
{ {
// TODO: We don't support old data for now // TODO: We don't support old data for now
} }
void void
BPicture::set_token(int32 _token) BPicture::SetToken(int32 _token)
{ {
token = _token; token = _token;
} }
bool bool
BPicture::assert_local_copy() BPicture::_AssertLocalCopy()
{ {
if (extent->Data() != NULL) if (extent->Data() != NULL)
return true; return true;
@@ -388,6 +399,69 @@ BPicture::assert_local_copy()
if (token == -1) if (token == -1)
return false; return false;
return _Download() == B_OK;
}
bool
BPicture::_AssertOldLocalCopy()
{
// TODO: We don't support old data for now
return false;
}
bool
BPicture::_AssertServerCopy()
{
if (token != -1)
return true;
if (extent->Data() == NULL)
return false;
for (int32 i = 0; i < extent->CountPictures(); i++)
extent->PictureAt(i)->_AssertServerCopy();
return _Upload() == B_OK;
}
status_t
BPicture::_Upload()
{
ASSERT((token == -1));
ASSERT((extent->Data() != NULL));
BPrivate::AppServerLink link;
link.StartMessage(AS_CREATE_PICTURE);
link.Attach<int32>(extent->CountPictures());
for (int32 i = 0; i < extent->CountPictures(); i++) {
BPicture *picture = extent->PictureAt(i);
if (picture)
link.Attach<int32>(picture->token);
}
link.Attach<int32>(extent->Size());
link.Attach(extent->Data(), extent->Size());
status_t status = B_ERROR;
if (link.FlushWithReply(status) == B_OK
&& status == B_OK)
link.Read<int32>(&token);
return status;
}
status_t
BPicture::_Download()
{
ASSERT((extent->Data() == NULL));
ASSERT((token != -1));
BPrivate::AppServerLink link; BPrivate::AppServerLink link;
link.StartMessage(AS_DOWNLOAD_PICTURE); link.StartMessage(AS_DOWNLOAD_PICTURE);
@@ -412,50 +486,7 @@ BPicture::assert_local_copy()
link.Read(const_cast<void *>(extent->Data()), size); link.Read(const_cast<void *>(extent->Data()), size);
} }
return status == B_OK; return status;
}
bool
BPicture::assert_old_local_copy()
{
// TODO: We don't support old data for now
return false;
}
bool
BPicture::assert_server_copy()
{
if (token != -1)
return true;
if (extent->Data() == NULL)
return false;
for (int32 i = 0; i < extent->CountPictures(); i++)
extent->PictureAt(i)->assert_server_copy();
BPrivate::AppServerLink link;
link.StartMessage(AS_CREATE_PICTURE);
link.Attach<int32>(extent->CountPictures());
for (int32 i = 0; i < extent->CountPictures(); i++) {
BPicture *picture = extent->PictureAt(i);
if (picture)
link.Attach<int32>(picture->token);
}
link.Attach<int32>(extent->Size());
link.Attach(extent->Data(), extent->Size());
status_t status = B_ERROR;
if (link.FlushWithReply(status) == B_OK
&& status == B_OK)
link.Read<int32>(&token);
return token != -1;
} }
@@ -463,7 +494,7 @@ const void *
BPicture::Data() const BPicture::Data() const
{ {
if (extent->Data() == NULL) if (extent->Data() == NULL)
const_cast<BPicture*>(this)->assert_local_copy(); const_cast<BPicture*>(this)->_AssertLocalCopy();
return extent->Data(); return extent->Data();
} }
@@ -473,35 +504,27 @@ int32
BPicture::DataSize() const BPicture::DataSize() const
{ {
if (extent->Data() == NULL) if (extent->Data() == NULL)
const_cast<BPicture*>(this)->assert_local_copy(); const_cast<BPicture*>(this)->_AssertLocalCopy();
return extent->Size(); return extent->Size();
} }
void void
BPicture::usurp(BPicture *lameDuck) BPicture::Usurp(BPicture *lameDuck)
{ {
if (token != -1) { _DisposeData();
BPrivate::AppServerLink link;
link.StartMessage(AS_DELETE_PICTURE); // Reinitializes the BPicture
link.Attach<int32>(token); _InitData();
link.Flush();
delete extent;
// Reinitializes the BPicture // Do the Usurping
init_data();
}
// Do the usurping
usurped = lameDuck; usurped = lameDuck;
} }
BPicture * BPicture *
BPicture::step_down() BPicture::StepDown()
{ {
BPicture *lameDuck = usurped; BPicture *lameDuck = usurped;
usurped = NULL; usurped = NULL;
+4 -4
View File
@@ -3095,7 +3095,7 @@ void
BView::BeginPicture(BPicture *picture) BView::BeginPicture(BPicture *picture)
{ {
if (do_owner_check() && picture && picture->usurped == NULL) { if (do_owner_check() && picture && picture->usurped == NULL) {
picture->usurp(cpicture); picture->Usurp(cpicture);
cpicture = picture; cpicture = picture;
fOwner->fLink->StartMessage(AS_LAYER_BEGIN_PICTURE); fOwner->fLink->StartMessage(AS_LAYER_BEGIN_PICTURE);
@@ -3115,7 +3115,7 @@ BView::AppendToPicture(BPicture *picture)
BeginPicture(picture); BeginPicture(picture);
} else { } else {
picture->set_token(-1); picture->set_token(-1);
picture->usurp(cpicture); picture->Usurp(cpicture);
cpicture = picture; cpicture = picture;
fOwner->fLink->StartMessage(AS_LAYER_APPEND_TO_PICTURE); fOwner->fLink->StartMessage(AS_LAYER_APPEND_TO_PICTURE);
fOwner->fLink->Attach<int32>(token); fOwner->fLink->Attach<int32>(token);
@@ -3137,8 +3137,8 @@ BView::EndPicture()
&& code == B_OK && code == B_OK
&& fOwner->fLink->Read<int32>(&token) == B_OK) { && fOwner->fLink->Read<int32>(&token) == B_OK) {
BPicture *picture = cpicture; BPicture *picture = cpicture;
cpicture = picture->step_down(); cpicture = picture->StepDown();
picture->set_token(token); picture->SetToken(token);
return picture; return picture;
} }