Subversion Repositories public

Rev

Rev 55 | Rev 65 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 55 Rev 63
Line 3... Line 3...
3
/**
3
/**
4
 * \file inotify-cxx.h
4
 * \file inotify-cxx.h
5
 *
5
 *
6
 * inotify C++ interface
6
 * inotify C++ interface
7
 *
7
 *
8
 * Copyright (C) 2006 Lukas Jelinek, <lukas@aiken.cz>
8
 * Copyright (C) 2006, 2007 Lukas Jelinek, <lukas@aiken.cz>
9
 *
9
 *
10
 * This program is free software; you can redistribute it and/or
10
 * This program is free software; you can redistribute it and/or
11
 * modify it under the terms of one of the following licenses:
11
 * modify it under the terms of one of the following licenses:
12
 *
12
 *
13
 * \li 1. X11-style license (see LICENSE-X11)
13
 * \li 1. X11-style license (see LICENSE-X11)
Line 49... Line 49...
49
/**
49
/**
50
 * It prepends the message by the function name.
50
 * It prepends the message by the function name.
51
 */
51
 */
52
#define IN_EXC_MSG(msg) (std::string(__PRETTY_FUNCTION__) + ": " + msg)
52
#define IN_EXC_MSG(msg) (std::string(__PRETTY_FUNCTION__) + ": " + msg)
53
53
-
 
54
/// inotify capability/limit identifiers 
-
 
55
typedef enum
-
 
56
{
-
 
57
  IN_MAX_EVENTS     = 0,  ///< max. events in the kernel queue
-
 
58
  IN_MAX_INSTANCES  = 1,  ///< max. inotify file descriptors per process
-
 
59
  IN_MAX_WATCHES    = 2   ///< max. watches per file descriptor
-
 
60
} InotifyCapability_t;
-
 
61
54
/// inotify-cxx thread safety
62
/// inotify-cxx thread safety
55
/**
63
/**
56
 * If this symbol is defined you can use this interface safely
64
 * If this symbol is defined you can use this interface safely
57
 * threaded applications. Remember that it slightly degrades
65
 * threaded applications. Remember that it slightly degrades
58
 * performance.
66
 * performance.
Line 467... Line 475...
467
  inline bool IsEnabled() const
475
  inline bool IsEnabled() const
468
  {
476
  {
469
    return m_fEnabled;
477
    return m_fEnabled;
470
  }
478
  }
471
 
479
 
-
 
480
  /// Checks whether the watch is recursive.
-
 
481
  /**
-
 
482
   * A recursive watch monitors a directory itself and all
-
 
483
   * its subdirectories. This watch is a logical object
-
 
484
   * which may have many underlying kernel watches.
-
 
485
   *
-
 
486
   * \return currently always false (recursive watches not yet supported)
-
 
487
   * \attention Recursive watches are currently NOT supported.
-
 
488
   *            They are planned for future versions.
-
 
489
   */
-
 
490
  inline bool IsRecursive() const
-
 
491
  {
-
 
492
    return false;    
-
 
493
  }
-
 
494
 
472
private:
495
private:
473
  friend class Inotify;
496
  friend class Inotify;
474
497
475
  std::string m_path;   ///< watched file path
498
  std::string m_path;   ///< watched file path
476
  uint32_t m_uMask;     ///< event mask
499
  uint32_t m_uMask;     ///< event mask
477
  int32_t m_wd;         ///< watch descriptor
500
  int32_t m_wd;         ///< watch descriptor
478
  Inotify* m_pInotify;  ///< inotify object
501
  Inotify* m_pInotify;  ///< inotify object
479
  bool m_fEnabled;      ///< events enabled yes/no
502
  bool m_fEnabled;      ///< events enabled yes/no
480
 
503
 
481
  IN_LOCK_DECL
504
  IN_LOCK_DECL
-
 
505
 
-
 
506
  /// Disables the watch (if it has the one-shot flag).
-
 
507
  /**
-
 
508
   * This method must be called after receiving an event.
-
 
509
   * It ensures the watch object is consistent with the kernel
-
 
510
   * data.
-
 
511
   */
-
 
512
  void OnOneshotEvent();
482
};
513
};
483
514
484
515
485
/// Mapping from watch descriptors to watch objects.
516
/// Mapping from watch descriptors to watch objects.
486
typedef std::map<int32_t, InotifyWatch*> IN_WATCH_MAP;
517
typedef std::map<int32_t, InotifyWatch*> IN_WATCH_MAP;
Line 717... Line 748...
717
   * \throw InotifyException thrown if setting mode failed
748
   * \throw InotifyException thrown if setting mode failed
718
   *
749
   *
719
   * \sa GetDescriptor()
750
   * \sa GetDescriptor()
720
   */
751
   */
721
  void SetNonBlock(bool fNonBlock) throw (InotifyException);
752
  void SetNonBlock(bool fNonBlock) throw (InotifyException);
-
 
753
 
-
 
754
  /// Acquires a particular inotify capability/limit.
-
 
755
  /**
-
 
756
   * \param[in] cap capability/limit identifier
-
 
757
   * \return capability/limit value
-
 
758
   * \throw InotifyException thrown if the given value cannot be acquired
-
 
759
   */
-
 
760
  static uint32_t GetCapability(InotifyCapability_t cap) throw (InotifyException);
-
 
761
 
-
 
762
  /// Modifies a particular inotify capability/limit.
