Subversion Repositories public

Rev

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

Rev 47 Rev 49
Line 28... Line 28...
28
28
29
#include <string>
29
#include <string>
30
#include <deque>
30
#include <deque>
31
#include <map>
31
#include <map>
32
32
33
// Please ensure that the following headers take the right place.
33
// Please ensure that the following headers take the right place
34
#include <sys/inotify.h>
34
#include <sys/inotify.h>
-
 
35
-
 
36
// Use this if syscalls not defined
-
 
37
#ifndef __NR_inotify_init
35
#include <sys/inotify-syscalls.h>
38
#include <sys/inotify-syscalls.h>
-
 
39
#endif // __NR_inotify_init
36
40
37
/// Event struct size
41
/// Event struct size
38
#define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
42
#define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
39
43
40
/// Event buffer length
44
/// Event buffer length
Line 316... Line 320...
316
  inline uint32_t GetMask() const
320
  inline uint32_t GetMask() const
317
  {
321
  {
318
    return (uint32_t) m_uMask;
322
    return (uint32_t) m_uMask;
319
  }
323
  }
320
 
324
 
-
 
325
  /// Sets the watch event mask.
-
 
326
  /**
-
 
327
   * If the watch is active (added to an instance of Inofify)
-
 
328
   * this method may fail due to unsuccessful re-setting
-
 
329
   * the watch in the kernel.
-
 
330
   *
-
 
331
   * \param[in] uMask event mask
-
 
332
   *
-
 
333
   * \throw InotifyException thrown if changing fails
-
 
334
   */
-
 
335
  void SetMask(uint32_t uMask) throw (InotifyException);  
-
 
336
 
321
  /// Returns the appropriate inotify class instance.
337
  /// Returns the appropriate inotify class instance.
322
  /**
338
  /**
323
   * \return inotify instance
339
   * \return inotify instance
324
   */
340
   */
325
  inline Inotify* GetInotify()
341
  inline Inotify* GetInotify()
326
  {
342
  {
327
    return m_pInotify;
343
    return m_pInotify;
328
  }
344
  }
329
 
345
 
330
  inline void SetEnabled(bool fEnabled)
346
  /// Enables/disables the watch.
-
 
347
  /**
-
 
348
   * If the watch is active (added to an instance of Inofify)
-
 
349
   * this method may fail due to unsuccessful re-setting
-
 
350
   * the watch in the kernel.
-
 
351
   *
-
 
352
   * Re-setting the current state has no effect.
331
  {
353
   *
332
    m_fEnabled = fEnabled;
354
   * \param[in] fEnabled set enabled yes/no
333
  }  
355
   *
-
 
356
   * \throw InotifyException thrown if enabling/disabling fails
-
 
357
   */
-
 
358
  void SetEnabled(bool fEnabled) throw (InotifyException);
334
 
359
 
-
 
360
  /// Checks whether the watch is enabled.
-
 
361
  /**
-
 
362
   * \return true = enables, false = disabled
-
 
363
   */
335
  inline bool IsEnabled() const
364
  inline bool IsEnabled() const
336
  {
365
  {
337
    return m_fEnabled;
366
    return m_fEnabled;
338
  }
367
  }
339
 
368
 
Line 349... Line 378...
349
378
350
379
351
/// Mapping from watch descriptors to watch objects.
380
/// Mapping from watch descriptors to watch objects.
352
typedef std::map<int32_t, InotifyWatch*> IN_WATCH_MAP;
381
typedef std::map<int32_t, InotifyWatch*> IN_WATCH_MAP;
353
382
-
 
383
/// Mapping from paths to watch objects.
-
 
384
typedef std::map<std::string, InotifyWatch*> IN_WP_MAP;
-
 
