Subversion Repositories public

Rev

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

Rev 3 Rev 11
Line 38... Line 38...
38
#define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
38
#define INOTIFY_EVENT_SIZE (sizeof(struct inotify_event))
39
39
40
/// Event buffer length
40
/// Event buffer length
41
#define INOTIFY_BUFLEN (1024 * (INOTIFY_EVENT_SIZE + 16))
41
#define INOTIFY_BUFLEN (1024 * (INOTIFY_EVENT_SIZE + 16))
42
42
-
 
43
-
 
44
// forward declaration
-
 
45
class InotifyWatch;
-
 
46
class Inotify;
-
 
47
-
 
48
43
/// inotify event class
49
/// inotify event class
44
/**
50
/**
45
 * It holds all information about inotify event and provides
51
 * It holds all information about inotify event and provides
46
 * access to its particular values.
52
 * access to its particular values.
47
 */
53
 */
Line 54... Line 60...
54
   */
60
   */
55
  InotifyEvent()
61
  InotifyEvent()
56
  {
62
  {
57
    memset(&m_evt, 0, sizeof(m_evt));
63
    memset(&m_evt, 0, sizeof(m_evt));
58
    m_evt.wd = (int32_t) -1;
64
    m_evt.wd = (int32_t) -1;
-
 
65
    m_pWatch = NULL;
59
  }
66
  }
60
 
67
 
61
  /// Constructor.
68
  /// Constructor.
62
  /**
69
  /**
63
   * Creates an event based on inotify event data.
70
   * Creates an event based on inotify event data.
64
   * For NULL pointer it works the same way as InotifyEvent().
71
   * For NULL pointers it works the same way as InotifyEvent().
65
   *
72
   *
66
   * \param[in] pEvt event data
73
   * \param[in] pEvt event data
-
 
74
   * \param[in] pWatch inotify watch
67
   */
75
   */
68
  InotifyEvent(const struct inotify_event* pEvt)
76
  InotifyEvent(const struct inotify_event* pEvt, InotifyWatch* pWatch)
69
  {
77
  {
70
    if (pEvt != NULL) {
78
    if (pEvt != NULL) {
71
      memcpy(&m_evt, pEvt, sizeof(m_evt));
79
      memcpy(&m_evt, pEvt, sizeof(m_evt));
72
      if (pEvt->name != NULL)
80
      if (pEvt->name != NULL)
73
        m_name = pEvt->name;
81
        m_name = pEvt->name;
-
 
82
      m_pWatch = pWatch;
74
    }
83
    }
75
    else {
84
    else {
76
      memset(&m_evt, 0, sizeof(m_evt));
85
      memset(&m_evt, 0, sizeof(m_evt));
77
      m_evt.wd = (int32_t) -1;
86
      m_evt.wd = (int32_t) -1;
-
 
87
      m_pWatch = NULL;
78
    }
88
    }
79
  }
89
  }
80
 
90
 
81
  /// Destructor.
91
  /// Destructor.
82
  ~InotifyEvent() {}
92
  ~InotifyEvent() {}
Line 101... Line 111...
101
  inline uint32_t GetMask() const
111
  inline uint32_t GetMask() const
102
  {
112
  {
103
    return (uint32_t) m_evt.mask;
113
    return (uint32_t) m_evt.mask;
104
  }
114
  }
105
 
115
 
-
 
116
  /// Checks a value for the event type.
-
 
117
  /**
-
 
118
   * \param[in] uValue checked value
-
 
119
   * \param[in] uType type which is checked for
-
 
120
   * \return true = the value contains the given type, false = otherwise
-
 
121
   */
-
 
122
  inline static bool IsType(uint32_t uValue, uint32_t uType)
-
 
123
  {
-
 
124
    return ((uValue & uType) != 0) && ((~uValue & uType) == 0);
-
 
125
  }
-
 
126
 
106
  /// Checks for the event type.
127
  /// Checks for the event type.
107
  /**
128
  /**
108
   * \param[in] uType type which is checked for
129
   * \param[in] uType type which is checked for
109
   * \return true = event mask contains the given type, false = otherwise
130
   * \return true = event mask contains the given type, false = otherwise
110
   */
131
   */
111
  inline bool IsType(uint32_t uType) const
132
  inline bool IsType(uint32_t uType) const
112
  {
133
  {
113
    return (((uint32_t) m_evt.mask) & uType) != 0;
134
    return IsType((uint32_t) m_evt.mask, uType);
114
  }
135
  }
