/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. #import <Foundation/Foundation.h>
  19. #import <sys/event.h> // for kqueue() and kevent and the NOTE_* constants
  20. // Event constants
  21. enum {
  22. kGTMFileSystemKQueueDeleteEvent = NOTE_DELETE,
  23. kGTMFileSystemKQueueWriteEvent = NOTE_WRITE,
  24. kGTMFileSystemKQueueExtendEvent = NOTE_EXTEND,
  25. kGTMFileSystemKQueueAttributeChangeEvent = NOTE_ATTRIB,
  26. kGTMFileSystemKQueueLinkChangeEvent = NOTE_LINK,
  27. kGTMFileSystemKQueueRenameEvent = NOTE_RENAME,
  28. kGTMFileSystemKQueueRevokeEvent = NOTE_REVOKE,
  29. kGTMFileSystemKQueueAllEvents = NOTE_DELETE | NOTE_WRITE | NOTE_EXTEND |
  30. NOTE_ATTRIB | NOTE_LINK | NOTE_RENAME |
  31. NOTE_REVOKE,
  32. };
  33. typedef unsigned int GTMFileSystemKQueueEvents;
  34. // GTMFileSystemKQueue.
  35. //
  36. // This is a very simple, easy-to-use class for registering handlers that get
  37. // called when a events happen to a given file system path.
  38. //
  39. // The default runloop for the first path kqueued is used for notification
  40. // delivery, so keep that in mind when you're using this class. This class
  41. // explicitly does not handle arbitrary runloops and threading.
  42. //
  43. @interface GTMFileSystemKQueue : NSObject {
  44. @private
  45. NSString *path_;
  46. int fd_;
  47. GTMFileSystemKQueueEvents events_;
  48. BOOL acrossReplace_;
  49. __weak id target_;
  50. SEL action_;
  51. }
  52. // |path| is the full path to monitor. |events| is a combination of events
  53. // listed above that you want notification of. |acrossReplace| will cause this
  54. // object to reattach when a the file is deleted & recreated or moved out of the
  55. // way and a new one put in place. |selector| should be of the signature:
  56. // - (void)fileSystemKQueue:(GTMFileSystemKQueue *)fskq
  57. // events:(GTMFileSystemKQueueEvents)events;
  58. // where the events can be one or more of the events listed above ORed together.
  59. //
  60. // NOTE: |acrossReplace| is not fool proof. If the file is renamed/deleted,
  61. // then the object will make one attempt at the time it gets the rename/delete
  62. // to reopen the file. If the new file has not been created, no more action is
  63. // taken. To handle the file coming into existance later, you need to monitor
  64. // the directory in some other way.
  65. - (id)initWithPath:(NSString *)path
  66. forEvents:(GTMFileSystemKQueueEvents)events
  67. acrossReplace:(BOOL)acrossReplace
  68. target:(id)target
  69. action:(SEL)action;
  70. - (NSString *)path;
  71. @end