From 053bb7380a14cb55cd8dfcdf6d5ec753b0355f1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 24 Feb 2004 03:27:45 +0000 Subject: [PATCH] Added a UpdateIfNeeded() method that you can call when you are not interested in the data at all. No longer imitates the BHandler observer model, but directly send its update messages to the observers. Now also stores the entry_ref of the file/device in the editor. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6704 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/diskprobe/DataEditor.cpp | 35 +++++++++++++++++++++++-------- src/apps/diskprobe/DataEditor.h | 8 +++++-- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/apps/diskprobe/DataEditor.cpp b/src/apps/diskprobe/DataEditor.cpp index c6cabbf919..66d7a2c7cc 100644 --- a/src/apps/diskprobe/DataEditor.cpp +++ b/src/apps/diskprobe/DataEditor.cpp @@ -195,6 +195,8 @@ DataEditor::SetTo(BEntry &entry, const char *attribute) fIsReadOnly = true; } + entry.GetRef(&fRef); + struct stat stat; stat.st_mode = 0; @@ -435,6 +437,7 @@ DataEditor::SetViewOffset(off_t offset) fViewOffset = offset; fNeedsUpdate = true; + SendNotices(kMsgDataEditorOffsetChange); return B_OK; } @@ -485,19 +488,36 @@ DataEditor::Update() status_t -DataEditor::GetViewBuffer(const uint8 **_buffer) +DataEditor::UpdateIfNeeded(bool *_updated = NULL) { - if (!IsLocked()) - debugger("DataEditor: view not locked"); + if (!fNeedsUpdate) { + if (_updated) + *_updated = false; + return B_OK; + } status_t status = B_OK; if (fView == NULL) status = SetViewOffset(fViewOffset); - if (status == B_OK && fNeedsUpdate) + if (status == B_OK && fNeedsUpdate) { status = Update(); + if (status == B_OK && _updated) + *_updated = true; + } + return status; +} + + +status_t +DataEditor::GetViewBuffer(const uint8 **_buffer) +{ + if (!IsLocked()) + debugger("DataEditor: view not locked"); + + status_t status = UpdateIfNeeded(); if (status < B_OK) return status; @@ -515,12 +535,9 @@ DataEditor::SendNotices(uint32 what, BMessage *message) BMessage *notice; if (message) { notice = new BMessage(*message); - notice->what = B_OBSERVER_NOTICE_CHANGE; - notice->AddInt32(B_OBSERVE_ORIGINAL_WHAT, message->what); + notice->what = what; } else - notice = new BMessage(B_OBSERVER_NOTICE_CHANGE); - - notice->AddInt32(B_OBSERVE_WHAT_CHANGE, what); + notice = new BMessage(what); for (int32 i = fObservers.CountItems(); i-- > 0;) { BMessenger *messenger = fObservers.ItemAt(i); diff --git a/src/apps/diskprobe/DataEditor.h b/src/apps/diskprobe/DataEditor.h index 07a7cc794e..8e19e4f6b3 100644 --- a/src/apps/diskprobe/DataEditor.h +++ b/src/apps/diskprobe/DataEditor.h @@ -61,6 +61,7 @@ class DataEditor : public BLocker { void SetBlockSize(size_t size); size_t BlockSize() const { return fBlockSize; } + status_t UpdateIfNeeded(bool *_updated = NULL); status_t GetViewBuffer(const uint8 **_buffer); status_t StartWatching(BMessenger target); @@ -69,6 +70,7 @@ class DataEditor : public BLocker { void StopWatching(BHandler *handler, BLooper *looper = NULL); BFile &File() { return fFile; } + const entry_ref &Ref() const { return fRef; } private: void SendNotices(uint32 what, BMessage *message = NULL); @@ -79,6 +81,7 @@ class DataEditor : public BLocker { BObjectList fObservers; + entry_ref fRef; BFile fFile; const char *fAttribute; bool fIsDevice, fIsReadOnly; @@ -96,7 +99,8 @@ class DataEditor : public BLocker { size_t fBlockSize; }; -static const uint32 kDataEditorStateChange = 'deSC'; -static const uint32 kDataEditorUpdate = 'deUp'; +static const uint32 kMsgDataEditorStateChange = 'deSC'; +static const uint32 kMsgDataEditorUpdate = 'deUp'; +static const uint32 kMsgDataEditorOffsetChange = 'deOC'; #endif /* DATA_EDITOR_H */