Extended watching mechanism (it now works more like the BHandler watching
mechanism) - it's not really used yet, though. Fixed some variable initialization bugs and missing return values. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6566 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -9,6 +9,8 @@
|
|||||||
#include <Autolock.h>
|
#include <Autolock.h>
|
||||||
#include <NodeMonitor.h>
|
#include <NodeMonitor.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
class DataChange {
|
class DataChange {
|
||||||
public:
|
public:
|
||||||
@@ -170,7 +172,7 @@ status_t
|
|||||||
DataEditor::SetTo(const char *path, const char *attribute)
|
DataEditor::SetTo(const char *path, const char *attribute)
|
||||||
{
|
{
|
||||||
BEntry entry(path);
|
BEntry entry(path);
|
||||||
SetTo(entry, attribute);
|
return SetTo(entry, attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -178,7 +180,7 @@ status_t
|
|||||||
DataEditor::SetTo(entry_ref &ref, const char *attribute)
|
DataEditor::SetTo(entry_ref &ref, const char *attribute)
|
||||||
{
|
{
|
||||||
BEntry entry(&ref);
|
BEntry entry(&ref);
|
||||||
SetTo(entry, attribute);
|
return SetTo(entry, attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -195,18 +197,32 @@ DataEditor::SetTo(BEntry &entry, const char *attribute)
|
|||||||
fIsReadOnly = true;
|
fIsReadOnly = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct stat stat;
|
||||||
|
stat.st_mode = 0;
|
||||||
|
|
||||||
|
fFile.GetStat(&stat);
|
||||||
|
fIsDevice = (stat.st_mode & (S_IFBLK | S_IFCHR)) != 0;
|
||||||
|
|
||||||
|
// ToDo: add support for devices and attributes!
|
||||||
status = fFile.GetSize(&fSize);
|
status = fFile.GetSize(&fSize);
|
||||||
if (status < B_OK) {
|
if (status < B_OK) {
|
||||||
fFile.Unset();
|
fFile.Unset();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (attribute != NULL)
|
||||||
|
fAttribute = strdup(attribute);
|
||||||
|
else
|
||||||
|
fAttribute = NULL;
|
||||||
|
|
||||||
|
fView = NULL;
|
||||||
fBlockSize = 512;
|
fBlockSize = 512;
|
||||||
fAttribute = attribute;
|
fRealViewOffset = 0;
|
||||||
fRealViewOffset = -1;
|
|
||||||
fViewOffset = 0;
|
fViewOffset = 0;
|
||||||
fRealViewSize = fViewSize = fBlockSize;
|
fRealViewSize = fViewSize = fBlockSize;
|
||||||
fNeedsUpdate = true;
|
fNeedsUpdate = true;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -384,6 +400,7 @@ status_t
|
|||||||
DataEditor::SetFileSize(off_t size)
|
DataEditor::SetFileSize(off_t size)
|
||||||
{
|
{
|
||||||
fSize = size;
|
fSize = size;
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -399,6 +416,8 @@ DataEditor::SetViewOffset(off_t offset)
|
|||||||
fRealViewOffset = (offset / fBlockSize) * fBlockSize;
|
fRealViewOffset = (offset / fBlockSize) * fBlockSize;
|
||||||
fViewOffset = offset;
|
fViewOffset = offset;
|
||||||
fNeedsUpdate = true;
|
fNeedsUpdate = true;
|
||||||
|
|
||||||
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -483,21 +502,75 @@ DataEditor::Unlock()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DataEditor::SendNotices(uint32 what, BMessage *message)
|
||||||
|
{
|
||||||
|
if (fObservers.CountItems() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
BMessage *notice;
|
||||||
|
if (message) {
|
||||||
|
notice = new BMessage(*message);
|
||||||
|
notice->what = B_OBSERVER_NOTICE_CHANGE;
|
||||||
|
notice->AddInt32(B_OBSERVE_ORIGINAL_WHAT, message->what);
|
||||||
|
} else
|
||||||
|
notice = new BMessage(B_OBSERVER_NOTICE_CHANGE);
|
||||||
|
|
||||||
|
notice->AddInt32(B_OBSERVE_WHAT_CHANGE, what);
|
||||||
|
|
||||||
|
for (int32 i = fObservers.CountItems(); i-- > 0;) {
|
||||||
|
BMessenger *messenger = fObservers.ItemAt(i);
|
||||||
|
messenger->SendMessage(notice);
|
||||||
|
}
|
||||||
|
|
||||||
|
delete notice;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
DataEditor::StartWatching(BMessenger target)
|
DataEditor::StartWatching(BMessenger target)
|
||||||
{
|
{
|
||||||
|
BAutolock locker(fLock);
|
||||||
|
|
||||||
node_ref node;
|
node_ref node;
|
||||||
status_t status = fFile.GetNodeRef(&node);
|
status_t status = fFile.GetNodeRef(&node);
|
||||||
if (status < B_OK)
|
if (status < B_OK)
|
||||||
return status;
|
return status;
|
||||||
|
|
||||||
|
fObservers.AddItem(new BMessenger(target));
|
||||||
|
|
||||||
return watch_node(&node, B_WATCH_STAT | B_WATCH_ATTR, target);
|
return watch_node(&node, B_WATCH_STAT | B_WATCH_ATTR, target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
DataEditor::StartWatching(BHandler *handler, BLooper *looper)
|
||||||
|
{
|
||||||
|
return StartWatching(BMessenger(handler, looper));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DataEditor::StopWatching(BMessenger target)
|
DataEditor::StopWatching(BMessenger target)
|
||||||
{
|
{
|
||||||
|
BAutolock locker(fLock);
|
||||||
|
|
||||||
|
for (int32 i = fObservers.CountItems(); i-- > 0;) {
|
||||||
|
BMessenger *messenger = fObservers.ItemAt(i);
|
||||||
|
if (*messenger == target) {
|
||||||
|
fObservers.RemoveItemAt(i);
|
||||||
|
delete messenger;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stop_watching(target);
|
stop_watching(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
DataEditor::StopWatching(BHandler *handler, BLooper *looper)
|
||||||
|
{
|
||||||
|
StopWatching(BMessenger(handler, looper));
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,8 +29,11 @@ class DataEditor {
|
|||||||
|
|
||||||
bool IsReadOnly() const { return fIsReadOnly; }
|
bool IsReadOnly() const { return fIsReadOnly; }
|
||||||
bool IsDevice() const { return fIsDevice; }
|
bool IsDevice() const { return fIsDevice; }
|
||||||
|
bool IsAttribute() const { return fAttribute != NULL; }
|
||||||
//bool IsModified() const { return fIsModified; }
|
//bool IsModified() const { return fIsModified; }
|
||||||
|
|
||||||
|
const char *Attribute() const { return fAttribute; }
|
||||||
|
|
||||||
status_t InitCheck();
|
status_t InitCheck();
|
||||||
|
|
||||||
status_t Replace(off_t offset, const uint8 *data, size_t length);
|
status_t Replace(off_t offset, const uint8 *data, size_t length);
|
||||||
@@ -65,16 +68,21 @@ class DataEditor {
|
|||||||
void Unlock();
|
void Unlock();
|
||||||
|
|
||||||
status_t StartWatching(BMessenger target);
|
status_t StartWatching(BMessenger target);
|
||||||
|
status_t StartWatching(BHandler *handler, BLooper *looper = NULL);
|
||||||
void StopWatching(BMessenger target);
|
void StopWatching(BMessenger target);
|
||||||
|
void StopWatching(BHandler *handler, BLooper *looper = NULL);
|
||||||
|
|
||||||
BFile &File() { return fFile; }
|
BFile &File() { return fFile; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void SendNotices(uint32 what, BMessage *message = NULL);
|
||||||
status_t Update();
|
status_t Update();
|
||||||
void AddChange(DataChange *change);
|
void AddChange(DataChange *change);
|
||||||
void ApplyChanges();
|
void ApplyChanges();
|
||||||
void RemoveRedos();
|
void RemoveRedos();
|
||||||
|
|
||||||
|
BObjectList<BMessenger> fObservers;
|
||||||
|
|
||||||
BFile fFile;
|
BFile fFile;
|
||||||
const char *fAttribute;
|
const char *fAttribute;
|
||||||
bool fIsDevice, fIsReadOnly;
|
bool fIsDevice, fIsReadOnly;
|
||||||
@@ -93,4 +101,9 @@ class DataEditor {
|
|||||||
size_t fBlockSize;
|
size_t fBlockSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const uint32 kMsgDataEditorUndoState = 'deUS';
|
||||||
|
static const uint32 kMsgDataEditorRedoState = 'deRS';
|
||||||
|
static const uint32 kMsgDataEditorModifiedState = 'deMS';
|
||||||
|
static const uint32 kMsgDataEditorUpdate = 'deUp';
|
||||||
|
|
||||||
#endif /* DATA_EDITOR_H */
|
#endif /* DATA_EDITOR_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user