s3/docs: Fix serveral typos.
[Samba.git] / source / include / async_req.h
blobfb463d5b9a172145bb1149fbce8f18540c0a48c1
1 /*
2 Unix SMB/CIFS implementation.
3 Infrastructure for async requests
4 Copyright (C) Volker Lendecke 2008
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef __ASYNC_REQ_H__
21 #define __ASYNC_REQ_H__
23 #include "includes.h"
26 * An async request moves between the following 4 states.
28 enum async_req_state {
29 ASYNC_REQ_INIT, /* we are creating the request */
30 ASYNC_REQ_IN_PROGRESS, /* we are waiting the request to complete */
31 ASYNC_REQ_DONE, /* the request is finished */
32 ASYNC_REQ_ERROR }; /* an error has occured */
34 struct async_req {
35 /* the external state - will be queried by the caller */
36 enum async_req_state state;
38 /* a private pointer for use by the async function implementation */
39 void *private_data;
41 /* print yourself, for debugging purposes */
42 char *(*print)(TALLOC_CTX *mem_ctx, struct async_req *);
44 /* status code when finished */
45 NTSTATUS status;
47 /* the event context we are using */
48 struct event_context *event_ctx;
50 /* information on what to do on completion */
51 struct {
52 void (*fn)(struct async_req *);
53 void *priv;
54 } async;
58 * Print an async_req structure for debugging purposes
60 char *async_req_print(TALLOC_CTX *mem_ctx, struct async_req *req);
63 * Create an async request
65 struct async_req *async_req_new(TALLOC_CTX *mem_ctx, struct event_context *ev);
68 * An async request has successfully finished, invoke the callback
70 void async_req_done(struct async_req *req);
73 * An async request has seen an error, invoke the callback
75 void async_req_error(struct async_req *req, NTSTATUS status);
78 * If a request is finished or ends in error even before it has the chance to
79 * trigger the event loop, post a status. This creates an immediate timed
80 * event to call the async function if there is any.
82 bool async_post_status(struct async_req *req, NTSTATUS status);
85 * Convenience helper to easily check alloc failure within a callback.
87 * Call pattern would be
88 * p = talloc(mem_ctx, bla);
89 * if (async_req_nomem(p, req)) {
90 * return;
91 * }
94 bool async_req_nomem(const void *p, struct async_req *req);
96 #endif