115
 
136
 
116
  /// Returns the event cookie.
137
  /// Returns the event cookie.
117
  /**
138
  /**
118
   * \return event cookie
139
   * \return event cookie
Line 147... Line 168...
147
  inline void GetName(std::string& rName) const
168
  inline void GetName(std::string& rName) const
148
  {
169
  {
149
    rName = GetName();
170
    rName = GetName();
150
  }
171
  }
151
 
172
 
-
 
173
  /// Returns the source watch.
-
 
174
  /**
-
 
175
   * \return source watch
-
 
176
   */
-
 
177
  inline InotifyWatch* GetWatch()
-
 
178
  {
-
 
179
    return m_pWatch;
-
 
180
  }
-
 
181
 
152
  /// Returns the event raw data.
182
  /// Returns the event raw data.
153
  /**
183
  /**
154
   * For NULL pointer it does nothing.
184
   * For NULL pointer it does nothing.
155
   *
185
   *
156
   * \param[in,out] pEvt event data
186
   * \param[in,out] pEvt event data
Line 168... Line 198...
168
  inline void GetData(struct inotify_event& rEvt)
198
  inline void GetData(struct inotify_event& rEvt)
169
  {
199
  {
170
    memcpy(&rEvt, &m_evt, sizeof(m_evt));
200
    memcpy(&rEvt, &m_evt, sizeof(m_evt));
171
  }
201
  }
172
 
202
 
-
 
203
  /// Finds the appropriate mask for a name.
-
 
204
  /**
-
 
205
   * \param[in] rName mask name
-
 
206
   * \return mask for name; 0 on failure
-
 
207
   */
-
 
208
  static uint32_t GetMaskByName(const std::string& rName);
-
 
209
 
-
 
210
  /// Fills the string with all types contained in an event mask value.
-
 
211
  /**
-
 
212
   * \param[in] uValue event mask value
-
 
213
   * \param[out] rStr dumped event types
-
 
214
   */
-
 
215
  static void DumpTypes(uint32_t uValue, std::string& rStr);
-
 
216
 
173
  /// Fills the string with all types contained in the event mask.
217
  /// Fills the string with all types contained in the event mask.
174
  /**
218
  /**
175
   * \param[out] rStr dumped event types
219
   * \param[out] rStr dumped event types
176
   */
220
   */
177
  void DumpTypes(std::string& rStr) const;
221
  void DumpTypes(std::string& rStr) const;
178
 
222
 
179
private:
223
private:
180
  struct inotify_event m_evt; ///< event structure
224
  struct inotify_event m_evt; ///< event structure
181
  std::string m_name;         ///< event name
225
  std::string m_name;         ///< event name
-
 
226
  InotifyWatch* m_pWatch;     ///< source watch
182
};
227
};
183
228
184
229
185
class Inotify;  // forward declaration
-
 
186
-
 
187
230
188
/// inotify watch class
231
/// inotify watch class
189
class InotifyWatch
232
class InotifyWatch
190
{
233
{
191
public:
234
public:
Line 232... Line 275...
232
  inline uint32_t GetMask() const
275
  inline uint32_t GetMask() const
233
  {
276
  {
234
    return (uint32_t) m_uMask;
277
    return (uint32_t) m_uMask;
235
  }
278
  }
236
 
279
 
-
 
280
  /// Returns the appropriate inotify class instance.
-
 
281
  /**
-
 
282
   * \return inotify instance
-
 
283
   */
-
 
284
  inline Inotify* GetInotify()
-
 
285
  {
-
 
286
    return m_pInotify;
-
 
287
  }
-
 
288
 
237
private:
289
private:
238
  friend class Inotify;
290
  friend class Inotify;
239
291
240
  std::string m_path;   ///< watched file path
292
  std::string m_path;   ///< watched file path
241
  uint32_t m_uMask;     ///< event mask
293
  uint32_t m_uMask;     ///< event mask
242
  int32_t m_wd;         ///< watch descriptor
294
  int32_t m_wd;         ///< watch descriptor
-
 
295
  Inotify* m_pInotify;  ///< inotify object
243
};
296
};
244
297
245
298
246
/// Mapping from watch descriptors to watch objects.
299
/// Mapping from watch descriptors to watch objects.
247
typedef std::map<int32_t, InotifyWatch*> IN_WATCH_MAP;
300
typedef std::map<int32_t, InotifyWatch*> IN_WATCH_MAP;