-rw-r--r-- | libopie2/opiecore/ofilenotify.cpp | 58 | ||||
-rw-r--r-- | libopie2/opiecore/ofilenotify.h | 37 |
2 files changed, 94 insertions, 1 deletions
diff --git a/libopie2/opiecore/ofilenotify.cpp b/libopie2/opiecore/ofilenotify.cpp index 4264327..36ec6bf 100644 --- a/libopie2/opiecore/ofilenotify.cpp +++ b/libopie2/opiecore/ofilenotify.cpp @@ -38,48 +38,104 @@ using namespace Opie::Core; #include <qintdict.h> #include <qdir.h> /* STD */ #include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <fcntl.h> #include <assert.h> #include <string.h> #include <errno.h> #include <unistd.h> static QIntDict<OFileNotification> notification_list; QSocketNotifier* OFileNotification::_sn; int OFileNotification::_fd = -1; #define INOTIFY_DEVICE "/dev/inotify" namespace Opie { namespace Core { //================================================================================================= +// OFile +//================================================================================================= + +OFile::OFile() : QObject( 0, 0 ), QFile() +{ + qDebug( "OFile()" ); +} + +OFile::OFile( const QString& name ) : QObject( 0, 0 ), QFile( name ) +{ + qDebug( "OFile()" ); +} + +OFile::~OFile() +{ + qDebug( "~OFile()" ); +} + +void OFile::connectNotify( const char *signal ) +{ + QString s = normalizeSignalSlot( signal+1 ); + qDebug( "OFile::connectNotify() signal = '%s'", (const char*) s ); + + if ( s.startsWith( "accessed" ) ) + + + + + + + + QObject::connectNotify( signal ); + +/* + void accessed( const QString& ); + void modified( const QString& ); + void attributed( const QString& ); + void closed( const QString&, bool ); + void opened( const QString& ); + void deleted( const QString& ); + void unmounted( const QString& ); +*/ + +} + +void OFile::disconnectNotify( const char* signal ) +{ + qDebug( "OFile::disconnectNotify() signal = '%s'", signal ); + QObject::disconnectNotify( signal ); +} + +int OFile::startWatch( int mode ) +{ +} + +//================================================================================================= // OFileNotificationEvent //================================================================================================= OFileNotificationEvent::OFileNotificationEvent( OFileNotification* parent, int wd, unsigned int mask, unsigned int cookie, const QString& name ) :_parent( parent ), _wd( wd ), _mask( mask ), _cookie( cookie ), _name( name ) { qDebug( "OFileNotificationEvent()" ); } OFileNotificationEvent::~OFileNotificationEvent() { qDebug( "~OFileNotificationEvent()" ); } //================================================================================================= // OFileNotification //================================================================================================= OFileNotification::OFileNotification( QObject* parent, const char* name ) :QObject( parent, name ), _active( false ), _multi( true ) { qDebug( "OFileNotification::OFileNotification()" ); } @@ -198,49 +254,49 @@ bool OFileNotification::activate( const OFileNotificationEvent* e ) case DeleteSelf: emit deleted( _path ); break; case Unmount: emit unmounted( _path ); break; default: assert( 0 ); } 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]; - size_t buffer_i; + ssize_t buffer_i; struct inotify_event *pevent, *event; ssize_t r; size_t event_size; int count = 0; r = ::read(_fd, buffer, 16384); if ( r <= 0 ) return; buffer_i = 0; 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 ); } diff --git a/libopie2/opiecore/ofilenotify.h b/libopie2/opiecore/ofilenotify.h index 5bbf421..05343b9 100644 --- a/libopie2/opiecore/ofilenotify.h +++ b/libopie2/opiecore/ofilenotify.h @@ -17,52 +17,89 @@ _;:, .> :=|. This program is free software; you can _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef OFILENOTIFY_H #define OFILENOTIFY_H #if defined (__GNUC__) && (__GNUC__ < 3) #define _GNU_SOURCE #endif #include "linux_inotify.h" /* QT */ #include <qsocketnotifier.h> #include <qsignal.h> #include <qstring.h> +#include <qobject.h> +#include <qfile.h> namespace Opie { namespace Core { +class OFile : public QObject, public QFile +{ + Q_OBJECT + + public: + OFile(); + OFile( const QString & name ); + virtual ~OFile(); + + protected: + virtual void connectNotify( const char* signal ); + virtual void disconnectNotify( const char* signal ); + + private: + int startWatch( int mode ); + + signals: + void accessed( const QString& ); + void modified( const QString& ); + void attributed( const QString& ); + void closed( const QString&, bool ); + void opened( const QString& ); + void deleted( const QString& ); + void unmounted( const QString& ); +}; + +/* + void movedTo( const QString&, const QString& ); + void movedFrom( const QString&, const QString& ); + void deletedSubdir( const QString&, const QString& ); + void deletedFile( const QString&, const QString& ); + void createdSubdir( const QString&, const QString& ); + void createdFile( const QString&, const QString& ); +*/ + class OFileNotificationEvent; /*====================================================================================== * OFileNotificationType *======================================================================================*/ /** * @brief An enumerate for the different types of file notifications * * This enumerate provides a means to specify the type of events that you are interest in. * Valid values are: * <ul> * <li>Access: The file was accessed (read) * <li>Modify The file was modified (write,truncate) * <li>Attrib = The file had its attributes changed (chmod,chown,chgrp) * <li>CloseWrite = Writable file was closed * <li>CloseNoWrite = Unwritable file was closed * <li>Open = File was opened * <li>MovedFrom = File was moved from X * <li>MovedTo = File was moved to Y * <li>DeleteSubdir = Subdir was deleted * <li>DeleteFile = Subfile was deleted * <li>CreateSubdir = Subdir was created * <li>CreateFile = Subfile was created |