Subversion Repositories public

Rev

Rev 27 | Rev 33 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 27 Rev 29
Line 24... Line 24...
24
#include <unistd.h>
24
#include <unistd.h>
25
#include <fcntl.h>
25
#include <fcntl.h>
26
26
27
#include "inotify-cxx.h"
27
#include "inotify-cxx.h"
28
28
-
 
29
/// procfs inotify base path
-
 
30
#define PROCFS_INOTIFY_BASE "/proc/sys/fs/inotify/"
-
 
31
29
/// dump separator (between particular entries)
32
/// dump separator (between particular entries)
30
#define DUMP_SEP \
33
#define DUMP_SEP \
31
  ({ \
34
  ({ \
32
    if (!rStr.empty()) { \
35
    if (!rStr.empty()) { \
33
      rStr.append(","); \
36
      rStr.append(","); \
Line 92... Line 95...
92
#ifdef IN_ONLYDIR
95
#ifdef IN_ONLYDIR
93
  else if (rName == "IN_ONLYDIR")
96
  else if (rName == "IN_ONLYDIR")
94
    return IN_ONLYDIR;
97
    return IN_ONLYDIR;
95
#endif // IN_ONLYDIR
98
#endif // IN_ONLYDIR
96
   
99
-
 
100
#ifdef IN_MOVE_SELF
-
 
101
  else if (rName == "IN_MOVE_SELF")
-
 
102
    return IN_MOVE_SELF;
-
 
103
#endif // IN_MOVE_SELF
-
 
104
   
97
  return (uint32_t) 0;
105
  return (uint32_t) 0;
98
}
106
}
99
107
100
void InotifyEvent::DumpTypes(uint32_t uValue, std::string& rStr)
108
void InotifyEvent::DumpTypes(uint32_t uValue, std::string& rStr)
101
{
109
{
Line 194... Line 202...
194
  if (IsType(uValue, IN_ONLYDIR)) {
202
  if (IsType(uValue, IN_ONLYDIR)) {
195
    DUMP_SEP;
203
    DUMP_SEP;
196
    rStr.append("IN_ONLYDIR");
204
    rStr.append("IN_ONLYDIR");
197
  }
205
  }
198
#endif // IN_ONLYDIR
206
#endif // IN_ONLYDIR
-
 
207
-
 
208
#ifdef IN_MOVE_SELF
-
 
209
  if (IsType(uValue, IN_MOVE_SELF)) {
-
 
210
    DUMP_SEP;
-
 
211
    rStr.append("IN_MOVE_SELF");    
-
 
212
  }
-
 
213
#endif // IN_MOVE_SELF
199
}
214
}
200
215
201
void InotifyEvent::DumpTypes(std::string& rStr) const
216
void InotifyEvent::DumpTypes(std::string& rStr) const
202
{
217
{
203
  DumpTypes(m_uMask, rStr);
218
  DumpTypes(m_uMask, rStr);
Line 506... Line 521...
506
  }
521
  }
507
   
522
   
508
  IN_WRITE_END
523
  IN_WRITE_END
509
}  
524
}
510
525
-
 
526
uint32_t Inotify::GetCapability(InotifyCapability_t cap) throw (InotifyException)
-
 
527
{
-
 
528
  FILE* f = fopen(GetCapabilityPath(cap).c_str(), "r");
-
 
529
  if (f == NULL)
-
 
530
    throw InotifyException(IN_EXC_MSG("cannot get capability"), errno, NULL);
-
 
531
   
-
 
532
  unsigned int val = 0;
-
 
533
  if (fscanf(f, "%u", &val) != 1) {
-
 
534
    fclose(f);
-
 
535
    throw InotifyException(IN_EXC_MSG("cannot get capability"), EIO, NULL);
-
 
536
  }
-
 
537
 
-
 
538
  fclose(f);
-
 
539
 
-
 
540
  return (uint32_t) val;
-
 
541
}
-
 
542
-
 
543
void Inotify::SetCapability(InotifyCapability_t cap, uint32_t val) throw (InotifyException)
-
 
544
{
-
 
545
  FILE* f = fopen(GetCapabilityPath(cap).c_str(), "w");
-
 
546
  if (f == NULL)
-
 
547
    throw InotifyException(IN_EXC_MSG("cannot set capability"), errno, NULL);
-
 
548
   
-
 
549
  if (fprintf(f, "%u", (unsigned int) val) <= 0) {
-
 
550
    fclose(f);
-
 
551
    throw InotifyException(IN_EXC_MSG("cannot set capability"), EIO, NULL);
-
 
552
  }
-
 
553
 
-
 
554
  fclose(f);
-
 
555
}
-
 
556
-
 
557
std::string Inotify::GetCapabilityPath(InotifyCapability_t cap) throw (InotifyException)
-
 
558
{
-
 
559
  std::string path(PROCFS_INOTIFY_BASE);
-
 
560
 
-
 
561
  switch (cap) {
-
 
562
    case IN_MAX_EVENTS:
-
 
563
      path.append("max_queued_events");
-
 
564
      break;
-
 
565
    case IN_MAX_INSTANCES:
-
 
566
      path.append("max_user_instances");
-
 
567
      break;
-
 
568
    case IN_MAX_WATCHES:
-
 
569
      path.append("max_user_watches");
-
 
570
      break;
-
 
571
    default:
-
 
572
      throw InotifyException(IN_EXC_MSG("unknown capability type"), EINVAL, NULL);
-
 
573
  }
-
 
574
 
-
 
575
  return path;
-
 
576
}
-
 
577