2
* Copyright © 2006 Novell, Inc.
4
* Permission to use, copy, modify, distribute, and sell this software
5
* and its documentation for any purpose is hereby granted without
6
* fee, provided that the above copyright notice appear in all copies
7
* and that both that copyright notice and this permission notice
8
* appear in supporting documentation, and that the name of
9
* Novell, Inc. not be used in advertising or publicity pertaining to
10
* distribution of the software without specific, written prior permission.
11
* Novell, Inc. makes no representations about the suitability of this
12
* software for any purpose. It is provided "as is" without express or
15
* NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
17
* NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
19
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
20
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23
* Author: David Reveman <davidr@novell.com>
28
COMPIZ_PLUGIN_20081216 (inotify, InotifyPluginVTable)
30
InotifyScreen::InotifyScreen (CompScreen *screen) :
31
PrivateHandler<InotifyScreen, CompScreen> (screen)
35
fdHandle = screen->addWatchFd (fd,
36
POLLIN | POLLPRI | POLLHUP | POLLERR,
37
boost::bind (&InotifyScreen::processEvents,
40
ScreenInterface::setHandler (screen, true);
42
const CompFileWatchList &watchList = screen->getFileWatches ();
43
CompFileWatchList::const_iterator iter;
45
for (iter = watchList.begin (); iter != watchList.end (); ++iter)
46
fileWatchAdded (*iter);
49
InotifyScreen::~InotifyScreen ()
51
const CompFileWatchList &watchList = screen->getFileWatches ();
52
CompFileWatchList::const_iterator iter;
54
for (iter = watchList.begin (); iter != watchList.end (); ++iter)
55
fileWatchRemoved (*iter);
57
screen->removeWatchFd (fdHandle);
63
InotifyScreen::processEvents ()
65
char buf[256 * (sizeof (struct inotify_event) + 16)];
68
len = read (fd, buf, sizeof (buf));
75
struct inotify_event *event;
77
WatchList::iterator iter;
78
const CompFileWatchList &list = screen->getFileWatches ();
79
CompFileWatchList::const_iterator wIter;
83
event = (struct inotify_event *) &buf[i];
85
for (iter = watches.begin (); iter != watches.end (); ++iter)
86
if ((*iter).wd = event->wd)
89
if (iter != watches.end ())
91
for (wIter = list.begin (); wIter != list.end (); ++iter)
92
if ((*iter).handle == (*wIter)->handle)
95
if (wIter != list.end ())
97
const char *name = (event->len) ? event->name : NULL;
98
(*wIter)->callBack (name);
102
i += sizeof (*event) + event->len;
108
inotifyMask (CompFileWatch *watch)
110
unsigned int mask = 0;
112
if (watch->mask & NOTIFY_CREATE_MASK)
115
if (watch->mask & NOTIFY_DELETE_MASK)
118
if (watch->mask & NOTIFY_MOVE_MASK)
121
if (watch->mask & NOTIFY_MODIFY_MASK)
128
InotifyScreen::fileWatchAdded (CompFileWatch *fileWatch)
132
iw.handle = fileWatch->handle;
133
iw.wd = inotify_add_watch (fd, fileWatch->path.c_str (),
134
inotifyMask (fileWatch));
137
perror ("inotify_add_watch");
141
watches.push_back (iw);
145
InotifyScreen::fileWatchRemoved (CompFileWatch *fileWatch)
147
WatchList::iterator iter;
149
for (iter = watches.begin (); iter != watches.end (); ++iter)
151
if ((*iter).handle == fileWatch->handle)
153
if (inotify_rm_watch (fd, (*iter).wd))
154
perror ("inotify_rm_watch");
155
watches.erase (iter);
162
InotifyPluginVTable::init ()
164
if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
167
getMetadata ()->addFromFile (name ());