summaryrefslogtreecommitdiff
path: root/libopie2/opiecore/linux
Side-by-side diff
Diffstat (limited to 'libopie2/opiecore/linux') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/linux/ofilenotify.cpp40
-rw-r--r--libopie2/opiecore/linux/ofilenotify.h3
2 files changed, 25 insertions, 18 deletions
diff --git a/libopie2/opiecore/linux/ofilenotify.cpp b/libopie2/opiecore/linux/ofilenotify.cpp
index a7820ee..68c5a96 100644
--- a/libopie2/opiecore/linux/ofilenotify.cpp
+++ b/libopie2/opiecore/linux/ofilenotify.cpp
@@ -215,74 +215,80 @@ void OFileNotification::stop()
OFileNotificationType OFileNotification::type() const
{
return _type;
}
QString OFileNotification::path() const
{
return _path;
}
bool OFileNotification::isSingleShot() const
{
return !_multi;
}
bool OFileNotification::activate( const OFileNotificationEvent* e )
{
qDebug( "OFileNotification::activate(): e = ( %s, %d, 0x%08x, %d, %s )", (const char*) _path, e->descriptor(), e->mask(), e->cookie(), (const char*) e->name() );
+ //FIXME: Should we really deliver QueueOverflow and/or Ignore to user level code?
+
// dumb signal
_signal.activate();
// generic signal
emit triggered( _path, e->mask(), e->name() );
// specialized signals
switch ( e->mask() )
{
- case Access: emit accessed( _path ); break;
- case Modify: emit modified( _path ); break;
- case Attrib: emit attributed( _path); break;
- case CloseWrite: emit closed( _path, true ); break;
- case CloseNoWrite: emit closed( _path, false ); break;
- case Open: emit opened( _path ); break;
- case MovedFrom: emit movedFrom( _path, e->name() ); break;
- case MovedTo: emit movedTo( _path, e->name() ); break;
- case DeleteSubdir: emit deletedSubdir( _path, e->name() ); break;
- case DeleteFile: emit deletedFile( _path, e->name() ); break;
- case CreateSubdir: emit createdSubdir( _path, e->name() ); break;
- case CreateFile: emit createdFile( _path, e->name() ); break;
- case DeleteSelf: emit deleted( _path ); break;
- case Unmount: emit unmounted( _path ); break;
+ case Access: emit accessed( _path ); break;
+ case Modify: emit modified( _path ); break;
+ case Attrib: emit attributed( _path); break;
+ case CloseWrite: emit closed( _path, true ); break;
+ case CloseNoWrite: emit closed( _path, false ); break;
+ case Open: emit opened( _path ); break;
+ case MovedFrom: emit movedFrom( _path, e->name() ); break;
+ case MovedTo: emit movedTo( _path, e->name() ); break;
+ case DeleteSubdir: emit deletedSubdir( _path, e->name() ); break;
+ case DeleteFile: emit deletedFile( _path, e->name() ); break;
+ case CreateSubdir: emit createdSubdir( _path, e->name() ); break;
+ case CreateFile: emit createdFile( _path, e->name() ); break;
+ case DeleteSelf: emit deleted( _path ); break;
+ case Unmount: emit unmounted( _path ); break;
+ case _QueueOverflow: qFatal( "OFileNotification::activate() - Inotify Event Queue Overload!" ); break;
+ case _Ignored: qWarning( "OFileNotification::activate() - Further Events for '%s' will be ignored", (const char*) _path ); break;
default: assert( 0 );
}
+ delete e;
+
if ( !_multi ) stop();
return true;
}
bool OFileNotification::singleShot( const QString& path, QObject* receiver, const char* member, OFileNotificationType type )
{
OFileNotification* ofn = new OFileNotification();
ofn->_signal.connect( receiver, member );
return ofn->watch( path, true, type ) != -1;
}
void OFileNotification::inotifyEventHandler()
{
qDebug( "OFileNotification::inotifyEventHandler(): reached." );
char buffer[16384];
ssize_t buffer_i;
struct inotify_event *pevent, *event;
ssize_t r;
size_t event_size;
int count = 0;
@@ -296,97 +302,97 @@ void OFileNotification::inotifyEventHandler()
while ( buffer_i < r )
{
pevent = (struct inotify_event *)&buffer[buffer_i];
event_size = sizeof(struct inotify_event) + pevent->len;
OFileNotificationEvent* e = new OFileNotificationEvent( notification_list[ pevent->wd ], pevent->wd, pevent->mask,
pevent->cookie, pevent->len ? pevent->name : 0 );
e->activate();
buffer_i += event_size;
count++;
}
qDebug( "OFileNotification::inotifyEventHandler(): processed %d events", count );
}
bool OFileNotification::registerEventHandler()
{
OFileNotification::_fd = ::open( INOTIFY_DEVICE, O_RDONLY );
if ( OFileNotification::_fd < 0 )
{
qWarning( "OFileNotification::registerEventHandler(): couldn't register event handler: %s", strerror( errno ) );
return false;
}
- OFileNotification::_sn = new QSocketNotifier( _fd, QSocketNotifier::Read, this, "inotify event" );
+ OFileNotification::_sn = new QSocketNotifier( _fd, QSocketNotifier::Read );
connect( OFileNotification::_sn, SIGNAL( activated(int) ), this, SLOT( inotifyEventHandler() ) );
qDebug( "OFileNotification::registerEventHandler(): done" );
return true;
}
void OFileNotification::unregisterEventHandler()
{
if ( _sn ) delete _sn;
if ( OFileNotification::_fd )
::close( OFileNotification::_fd );
qDebug( "OFileNotification::unregisterEventHandler(): done" );
}
//=================================================================================================
// ODirNotification
//=================================================================================================
ODirNotification::ODirNotification( QObject* parent, const char* name )
:QObject( parent, name ), _topfilenotification( 0 ), _type( Nothing ), _depth( -123 )
{
qDebug( "ODirNotification::ODirNotification()" );
}
ODirNotification::~ODirNotification()
{
qDebug( "ODirNotification::~ODirNotification()" );
}
-/*
+/**
Love-Trowbridge recursive directory scanning algorithm:
Step 1. Start at initial directory foo. Add watch.
Step 2. Setup handlers for watch created in Step 1.
Specifically, ensure that a directory created
in foo will result in a handled CREATE_SUBDIR
event.
Step 3. Read the contents of foo.
Step 4. For each subdirectory of foo read in step 3, repeat
step 1.
Step 5. For any CREATE_SUBDIR event on bar, if a watch is
not yet created on bar, repeat step 1 on bar.
-*/
+**/
int ODirNotification::watch( const QString& path, bool sshot, OFileNotificationType type, int recurse )
{
if ( _type == Nothing ) _type = type; // only set it once - for the top level call
OFileNotificationType subtype = ( recurse != 0 ) ? (OFileNotificationType) int( _type | CreateSubdir ) : _type;
qDebug( "ODirNotification::watch( %s, %d, 0x%08x, %d )", (const char*) path, sshot, subtype, recurse );
OFileNotification* fn = new OFileNotification( this, "ODirNotification delegate" );
int result = fn->startWatching( path, sshot, subtype );
if ( result != -1 )
{
if ( !_topfilenotification ) _topfilenotification = fn; // only set it once - for the top level call
if ( _depth == -123 ) _depth = recurse; // only set it once - for the top level call
connect( fn, SIGNAL( triggered( const QString&, unsigned int, const QString& ) ), this, SIGNAL( triggered( const QString&, unsigned int, const QString& ) ) );
connect( fn, SIGNAL( accessed( const QString& ) ), this, SIGNAL( accessed( const QString& ) ) );
connect( fn, SIGNAL( modified( const QString& ) ), this, SIGNAL( modified( const QString& ) ) );
connect( fn, SIGNAL( attributed( const QString& ) ), this, SIGNAL( attributed( const QString& ) ) );
connect( fn, SIGNAL( closed( const QString&, bool ) ), this, SIGNAL( closed( const QString&, bool ) ) );
connect( fn, SIGNAL( opened( const QString& ) ), this, SIGNAL( opened( const QString& ) ) );
connect( fn, SIGNAL( movedTo( const QString&, const QString& ) ), this, SIGNAL( movedTo( const QString&, const QString& ) ) );
connect( fn, SIGNAL( movedFrom( const QString&, const QString& ) ), this, SIGNAL( movedFrom( const QString&, const QString& ) ) );
connect( fn, SIGNAL( deletedSubdir( const QString&, const QString& ) ), this, SIGNAL( deletedSubdir( const QString&, const QString& ) ) );
diff --git a/libopie2/opiecore/linux/ofilenotify.h b/libopie2/opiecore/linux/ofilenotify.h
index 17e6b5d..c713b30 100644
--- a/libopie2/opiecore/linux/ofilenotify.h
+++ b/libopie2/opiecore/linux/ofilenotify.h
@@ -236,49 +236,50 @@ class OFileNotification : public QObject
private:
bool registerEventHandler();
void unregisterEventHandler();
QString _path;
OFileNotificationType _type;
QSignal _signal;
bool _active;
bool _multi;
static QSocketNotifier* _sn;
int _wd; // inotify watch descriptor
static int _fd; // inotify device descriptor
friend class OFileNotificationEvent;
};
/*======================================================================================
* ODirNotification
*======================================================================================*/
/**
* @brief Represents a directory notification
*
* This class allows to watch for events happening to directories
- * It uses the OFileNotification class
+ * It uses the OFileNotification class and (for recursive watches)
+ * implements the Love-Trowbridge recursive directory scanning algorithm.
*
* @see http://www.kernel.org/pub/linux/kernel/people/rml/inotify/
*
* @author Michael 'Mickey' Lauer <mickey@vanille.de>
*
**/
class ODirNotification : public QObject
{
Q_OBJECT
public:
ODirNotification( QObject* parent = 0, const char* name = 0 );
~ODirNotification();
/**
* Starts to watch for @a type changes to @a path. Recurse @a recurse levels down the filesystem tree,
* use 0 for no recursion and -1 for unlimited recursion.
* Set @a sshot to True if you want to be notified only once.
**/
int watch( const QString& path, bool sshot = false, OFileNotificationType type = Modify, int recurse = 0 );
signals:
/**
* This signal is emitted if an event happens of the specified type happens to the directory being watched.