rlib
Convenience library for useful things
Loading...
Searching...
No Matches
rcbctx.h
Go to the documentation of this file.
1/* RLIB - Convenience library for useful things
2 * Copyright (C) 2018 Haakon Sporsheim <haakon.sporsheim@gmail.com>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 3.0 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library.
16 * See the COPYING file at the root of the source repository.
17 */
18#ifndef __R_CBCTX_H__
19#define __R_CBCTX_H__
20
21#if !defined(__RLIB_H_INCLUDE_GUARD__) && !defined(RLIB_COMPILATION)
22#error "#include <rlib.h> only please."
23#endif
24
50#include <rlib/rtypes.h>
51
53
68
69static inline void r_func_callback_ctx_init (RFuncCallbackCtx * ctx,
70 RFunc cb, rpointer data, RDestroyNotify datanotify,
71 rpointer user, RDestroyNotify usernotify)
72{
73 ctx->cb = cb;
74 ctx->data = data;
75 ctx->datanotify = datanotify;
76 ctx->user = user;
77 ctx->usernotify = usernotify;
78}
79static inline void r_func_callback_ctx_clear (RFuncCallbackCtx * ctx)
80{
81 if (ctx->datanotify != NULL)
82 ctx->datanotify (ctx->data);
83 if (ctx->usernotify != NULL)
84 ctx->usernotify (ctx->user);
85}
86static inline void r_func_callback_ctx_call (RFuncCallbackCtx * ctx)
87{
88 ctx->cb (ctx->data, ctx->user);
89}
90
91
105
106static inline void r_func_return_callback_ctx_init (RFuncReturnCallbackCtx * ctx,
107 RFuncReturn cb, rpointer data, RDestroyNotify datanotify,
108 rpointer user, RDestroyNotify usernotify)
109{
110 ctx->cb = cb;
111 ctx->data = data;
112 ctx->datanotify = datanotify;
113 ctx->user = user;
114 ctx->usernotify = usernotify;
115}
116static inline void r_func_return_callback_ctx_clear (RFuncReturnCallbackCtx * ctx)
117{
118 if (ctx->datanotify != NULL)
119 ctx->datanotify (ctx->data);
120 if (ctx->usernotify != NULL)
121 ctx->usernotify (ctx->user);
122}
123static inline rboolean r_func_return_callback_ctx_call (RFuncReturnCallbackCtx * ctx)
124{
125 return ctx->cb (ctx->data, ctx->user);
126}
127
128
129R_END_DECLS
130
133#endif /* __R_CBCTX_H__ */
#define NULL
Null pointer constant (defined only if absent).
Definition rmacros.h:126
#define R_BEGIN_DECLS
Open an extern "C" block under C++ (no-op in C).
Definition rmacros.h:196
int rboolean
Boolean type (typedef'd to int).
Definition rtypes.h:59
void(* RFunc)(rpointer data, rpointer user)
Generic iteration callback over (data, user) pairs.
Definition rtypes.h:403
void(* RDestroyNotify)(rpointer ptr)
Destructor callback: free / release the value at ptr.
Definition rtypes.h:401
void * rpointer
Generic pointer (alias for void *).
Definition rtypes.h:327
rboolean(* RFuncReturn)(rpointer data, rpointer user)
Iteration callback that can short-circuit by returning FALSE.
Definition rtypes.h:419
Foundational type aliases used by every rlib header.
Callback context for a void-returning function.
Definition rcbctx.h:61
RDestroyNotify datanotify
Definition rcbctx.h:64
rpointer user
Definition rcbctx.h:65
rpointer data
Definition rcbctx.h:63
RDestroyNotify usernotify
Definition rcbctx.h:66
RFunc cb
Definition rcbctx.h:62
Callback context for a function that returns rboolean.
Definition rcbctx.h:98
RDestroyNotify datanotify
Definition rcbctx.h:101
RDestroyNotify usernotify
Definition rcbctx.h:103
rpointer data
Definition rcbctx.h:100
rpointer user
Definition rcbctx.h:102
RFuncReturn cb
Definition rcbctx.h:99