PageRenderTime 12ms CodeModel.GetById 8ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/google-toolbox-for-mac/Foundation/GTMFileSystemKQueue.h

http://macfuse.googlecode.com/
C++ Header | 78 lines | 31 code | 7 blank | 40 comment | 0 complexity | e0791aba9449c10d8ec2b0a865af2738 MD5 | raw file
 1//
 2//  GTMFileSystemKQueue.h
 3//
 4//  Copyright 2008 Google Inc.
 5//
 6//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
 7//  use this file except in compliance with the License.  You may obtain a copy
 8//  of the License at
 9// 
10//  http://www.apache.org/licenses/LICENSE-2.0
11// 
12//  Unless required by applicable law or agreed to in writing, software
13//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
15//  License for the specific language governing permissions and limitations under
16//  the License.
17//
18
19#import <Foundation/Foundation.h>
20
21#import <sys/event.h>  // for kqueue() and kevent and the NOTE_* constants
22
23//  Event constants
24enum {
25  kGTMFileSystemKQueueDeleteEvent = NOTE_DELETE,
26  kGTMFileSystemKQueueWriteEvent = NOTE_WRITE,
27  kGTMFileSystemKQueueExtendEvent = NOTE_EXTEND,
28  kGTMFileSystemKQueueAttributeChangeEvent = NOTE_ATTRIB,
29  kGTMFileSystemKQueueLinkChangeEvent = NOTE_LINK,
30  kGTMFileSystemKQueueRenameEvent = NOTE_RENAME,
31  kGTMFileSystemKQueueRevokeEvent = NOTE_REVOKE,
32  kGTMFileSystemKQueueAllEvents = NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND |
33                                  NOTE_ATTRIB | NOTE_LINK | NOTE_RENAME |
34                                  NOTE_REVOKE,
35};
36typedef unsigned int GTMFileSystemKQueueEvents;
37
38// GTMFileSystemKQueue.
39//
40// This is a very simple, easy-to-use class for registering handlers that get
41// called when a events happen to a given file system path.
42//
43// The default runloop for the first path kqueued is used for notification
44// delivery, so keep that in mind when you're using this class.  This class
45// explicitly does not handle arbitrary runloops and threading.
46//
47@interface GTMFileSystemKQueue : NSObject {
48 @private
49  NSString *path_;
50  int fd_;
51  GTMFileSystemKQueueEvents events_;
52  BOOL acrossReplace_;
53  __weak id target_;
54  SEL action_;
55}
56
57// |path| is the full path to monitor.  |events| is a combination of events
58// listed above that you want notification of.  |acrossReplace| will cause this
59// object to reattach when a the file is deleted & recreated or moved out of the
60// way and a new one put in place.  |selector| should be of the signature:
61//    - (void)fileSystemKQueue:(GTMFileSystemKQueue *)fskq
62//                      events:(GTMFileSystemKQueueEvents)events;
63// where the events can be one or more of the events listed above ORed together.
64//
65// NOTE: |acrossReplace| is not fool proof.  If the file is renamed/deleted,
66// then the object will make one attempt at the time it gets the rename/delete
67// to reopen the file.  If the new file has not been created, no more action is
68// taken.  To handle the file coming into existance later, you need to monitor
69// the directory in some other way.
70- (id)initWithPath:(NSString *)path
71         forEvents:(GTMFileSystemKQueueEvents)events
72     acrossReplace:(BOOL)acrossReplace
73            target:(id)target
74            action:(SEL)action;
75
76- (NSString *)path;
77
78@end