Add data structure for watch descriptor management
For watching whole trees - a change which is upcoming - the watch descriptor IDs will have to be managed in multiple lists. The InotifyWatchManager encapsulates the managment logic within a nice API.
This commit is contained in:
18
Sources/Inotify/InotifyWatchManager.swift
Normal file
18
Sources/Inotify/InotifyWatchManager.swift
Normal file
@@ -0,0 +1,18 @@
|
||||
struct InotifyWatchManager {
|
||||
private var watchPaths: [CInt: String] = [:]
|
||||
private var activeWatches: Set<CInt> = []
|
||||
|
||||
mutating func add(_ path: String, withId watchDescriptor: CInt) {
|
||||
self.watchPaths[watchDescriptor] = path
|
||||
self.activeWatches.insert(watchDescriptor)
|
||||
}
|
||||
|
||||
mutating func remove(forId watchDescriptor: CInt) {
|
||||
self.watchPaths.removeValue(forKey: watchDescriptor)
|
||||
self.activeWatches.remove(watchDescriptor)
|
||||
}
|
||||
|
||||
func path(forId watchDescriptor: CInt) -> String? {
|
||||
return self.watchPaths[watchDescriptor]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user