Multi-threading GPGME
Marc Mutz
mutz@kde.org
Fri Jan 3 14:27:02 2003
--Boundary-03=_z5YF+e6m7ubkOAb
Content-Type: multipart/mixed;
boundary="Boundary-01=_z5YF+nFhWOAi5I7"
Content-Transfer-Encoding: 7bit
Content-Description: signed data
Content-Disposition: inline
--Boundary-01=_z5YF+nFhWOAi5I7
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Content-Description: body text
Content-Disposition: inline
Hi Marcus!
On Thursday 02 January 2003 22:45, Marcus Brinkmann wrote:
<snip>
> Please read the following sections in the manual:
>
> * Multi Threading:: How GPGME can be used in an MT
> environment.
>
> * Using External Event Loops:: Advanced control over what happens
> when.
<snip>
Would you like to accept the attached patch to gpgme.texi that shows how=20
to integrate gpgme with Qt's event loop?
Marc
=2D-=20
The [Sonny Bono Copyright Term Extension Act] expands copyright not
only for future, but also for existing works, even though their
authors obviously don't need any additional incentive to create them.
-- "The Progress Of Science And Useful Arts":
Why Copyright Today Threatens Intellectual Freedom,
Free Expression Policy Project
--Boundary-01=_z5YF+nFhWOAi5I7
Content-Type: text/x-diff;
charset="us-ascii";
name="gpgme.texi.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline; filename="gpgme.texi.diff"
=2D-- gpgme.texi~ 2002-11-12 20:32:06.000000000 +0100
+++ gpgme.texi 2003-01-02 22:53:19.000000000 +0100
@@ -194,6 +194,7 @@
* I/O Callback Example:: An example how to use I/O callbacks.
* I/O Callback Example GTK+:: How to integrate @acronym{GPGME} in GTK+.
* I/O Callback Example GDK:: How to integrate @acronym{GPGME} in GDK.
+* I/O Callback Example Qt:: How to integrate @acronym{GPGME} in Qt.
=20
@end detailmenu
@end menu
@@ -2859,6 +2860,7 @@
* I/O Callback Example:: An example how to use I/O callbacks.
* I/O Callback Example GTK+:: How to use @acronym{GPGME} with GTK+.
* I/O Callback Example GDK:: How to use @acronym{GPGME} with GDK.
+* I/O Callback Example Qt:: How to use @acronym{GPGME} with Qt.
@end menu
=20
=20
@@ -3349,6 +3351,74 @@
@end example
=20
=20
+@node I/O Callback Example Qt
+@subsubsection I/O Callback Example Qt
+@cindex Qt, using @acronym{GPGME} with
+
+The I/O callback interface can also be used to integrate
+@acronym{GPGME} with the Qt event loop. The following code snippets
+show how this can be done using the appropriate register and remove
+I/O callback functions. In this example, the private data of the
+register I/O callback function is unused. The event notifications is
+missing because it does not require any Qt specific setup.
+
+@example
+#include <qsocketnotifier.h>
+#include <qapplication.h>
+
+struct IOCB @{
+ IOCB( GpgmeIOCb f, void * d, QSocketNotifier * n )
+ : func( f ), data( d ), notifier( n ) @{@}
+ GpgmeIOCb func;
+ void * data;
+ QSocketNotifier * notifier;
+@}
+
+class MyApp : public QApplication @{
+
+ // ...
+ =20
+ static void registerGpgmeIOCallback( void * data, int fd, int dir,
+ GpgmeIOCb func, void * func_data,
+ void ** tag ) @{
+ QSocketNotifier * n =3D
+ new QSocketNotifier( fd, dir ? QSocketNotifier::Read
+ : QSocketNotifier::Write );
+ connect( n, SIGNAL(activated(int)),
+ qApp, SLOT(slotGpgmeIOCallback(int)) );
+ qApp->mIOCBs.push_back( IOCB( func, func_data, n ) );
+ *tag =3D (void*)n;
+ @}
+
+ static void removeGpgmeIOCallback( void * tag ) @{
+ if ( !tag ) return;
+ QSocketNotifier * n =3D static_cast<QSocketNotifier*>( tag );
+ for ( QValueList<IOCB>::iterator it =3D qApp->mIOCBs.begin() ;
+ it !=3D qApp->mIOCBs.end() ; ++it )
+ if ( it->notifier =3D=3D n ) @{
+ delete it->notifier;
+ qApp->mIOCBs.erase( it );
+ return;
+ @}
+ @}
+
+public slots:
+ void slotGpgmeIOCallback( int fd ) @{
+ for ( QValueList<IOCB>::const_iterator it =3D mIOCBs.begin() ;
+ it !=3D mIOCBs.end() ; ++it )
+ if ( it->notifier && it->notifier->socket() =3D=3D fd )
+ (*(it->func)) ( it->func_data, fd );
+ @}
+
+ // ...
+
+private:
+ QValueList<IOCB> mIOCBs;
+ // ...
+@};
+@end example
+
+
@include gpl.texi
=20
=20
--Boundary-01=_z5YF+nFhWOAi5I7--
--Boundary-03=_z5YF+e6m7ubkOAb
Content-Type: application/pgp-signature
Content-Description: signature
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQA+FY5z3oWD+L2/6DgRAthMAJ9hIvHEkg5EmdRE3MFr5hLBn93Q7gCgyrsj
BxG6u2Xg3W2RZWecvUojbXs=
=rWN4
-----END PGP SIGNATURE-----
--Boundary-03=_z5YF+e6m7ubkOAb--