Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
5.1 KiB

  1. #---------------------------------------------------------------------
  2. package Win32::ChangeNotify;
  3. #
  4. # Copyright 1998 Christopher J. Madsen
  5. #
  6. # Created: 3 Feb 1998 from the ActiveWare version
  7. # (c) 1995 Microsoft Corporation. All rights reserved.
  8. # Developed by ActiveWare Internet Corp., http://www.ActiveWare.com
  9. #
  10. # Other modifications (c) 1997 by Gurusamy Sarathy <[email protected]>
  11. #
  12. # Author: Christopher J. Madsen <[email protected]>
  13. # Version: 1.00 (6-Feb-1998)
  14. #
  15. # This program is free software; you can redistribute it and/or modify
  16. # it under the same terms as Perl itself.
  17. #
  18. # This program is distributed in the hope that it will be useful,
  19. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See either the
  21. # GNU General Public License or the Artistic License for more details.
  22. #
  23. # Monitor directory for changes
  24. #---------------------------------------------------------------------
  25. $VERSION = '1.01';
  26. use Carp;
  27. use Win32::IPC 1.00 '/./'; # Import everything
  28. require Exporter;
  29. require DynaLoader;
  30. @ISA = qw(Exporter DynaLoader Win32::IPC);
  31. # Items to export into callers namespace by default. Note: do not export
  32. # names by default without a very good reason. Use EXPORT_OK instead.
  33. # Do not simply export all your public functions/methods/constants.
  34. @EXPORT = qw(
  35. FILE_NOTIFY_CHANGE_ATTRIBUTES
  36. FILE_NOTIFY_CHANGE_DIR_NAME
  37. FILE_NOTIFY_CHANGE_FILE_NAME
  38. FILE_NOTIFY_CHANGE_LAST_WRITE
  39. FILE_NOTIFY_CHANGE_SECURITY
  40. FILE_NOTIFY_CHANGE_SIZE
  41. INFINITE
  42. );
  43. @EXPORT_OK = qw(
  44. wait_all wait_any
  45. );
  46. sub AUTOLOAD {
  47. # This AUTOLOAD is used to 'autoload' constants from the constant()
  48. # XS function.
  49. my($constname);
  50. ($constname = $AUTOLOAD) =~ s/.*::_//;
  51. #reset $! to zero to reset any current errors.
  52. $!=0;
  53. my $val = constant($constname, @_ ? $_[0] : 0);
  54. if ($! != 0) {
  55. ($pack,$file,$line) = caller;
  56. die "Your vendor has not defined Win32::ChangeNotify macro $constname, used at $file line $line.";
  57. }
  58. eval "sub $AUTOLOAD { $val }";
  59. goto &$AUTOLOAD;
  60. }
  61. bootstrap Win32::ChangeNotify;
  62. sub new {
  63. my ($class,$path,$subtree,$filter) = @_;
  64. if ($filter =~ /\A[\s|A-Z_]+\Z/i) {
  65. $filter = 0;
  66. foreach (split(/[\s|]+/, $_[3])) {
  67. $filter |= constant("FILE_NOTIFY_CHANGE_" . uc $_);
  68. carp "Invalid filter $_" if $!;
  69. }
  70. }
  71. _new($class,$path,$subtree,$filter);
  72. } # end new
  73. sub Close { &close }
  74. sub FindFirst { $_[0] = Win32::ChangeNotify->_new(@_[1..3]); }
  75. sub FindNext { &reset }
  76. 1;
  77. __END__
  78. =head1 NAME
  79. Win32::ChangeNotify - Monitor events related to files and directories
  80. =head1 SYNOPSIS
  81. require Win32::ChangeNotify;
  82. $notify = Win32::ChangeNotify->new($Path,$WatchSubTree,$Events);
  83. $notify->wait or warn "Something failed: $!\n";
  84. # There has been a change.
  85. =head1 DESCRIPTION
  86. This module allows the user to use a Win32 change notification event
  87. object from Perl. This allows the Perl program to monitor events
  88. relating to files and directory trees.
  89. The C<wait> method and C<wait_all> & C<wait_any> functions are
  90. inherited from the L<"Win32::IPC"> module.
  91. =head2 Methods
  92. =over 4
  93. =item $notify = Win32::ChangeNotify->new($path, $subtree, $filter)
  94. Constructor for a new ChangeNotification object. C<$path> is the
  95. directory to monitor. If C<$subtree> is true, then all directories
  96. under C<$path> will be monitored. C<$filter> indicates what events
  97. should trigger a notification. It should be a string containing any
  98. of the following flags (separated by whitespace and/or C<|>).
  99. ATTRIBUTES Any attribute change
  100. DIR_NAME Any directory name change
  101. FILE_NAME Any file name change (creating/deleting/renaming)
  102. LAST_WRITE Any change to a file's last write time
  103. SECURITY Any security descriptor change
  104. SIZE Any change in a file's size
  105. (C<$filter> can also be an integer composed from the
  106. C<FILE_NOTIFY_CHANGE_*> constants.)
  107. =item $notify->close
  108. Shut down monitoring. You could just C<undef $notify> instead (but
  109. C<close> works even if there are other copies of the object). This
  110. happens automatically when your program exits.
  111. =item $notify->reset
  112. Resets the ChangeNotification object after a change has been detected.
  113. The object will become signalled again after the next change. (It is
  114. OK to call this immediately after C<new>, but it is not required.)
  115. =item $notify->wait
  116. See L<"Win32::IPC">. Remember to call C<reset> afterwards if you want
  117. to continue monitoring.
  118. =back
  119. =head2 Deprecated Functions and Methods
  120. B<Win32::ChangeNotify> still supports the ActiveWare syntax, but its
  121. use is deprecated.
  122. =over 4
  123. =item FindFirst($Obj,$PathName,$WatchSubTree,$Filter)
  124. Use
  125. $Obj = Win32::ChangeNotify->new($PathName,$WatchSubTree,$Filter)
  126. instead.
  127. =item $obj->FindNext()
  128. Use C<$obj-E<gt>reset> instead.
  129. =item $obj->Close()
  130. Use C<$obj-E<gt>close> instead.
  131. =back
  132. =head1 AUTHOR
  133. Christopher J. Madsen E<lt>F<[email protected]>E<gt>
  134. Loosely based on the original module by ActiveWare Internet Corp.,
  135. F<http://www.ActiveWare.com>
  136. =cut
  137. # Local Variables:
  138. # tmtrack-file-task: "Win32::ChangeNotify"
  139. # End: