libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_c_closure.h
Go to the documentation of this file.
1/*! \file
2 * \ingroup signals
3 * \brief GblCClosure, C function callback closure, and API
4 *
5 * This file contains the definition of and API around
6 * GblCClosure, which is the plain C function implementation
7 * of the GblClosure type.
8 *
9 * It simply stores the value of a generic C function pointer,
10 * expecting to have either a marshal or meta marshal which
11 * converts arguments into plain C types, casts the callback
12 * to its correct type, invokes it, passing the arguments,
13 * and stores its return value as a GblVariant.
14 *
15 * \author 2023 Falco Girgis
16 * \copyright MIT License
17 */
18#ifndef GIMBAL_C_CLOSURE_H
19#define GIMBAL_C_CLOSURE_H
20
21#include "gimbal_closure.h"
22
23/*! \name Type System
24 * \brief Type UUID and cast operators
25 * @{
26 */
27#define GBL_C_CLOSURE_TYPE (GBL_TYPEID(GblCClosure)) //!< Type UUID of GblCClosure
28#define GBL_C_CLOSURE(self) (GBL_CAST(GblCClosure, self)) //!< Function-style GblInstance cast
29#define GBL_C_CLOSURE_CLASS(klass) (GBL_CLASS_CAST(GblCClosure, klass)) //!< Function-style GblClass cast
30#define GBL_C_CLOSURE_GET_CLASS(self) (GBL_CLASSOF(GblCClosure, self)) //!< Get GblCClosureClass from GblInstance
31//! @}
32
33#define GBL_SELF_TYPE GblCClosure
34
36
37/*! \struct GblCClosureClass
38 * \brief GblClass VTable for GblCClosure
39 * \extends GblClosureClass
40 *
41 * No public members.
42 *
43 * \sa GblCClosure
44 */
45GBL_CLASS_DERIVE_EMPTY(GblCClosure, GblClosure)
46
47/*! \struct GblCClosure
48 * \brief Closure type for invoking C functions
49 * \extends GblClosure
50 * \ingroup signals
51 *
52 * GblCClosure is a GblClosure which is used to
53 * marshal generic arguments into a C function
54 * pointer and marshal out the return value.
55 *
56 * \sa GblClosure
57 */
60 GblFnPtr pFnCallback; //!< PRIVATE: C Function pointer to invoke as a callback
63
64//! Returns the GblType UUID for GblCClosure
66
67/*! \name Lifetime Management
68 * \brief Methods for managing GblCClosure lifetime
69 * \relatesalso GblCClosure
70 * @{
71 */
72//! Creates a GblCClosure instance with the given callback and userdata, returning a pointer to it
73GBL_EXPORT GblCClosure* GblCClosure_create (GblFnPtr pFnCallback,
74 void* pUserdata) GBL_NOEXCEPT;
75//! Creates and returns a new reference to the given GblCClosure, incrementing its refcount.
77//! Releases the reference to the given GblCClosure, destroying it upon hitting zero.
79//! @}
80
81/*! \name Accessors
82 * \brief Get/Set methods for GblCClosure
83 * \relatesalso GblCClosure
84 * @{
85 */
86//! Sets the C callback function of the given GblCClosure instance.
88 GblFnPtr pFnCallback) GBL_NOEXCEPT;
89//! Returns the C callback function of the given GblClosure instance.
91//! @}
92
94
95#undef GBL_SELF_TYPE
96
97#endif // GIMBAL_C_CLOSURE_H
GblType GblCClosure_type(void)
Returns the GblType UUID for GblCClosure.
#define GBL_CLASS_CAST(cType, klass)
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_TYPEID(instanceStruct)
#define GBL_INSTANCE_DERIVE(derivedInstance, baseInstance)
#define GBL_PRIVATE_BEGIN
#define GBL_INSTANCE_END
#define GBL_CLASS_DERIVE_EMPTY(...)
#define GBL_EXPORT
#define GBL_PRIVATE_END
Private data structure.
#define GBL_CLASSOF(cType, self)
#define GBL_CAST(cType, self)
void(* GblFnPtr)()
Type used for holding an untyped function pointer.
uint16_t GblRefCount
Type able to hold a reference counter across the codebase.
uintptr_t GblType
Meta Type UUID.
Definition gimbal_type.h:51
Closure type for invoking C functions.
GblRefCount GblCClosure_unref(GblCClosure *pSelf)
Releases the reference to the given GblCClosure, destroying it upon hitting zero.
void GblCClosure_setCallback(GblCClosure *pSelf, GblFnPtr pFnCallback)
Sets the C callback function of the given GblCClosure instance.
GblFnPtr pFnCallback
PRIVATE: C Function pointer to invoke as a callback.
GblFnPtr GblCClosure_callback(const GblCClosure *pSelf)
Returns the C callback function of the given GblClosure instance.
GblCClosure * GblCClosure_ref(GblCClosure *pSelf)
Creates and returns a new reference to the given GblCClosure, incrementing its refcount.
GblCClosure * GblCClosure_create(GblFnPtr pFnCallback, void *pUserdata)
Creates a GblCClosure instance with the given callback and userdata, returning a pointer to it.