summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--examples/opiecore/onotifydemo/onotifydemo.cpp14
-rw-r--r--examples/opiecore/onotifydemo/onotifydemo.h2
-rw-r--r--libopie2/opiecore/ofilenotify.cpp122
-rw-r--r--libopie2/opiecore/ofilenotify.h63
4 files changed, 163 insertions, 38 deletions
diff --git a/examples/opiecore/onotifydemo/onotifydemo.cpp b/examples/opiecore/onotifydemo/onotifydemo.cpp
index 2beda2a..e147c6a 100644
--- a/examples/opiecore/onotifydemo/onotifydemo.cpp
+++ b/examples/opiecore/onotifydemo/onotifydemo.cpp
@@ -102,3 +102,3 @@ DemoApp::DemoApp( int argc, char** argv ) : OApplication( argc, argv, "libopie2
102 { 102 {
103 success = OFileNotification::singleShot( filename, this, SLOT( unnamedTrigger() ), (OFileNotificationType) fntype ); 103 success = OFileNotification::singleShot( filename, this, SLOT(unnamedTrigger()), (OFileNotificationType) fntype );
104 } 104 }
@@ -108,4 +108,5 @@ DemoApp::DemoApp( int argc, char** argv ) : OApplication( argc, argv, "libopie2
108 success = fn->watch( filename, false, (OFileNotificationType) fntype ); 108 success = fn->watch( filename, false, (OFileNotificationType) fntype );
109 connect( fn, SIGNAL( triggered( const QString& ) ), this, SLOT( namedTrigger( const QString& ) ) ); 109 connect( fn, SIGNAL(triggered(const QString&,unsigned int,const QString&)),
110 } 110 this, SLOT(namedTrigger(const QString&,unsigned int,const QString&)) );
111 }
111 } 112 }
@@ -115,3 +116,4 @@ DemoApp::DemoApp( int argc, char** argv ) : OApplication( argc, argv, "libopie2
115 success = dn->watch( filename, !multi, (OFileNotificationType) fntype ); 116 success = dn->watch( filename, !multi, (OFileNotificationType) fntype );
116 connect( dn, SIGNAL( triggered( const QString& ) ), this, SLOT( namedTrigger( const QString& ) ) ); 117 connect( dn, SIGNAL(triggered(const QString&,unsigned int,const QString&)),
118 this, SLOT(namedTrigger(const QString&,unsigned int,const QString&)) );
117 } 119 }
@@ -164,5 +166,5 @@ DemoApp::DemoApp( int argc, char** argv ) : OApplication( argc, argv, "libopie2
164 166
165 void DemoApp::namedTrigger( const QString& path ) 167 void DemoApp::namedTrigger( const QString& path, unsigned int type, const QString& name )
166 { 168 {
167 owarn << "DemoApp::named trigger = " << path << " : F I R E !!!!!" << oendl; 169 owarn << "DemoApp::named trigger = ( " << path << ", " << type << ", " << name << " ) : F I R E !!!!!" << oendl;
168 } 170 }
diff --git a/examples/opiecore/onotifydemo/onotifydemo.h b/examples/opiecore/onotifydemo/onotifydemo.h
index f6ac5ea..20019e4 100644
--- a/examples/opiecore/onotifydemo/onotifydemo.h
+++ b/examples/opiecore/onotifydemo/onotifydemo.h
@@ -22,3 +22,3 @@ public slots:
22 void unnamedTrigger(); 22 void unnamedTrigger();
23 void namedTrigger( const QString& name ); 23 void namedTrigger( const QString&, unsigned int, const QString& );
24 24
diff --git a/libopie2/opiecore/ofilenotify.cpp b/libopie2/opiecore/ofilenotify.cpp
index 11d4f87..4264327 100644
--- a/libopie2/opiecore/ofilenotify.cpp
+++ b/libopie2/opiecore/ofilenotify.cpp
@@ -60,2 +60,20 @@ namespace Core {
60 60
61//=================================================================================================
62// OFileNotificationEvent
63//=================================================================================================
64OFileNotificationEvent::OFileNotificationEvent( OFileNotification* parent, int wd, unsigned int mask, unsigned int cookie, const QString& name )
65 :_parent( parent ), _wd( wd ), _mask( mask ), _cookie( cookie ), _name( name )
66{
67 qDebug( "OFileNotificationEvent()" );
68}
69
70
71OFileNotificationEvent::~OFileNotificationEvent()
72{
73 qDebug( "~OFileNotificationEvent()" );
74}
75
76//=================================================================================================
77// OFileNotification
78//=================================================================================================
61OFileNotification::OFileNotification( QObject* parent, const char* name ) 79OFileNotification::OFileNotification( QObject* parent, const char* name )
@@ -154,7 +172,34 @@ QString OFileNotification::path() const
154 172
155bool OFileNotification::activate() 173bool OFileNotification::activate( const OFileNotificationEvent* e )
156{ 174{
157 emit triggered( _path ); 175 qDebug( "OFileNotification::activate(): e = ( %s, %d, 0x%08x, %d, %s )", (const char*) _path, e->descriptor(), e->mask(), e->cookie(), (const char*) e->name() );
176
177 // dumb signal
158 _signal.activate(); 178 _signal.activate();
179
180 // generic signal
181 emit triggered( _path, e->mask(), e->name() );
182
183 // specialized signals
184 switch ( e->mask() )
185 {
186 case Access: emit accessed( _path ); break;
187 case Modify: emit modified( _path ); break;
188 case Attrib: emit attributed( _path); break;
189 case CloseWrite: emit closed( _path, true ); break;
190 case CloseNoWrite: emit closed( _path, false ); break;
191 case Open: emit opened( _path ); break;
192 case MovedFrom: emit movedFrom( _path, e->name() ); break;
193 case MovedTo: emit movedTo( _path, e->name() ); break;
194 case DeleteSubdir: emit deletedSubdir( _path, e->name() ); break;
195 case DeleteFile: emit deletedFile( _path, e->name() ); break;
196 case CreateSubdir: emit createdSubdir( _path, e->name() ); break;
197 case CreateFile: emit createdFile( _path, e->name() ); break;
198 case DeleteSelf: emit deleted( _path ); break;
199 case Unmount: emit unmounted( _path ); break;
200 default: assert( 0 );
201 }
202
159 if ( !_multi ) stop(); 203 if ( !_multi ) stop();
204
160 return true; 205 return true;
@@ -173,3 +218,3 @@ void OFileNotification::inotifyEventHandler()
173{ 218{
174 qWarning( "OFileNotification::__eventHandler(): reached." ); 219 qDebug( "OFileNotification::inotifyEventHandler(): reached." );
175 220
@@ -190,22 +235,12 @@ void OFileNotification::inotifyEventHandler()
190 { 235 {
191 /* Parse events and queue them ! */ 236 pevent = (struct inotify_event *)&buffer[buffer_i];
192 pevent = (struct inotify_event *)&buffer[buffer_i]; 237 event_size = sizeof(struct inotify_event) + pevent->len;
193 event_size = sizeof(struct inotify_event) + pevent->len; 238 OFileNotificationEvent* e = new OFileNotificationEvent( notification_list[ pevent->wd ], pevent->wd, pevent->mask,
194 qDebug( "pevent->len = %d\n", pevent->len); 239 pevent->cookie, pevent->len ? pevent->name : 0 );
195 240 e->activate();
196 OFileNotification* fn = notification_list[ pevent->wd ]; 241 buffer_i += event_size;
197 if ( fn ) 242 count++;
198 fn->activate();
199 else
200 assert( false );
201
202 //event = malloc(event_size);
203 //memmove(event, pevent, event_size);
204 //queue_enqueue(event, q);
205 buffer_i += event_size;
206 count++;
207 } 243 }
208 244
209 qDebug( "received %d events...", count ); 245 qDebug( "OFileNotification::inotifyEventHandler(): processed %d events", count );
210 return;
211} 246}
@@ -264,5 +299,18 @@ int ODirNotification::watch( const QString& path, bool sshot, OFileNotificationT
264 { 299 {
265 connect( fn, SIGNAL( triggered( const QString& ) ), this, SIGNAL( triggered( const QString& ) ) ); 300 connect( fn, SIGNAL( triggered( const QString&, unsigned int, const QString& ) ), this, SIGNAL( triggered( const QString&, unsigned int, const QString& ) ) );
266 return result; 301 connect( fn, SIGNAL( accessed( const QString& ) ), this, SIGNAL( accessed( const QString& ) ) );
302 connect( fn, SIGNAL( modified( const QString& ) ), this, SIGNAL( modified( const QString& ) ) );
303 connect( fn, SIGNAL( attributed( const QString& ) ), this, SIGNAL( attributed( const QString& ) ) );
304 connect( fn, SIGNAL( closed( const QString&, bool ) ), this, SIGNAL( closed( const QString&, bool ) ) );
305 connect( fn, SIGNAL( opened( const QString& ) ), this, SIGNAL( opened( const QString& ) ) );
306 connect( fn, SIGNAL( movedTo( const QString&, const QString& ) ), this, SIGNAL( movedTo( const QString&, const QString& ) ) );
307 connect( fn, SIGNAL( movedFrom( const QString&, const QString& ) ), this, SIGNAL( movedFrom( const QString&, const QString& ) ) );
308 connect( fn, SIGNAL( deletedSubdir( const QString&, const QString& ) ), this, SIGNAL( deletedSubdir( const QString&, const QString& ) ) );
309 connect( fn, SIGNAL( deletedFile( const QString&, const QString& ) ), this, SIGNAL( deletedFile( const QString&, const QString& ) ) );;
310 connect( fn, SIGNAL( createdSubdir( const QString&, const QString& ) ), this, SIGNAL( createdSubdir( const QString&, const QString& ) ) );
311 connect( fn, SIGNAL( createdFile( const QString&, const QString& ) ), this, SIGNAL( createdFile( const QString&, const QString& ) ) );
312 connect( fn, SIGNAL( deleted( const QString& ) ), this, SIGNAL( deleted( const QString& ) ) );
313 connect( fn, SIGNAL( unmounted( const QString& ) ), this, SIGNAL( unmounted( const QString& ) ) );
267 } 314 }
315 return result;
268 } 316 }
@@ -270,4 +318,4 @@ int ODirNotification::watch( const QString& path, bool sshot, OFileNotificationT
270 { 318 {
271 qDebug( "ODirNotification::watch(), recursion not yet implemented... :)" ); 319
272 return -1; 320 return 1;
273 } 321 }
@@ -275,2 +323,26 @@ int ODirNotification::watch( const QString& path, bool sshot, OFileNotificationT
275 323
324
325// void ODirNotification::subdirCreated( const QString& name )
326
327
328/*
329 Love-Trowbridge recursive directory scanning algorithm:
330
331 Step 1. Start at initial directory foo. Add watch.
332
333 Step 2. Setup handlers for watch created in Step 1.
334 Specifically, ensure that a directory created
335 in foo will result in a handled CREATE_SUBDIR
336 event.
337
338 Step 3. Read the contents of foo.
339
340 Step 4. For each subdirectory of foo read in step 3, repeat
341 step 1.
342
343 Step 5. For any CREATE_SUBDIR event on bar, if a watch is
344 not yet created on bar, repeat step 1 on bar.
345*/
346
347
276} // namespace Ui 348} // namespace Ui
diff --git a/libopie2/opiecore/ofilenotify.h b/libopie2/opiecore/ofilenotify.h
index 3eb917e..5bbf421 100644
--- a/libopie2/opiecore/ofilenotify.h
+++ b/libopie2/opiecore/ofilenotify.h
@@ -44,2 +44,4 @@ namespace Core {
44 44
45class OFileNotificationEvent;
46
45/*====================================================================================== 47/*======================================================================================
@@ -170,9 +172,19 @@ class OFileNotification : public QObject
170 signals: 172 signals:
171 /** 173 void triggered( const QString&, unsigned int, const QString& );
172 * This signal is emitted if an event happens of the specified type happens to the file being watched. 174 void accessed( const QString& );
173 **/ 175 void modified( const QString& );
174 void triggered( const QString& name ); 176 void attributed( const QString& );
177 void closed( const QString&, bool );
178 void opened( const QString& );
179 void movedTo( const QString&, const QString& );
180 void movedFrom( const QString&, const QString& );
181 void deletedSubdir( const QString&, const QString& );
182 void deletedFile( const QString&, const QString& );
183 void createdSubdir( const QString&, const QString& );
184 void createdFile( const QString&, const QString& );
185 void deleted( const QString& );
186 void unmounted( const QString& );
175 187
176 protected: 188 protected:
177 bool activate(); 189 bool activate( const OFileNotificationEvent* e );
178 190
@@ -193,2 +205,4 @@ class OFileNotification : public QObject
193 static int _fd; // inotify device descriptor 205 static int _fd; // inotify device descriptor
206
207 friend class OFileNotificationEvent;
194}; 208};
@@ -229,3 +243,40 @@ class ODirNotification : public QObject
229 **/ 243 **/
230 void triggered( const QString& name ); 244 void triggered( const QString&, unsigned int, const QString& );
245 void accessed( const QString& );
246 void modified( const QString& );
247 void attributed( const QString& );
248 void closed( const QString&, bool );
249 void opened( const QString& );
250 void movedTo( const QString&, const QString& );
251 void movedFrom( const QString&, const QString& );
252 void deletedSubdir( const QString&, const QString& );
253 void deletedFile( const QString&, const QString& );
254 void createdSubdir( const QString&, const QString& );
255 void createdFile( const QString&, const QString& );
256 void deleted( const QString& );
257 void unmounted( const QString& );
258};
259
260/*======================================================================================
261 * OFileNotificationEvent
262 *======================================================================================*/
263
264class OFileNotificationEvent
265{
266 public:
267 OFileNotificationEvent( OFileNotification* parent, int wd, unsigned int mask, unsigned int cookie, const QString& name );
268 ~OFileNotificationEvent();
269 OFileNotification* parent() const { return _parent; };
270 int descriptor() const { return _wd; };
271 unsigned int mask() const { return _mask; };
272 unsigned int cookie() const { return _cookie; };
273 QString name() const { return _name; };
274 void activate() { _parent->activate( this ); };
275
276 private:
277 OFileNotification* _parent;
278 int _wd;
279 unsigned int _mask;
280 unsigned int _cookie;
281 QString _name;
231}; 282};