summaryrefslogtreecommitdiff
path: root/libopie2
authormickeyl <mickeyl>2004-04-16 18:09:45 (UTC)
committer mickeyl <mickeyl>2004-04-16 18:09:45 (UTC)
commit71b24a42daccd45fe80b2a669c3a88cfc5dcf608 (patch) (unidiff)
tree073f505661af9e4a3c68383c1a10ff45e164047d /libopie2
parent746f8154b5b81621ee55d24c8ed2cbc05d402490 (diff)
downloadopie-71b24a42daccd45fe80b2a669c3a88cfc5dcf608.zip
opie-71b24a42daccd45fe80b2a669c3a88cfc5dcf608.tar.gz
opie-71b24a42daccd45fe80b2a669c3a88cfc5dcf608.tar.bz2
initial checkin of file and directory notifying classes
this is work in progress. don't look to close yet
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opiecore/ofilenotify.cpp159
-rw-r--r--libopie2/opiecore/ofilenotify.h72
-rw-r--r--libopie2/opiecore/opiecore.pro14
3 files changed, 239 insertions, 6 deletions
diff --git a/libopie2/opiecore/ofilenotify.cpp b/libopie2/opiecore/ofilenotify.cpp
new file mode 100644
index 0000000..2242570
--- a/dev/null
+++ b/libopie2/opiecore/ofilenotify.cpp
@@ -0,0 +1,159 @@
1/*
2                This file is part of the Opie Project
3 =. Copyright (C) 2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5          .>+-=
6_;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software
10- .   .-<_>     .<> Foundation; either version 2 of the License,
11    ._= =}       : or (at your option) any later version.
12   .%`+i>       _;_.
13   .i_,=:_.      -<s. This program is distributed in the hope that
14    +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15   : ..    .:,     . . . without even the implied warranty of
16   =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17 _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details.
20:     =  ...= . :.=-
21-.   .:....=;==+<; You should have received a copy of the GNU
22 -_. . .   )=.  = Library General Public License along with
23   --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA.
27*/
28
29#include "ofilenotify.h"
30using namespace Opie::Core;
31
32/* OPIE */
33
34/* QT */
35#include <qsignal.h>
36#include <qintdict.h>
37#include <qdir.h>
38
39/* STD */
40#include <sys/types.h>
41#include <sys/stat.h>
42#include <fcntl.h>
43#include <string.h>
44#include <errno.h>
45
46namespace Opie {
47namespace Core {
48
49class OFileNotification
50{
51 public:
52 OFileNotification( QObject* receiver, const char* member, OFileNotificationType type ) : _type( type )
53 {
54 _signal.connect( receiver, member );
55 }
56 ~OFileNotification()
57 {
58 }
59
60 void activate()
61 {
62 _signal.activate();
63 }
64
65 OFileNotificationType type()
66 {
67 return _type;
68 }
69
70 private:
71 OFileNotificationType _type;
72 QSignal _signal;
73};
74
75
76static QIntDict<OFileNotification> notification_list;
77
78
79void OFileNotifier::singleShot( const QString& path, QObject* receiver, const char* member, OFileNotificationType type )
80{
81 int fd = ::open( (const char*) path, O_RDONLY );
82 if ( fd != -1 )
83 {
84 if ( notification_list.isEmpty() )
85 {
86 OFileNotifier::registerSignalHandler();
87 }
88 int result = ::fcntl( fd, F_SETSIG, SIGRTMIN );
89 if ( result == -1 )
90 {
91 qWarning( "OFileNotifier::singleShot(): Can't subscribe to '%s': %s.", (const char*) path, strerror( errno ) );
92 return;
93 }
94 result = ::fcntl( fd, F_NOTIFY, type );
95 if ( result == -1 )
96 {
97 qWarning( "OFileNotifier::singleShot(): Can't subscribe to '%s': %s.", (const char*) path, strerror( errno ) );
98 return;
99 }
100 qDebug( "OFileNotifier::singleShot(): Subscribed for changes to %s (fd = %d)", (const char*) path, fd );
101 notification_list.insert( fd, new OFileNotification( receiver, member, type ) );
102 }
103 else
104 {
105 qWarning( "OFileNotifier::singleShot(): Error with path '%s': %s.", (const char*) path, strerror( errno ) );
106 }
107}
108
109
110void OFileNotifier::__signalHandler( int sig, siginfo_t *si, void *data )
111{
112 qWarning( "OFileNotifier::__signalHandler(): reached." );
113 int fd = si->si_fd;
114 OFileNotification* fn = notification_list[fd];
115 if ( fn )
116 {
117 fn->activate();
118 #if 1
119 if ( !(fn->type() & Multi) )
120 {
121 qDebug( "OFileNotifier::__signalHandler(): '%d' was singleShot. Removing from list.", fd );
122 notification_list.remove( fd );
123 if ( notification_list.isEmpty() )
124 {
125 OFileNotifier::unregisterSignalHandler();
126 }
127 }
128 #endif
129 }
130 else
131 {
132 qWarning( "OFileNotifier::__signalHandler(): D'oh! Called without fd in notification_list. Race condition?" );
133 }
134}
135
136
137void OFileNotifier::registerSignalHandler()
138{
139 struct sigaction act;
140 act.sa_sigaction = OFileNotifier::__signalHandler;
141 ::sigemptyset( &act.sa_mask );
142 act.sa_flags = SA_SIGINFO;
143 ::sigaction( SIGRTMIN, &act, NULL );
144 qDebug( "OFileNotifier::registerSignalHandler(): done" );
145}
146
147
148void OFileNotifier::unregisterSignalHandler()
149{
150 struct sigaction act;
151 act.sa_sigaction = ( void (*)(int, siginfo_t*, void*) ) SIG_DFL;
152 sigemptyset( &act.sa_mask );
153 ::sigaction( SIGRTMIN, &act, NULL );
154 qDebug( "OFileNotifier::unregisterSignalHandler(): done" );
155}
156
157
158}
159}
diff --git a/libopie2/opiecore/ofilenotify.h b/libopie2/opiecore/ofilenotify.h
new file mode 100644
index 0000000..638eb6c
--- a/dev/null
+++ b/libopie2/opiecore/ofilenotify.h
@@ -0,0 +1,72 @@
1/*
2                This file is part of the Opie Project
3 =. Copyright (C) 2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5          .>+-=
6_;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software
10- .   .-<_>     .<> Foundation; either version 2 of the License,
11    ._= =}       : or (at your option) any later version.
12   .%`+i>       _;_.
13   .i_,=:_.      -<s. This program is distributed in the hope that
14    +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15   : ..    .:,     . . . without even the implied warranty of
16   =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17 _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details.
20:     =  ...= . :.=-
21-.   .:....=;==+<; You should have received a copy of the GNU
22 -_. . .   )=.  = Library General Public License along with
23   --        :-=` this library; see the file COPYING.LIB.
24 If not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA.
27*/
28
29#ifndef OFILENOTIFY_H
30#define OFILENOTIFY_H
31
32/* QT */
33#include <qstring.h>
34#include <qobject.h>
35
36/* STD */
37#include <signal.h>
38#include <fcntl.h>
39
40namespace Opie {
41namespace Core {
42
43enum OFileNotificationType { Single = 0x0000000,
44 Multi = DN_MULTISHOT,
45 Access = DN_ACCESS,
46 Modify = DN_MODIFY,
47 Create = DN_CREATE,
48 Delete = DN_DELETE,
49 Rename = DN_RENAME,
50 Attrib = DN_ATTRIB };
51
52class OFileNotifier : public QObject
53{
54 public:
55 static void singleShot( const QString& path,
56 QObject *receiver, const char *member,
57 OFileNotificationType type = Modify );
58 protected:
59 static void registerSignalHandler();
60 static void unregisterSignalHandler();
61 static void __signalHandler( int sig, siginfo_t *si, void *data );
62
63 private:
64 OFileNotifier();
65 ~OFileNotifier();
66};
67
68}
69}
70
71#endif
72
diff --git a/libopie2/opiecore/opiecore.pro b/libopie2/opiecore/opiecore.pro
index 171bb0c..ee42368 100644
--- a/libopie2/opiecore/opiecore.pro
+++ b/libopie2/opiecore/opiecore.pro
@@ -1,34 +1,36 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on 2CONFIG += qt warn_on
3DESTDIR = $(OPIEDIR)/lib 3DESTDIR = $(OPIEDIR)/lib
4HEADERS = oapplication.h \ 4HEADERS = oapplication.h \
5 oconfig.h \ 5 oconfig.h \
6 odebug.h \ 6 odebug.h \
7 ofilenotify.h \
7 oglobal.h \ 8 oglobal.h \
8 oglobalsettings.h \ 9 oglobalsettings.h \
9 okeyconfigmanager.h \ 10 okeyconfigmanager.h \
10 oprocess.h \ 11 oprocess.h \
11 oprocctrl.h \ 12 oprocctrl.h \
12 osmartpointer.h \ 13 osmartpointer.h \
13 ostorageinfo.h \ 14 ostorageinfo.h \
14 xmltree.h 15 xmltree.h
15 16
16SOURCES = oapplication.cpp \ 17SOURCES = oapplication.cpp \
17 oconfig.cpp \ 18 oconfig.cpp \
18 odebug.cpp \ 19 odebug.cpp \
20 ofilenotify.cpp \
19 oglobal.cpp \ 21 oglobal.cpp \
20 oglobalsettings.cpp \ 22 oglobalsettings.cpp \
21 okeyconfigmanager.cpp \ 23 okeyconfigmanager.cpp \
22 oprocess.cpp \ 24 oprocess.cpp \
23 oprocctrl.cpp \ 25 oprocctrl.cpp \
24 ostorageinfo.cpp \ 26 ostorageinfo.cpp \
25 xmltree.cpp 27 xmltree.cpp
26 28
27include ( device/device.pro ) 29include ( device/device.pro )
28 30
29INTERFACES = 31INTERFACES =
30TARGET = opiecore2 32TARGET = opiecore2
31VERSION = 1.9.0 33VERSION = 1.9.1
32INCLUDEPATH += $(OPIEDIR)/include 34INCLUDEPATH += $(OPIEDIR)/include
33DEPENDPATH += $(OPIEDIR)/include 35DEPENDPATH += $(OPIEDIR)/include
34 36