Moved some functions around, some minor cleanups...
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20287 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <new>
|
||||||
|
|
||||||
struct _BPictureExtent_ {
|
struct _BPictureExtent_ {
|
||||||
_BPictureExtent_(const int32 &size = 0);
|
_BPictureExtent_(const int32 &size = 0);
|
||||||
@@ -115,23 +116,22 @@ BPicture::BPicture(BMessage *archive)
|
|||||||
{
|
{
|
||||||
init_data();
|
init_data();
|
||||||
|
|
||||||
int32 version, size;
|
int32 version;
|
||||||
int8 endian;
|
|
||||||
const void *data;
|
|
||||||
|
|
||||||
if (archive->FindInt32("_ver", &version) != B_OK)
|
if (archive->FindInt32("_ver", &version) != B_OK)
|
||||||
version = 0;
|
version = 0;
|
||||||
|
|
||||||
|
int8 endian;
|
||||||
if (archive->FindInt8("_endian", &endian) != B_OK)
|
if (archive->FindInt8("_endian", &endian) != B_OK)
|
||||||
endian = 0;
|
endian = 0;
|
||||||
|
|
||||||
|
const void *data;
|
||||||
|
int32 size;
|
||||||
if (archive->FindData("_data", B_RAW_TYPE, &data, (ssize_t*)&size) != B_OK)
|
if (archive->FindData("_data", B_RAW_TYPE, &data, (ssize_t*)&size) != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Load sub pictures
|
// Load sub pictures
|
||||||
BMessage picMsg;
|
BMessage picMsg;
|
||||||
int32 i = 0;
|
int32 i = 0;
|
||||||
|
|
||||||
while (archive->FindMessage("piclib", i++, &picMsg) == B_OK) {
|
while (archive->FindMessage("piclib", i++, &picMsg) == B_OK) {
|
||||||
BPicture *pic = new BPicture(&picMsg);
|
BPicture *pic = new BPicture(&picMsg);
|
||||||
extent->AddPicture(pic);
|
extent->AddPicture(pic);
|
||||||
@@ -144,25 +144,8 @@ BPicture::BPicture(BMessage *archive)
|
|||||||
|
|
||||||
// swap_data(extent->fNewData, extent->fNewSize);
|
// swap_data(extent->fNewData, extent->fNewSize);
|
||||||
|
|
||||||
if (extent->Size() > 0) {
|
if (extent->Size() > 0)
|
||||||
BPrivate::AppServerLink link;
|
assert_server_copy();
|
||||||
|
|
||||||
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 != NULL)
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do we just free the data now?
|
// Do we just free the data now?
|
||||||
@@ -181,6 +164,23 @@ BPicture::BPicture(BMessage *archive)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BPicture::BPicture(const void *data, int32 size)
|
||||||
|
{
|
||||||
|
init_data();
|
||||||
|
import_old_data(data, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
BPicture::init_data()
|
||||||
|
{
|
||||||
|
token = -1;
|
||||||
|
usurped = NULL;
|
||||||
|
|
||||||
|
extent = new (nothrow) _BPictureExtent_;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BPicture::~BPicture()
|
BPicture::~BPicture()
|
||||||
{
|
{
|
||||||
if (token != -1) {
|
if (token != -1) {
|
||||||
@@ -339,24 +339,10 @@ BPicture::Unflatten(BDataIO *stream)
|
|||||||
|
|
||||||
// swap_data(extent->fNewData, extent->fNewSize);
|
// swap_data(extent->fNewData, extent->fNewSize);
|
||||||
|
|
||||||
BPrivate::AppServerLink link;
|
if (!assert_server_copy())
|
||||||
|
return B_ERROR;
|
||||||
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 = B_ERROR;
|
|
||||||
if (link.FlushWithReply(status) == B_OK
|
|
||||||
&& status == B_OK)
|
|
||||||
link.Read<int32>(&token);
|
|
||||||
|
|
||||||
|
// Data is now kept server side, remove the local copy
|
||||||
if (extent->Data() != NULL)
|
if (extent->Data() != NULL)
|
||||||
extent->SetSize(0);
|
extent->SetSize(0);
|
||||||
|
|
||||||
@@ -364,32 +350,12 @@ BPicture::Unflatten(BDataIO *stream)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BPicture::_ReservedPicture1() {}
|
|
||||||
void BPicture::_ReservedPicture2() {}
|
|
||||||
void BPicture::_ReservedPicture3() {}
|
|
||||||
|
|
||||||
|
|
||||||
BPicture &
|
|
||||||
BPicture::operator=(const BPicture &)
|
|
||||||
{
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
BPicture::init_data()
|
|
||||||
{
|
|
||||||
token = -1;
|
|
||||||
usurped = NULL;
|
|
||||||
|
|
||||||
extent = new _BPictureExtent_;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BPicture::import_data(const void *data, int32 size, BPicture **subs,
|
BPicture::import_data(const void *data, int32 size, BPicture **subs,
|
||||||
int32 subCount)
|
int32 subCount)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
if (data == NULL || size == 0)
|
if (data == NULL || size == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -407,7 +373,7 @@ BPicture::import_data(const void *data, int32 size, BPicture **subs,
|
|||||||
status_t status = B_ERROR;
|
status_t status = B_ERROR;
|
||||||
if (link.FlushWithReply(status) == B_OK
|
if (link.FlushWithReply(status) == B_OK
|
||||||
&& status == B_OK)
|
&& status == B_OK)
|
||||||
link.Read<int32>(&token);
|
link.Read<int32>(&token);*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -479,7 +445,7 @@ BPicture::assert_local_copy()
|
|||||||
link.Read<int32>(&size);
|
link.Read<int32>(&size);
|
||||||
status = extent->SetSize(size);
|
status = extent->SetSize(size);
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
link.Read(const_cast<void *>(extent->Data()), extent->Size());
|
link.Read(const_cast<void *>(extent->Data()), size);
|
||||||
}
|
}
|
||||||
|
|
||||||
return status == B_OK;
|
return status == B_OK;
|
||||||
@@ -515,28 +481,27 @@ BPicture::assert_server_copy()
|
|||||||
extent->PictureAt(i)->assert_server_copy();
|
extent->PictureAt(i)->assert_server_copy();
|
||||||
|
|
||||||
BPrivate::AppServerLink link;
|
BPrivate::AppServerLink link;
|
||||||
|
|
||||||
link.StartMessage(AS_CREATE_PICTURE);
|
link.StartMessage(AS_CREATE_PICTURE);
|
||||||
link.Attach<int32>(extent->CountPictures());
|
link.Attach<int32>(extent->CountPictures());
|
||||||
for (int32 i = 0; i < extent->CountPictures(); i++)
|
|
||||||
link.Attach<int32>(extent->PictureAt(i)->token);
|
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<int32>(extent->Size());
|
||||||
link.Attach(extent->Data(), extent->Size());
|
link.Attach(extent->Data(), extent->Size());
|
||||||
|
|
||||||
status_t status = B_ERROR;
|
status_t status = B_ERROR;
|
||||||
if (link.FlushWithReply(status) == B_OK && status == B_OK)
|
if (link.FlushWithReply(status) == B_OK
|
||||||
|
&& status == B_OK)
|
||||||
link.Read<int32>(&token);
|
link.Read<int32>(&token);
|
||||||
|
|
||||||
return token != -1;
|
return token != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BPicture::BPicture(const void *data, int32 size)
|
|
||||||
{
|
|
||||||
init_data();
|
|
||||||
import_old_data(data, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const void *
|
const void *
|
||||||
BPicture::Data() const
|
BPicture::Data() const
|
||||||
{
|
{
|
||||||
@@ -598,6 +563,18 @@ BPicture::step_down()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BPicture::_ReservedPicture1() {}
|
||||||
|
void BPicture::_ReservedPicture2() {}
|
||||||
|
void BPicture::_ReservedPicture3() {}
|
||||||
|
|
||||||
|
|
||||||
|
BPicture &
|
||||||
|
BPicture::operator=(const BPicture &)
|
||||||
|
{
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
do_playback(void * data, int32 size, BList* pictures,
|
do_playback(void * data, int32 size, BList* pictures,
|
||||||
void **callBackTable, int32 tableEntries, void *user)
|
void **callBackTable, int32 tableEntries, void *user)
|
||||||
@@ -608,7 +585,7 @@ do_playback(void * data, int32 size, BList* pictures,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// _BPictureExtent_
|
||||||
_BPictureExtent_::_BPictureExtent_(const int32 &size)
|
_BPictureExtent_::_BPictureExtent_(const int32 &size)
|
||||||
:
|
:
|
||||||
fNewData(NULL),
|
fNewData(NULL),
|
||||||
@@ -652,16 +629,27 @@ _BPictureExtent_::ImportData(BDataIO *stream)
|
|||||||
if (stream == NULL)
|
if (stream == NULL)
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
status_t status = B_OK;
|
|
||||||
int32 size;
|
int32 size;
|
||||||
stream->Read(&size, sizeof(size));
|
ssize_t bytesRead = stream->Read(&size, sizeof(size));
|
||||||
|
if (bytesRead < B_OK)
|
||||||
|
return bytesRead;
|
||||||
|
if (bytesRead != (ssize_t)sizeof(size))
|
||||||
|
return B_IO_ERROR;
|
||||||
|
|
||||||
|
status_t status = B_OK;
|
||||||
if (Size() != size)
|
if (Size() != size)
|
||||||
status = SetSize(size);
|
status = SetSize(size);
|
||||||
|
|
||||||
if (status == B_OK)
|
if (status < B_OK)
|
||||||
stream->Read(fNewData, size);
|
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
|
bytesRead = stream->Read(fNewData, size);
|
||||||
|
if (bytesRead < B_OK)
|
||||||
|
return bytesRead;
|
||||||
|
if (bytesRead != (ssize_t)size)
|
||||||
|
return B_IO_ERROR;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user