Leaked source code of windows server 2003
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.

186 lines
5.2 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.02 (13-Jun-1999)
  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.02';
  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. if ($constname =~ /^(?:FILE_NOTIFY_CHANGE_|INFINITE)/) {
  52. my $val = constant($constname);
  53. croak("$constname is not defined by Win32::ChangeNotify") if $! != 0;
  54. eval "sub $AUTOLOAD { $val }";
  55. goto &$AUTOLOAD;
  56. }
  57. } # end AUTOLOAD
  58. bootstrap Win32::ChangeNotify;
  59. sub new {
  60. my ($class,$path,$subtree,$filter) = @_;
  61. if ($filter =~ /\A[\s|A-Z_]+\Z/i) {
  62. $filter = 0;
  63. foreach (split(/[\s|]+/, $_[3])) {
  64. $filter |= constant("FILE_NOTIFY_CHANGE_" . uc $_);
  65. carp "Invalid filter $_" if $!;
  66. }
  67. }
  68. _new($class,$path,$subtree,$filter);
  69. } # end new
  70. sub Close { &close }
  71. sub FindFirst { $_[0] = Win32::ChangeNotify->_new(@_[1..3]); }
  72. sub FindNext { &reset }
  73. 1;
  74. __END__
  75. =head1 NAME
  76. Win32::ChangeNotify - Monitor events related to files and directories
  77. =head1 SYNOPSIS
  78. require Win32::ChangeNotify;
  79. $notify = Win32::ChangeNotify->new($Path,$WatchSubTree,$Events);
  80. $notify->wait or warn "Something failed: $!\n";
  81. # There has been a change.
  82. =head1 DESCRIPTION
  83. This module allows the user to use a Win32 change notification event
  84. object from Perl. This allows the Perl program to monitor events
  85. relating to files and directory trees.
  86. The C<wait> method and C<wait_all> & C<wait_any> functions are
  87. inherited from the L<"Win32::IPC"> module.
  88. =head2 Methods
  89. =over 4
  90. =item $notify = Win32::ChangeNotify->new($path, $subtree, $filter)
  91. Constructor for a new ChangeNotification object. C<$path> is the
  92. directory to monitor. If C<$subtree> is true, then all directories
  93. under C<$path> will be monitored. C<$filter> indicates what events
  94. should trigger a notification. It should be a string containing any
  95. of the following flags (separated by whitespace and/or C<|>).
  96. ATTRIBUTES Any attribute change
  97. DIR_NAME Any directory name change
  98. FILE_NAME Any file name change (creating/deleting/renaming)
  99. LAST_WRITE Any change to a file's last write time
  100. SECURITY Any security descriptor change
  101. SIZE Any change in a file's size
  102. (C<$filter> can also be an integer composed from the
  103. C<FILE_NOTIFY_CHANGE_*> constants.)
  104. =item $notify->close
  105. Shut down monitoring. You could just C<undef $notify> instead (but
  106. C<close> works even if there are other copies of the object). This
  107. happens automatically when your program exits.
  108. =item $notify->reset
  109. Resets the ChangeNotification object after a change has been detected.
  110. The object will become signalled again after the next change. (It is
  111. OK to call this immediately after C<new>, but it is not required.)
  112. =item $notify->wait
  113. See L<"Win32::IPC">. Remember to call C<reset> afterwards if you want
  114. to continue monitoring.
  115. =back
  116. =head2 Deprecated Functions and Methods
  117. B<Win32::ChangeNotify> still supports the ActiveWare syntax, but its
  118. use is deprecated.
  119. =over 4
  120. =item FindFirst($Obj,$PathName,$WatchSubTree,$Filter)
  121. Use
  122. $Obj = Win32::ChangeNotify->new($PathName,$WatchSubTree,$Filter)
  123. instead.
  124. =item $obj->FindNext()
  125. Use C<$obj-E<gt>reset> instead.
  126. =item $obj->Close()
  127. Use C<$obj-E<gt>close> instead.
  128. =back
  129. =head1 AUTHOR
  130. Christopher J. Madsen E<lt>F<[email protected]>E<gt>
  131. Loosely based on the original module by ActiveWare Internet Corp.,
  132. F<http://www.ActiveWare.com>
  133. =cut
  134. # Local Variables:
  135. # tmtrack-file-task: "Win32::ChangeNotify"
  136. # End: