The DataEditor class is now subclasses from BLocker instead of aggregating

it. This way, it can directly be used in the BAutolock class, and also provides
some more sophisticated locking functions.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6621 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2004-02-18 02:31:48 +00:00
parent 8e900a6933
commit f7efc8f447
2 changed files with 13 additions and 36 deletions

View File

@ -136,31 +136,27 @@ ReplaceChange::Revert(off_t bufferOffset, uint8 *buffer, size_t bufferSize)
DataEditor::DataEditor() DataEditor::DataEditor()
: : BLocker("data view")
fLock("data view")
{ {
} }
DataEditor::DataEditor(entry_ref &ref, const char *attribute) DataEditor::DataEditor(entry_ref &ref, const char *attribute)
: : BLocker("data view")
fLock("data view")
{ {
SetTo(ref, attribute); SetTo(ref, attribute);
} }
DataEditor::DataEditor(BEntry &entry, const char *attribute) DataEditor::DataEditor(BEntry &entry, const char *attribute)
: : BLocker("data view")
fLock("data view")
{ {
SetTo(entry, attribute); SetTo(entry, attribute);
} }
DataEditor::DataEditor(const DataEditor &editor) DataEditor::DataEditor(const DataEditor &editor)
: : BLocker("data view")
fLock("data view")
{ {
} }
@ -290,7 +286,7 @@ DataEditor::AddChange(DataChange *change)
status_t status_t
DataEditor::Replace(off_t offset, const uint8 *data, size_t length) DataEditor::Replace(off_t offset, const uint8 *data, size_t length)
{ {
if (!fLock.IsLocked()) if (!IsLocked())
debugger("DataEditor: view not locked"); debugger("DataEditor: view not locked");
if (fNeedsUpdate) { if (fNeedsUpdate) {
@ -309,7 +305,7 @@ DataEditor::Replace(off_t offset, const uint8 *data, size_t length)
status_t status_t
DataEditor::Remove(off_t offset, off_t length) DataEditor::Remove(off_t offset, off_t length)
{ {
if (!fLock.IsLocked()) if (!IsLocked())
debugger("DataEditor: view not locked"); debugger("DataEditor: view not locked");
// not yet implemented // not yet implemented
@ -321,7 +317,7 @@ DataEditor::Remove(off_t offset, off_t length)
status_t status_t
DataEditor::Insert(off_t offset, const uint8 *text, size_t length) DataEditor::Insert(off_t offset, const uint8 *text, size_t length)
{ {
if (!fLock.IsLocked()) if (!IsLocked())
debugger("DataEditor: view not locked"); debugger("DataEditor: view not locked");
// not yet implemented // not yet implemented
@ -369,7 +365,7 @@ DataEditor::RemoveRedos()
status_t status_t
DataEditor::Undo() DataEditor::Undo()
{ {
BAutolock locker(fLock); BAutolock locker(this);
if (!CanUndo()) if (!CanUndo())
return B_ERROR; return B_ERROR;
@ -389,7 +385,7 @@ DataEditor::Undo()
status_t status_t
DataEditor::Redo() DataEditor::Redo()
{ {
BAutolock locker(fLock); BAutolock locker(this);
if (!CanRedo()) if (!CanRedo())
return B_ERROR; return B_ERROR;
@ -490,7 +486,7 @@ DataEditor::Update()
status_t status_t
DataEditor::GetViewBuffer(const uint8 **_buffer) DataEditor::GetViewBuffer(const uint8 **_buffer)
{ {
if (!fLock.IsLocked()) if (!IsLocked())
debugger("DataEditor: view not locked"); debugger("DataEditor: view not locked");
status_t status = B_OK; status_t status = B_OK;
@ -509,20 +505,6 @@ DataEditor::GetViewBuffer(const uint8 **_buffer)
} }
bool
DataEditor::Lock()
{
return fLock.Lock();
}
void
DataEditor::Unlock()
{
fLock.Unlock();
}
void void
DataEditor::SendNotices(uint32 what, BMessage *message) DataEditor::SendNotices(uint32 what, BMessage *message)
{ {
@ -551,7 +533,7 @@ DataEditor::SendNotices(uint32 what, BMessage *message)
status_t status_t
DataEditor::StartWatching(BMessenger target) DataEditor::StartWatching(BMessenger target)
{ {
BAutolock locker(fLock); BAutolock locker(this);
node_ref node; node_ref node;
status_t status = fFile.GetNodeRef(&node); status_t status = fFile.GetNodeRef(&node);
@ -574,7 +556,7 @@ DataEditor::StartWatching(BHandler *handler, BLooper *looper)
void void
DataEditor::StopWatching(BMessenger target) DataEditor::StopWatching(BMessenger target)
{ {
BAutolock locker(fLock); BAutolock locker(this);
for (int32 i = fObservers.CountItems(); i-- > 0;) { for (int32 i = fObservers.CountItems(); i-- > 0;) {
BMessenger *messenger = fObservers.ItemAt(i); BMessenger *messenger = fObservers.ItemAt(i);

View File

@ -14,7 +14,7 @@
class DataChange; class DataChange;
class DataEditor { class DataEditor : public BLocker {
public: public:
DataEditor(); DataEditor();
DataEditor(entry_ref &ref, const char *attribute = NULL); DataEditor(entry_ref &ref, const char *attribute = NULL);
@ -63,10 +63,6 @@ class DataEditor {
status_t GetViewBuffer(const uint8 **_buffer); status_t GetViewBuffer(const uint8 **_buffer);
BLocker &Locker() { return fLock; }
bool Lock();
void Unlock();
status_t StartWatching(BMessenger target); status_t StartWatching(BMessenger target);
status_t StartWatching(BHandler *handler, BLooper *looper = NULL); status_t StartWatching(BHandler *handler, BLooper *looper = NULL);
void StopWatching(BMessenger target); void StopWatching(BMessenger target);
@ -92,7 +88,6 @@ class DataEditor {
DataChange *fFirstChange; DataChange *fFirstChange;
DataChange *fLastChange; DataChange *fLastChange;
BLocker fLock;
uint8 *fView; uint8 *fView;
off_t fRealViewOffset, fViewOffset; off_t fRealViewOffset, fViewOffset;
size_t fRealViewSize, fViewSize; size_t fRealViewSize, fViewSize;