1 /* fswatcher.h
2  *
3  * Copyright (C) 2004-2013 Free Software Foundation, Inc.
4  *
5  * Author: Enrico Sersale <enrico@imago.ro>
6  * Date: February 2004
7  *
8  * This file is part of the GNUstep GWorkspace application
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
23  */
24 
25 #ifndef FSWATCHER_H
26 #define FSWATCHER_H
27 
28 #import <Foundation/Foundation.h>
29 #import "DBKPathsTree.h"
30 
31 @class Watcher;
32 
33 @protocol	FSWClientProtocol <NSObject>
34 
35 - (oneway void)watchedPathDidChange:(NSData *)dirinfo;
36 
37 - (oneway void)globalWatchedPathDidChange:(NSDictionary *)dirinfo;
38 
39 @end
40 
41 
42 @protocol	FSWatcherProtocol
43 
44 - (oneway void)registerClient:(id <FSWClientProtocol>)client
45               isGlobalWatcher:(BOOL)global;
46 
47 - (oneway void)unregisterClient:(id <FSWClientProtocol>)client;
48 
49 - (oneway void)client:(id <FSWClientProtocol>)client
50                           addWatcherForPath:(NSString *)path;
51 
52 - (oneway void)client:(id <FSWClientProtocol>)client
53                           removeWatcherForPath:(NSString *)path;
54 
55 @end
56 
57 
58 @interface FSWClientInfo: NSObject
59 {
60   NSConnection *conn;
61   id <FSWClientProtocol> client;
62   NSCountedSet *wpaths;
63   BOOL global;
64 }
65 
66 - (void)setConnection:(NSConnection *)connection;
67 
68 - (NSConnection *)connection;
69 
70 - (void)setClient:(id <FSWClientProtocol>)clnt;
71 
72 - (id <FSWClientProtocol>)client;
73 
74 - (void)addWatchedPath:(NSString *)path;
75 
76 - (void)removeWatchedPath:(NSString *)path;
77 
78 - (BOOL)isWatchingPath:(NSString *)path;
79 
80 - (NSSet *)watchedPaths;
81 
82 - (void)setGlobal:(BOOL)value;
83 
84 - (BOOL)isGlobal;
85 
86 @end
87 
88 
89 @interface FSWatcher: NSObject
90 {
91   NSConnection *conn;
92   NSMutableArray *clientsInfo;
93   NSMapTable *watchers;
94 
95   pcomp *includePathsTree;
96   pcomp *excludePathsTree;
97   NSMutableSet *excludedSuffixes;
98 
99   NSFileManager *fm;
100   NSNotificationCenter *nc;
101   NSNotificationCenter *dnc;
102 }
103 
104 - (BOOL)connection:(NSConnection *)ancestor
105             shouldMakeNewConnection:(NSConnection *)newConn;
106 
107 - (void)connectionBecameInvalid:(NSNotification *)notification;
108 
109 - (void)setDefaultGlobalPaths;
110 
111 - (void)globalPathsChanged:(NSNotification *)notification;
112 
113 - (oneway void)registerClient:(id <FSWClientProtocol>)client
114               isGlobalWatcher:(BOOL)global;
115 
116 - (oneway void)unregisterClient:(id <FSWClientProtocol>)client;
117 
118 - (FSWClientInfo *)clientInfoWithConnection:(NSConnection *)connection;
119 
120 - (FSWClientInfo *)clientInfoWithRemote:(id)remote;
121 
122 - (oneway void)client:(id <FSWClientProtocol>)client
123                                 addWatcherForPath:(NSString *)path;
124 
125 - (oneway void)client:(id <FSWClientProtocol>)client
126                                 removeWatcherForPath:(NSString *)path;
127 
128 - (Watcher *)watcherForPath:(NSString *)path;
129 
130 - (void)watcherTimeOut:(NSTimer *)sender;
131 
132 - (void)removeWatcher:(Watcher *)awatcher;
133 
134 - (pcomp *)includePathsTree;
135 
136 - (pcomp *)excludePathsTree;
137 
138 - (NSSet *)excludedSuffixes;
139 
140 - (BOOL)isGlobalValidPath:(NSString *)path;
141 
142 - (void)notifyClients:(NSDictionary *)info;
143 
144 - (void)notifyGlobalWatchingClients:(NSDictionary *)info;
145 
146 @end
147 
148 
149 @interface Watcher: NSObject
150 {
151   NSString *watchedPath;
152   BOOL isdir;
153   NSArray *pathContents;
154   int listeners;
155   NSDate *date;
156   BOOL isOld;
157   NSFileManager *fm;
158   FSWatcher *fswatcher;
159   NSTimer *timer;
160 }
161 
162 - (id)initWithWatchedPath:(NSString *)path
163                 fswatcher:(id)fsw;
164 
165 - (void)watchFile;
166 
167 - (void)addListener;
168 
169 - (void)removeListener;
170 
171 - (BOOL)isWatchingPath:(NSString *)apath;
172 
173 - (NSString *)watchedPath;
174 
175 - (BOOL)isOld;
176 
177 - (NSTimer *)timer;
178 
179 @end
180 
181 
182 #endif // FSWATCHER_H
183