1 module beangle.fs.inotify;
2 import core.sys.linux.sys.inotify;
3 
4 public struct Event{
5   int wd;// watch descriptor
6   uint mask; // watch event set
7   uint cookie;
8   string path;
9   string toString(){
10     import std.array : appender;
11     import std.conv;
12     auto buf = appender!string();
13     buf.put( "{wd:");
14     buf.put( wd.to!string);
15     buf.put( ",path:\"");
16     buf.put( path);
17     buf.put( "\",mask:");
18     buf.put( mask.to!string);
19     buf.put( ",events:\"");
20     buf.put( eventNames( mask));
21     buf.put( "\",cookie:");
22     buf.put( cookie.to!string);
23     buf.put( "}");
24     return buf.data;
25   }
26 }
27 
28 string eventNames(uint events,char sep=','){
29   import std.array : appender;
30   import std.conv;
31   auto buf = appender!string();
32   if ( IN_ACCESS & events ) {
33     buf.put( sep);
34     buf.put( "ACCESS" );
35   }
36   if ( IN_MODIFY & events ) {
37     buf.put( sep );
38     buf.put( "MODIFY" );
39   }
40   if ( IN_ATTRIB & events ) {
41     buf.put( sep );
42     buf.put( "ATTRIB" );
43   }
44   if ( IN_CLOSE_WRITE & events ) {
45     buf.put( sep );
46     buf.put( "CLOSE_WRITE" );
47   }
48   if ( IN_CLOSE_NOWRITE & events ) {
49     buf.put( sep );
50     buf.put( "CLOSE_NOWRITE" );
51   }
52   if ( IN_OPEN & events ) {
53     buf.put( sep );
54     buf.put( "OPEN" );
55   }
56   if ( IN_MOVED_FROM & events ) {
57     buf.put( sep );
58     buf.put( "MOVED_FROM" );
59   }
60   if ( IN_MOVED_TO & events ) {
61     buf.put( sep );
62     buf.put( "MOVED_TO" );
63   }
64   if ( IN_CREATE & events ) {
65     buf.put( sep );
66     buf.put( "CREATE" );
67   }
68   if ( IN_DELETE & events ) {
69     buf.put( sep );
70     buf.put( "DELETE" );
71   }
72   if ( IN_DELETE_SELF & events ) {
73     buf.put( sep );
74     buf.put( "DELETE_SELF" );
75   }
76   if ( IN_UNMOUNT & events ) {
77     buf.put( sep );
78     buf.put( "UNMOUNT" );
79   }
80   if ( IN_Q_OVERFLOW & events ) {
81     buf.put( sep );
82     buf.put( "Q_OVERFLOW" );
83   }
84   if ( IN_IGNORED & events ) {
85     buf.put( sep );
86     buf.put( "IGNORED" );
87   }
88   if ( IN_CLOSE & events ) {
89     buf.put( sep );
90     buf.put( "CLOSE" );
91   }
92   if ( IN_MOVE_SELF & events ) {
93     buf.put( sep );
94     buf.put( "MOVE_SELF" );
95   }
96   if ( IN_ISDIR & events ) {
97     buf.put( sep );
98     buf.put( "ISDIR" );
99   }
100   if ( IN_ONESHOT & events ) {
101     buf.put( sep );
102     buf.put( "ONESHOT" );
103   }
104   return buf.data[1..$];
105 }
106 
107 
108