2 Copyright (C) 2000 Werner Koch (dd9jn)
3 Copyright (C) 2001, 2002, 2003 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 General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (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 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GPGME; if not, write to the Free Software Foundation,
19 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
32 /* The user event loops are used for all asynchronous operations for
33 which a user callback is defined. */
36 /* Internal I/O Callbacks. */
39 _gpgme_user_io_cb_handler (void *data, int fd)
42 struct tag *tag = (struct tag *) data;
44 struct wait_item_s *item;
49 item = (struct wait_item_s *) ctx->fdt.fds[tag->idx].opaque;
52 err = (*item->handler) (item->handler_value, fd);
57 for (idx = 0; idx < ctx->fdt.size; idx++)
58 if (ctx->fdt.fds[idx].fd != -1)
59 _gpgme_io_close (ctx->fdt.fds[idx].fd);
60 _gpgme_engine_io_event (ctx->engine, GPGME_EVENT_DONE, &err);
66 for (i = 0; i < ctx->fdt.size; i++)
67 if (ctx->fdt.fds[i].fd != -1)
69 if (i == ctx->fdt.size)
70 _gpgme_engine_io_event (ctx->engine, GPGME_EVENT_DONE, &err);
76 /* Register the file descriptor FD with the handler FNC (which gets
77 FNC_DATA as its first argument) for the direction DIR. DATA should
78 be the context for which the fd is added. R_TAG will hold the tag
79 that can be used to remove the fd. */
81 _gpgme_wait_user_add_io_cb (void *data, int fd, int dir, gpgme_io_cb_t fnc,
82 void *fnc_data, void **r_tag)
84 gpgme_ctx_t ctx = (gpgme_ctx_t) data;
89 err = _gpgme_add_io_cb (data, fd, dir, fnc, fnc_data, r_tag);
94 err = (*ctx->io_cbs.add) (ctx->io_cbs.add_priv, fd, dir,
95 _gpgme_user_io_cb_handler, *r_tag,
98 _gpgme_remove_io_cb (*r_tag);
104 _gpgme_wait_user_remove_io_cb (void *data)
106 struct tag *tag = (struct tag *) data;
112 (*ctx->io_cbs.remove) (tag->user_tag);
113 _gpgme_remove_io_cb (data);
118 _gpgme_wait_user_event_cb (void *data, gpgme_event_io_t type, void *type_data)
120 gpgme_ctx_t ctx = data;
122 if (ctx->io_cbs.event)
123 (*ctx->io_cbs.event) (ctx->io_cbs.event_priv, type, type_data);