summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/ofilenotify.cpp8
-rw-r--r--libopie2/opiecore/ofilenotify.h3
2 files changed, 4 insertions, 7 deletions
diff --git a/libopie2/opiecore/ofilenotify.cpp b/libopie2/opiecore/ofilenotify.cpp
index 5e9f97b..bcfb1aa 100644
--- a/libopie2/opiecore/ofilenotify.cpp
+++ b/libopie2/opiecore/ofilenotify.cpp
@@ -1,113 +1,107 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 =. Copyright (C) 2004 Michael 'Mickey' Lauer <mickey@Vanille.de> 3 =. Copyright (C) 2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 .=l. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5          .>+-= 5          .>+-=
6_;:,     .>    :=|. This program is free software; you can 6_;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10- .   .-<_>     .<> Foundation; either version 2 of the License, 10- .   .-<_>     .<> Foundation; either version 2 of the License,
11    ._= =}       : or (at your option) any later version. 11    ._= =}       : or (at your option) any later version.
12   .%`+i>       _;_. 12   .%`+i>       _;_.
13   .i_,=:_.      -<s. This program is distributed in the hope that 13   .i_,=:_.      -<s. This program is distributed in the hope that
14    +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14    +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15   : ..    .:,     . . . without even the implied warranty of 15   : ..    .:,     . . . without even the implied warranty of
16   =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16   =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17 _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 17 _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more 18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details. 19++=   -.     .`     .: details.
20:     =  ...= . :.=- 20:     =  ...= . :.=-
21-.   .:....=;==+<; You should have received a copy of the GNU 21-.   .:....=;==+<; You should have received a copy of the GNU
22 -_. . .   )=.  = Library General Public License along with 22 -_. . .   )=.  = Library General Public License along with
23   --        :-=` this library; see the file COPYING.LIB. 23   --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation, 24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, 25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27*/ 27*/
28 28
29#include "ofilenotify.h" 29#include "ofilenotify.h"
30using namespace Opie::Core; 30using namespace Opie::Core;
31 31
32/* OPIE */ 32/* OPIE */
33 33
34/* QT */ 34/* QT */
35#include <qobject.h> 35#include <qobject.h>
36#include <qsignal.h> 36#include <qsignal.h>
37#include <qintdict.h> 37#include <qintdict.h>
38#include <qdir.h> 38#include <qdir.h>
39 39
40/* STD */ 40/* STD */
41#include <sys/types.h> 41#include <sys/types.h>
42#include <sys/stat.h> 42#include <sys/stat.h>
43#ifndef _GNU_SOURCE 43#include <fcntl.h>
44 #define _GNU_SOURCE
45 #include <fcntl.h>
46 #undef _GNU_SOURCE
47#else
48 #include <fcntl.h>
49#endif
50#include <string.h> 44#include <string.h>
51#include <errno.h> 45#include <errno.h>
52#include <unistd.h> 46#include <unistd.h>
53 47
54static QIntDict<OFileNotification> notification_list; 48static QIntDict<OFileNotification> notification_list;
55 49
56namespace Opie { 50namespace Opie {
57namespace Core { 51namespace Core {
58 52
59OFileNotification::OFileNotification( QObject* parent, const char* name ) 53OFileNotification::OFileNotification( QObject* parent, const char* name )
60 :QObject( parent, name ), _active( false ) 54 :QObject( parent, name ), _active( false )
61{ 55{
62 qDebug( "OFileNotification::OFileNotification()" ); 56 qDebug( "OFileNotification::OFileNotification()" );
63} 57}
64 58
65 59
66OFileNotification::~OFileNotification() 60OFileNotification::~OFileNotification()
67{ 61{
68 qDebug( "OFileNotification::~OFileNotification()" ); 62 qDebug( "OFileNotification::~OFileNotification()" );
69} 63}
70 64
71 65
72bool OFileNotification::isActive() const 66bool OFileNotification::isActive() const
73{ 67{
74 return _active; 68 return _active;
75} 69}
76 70
77 71
78int OFileNotification::start( const QString& path, bool sshot, OFileNotificationType type ) 72int OFileNotification::start( const QString& path, bool sshot, OFileNotificationType type )
79{ 73{
80 _path = QString::null; 74 _path = QString::null;
81 _fd = 0; 75 _fd = 0;
82 if ( _active ) stop(); 76 if ( _active ) stop();
83 77
84 int fd = ::open( (const char*) path, O_RDONLY ); 78 int fd = ::open( (const char*) path, O_RDONLY );
85 if ( fd != -1 ) 79 if ( fd != -1 )
86 { 80 {
87 if ( notification_list.isEmpty() ) 81 if ( notification_list.isEmpty() )
88 { 82 {
89 OFileNotification::registerSignalHandler(); 83 OFileNotification::registerSignalHandler();
90 } 84 }
91 int result = ::fcntl( fd, F_SETSIG, SIGRTMIN ); 85 int result = ::fcntl( fd, F_SETSIG, SIGRTMIN );
92 if ( result == -1 ) 86 if ( result == -1 )
93 { 87 {
94 qWarning( "OFileNotification::start(): Can't subscribe to '%s': %s.", (const char*) path, strerror( errno ) ); 88 qWarning( "OFileNotification::start(): Can't subscribe to '%s': %s.", (const char*) path, strerror( errno ) );
95 return -1; 89 return -1;
96 } 90 }
97 if ( !sshot ) (int) type |= (int) Multi; 91 if ( !sshot ) (int) type |= (int) Multi;
98 result = ::fcntl( fd, F_NOTIFY, type ); 92 result = ::fcntl( fd, F_NOTIFY, type );
99 if ( result == -1 ) 93 if ( result == -1 )
100 { 94 {
101 qWarning( "OFileNotification::start(): Can't subscribe to '%s': %s.", (const char*) path, strerror( errno ) ); 95 qWarning( "OFileNotification::start(): Can't subscribe to '%s': %s.", (const char*) path, strerror( errno ) );
102 return -1; 96 return -1;
103 } 97 }
104 qDebug( "OFileNotification::start(): Subscribed for changes to %s (fd = %d, mask = 0x%0x)", (const char*) path, fd, type ); 98 qDebug( "OFileNotification::start(): Subscribed for changes to %s (fd = %d, mask = 0x%0x)", (const char*) path, fd, type );
105 notification_list.insert( fd, this ); 99 notification_list.insert( fd, this );
106 _type = type; 100 _type = type;
107 _path = path; 101 _path = path;
108 _fd = fd; 102 _fd = fd;
109 return fd; 103 return fd;
110 } 104 }
111 else 105 else
112 { 106 {
113 qWarning( "OFileNotification::start(): Error with path '%s': %s.", (const char*) path, strerror( errno ) ); 107 qWarning( "OFileNotification::start(): Error with path '%s': %s.", (const char*) path, strerror( errno ) );
diff --git a/libopie2/opiecore/ofilenotify.h b/libopie2/opiecore/ofilenotify.h
index a14842a..3bc141d 100644
--- a/libopie2/opiecore/ofilenotify.h
+++ b/libopie2/opiecore/ofilenotify.h
@@ -1,92 +1,95 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 =. Copyright (C) 2004 Michael 'Mickey' Lauer <mickey@Vanille.de> 3 =. Copyright (C) 2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l. Copyright (C) The Opie Team <opie-devel@handhelds.org> 4 .=l. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5          .>+-= 5          .>+-=
6_;:,     .>    :=|. This program is free software; you can 6_;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10- .   .-<_>     .<> Foundation; either version 2 of the License, 10- .   .-<_>     .<> Foundation; either version 2 of the License,
11    ._= =}       : or (at your option) any later version. 11    ._= =}       : or (at your option) any later version.
12   .%`+i>       _;_. 12   .%`+i>       _;_.
13   .i_,=:_.      -<s. This program is distributed in the hope that 13   .i_,=:_.      -<s. This program is distributed in the hope that
14    +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14    +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15   : ..    .:,     . . . without even the implied warranty of 15   : ..    .:,     . . . without even the implied warranty of
16   =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16   =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17 _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 17 _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more 18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details. 19++=   -.     .`     .: details.
20:     =  ...= . :.=- 20:     =  ...= . :.=-
21-.   .:....=;==+<; You should have received a copy of the GNU 21-.   .:....=;==+<; You should have received a copy of the GNU
22 -_. . .   )=.  = Library General Public License along with 22 -_. . .   )=.  = Library General Public License along with
23   --        :-=` this library; see the file COPYING.LIB. 23   --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation, 24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, 25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA. 26 Boston, MA 02111-1307, USA.
27*/ 27*/
28 28
29#ifndef OFILENOTIFY_H 29#ifndef OFILENOTIFY_H
30#define OFILENOTIFY_H 30#define OFILENOTIFY_H
31#if defined (__GNUC__) && (__GNUC__ < 3)
32#define _GNU_SOURCE
33#endif
31 34
32/* QT */ 35/* QT */
33#include <qobject.h> 36#include <qobject.h>
34#include <qsignal.h> 37#include <qsignal.h>
35#include <qstring.h> 38#include <qstring.h>
36 39
37/* STD */ 40/* STD */
38#include <signal.h> 41#include <signal.h>
39#include <fcntl.h> 42#include <fcntl.h>
40 43
41namespace Opie { 44namespace Opie {
42namespace Core { 45namespace Core {
43 46
44enum OFileNotificationType { Single = 0x0000000, 47enum OFileNotificationType { Single = 0x0000000,
45 Multi = DN_MULTISHOT, 48 Multi = DN_MULTISHOT,
46 Access = DN_ACCESS, 49 Access = DN_ACCESS,
47 Modify = DN_MODIFY, 50 Modify = DN_MODIFY,
48 Create = DN_CREATE, 51 Create = DN_CREATE,
49 Delete = DN_DELETE, 52 Delete = DN_DELETE,
50 Rename = DN_RENAME, 53 Rename = DN_RENAME,
51 Attrib = DN_ATTRIB }; 54 Attrib = DN_ATTRIB };
52 55
53class OFileNotification : public QObject 56class OFileNotification : public QObject
54{ 57{
55 Q_OBJECT 58 Q_OBJECT
56 59
57 public: 60 public:
58 OFileNotification( QObject* parent = 0, const char* name = 0 ); 61 OFileNotification( QObject* parent = 0, const char* name = 0 );
59 ~OFileNotification(); 62 ~OFileNotification();
60 63
61 static void singleShot( const QString& path, QObject* receiver, const char* member, OFileNotificationType type = Modify ); 64 static void singleShot( const QString& path, QObject* receiver, const char* member, OFileNotificationType type = Modify );
62 65
63 int start( const QString& path, bool sshot = false, OFileNotificationType type = Modify ); 66 int start( const QString& path, bool sshot = false, OFileNotificationType type = Modify );
64 void stop(); 67 void stop();
65 68
66 OFileNotificationType type() const; 69 OFileNotificationType type() const;
67 QString path() const; 70 QString path() const;
68 int fileno() const; 71 int fileno() const;
69 bool isActive() const; 72 bool isActive() const;
70 73
71 signals: 74 signals:
72 void triggered(); 75 void triggered();
73 76
74 protected: 77 protected:
75 void activate(); 78 void activate();
76 static bool registerSignalHandler(); 79 static bool registerSignalHandler();
77 static void unregisterSignalHandler(); 80 static void unregisterSignalHandler();
78 static void __signalHandler( int sig, siginfo_t *si, void *data ); 81 static void __signalHandler( int sig, siginfo_t *si, void *data );
79 82
80 private: 83 private:
81 QString _path; 84 QString _path;
82 OFileNotificationType _type; 85 OFileNotificationType _type;
83 QSignal _signal; 86 QSignal _signal;
84 int _fd; 87 int _fd;
85 bool _active; 88 bool _active;
86}; 89};
87 90
88} 91}
89} 92}
90 93
91#endif 94#endif
92 95