385
354
386
355
/// inotify class
387
/// inotify class
356
class Inotify
388
class Inotify
357
{
389
{
358
public:
390
public:
Line 419... Line 451...
419
  /// Removes all watches.
451
  /// Removes all watches.
420
  void RemoveAll();
452
  void RemoveAll();
421
 
453
 
422
  /// Returns the count of watches.
454
  /// Returns the count of watches.
423
  /**
455
  /**
-
 
456
   * This is the total count of all watches (regardless whether
-
 
457
   * enabled or not).
-
 
458
   *
424
   * \return count of watches
459
   * \return count of watches
425
   */
460
   */
426
  inline size_t GetWatchCount() const
461
  inline size_t GetWatchCount() const
427
  {
462
  {
428
    return (size_t) m_watches.size();
463
    return (size_t) m_paths.size();
429
  }
464
  }
430
 
465
 
431
  /// Waits for inotify events.
466
  /// Waits for inotify events.
432
  /**
467
  /**
433
   * It waits until one or more events occur. When called
468
   * It waits until one or more events occur. When called
Line 497... Line 532...
497
  bool PeekEvent(InotifyEvent& rEvt) throw (InotifyException)
532
  bool PeekEvent(InotifyEvent& rEvt) throw (InotifyException)
498
  {
533
  {
499
    return PeekEvent(&rEvt);
534
    return PeekEvent(&rEvt);
500
  }
535
  }
501
 
536
 
502
  /// Searches for a watch.
537
  /// Searches for a watch by a watch descriptor.
503
  /**
538
  /**
504
   * It tries to find a watch by the given descriptor.
539
   * It tries to find a watch by the given descriptor.
505
   *
540
   *
506
   * \param[in] iDescriptor watch descriptor
541
   * \param[in] iDescriptor watch descriptor
507
   * \return found descriptor; NULL if no such watch exists
542
   * \return pointer to a watch; NULL if no such watch exists
508
   */
543
   */
509
  InotifyWatch* FindWatch(int iDescriptor);
544
  InotifyWatch* FindWatch(int iDescriptor);
510
 
545
 
-
 
546
  /// Searches for a watch by a filesystem path.
-
 
547
  /**
-
 
548
   * It tries to find a watch by the given filesystem path.
-
 
549
   *
-
 
550
   * \param[in] rPath filesystem path
-
 
551
   * \return pointer to a watch; NULL if no such watch exists
-
 
552
   *
-
 
553
   * \attention The path must be exactly identical to the one
-
 
554
   *            used for the searched watch. Be careful about
-
 
555
   *            absolute/relative and case-insensitive paths.
-
 
556
   */
-
 
557
   InotifyWatch* FindWatch(const std::string& rPath);
-
 
558
 
511
  /// Returns the file descriptor.
559
  /// Returns the file descriptor.
512
  /**
560
  /**
513
   * The descriptor can be used in standard low-level file
561
   * The descriptor can be used in standard low-level file
514
   * functions (poll(), select(), fcntl() etc.).
562
   * functions (poll(), select(), fcntl() etc.).
515
   *
563
   *
Line 536... Line 584...
536
   */
584
   */
537
  void SetNonBlock(bool fNonBlock) throw (InotifyException);
585
  void SetNonBlock(bool fNonBlock) throw (InotifyException);
538
586
539
private:
587
private:
540
  int m_fd;                             ///< file descriptor
588
  int m_fd;                             ///< file descriptor
541
  IN_WATCH_MAP m_watches;               ///< watches
589
  IN_WATCH_MAP m_watches;               ///< watches (by descriptors)
-
 
590
  IN_WP_MAP m_paths;                    ///< watches (by paths)
542
  unsigned char m_buf[INOTIFY_BUFLEN];  ///< buffer for events
591
  unsigned char m_buf[INOTIFY_BUFLEN];  ///< buffer for events
543
  std::deque<InotifyEvent> m_events;    ///< event queue
592
  std::deque<InotifyEvent> m_events;    ///< event queue
-
 
593
 
-
 
594
  friend class InotifyWatch;
544
};
595
};
545
596
546
597
547
#endif //_INOTIFYCXX_H_
598
#endif //_INOTIFYCXX_H_