-
 
763
  /**
-
 
764
   * \param[in] cap capability/limit identifier
-
 
765
   * \param[in] val new capability/limit value
-
 
766
   * \throw InotifyException thrown if the given value cannot be set
-
 
767
   * \attention Using this function requires root privileges.
-
 
768
   *            Beware of setting extensive values - it may seriously
-
 
769
   *            affect system performance and/or stability.
-
 
770
   */
-
 
771
  static void SetCapability(InotifyCapability_t cap, uint32_t val) throw (InotifyException);
-
 
772
 
-
 
773
  /// Returns the maximum number of events in the kernel queue.
-
 
774
  /**
-
 
775
   * \return maximum number of events in the kernel queue
-
 
776
   * \throw InotifyException thrown if the given value cannot be acquired
-
 
777
   */
-
 
778
  inline static uint32_t GetMaxEvents() throw (InotifyException)
-
 
779
  {
-
 
780
    return GetCapability(IN_MAX_EVENTS);
-
 
781
  }
-
 
782
 
-
 
783
  /// Sets the maximum number of events in the kernel queue.
-
 
784
  /**
-
 
785
   * \param[in] val new value
-
 
786
   * \throw InotifyException thrown if the given value cannot be set
-
 
787
   * \attention Using this function requires root privileges.
-
 
788
   *            Beware of setting extensive values - the greater value
-
 
789
   *            is set here the more physical memory may be used for the inotify
-
 
790
   *            infrastructure.
-
 
791
   */
-
 
792
  inline static void SetMaxEvents(uint32_t val) throw (InotifyException)
-
 
793
  {
-
 
794
    SetCapability(IN_MAX_EVENTS, val);
-
 
795
  }
-
 
796
 
-
 
797
  /// Returns the maximum number of inotify instances per process.
-
 
798
  /**
-
 
799
   * It means the maximum number of open inotify file descriptors
-
 
800
   * per running process.
-
 
801
   *
-
 
802
   * \return maximum number of inotify instances
-
 
803
   * \throw InotifyException thrown if the given value cannot be acquired
-
 
804
   */
-
 
805
  inline static uint32_t GetMaxInstances() throw (InotifyException)
-
 
806
  {
-
 
807
    return GetCapability(IN_MAX_INSTANCES);
-
 
808
  }
-
 
809
 
-
 
810
  /// Sets the maximum number of inotify instances per process.
-
 
811
  /**
-
 
812
   * \param[in] val new value
-
 
813
   * \throw InotifyException thrown if the given value cannot be set
-
 
814
   * \attention Using this function requires root privileges.
-
 
815
   *            Beware of setting extensive values - the greater value
-
 
816
   *            is set here the more physical memory may be used for the inotify
-
 
817
   *            infrastructure.
-
 
818
   */
-
 
819
  inline static void SetMaxInstances(uint32_t val) throw (InotifyException)
-
 
820
  {
-
 
821
    SetCapability(IN_MAX_INSTANCES, val);
-
 
822
  }
-
 
823
 
-
 
824
  /// Returns the maximum number of inotify watches per instance.
-
 
825
  /**
-
 
826
   * It means the maximum number of inotify watches per inotify
-
 
827
   * file descriptor.
-
 
828
   *
-
 
829
   * \return maximum number of inotify watches
-
 
830
   * \throw InotifyException thrown if the given value cannot be acquired
-
 
831
   */
-
 
832
  inline static uint32_t GetMaxWatches() throw (InotifyException)
-
 
833
  {
-
 
834
    return GetCapability(IN_MAX_WATCHES);
-
 
835
  }
-
 
836
 
-
 
837
  /// Sets the maximum number of inotify watches per instance.
-
 
838
  /**
-
 
839
   * \param[in] val new value
-
 
840
   * \throw InotifyException thrown if the given value cannot be set
-
 
841
   * \attention Using this function requires root privileges.
-
 
842
   *            Beware of setting extensive values - the greater value
-
 
843
   *            is set here the more physical memory may be used for the inotify
-
 
844
   *            infrastructure.
-
 
845
   */
-
 
846
  inline static void SetMaxWatches(uint32_t val) throw (InotifyException)
-
 
847
  {
-
 
848
    SetCapability(IN_MAX_WATCHES, val);
-
 
849
  }
722
850
723
private:
851
private:
724
  int m_fd;                             ///< file descriptor
852
  int m_fd;                             ///< file descriptor
725
  IN_WATCH_MAP m_watches;               ///< watches (by descriptors)
853
  IN_WATCH_MAP m_watches;               ///< watches (by descriptors)
726
  IN_WP_MAP m_paths;                    ///< watches (by paths)
854
  IN_WP_MAP m_paths;                    ///< watches (by paths)
Line 728... Line 856...
728
  std::deque<InotifyEvent> m_events;    ///< event queue
856
  std::deque<InotifyEvent> m_events;    ///< event queue
729
 
857
 
730
  IN_LOCK_DECL
858
  IN_LOCK_DECL
731
 
859
 
732
  friend class InotifyWatch;
860
  friend class InotifyWatch;
-
 
861
 
-
 
862
  static std::string GetCapabilityPath(InotifyCapability_t cap) throw (InotifyException);
733
};
863
};
734
864
735
865
736
#endif //_INOTIFYCXX_H_
866
#endif //_INOTIFYCXX_H_
737
867