4 Copyright (C) Amitay Isaacs 2015
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 __CTDB_REQID_H__
21 #define __CTDB_REQID_H__
28 * @brief Request id database
30 * CTDB tracks messsages using request id. CTDB stores client state for each
31 * request id to process the replies correctly.
35 * @brief Abstract struct to store request id database
39 #define REQID_INVALID 0xffffffff
42 * @brief Initialize request id database
44 * This returns a new request id context. Freeing this context will free
45 * all the memory associated with request id database.
47 * @param[in] mem_ctx Talloc memory context
48 * @param[in] start_id The initial id
49 * @param[out] result The new talloc_context structure
50 * @return 0 on success, errno on failure
52 int reqid_init(TALLOC_CTX
*mem_ctx
, int start_id
,
53 struct reqid_context
**result
);
56 * @brief Generate new request id and associate given data with the request id
58 * @param[in] reqid_ctx The request id context
59 * @param[in] private_data The state to associate with new request id
60 * @return new request id, REQID_INVALID on failure
62 uint32_t reqid_new(struct reqid_context
*reqid_ctx
, void *private_data
);
66 * @brief Fetch the data associated with the request id
68 * @param[in] reqid_ctx The request id context
69 * @param[in] reqid The request id
70 * @param[in] type The data type of the stored data
71 * @return the data stored for the reqid, NULL on failure
73 type
*reqid_find(struct reqid_context
*reqid_ctx
, uint32_t reqid
, #type);
75 void *_reqid_find(struct reqid_context
*reqid_ctx
, uint32_t reqid
);
76 #define reqid_find(ctx, reqid, type) \
77 (type *)talloc_check_name(_reqid_find(ctx, reqid), #type)
81 * @brief Remove the data associated with the request id
83 * @param[in] reqid_ctx The request id context
84 * @param[in] reqid The request id
85 * @return 0 on success, errno on failure
87 int reqid_remove(struct reqid_context
*reqid_ctx
, uint32_t reqid
);
89 #endif /* __CTDB_REQID_H__ */