Rev 13 | Rev 19 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 13 | Rev 17 | ||
---|---|---|---|
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 497... | Line 529... | ||
497 | bool PeekEvent(InotifyEvent& rEvt) throw (InotifyException) |
529 | bool PeekEvent(InotifyEvent& rEvt) throw (InotifyException) |
498 | {
|
530 | {
|
499 | return PeekEvent(&rEvt); |
531 | return PeekEvent(&rEvt); |
500 | }
|
532 | }
|
501 | 533 | ||
502 | /// Searches for a watch.
|
534 | /// Searches for a watch by a watch descriptor.
|
503 | /**
|
535 | /**
|
504 | * It tries to find a watch by the given descriptor.
|
536 | * It tries to find a watch by the given descriptor.
|
505 | *
|
537 | *
|
506 | * \param[in] iDescriptor watch descriptor
|
538 | * \param[in] iDescriptor watch descriptor
|
507 | * \return found descriptor; NULL if no such watch exists
|
539 | * \return pointer to a watch; NULL if no such watch exists
|
508 | */
|
540 | */
|
509 | InotifyWatch* FindWatch(int iDescriptor); |
541 | InotifyWatch* FindWatch(int iDescriptor); |
510 | 542 | ||
- | 543 | /// Searches for a watch by a filesystem path.
|
|
- | 544 | /**
|
|
- | 545 | * It tries to find a watch by the given filesystem path.
|
|
- | 546 | *
|
|
- | 547 | * \param[in] rPath filesystem path
|
|
- | 548 | * \return pointer to a watch; NULL if no such watch exists
|
|
- | 549 | *
|
|
- | 550 | * \attention The path must be exactly identical to the one
|
|
- | 551 | * used for the searched watch. Be careful about
|
|
- | 552 | * absolute/relative and case-insensitive paths.
|
|
- | 553 | */
|
|
- | 554 | InotifyWatch* FindWatch(const std::string& rPath); |
|
- | 555 | ||
511 | /// Returns the file descriptor.
|
556 | /// Returns the file descriptor.
|
512 | /**
|
557 | /**
|
513 | * The descriptor can be used in standard low-level file
|
558 | * The descriptor can be used in standard low-level file
|
514 | * functions (poll(), select(), fcntl() etc.).
|
559 | * functions (poll(), select(), fcntl() etc.).
|
515 | *
|
560 | *
|
Line 536... | Line 581... | ||
536 | */
|
581 | */
|
537 | void SetNonBlock(bool fNonBlock) throw (InotifyException); |
582 | void SetNonBlock(bool fNonBlock) throw (InotifyException); |
538 | 583 | ||
539 | private: |
584 | private: |
540 | int m_fd; ///< file descriptor |
585 | int m_fd; ///< file descriptor |
541 | IN_WATCH_MAP m_watches; ///< watches |
586 | IN_WATCH_MAP m_watches; ///< watches (by descriptors) |
- | 587 | IN_WP_MAP m_paths; ///< watches (by paths) |
|
542 | unsigned char m_buf[INOTIFY_BUFLEN]; ///< buffer for events |
588 | unsigned char m_buf[INOTIFY_BUFLEN]; ///< buffer for events |
543 | std::deque<InotifyEvent> m_events; ///< event queue |
589 | std::deque<InotifyEvent> m_events; ///< event queue |
- | 590 | ||
- | 591 | friend class InotifyWatch; |
|
544 | }; |
592 | }; |
545 | 593 | ||
546 | 594 | ||
547 | #endif //_INOTIFYCXX_H_
|
595 | #endif //_INOTIFYCXX_H_
|