GPGME multi threading
Marc Mutz
mutz@kde.org
Tue Jan 14 13:55:02 2003
--Boundary-03=_SKAJ+sztm5XRkXk
Content-Type: multipart/mixed;
boundary="Boundary-01=_9JAJ+iwTP16ytmz"
Content-Transfer-Encoding: 7bit
Content-Description: signed data
Content-Disposition: inline
--Boundary-01=_9JAJ+iwTP16ytmz
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Content-Description: body text
Content-Disposition: inline
On Monday 30 December 2002 21:26, Martin Galpin wrote:
<snip>
> I'm looking to use GPGME in a Qt application and I've noticed it does
> support multi threading. I was wondering how you go about enabling
> this for your program.
<snip>
You can do all gpgme related stuff non-blocking in the GUI thread. Just=20
hook gpgme up to Qt's event loop by doing something like the attached=20
mail with a new section for the gpgme manual shows.
Marc
=2D-=20
'When you see the ping of death, duck and cover.'
-- Bruce Schneier, Crypto-Gram Oct 2002
--Boundary-01=_9JAJ+iwTP16ytmz
Content-Type: message/rfc822;
name="forwarded message"
Content-Transfer-Encoding: quoted-printable
Content-Description: Marc Mutz <mutz@kde.org>: Re: Multi-threading GPGME
Content-Disposition: inline
Return-Path: <gpa-dev-admin@gnupg.org>
Delivered-To: mmutz@localhost.physik.uni-bielefeld.de
Received: from localhost (localhost.localdomain [127.0.0.1])
by dirichlet.physik.uni-bielefeld.de (Postfix) with ESMTP id 608691E0A7
for <mmutz@localhost>; Fri, 3 Jan 2003 19:21:50 -0500 (EST)
Received: from mail.uni-bielefeld.de [129.70.4.91]
by localhost with POP3 (fetchmail-6.1.0)
for mmutz@localhost (single-drop); Sat, 04 Jan 2003 01:21:50 +0100 (CET)
Received: from ktown.kde.org (kde.informatik.uni-kl.de [131.246.103.200])
by mail.uni-bielefeld.de
(Sun Internet Mail Server sims.4.0.2000.10.12.16.25.p8)
with SMTP id <0H85006GU456FO@mail.uni-bielefeld.de> for mmutz@sims-ms-daem=
on
(ORCPT rfc822;Marc.Mutz@uni-bielefeld.de); Fri,
3 Jan 2003 14:29:30 +0100 (MET)
Received: (qmail 15196 invoked by uid 1055); Fri, 03 Jan 2003 13:29:29 +0000
Received: (qmail 15188 invoked from network); Fri, 03 Jan 2003 13:29:28 +00=
00
Received: from trithemius.gnupg.org (217.69.76.44) by kde.informatik.uni-kl=
=2Ede
with SMTP; Fri, 03 Jan 2003 13:29:28 +0000
Received: from localhost ([127.0.0.1] helo=3Dtrithemius.gnupg.org)
by trithemius.gnupg.org with esmtp (Exim 3.35 #1 (Debian))
id 18URqq-0003AC-00; Fri, 03 Jan 2003 14:27:04 +0100
Received: from kerckhoffs.g10code.com ([217.69.77.222])
by trithemius.gnupg.org with esmtp (Exim 3.35 #1 (Debian))
id 18URqM-00039n-00 for <mm.gpa-dev@trithemius.gnupg.org>; Fri,
03 Jan 2003 14:26:34 +0100
Received: from max.kde.org ([134.2.170.93]) by kerckhoffs.g10code.com with
esmtp (Exim 3.35 #1 (Debian)) id 18URoQ-0004yB-00 for <gpa-dev@gnupg.org>;
Fri, 03 Jan 2003 14:24:34 +0100
Received: from dhcp200.hq (aktaia.intevation.org [212.95.126.10])
by max.kde.org (Postfix) with ESMTP id 6E45FB44AE for <gpa-dev@gnupg.org>;
Fri, 03 Jan 2003 14:14:37 +0100 (CET)
Date: Fri, 03 Jan 2003 14:21:48 +0100
=46rom: Marc Mutz <mutz@kde.org>
Subject: Re: Multi-threading GPGME
In-reply-to: <20030102214515.GD407@ulysses>
Sender: gpa-dev-admin@gnupg.org
To: gpa-dev@gnupg.org
Errors-To: gpa-dev-admin@gnupg.org
Message-id: <200301031421.50007@sendmail.mutz.com>
Organization: KDE
MIME-version: 1.0
Content-type: multipart/signed;
protocol=3D"application/pgp-signature";
micalg=3Dpgp-sha1;
boundary=3D"Boundary-03=3D_z5YF+e6m7ubkOAb";
charset=3D"us-ascii"
Content-transfer-encoding: 7bit
Precedence: bulk
Delivered-to: kde.org-mutz@kde.org
User-Agent: KMail/1.6
X-PGP-Key: 0xBDBFE838
X-BeenThere: gpa-dev@gnupg.org
X-Mailman-Version: 2.0.11
X-Original-Date: Fri, 3 Jan 2003 14:21:48 +0100
X-Spam-Status: No,
hits=3D-2.0 required=3D5.5 tests=3DIN_REP_TO,KNOWN_MAILING_LIST,NOSPAM_INC=
,PGP_SIGNATURE_2,
REFERENCES,SPAM_PHRASE_00_01,USER_AGENT version=3D2.42
X-Spam-Level:
References: <200301022131.03814.ep0ch@evobb.com> <20030102214515.GD407@ulys=
ses>
List-Post: <mailto:gpa-dev@gnupg.org>
List-Subscribe: <http://lists.gnupg.org/mailman/listinfo/gpa-dev>,
<mailto:gpa-dev-request@gnupg.org?subject=3Dsubscribe>
List-Unsubscribe: <http://lists.gnupg.org/mailman/listinfo/gpa-dev>,
<mailto:gpa-dev-request@gnupg.org?subject=3Dunsubscribe>
List-Archive: <http://lists.gnupg.org/pipermail/gpa-dev/>
List-Help: <mailto:gpa-dev-request@gnupg.org?subject=3Dhelp>
List-Id: Privacy Assistant development <gpa-dev.gnupg.org>
Status: R=20
X-Status: N
X-KMail-EncryptionState: =20
X-KMail-SignatureState: =20
X-KMail-MDN-Sent: =20
=2D-Boundary-03=3D_z5YF+e6m7ubkOAb
Content-Type: multipart/mixed;
boundary=3D"Boundary-01=3D_z5YF+nFhWOAi5I7"
Content-Transfer-Encoding: 7bit
Content-Description: signed data
Content-Disposition: inline
=2D-Boundary-01=3D_z5YF+nFhWOAi5I7
Content-Type: text/plain;
charset=3D"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=3D=
20
to integrate gpgme with Qt's event loop?
Marc
=3D2D-=3D20
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
=2D-Boundary-01=3D_z5YF+nFhWOAi5I7
Content-Type: text/x-diff;
charset=3D"us-ascii";
name=3D"gpgme.texi.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline; filename=3D"gpgme.texi.diff"
=3D2D-- 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.
=3D20
@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
=3D20
=3D20
@@ -3349,6 +3351,74 @@
@end example
=3D20
=3D20
+@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 @{
+
+ // ...
+ =3D20
+ static void registerGpgmeIOCallback( void * data, int fd, int dir,
+ GpgmeIOCb func, void * func_data,
+ void ** tag ) @{
+ QSocketNotifier * n =3D3D
+ 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 =3D3D (void*)n;
+ @}
+
+ static void removeGpgmeIOCallback( void * tag ) @{
+ if ( !tag ) return;
+ QSocketNotifier * n =3D3D static_cast<QSocketNotifier*>( tag );
+ for ( QValueList<IOCB>::iterator it =3D3D qApp->mIOCBs.begin() ;
+ it !=3D3D qApp->mIOCBs.end() ; ++it )
+ if ( it->notifier =3D3D=3D3D n ) @{
+ delete it->notifier;
+ qApp->mIOCBs.erase( it );
+ return;
+ @}
+ @}
+
+public slots:
+ void slotGpgmeIOCallback( int fd ) @{
+ for ( QValueList<IOCB>::const_iterator it =3D3D mIOCBs.begin() ;
+ it !=3D3D mIOCBs.end() ; ++it )
+ if ( it->notifier && it->notifier->socket() =3D3D=3D3D fd )
+ (*(it->func)) ( it->func_data, fd );
+ @}
+
+ // ...
+
+private:
+ QValueList<IOCB> mIOCBs;
+ // ...
+@};
+@end example
+
+
@include gpl.texi
=3D20
=3D20
=2D-Boundary-01=3D_z5YF+nFhWOAi5I7--
=2D-Boundary-03=3D_z5YF+e6m7ubkOAb
Content-Type: application/pgp-signature
Content-Description: signature
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQA+FY5z3oWD+L2/6DgRAthMAJ9hIvHEkg5EmdRE3MFr5hLBn93Q7gCgyrsj
BxG6u2Xg3W2RZWecvUojbXs=3D
=3DrWN4
=2D----END PGP SIGNATURE-----
=2D-Boundary-03=3D_z5YF+e6m7ubkOAb--
_______________________________________________
Gpa-dev mailing list
Gpa-dev@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gpa-dev
--Boundary-01=_9JAJ+iwTP16ytmz--
--Boundary-03=_SKAJ+sztm5XRkXk
Content-Type: application/pgp-signature
Content-Description: signature
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQA+JAKS3oWD+L2/6DgRAu0cAKDWCbLsGpvic1ajpOSTAWeJSDP0PQCgrOim
p7OR+4YSAIZYpZYThzZhSbM=
=jbtp
-----END PGP SIGNATURE-----
--Boundary-03=_SKAJ+sztm5XRkXk--