summaryrefslogtreecommitdiff
authorbrad <brad>2004-04-18 18:58:58 (UTC)
committer brad <brad>2004-04-18 18:58:58 (UTC)
commitb5d913c33546f9d29556bcab47d1d91a3ac94fd3 (patch) (unidiff)
tree4d08005d448ee1785ba4f67e75531137aed9d2e4
parentdf539f67050ebe61b5dc589f9c138bb9ef1719f6 (diff)
downloadopie-b5d913c33546f9d29556bcab47d1d91a3ac94fd3.zip
opie-b5d913c33546f9d29556bcab47d1d91a3ac94fd3.tar.gz
opie-b5d913c33546f9d29556bcab47d1d91a3ac94fd3.tar.bz2
Compile fix for gcc-2.95 <sigh>
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,227 +1,221 @@
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 ) );
114 return -1; 108 return -1;
115 } 109 }
116} 110}
117 111
118 112
119void OFileNotification::stop() 113void OFileNotification::stop()
120{ 114{
121 if ( !_active ) return; 115 if ( !_active ) return;
122 116
123 int result = ::fcntl( _fd, F_NOTIFY, 0 ); 117 int result = ::fcntl( _fd, F_NOTIFY, 0 );
124 if ( result == -1 ) 118 if ( result == -1 )
125 { 119 {
126 qWarning( "OFileNotification::stop(): Can't remove subscription to '%s': %s.", (const char*) _path, strerror( errno ) ); 120 qWarning( "OFileNotification::stop(): Can't remove subscription to '%s': %s.", (const char*) _path, strerror( errno ) );
127 } 121 }
128 else 122 else
129 { 123 {
130 ::close( _fd ); 124 ::close( _fd );
131 _type = Single; 125 _type = Single;
132 _path = QString::null; 126 _path = QString::null;
133 _fd = 0; 127 _fd = 0;
134 _active = false; 128 _active = false;
135 } 129 }
136} 130}
137 131
138 132
139OFileNotificationType OFileNotification::type() const 133OFileNotificationType OFileNotification::type() const
140{ 134{
141 return _type; 135 return _type;
142} 136}
143 137
144 138
145QString OFileNotification::path() const 139QString OFileNotification::path() const
146{ 140{
147 return _path; 141 return _path;
148} 142}
149 143
150int OFileNotification::fileno() const 144int OFileNotification::fileno() const
151{ 145{
152 return _fd; 146 return _fd;
153} 147}
154 148
155void OFileNotification::activate() 149void OFileNotification::activate()
156{ 150{
157 emit triggered(); 151 emit triggered();
158 _signal.activate(); 152 _signal.activate();
159} 153}
160 154
161 155
162void OFileNotification::singleShot( const QString& path, QObject* receiver, const char* member, OFileNotificationType type ) 156void OFileNotification::singleShot( const QString& path, QObject* receiver, const char* member, OFileNotificationType type )
163{ 157{
164 OFileNotification* ofn = new OFileNotification(); 158 OFileNotification* ofn = new OFileNotification();
165 ofn->_signal.connect( receiver, member ); 159 ofn->_signal.connect( receiver, member );
166 ofn->start( path, true, type ); 160 ofn->start( path, true, type );
167} 161}
168 162
169 163
170void OFileNotification::__signalHandler( int sig, siginfo_t *si, void *data ) 164void OFileNotification::__signalHandler( int sig, siginfo_t *si, void *data )
171{ 165{
172 qWarning( "OFileNotification::__signalHandler(): reached." ); 166 qWarning( "OFileNotification::__signalHandler(): reached." );
173 int fd = si->si_fd; 167 int fd = si->si_fd;
174 OFileNotification* fn = notification_list[fd]; 168 OFileNotification* fn = notification_list[fd];
175 if ( fn ) 169 if ( fn )
176 { 170 {
177 fn->activate(); 171 fn->activate();
178 #if 1 172 #if 1
179 if ( !(fn->type() & Multi) ) 173 if ( !(fn->type() & Multi) )
180 { 174 {
181 qDebug( "OFileNotification::__signalHandler(): '%d' was singleShot. Removing from list.", fd ); 175 qDebug( "OFileNotification::__signalHandler(): '%d' was singleShot. Removing from list.", fd );
182 notification_list.remove( fd ); 176 notification_list.remove( fd );
183 if ( notification_list.isEmpty() ) 177 if ( notification_list.isEmpty() )
184 { 178 {
185 OFileNotification::unregisterSignalHandler(); 179 OFileNotification::unregisterSignalHandler();
186 } 180 }
187 } 181 }
188 #endif 182 #endif
189 } 183 }
190 else 184 else
191 { 185 {
192 qWarning( "OFileNotification::__signalHandler(): D'oh! Called without fd in notification_list. Race condition?" ); 186 qWarning( "OFileNotification::__signalHandler(): D'oh! Called without fd in notification_list. Race condition?" );
193 } 187 }
194} 188}
195 189
196 190
197bool OFileNotification::registerSignalHandler() 191bool OFileNotification::registerSignalHandler()
198{ 192{
199 struct sigaction act; 193 struct sigaction act;
200 act.sa_sigaction = OFileNotification::__signalHandler; 194 act.sa_sigaction = OFileNotification::__signalHandler;
201 ::sigemptyset( &act.sa_mask ); 195 ::sigemptyset( &act.sa_mask );
202 act.sa_flags = SA_SIGINFO; 196 act.sa_flags = SA_SIGINFO;
203 if ( ::sigaction( SIGRTMIN, &act, NULL ) == -1 ) 197 if ( ::sigaction( SIGRTMIN, &act, NULL ) == -1 )
204 { 198 {
205 qWarning( "OFileNotification::registerSignalHandler(): couldn't register signal handler: %s", strerror( errno ) ); 199 qWarning( "OFileNotification::registerSignalHandler(): couldn't register signal handler: %s", strerror( errno ) );
206 return false; 200 return false;
207 } 201 }
208 qDebug( "OFileNotification::registerSignalHandler(): done" ); 202 qDebug( "OFileNotification::registerSignalHandler(): done" );
209} 203}
210 204
211 205
212void OFileNotification::unregisterSignalHandler() 206void OFileNotification::unregisterSignalHandler()
213{ 207{
214 struct sigaction act; 208 struct sigaction act;
215 act.sa_sigaction = ( void (*)(int, siginfo_t*, void*) ) SIG_DFL; 209 act.sa_sigaction = ( void (*)(int, siginfo_t*, void*) ) SIG_DFL;
216 ::sigemptyset( &act.sa_mask ); 210 ::sigemptyset( &act.sa_mask );
217 if ( ::sigaction( SIGRTMIN, &act, NULL ) == -1 ) 211 if ( ::sigaction( SIGRTMIN, &act, NULL ) == -1 )
218 if ( ::sigaction( SIGRTMIN, &act, NULL ) == -1 ) 212 if ( ::sigaction( SIGRTMIN, &act, NULL ) == -1 )
219 { 213 {
220 qWarning( "OFileNotification::unregisterSignalHandler(): couldn't deregister signal handler: %s", strerror( errno ) ); 214 qWarning( "OFileNotification::unregisterSignalHandler(): couldn't deregister signal handler: %s", strerror( errno ) );
221 } 215 }
222 qDebug( "OFileNotification::unregisterSignalHandler(): done" ); 216 qDebug( "OFileNotification::unregisterSignalHandler(): done" );
223} 217}
224 218
225 219
226} 220}
227} 221}
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