btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / diskprobe / DataEditor.h
blob1d0ef7c9c6ea8ef1949d59f9173b86b54a0baada
1 /*
2 * Copyright 2004-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef DATA_EDITOR_H
6 #define DATA_EDITOR_H
9 #include <File.h>
10 #include <Entry.h>
11 #include <Locker.h>
12 #include <ObjectList.h>
14 class BHandler;
15 class BLooper;
16 class BMessage;
17 class BMessenger;
19 class DataChange;
20 class StateWatcher;
23 class DataEditor : public BLocker {
24 public:
25 DataEditor();
26 DataEditor(entry_ref &ref, const char *attribute = NULL);
27 DataEditor(BEntry &entry, const char *attribute = NULL);
28 DataEditor(const DataEditor &editor);
29 ~DataEditor();
31 status_t SetTo(const char *path, const char *attribute = NULL);
32 status_t SetTo(entry_ref &ref, const char *attribute = NULL);
33 status_t SetTo(BEntry &entry, const char *attribute = NULL);
35 status_t Save();
37 bool IsReadOnly() const { return fIsReadOnly; }
38 bool IsDevice() const { return fIsDevice; }
39 bool IsAttribute() const { return fAttribute != NULL; }
40 bool IsModified() const { return fLastChange != fFirstChange; }
42 const char *Attribute() const { return fAttribute; }
43 type_code Type() const { return fType; }
45 status_t InitCheck();
47 status_t Replace(off_t offset, const uint8 *data, size_t length);
48 status_t Remove(off_t offset, off_t length);
49 status_t Insert(off_t offset, const uint8 *data, size_t length);
51 status_t MoveBy(int32 bytes);
52 status_t MoveTo(off_t offset);
54 status_t Undo();
55 status_t Redo();
57 bool CanUndo() const;
58 bool CanRedo() const;
60 status_t SetFileSize(off_t size);
61 off_t FileSize() const { return fSize; }
63 status_t SetViewOffset(off_t offset);
64 off_t ViewOffset() const { return fViewOffset; }
66 status_t SetViewSize(size_t size);
67 size_t ViewSize() const { return fViewSize; }
69 status_t SetBlockSize(size_t size);
70 size_t BlockSize() const { return fBlockSize; }
72 status_t UpdateIfNeeded(bool *_updated = NULL);
73 status_t ForceUpdate();
74 status_t GetViewBuffer(const uint8 **_buffer);
76 status_t StartWatching(BMessenger target);
77 status_t StartWatching(BHandler *handler, BLooper *looper = NULL);
78 void StopWatching(BMessenger target);
79 void StopWatching(BHandler *handler, BLooper *looper = NULL);
81 off_t Find(off_t startPosition, const uint8 *data, size_t dataSize,
82 bool caseInsensitive, bool cyclic,
83 BMessenger progressMessenger, volatile bool *stop = NULL);
85 BFile &File() { return fFile; }
86 const entry_ref &AttributeRef() const { return fAttributeRef; }
87 const entry_ref &Ref() const { return fRef; }
89 private:
90 friend class StateWatcher;
92 status_t SetViewOffset(off_t offset, bool sendNotices);
93 status_t SetViewSize(size_t size, bool sendNotices);
94 void SendNotices(uint32 what, BMessage *message = NULL);
95 void SendNotices(DataChange *change);
96 status_t Update();
97 void AddChange(DataChange *change);
98 void ApplyChanges();
99 void RemoveRedos();
101 BObjectList<BMessenger> fObservers;
103 entry_ref fRef, fAttributeRef;
104 BFile fFile;
105 const char *fAttribute;
106 type_code fType;
107 bool fIsDevice, fIsReadOnly;
108 off_t fRealSize, fSize;
110 BObjectList<DataChange> fChanges;
111 DataChange *fFirstChange;
112 DataChange *fLastChange;
113 int32 fChangesFromSaved;
115 uint8 *fView;
116 off_t fRealViewOffset, fViewOffset;
117 size_t fRealViewSize, fViewSize;
118 bool fNeedsUpdate;
120 size_t fBlockSize;
123 static const uint32 kMsgDataEditorStateChange = 'deSC';
124 static const uint32 kMsgDataEditorUpdate = 'deUp';
125 static const uint32 kMsgDataEditorParameterChange = 'dePC';
127 static const uint32 kMsgDataEditorFindProgress = 'deFP';
129 #endif /* DATA_EDITOR_H */