2 Copyright (C) 2000 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2002, 2003, 2004, 2005 g10 Code GmbH
5 This file is part of GPGME.
7 GPGME is free software; you can redistribute it and/or modify it
8 under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of
10 the License, or (at your option) any later version.
12 GPGME is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
34 /* The user event loops are used for all asynchronous operations for
35 which a user callback is defined. */
38 /* Internal I/O Callbacks. */
41 _gpgme_user_io_cb_handler (void *data, int fd)
43 gpgme_error_t err = 0;
44 gpgme_error_t op_err = 0;
45 struct tag *tag = (struct tag *) data;
54 err = gpg_error (GPG_ERR_CANCELED);
58 err = _gpgme_run_io_cb (&ctx->fdt.fds[tag->idx], 0, &op_err);
60 _gpgme_cancel_with_err (ctx, err, op_err);
65 for (i = 0; i < ctx->fdt.size; i++)
66 if (ctx->fdt.fds[i].fd != -1)
69 if (i == ctx->fdt.size)
71 struct gpgme_io_event_done_data done_data;
75 _gpgme_engine_io_event (ctx->engine, GPGME_EVENT_DONE, &done_data);
82 /* Register the file descriptor FD with the handler FNC (which gets
83 FNC_DATA as its first argument) for the direction DIR. DATA should
84 be the context for which the fd is added. R_TAG will hold the tag
85 that can be used to remove the fd. */
87 _gpgme_wait_user_add_io_cb (void *data, int fd, int dir, gpgme_io_cb_t fnc,
88 void *fnc_data, void **r_tag)
90 gpgme_ctx_t ctx = (gpgme_ctx_t) data;
95 err = _gpgme_add_io_cb (data, fd, dir, fnc, fnc_data, r_tag);
100 err = (*ctx->io_cbs.add) (ctx->io_cbs.add_priv, fd, dir,
101 _gpgme_user_io_cb_handler, *r_tag,
104 _gpgme_remove_io_cb (*r_tag);
110 _gpgme_wait_user_remove_io_cb (void *data)
112 struct tag *tag = (struct tag *) data;
118 (*ctx->io_cbs.remove) (tag->user_tag);
119 _gpgme_remove_io_cb (data);
124 _gpgme_wait_user_event_cb (void *data, gpgme_event_io_t type, void *type_data)
126 gpgme_ctx_t ctx = data;
128 if (ctx->io_cbs.event)
129 (*ctx->io_cbs.event) (ctx->io_cbs.event_priv, type, type_data);