2 * Copyright 2011, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Clemens Zeidler <haiku@clemens-zeidler.de>
18 #include "NodeMonitorHandler.h"
24 /*! Don't use it as the primary cookie storage. To be set in EntryCreated
25 in EntryViewInterface. */
33 operator()(const node_ref
& a
, const node_ref
& b
)
35 return a
.node
< b
.node
;
40 typedef std::map
<node_ref
, WatchedFile
, NodeRefComp
> WatchedFileList
;
43 class EntryViewInterface
{
45 virtual ~EntryViewInterface() {};
47 virtual void EntryCreated(WatchedFile
* file
) {};
48 virtual void EntryRemoved(WatchedFile
* file
) {};
49 virtual void EntryMoved(WatchedFile
* file
) {};
50 virtual void StatChanged(WatchedFile
* file
) {};
51 virtual void AttrChanged(WatchedFile
* file
) {};
53 virtual void EntriesCleared() {};
57 const uint32 kMsgAddRefs
= '&adr';
58 const uint32 kMsgCleared
= '&clr';
61 typedef std::vector
<entry_ref
> RefList
;
67 class FileMonitor
: public NodeMonitorHandler
{
69 FileMonitor(EntryViewInterface
* listener
);
72 void SetReadThread(ReadThread
* readThread
);
76 virtual void MessageReceived(BMessage
* message
);
78 virtual void EntryCreated(const char *name
, ino_t directory
,
79 dev_t device
, ino_t node
);
80 virtual void EntryRemoved(const char *name
, ino_t directory
,
81 dev_t device
, ino_t node
);
82 virtual void EntryMoved(const char *name
,
83 const char *fromName
, ino_t fromDirectory
,
84 ino_t toDirectory
, dev_t device
,
85 ino_t node
, dev_t nodeDevice
);
86 virtual void StatChanged(ino_t node
, dev_t device
,
88 virtual void AttrChanged(ino_t node
, dev_t device
);
91 WatchedFile
* _FindFile(dev_t device
, ino_t node
);
93 EntryViewInterface
* fListener
;
94 WatchedFileList fWatchedFileList
;
96 ReadThread
* fReadThread
;
97 RefList
* fCurrentReadList
;
98 uint32 fCurrentReadIndex
;
104 ReadThread(FileMonitor
* target
);
105 virtual ~ReadThread() {}
114 RefList
* ReadRefList();
118 virtual bool ReadNextEntry(entry_ref
& entry
) = 0;
122 friend int32
ReadThreadFunction(void *data
);
128 RefList
* fWriteRefList
;
129 RefList
* fReadRefList
;
134 inline void _PublishEntrys(BMessenger
& messenger
);
144 #endif // FILE_MONITOR_H