diff options
author | Simo Sorce <idra@samba.org> | 2009-02-28 15:44:30 -0500 |
---|---|---|
committer | Simo Sorce <idra@samba.org> | 2009-03-02 11:02:09 -0500 |
commit | 67d41d0fc7567cf141b12e866dd227d393e33551 (patch) | |
tree | 117ee0ddd513e0d2008c02d9ff5ead1dd7818ccc /lib/tevent/tevent.h | |
parent | 04a2b455a0385fc3aa23850d4841ab3495efc3e6 (diff) | |
download | samba-67d41d0fc7567cf141b12e866dd227d393e33551.tar.gz samba-67d41d0fc7567cf141b12e866dd227d393e33551.tar.bz2 samba-67d41d0fc7567cf141b12e866dd227d393e33551.zip |
Make struct tevent_req opaque
Move struct tevent_req in tevent_internal, and ad getters and setters
for private data and the callback function.
This patch also renames 'private_state' into 'data'. What is held in this
pointer is in fact data and not a state like enum tevent_req_state.
Calling it 'state' is confusing.
The functions addedd are:
tevent_req_set_callback() - sets req->async.fn and req->async.private_data
tevent_req_set_print_fn() - sets req->private_print
tevent_req_callback_data() - gets req->async.private_data
tevent_req_data() - gets rea->data
This way it is much simpler to keep API/ABI compatibility in the future.
Diffstat (limited to 'lib/tevent/tevent.h')
-rw-r--r-- | lib/tevent/tevent.h | 102 |
1 files changed, 13 insertions, 89 deletions
diff --git a/lib/tevent/tevent.h b/lib/tevent/tevent.h index 8c119ffb8e..5089d18ec2 100644 --- a/lib/tevent/tevent.h +++ b/lib/tevent/tevent.h @@ -183,98 +183,22 @@ enum tevent_req_state { * finished. This can happen while the completion function is called. */ -struct tevent_req { - /** - * @brief What to do on completion - * - * This is used for the user of an async request, fn is called when - * the request completes, either successfully or with an error. - */ - struct { - /** - * @brief Completion function - * Completion function, to be filled by the API user - */ - void (*fn)(struct tevent_req *); - /** - * @brief Private data for the completion function - */ - void *private_data; - } async; +struct tevent_req; - /** - * @brief Private state pointer for the actual implementation - * - * The implementation doing the work for the async request needs a - * current state like for example a fd event. The user of an async - * request should not touch this. - */ - void *private_state; +typedef void (*tevent_req_fn)(struct tevent_req *); - /** - * @brief A function to overwrite the default print function - * - * The implementation doing the work may want to imeplement a - * custom function to print the text representation of the async - * request. - */ - char *(*private_print)(struct tevent_req *req, TALLOC_CTX *mem_ctx); +void tevent_req_set_callback(struct tevent_req *req, tevent_req_fn fn, void *pvt); +void *_tevent_req_callback_data(struct tevent_req *req); +void *_tevent_req_data(struct tevent_req *req); - /** - * @brief Internal state of the request - * - * Callers should only access this via functions and never directly. - */ - struct { - /** - * @brief The talloc type of the private_state pointer - * - * This is filled by the tevent_req_create() macro. - * - * This for debugging only. - */ - const char *private_type; - - /** - * @brief The location where the request was created - * - * This uses the __location__ macro via the tevent_req_create() - * macro. - * - * This for debugging only. - */ - const char *location; - - /** - * @brief The external state - will be queried by the caller - * - * While the async request is being processed, state will remain in - * TEVENT_REQ_IN_PROGRESS. A request is finished if - * req->state>=TEVENT_REQ_DONE. - */ - enum tevent_req_state state; - - /** - * @brief status code when finished - * - * This status can be queried in the async completion function. It - * will be set to 0 when everything went fine. - */ - uint64_t error; - - /** - * @brief the timer event if tevent_req_post was used - * - */ - struct tevent_timer *trigger; - - /** - * @brief the timer event if tevent_req_set_timeout was used - * - */ - struct tevent_timer *timer; - } internal; -}; +#define tevent_req_callback_data(_req, _type) \ + talloc_get_type_abort(_tevent_req_callback_data(_req), _type) +#define tevent_req_data(_req, _type) \ + talloc_get_type_abort(_tevent_req_data(_req), _type) + +typedef char *(*tevent_req_print_fn)(struct tevent_req *, TALLOC_CTX *); + +void tevent_req_set_print_fn(struct tevent_req *req, tevent_req_print_fn fn); char *tevent_req_default_print(struct tevent_req *req, TALLOC_CTX *mem_ctx); |