libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_marshal.h
Go to the documentation of this file.
1/*! \file
2 * \brief Builtin GblMarshalFn functions and generator macros
3 * \ingroup signals
4 *
5 * This file contains the declarations and utilities for
6 * GblMarshalFn and various builtin implementations of it.
7 *
8 * \sa GblMarshalFn
9 *
10 * \author 2023 Falco Girgis
11 * \copyright MIT License
12 */
13#ifndef GIMBAL_MARSHAL_H
14#define GIMBAL_MARSHAL_H
15
16#include "../../core/gimbal_typedefs.h"
17#include "../types/gimbal_type.h"
18#include <stdarg.h>
19
20/*! \name Generator Macros
21 * \brief Macro utilities for autogenerating a GblMarshalFn
22 * @{
23 */
24//! Declares a GblMarshalFn for a GblCClosure which returns nothing and has the given name postfix (usually underscore separated arg types)
25#define GBL_DECL_CCLOSURE_MARSHAL_VOID__(postFix)
27//! Defines a GblMarshalFn for a GblCClosure autogenerating the implementation with the given info
28#define GBL_DEFINE_CCLOSURE_MARSHAL_VOID__(paramsPostfix, paramCount, paramList, argList)
29 GBL_DEFINE_CCLOSURE_MARSHAL_VOID___(paramsPostfix, paramCount, paramList, argList)
30//! @}
31
33
36
37/*! Function signature for a generic marshal function
38 * \ingroup signals
39 *
40 * Marshal functions form the basis of the closure system,
41 * and are used by all GblClosure instances. They are the primary
42 * entry point for generic function invocation, and are the glue
43 * between a generic GblClosure and an actual language-dependent
44 * real function call.
45 *
46 * They take a generic list of arguments, marshal them into an
47 * actual function (which is typically stored with GblClosure),
48 * then demarshal out the return type.
49 */
50typedef GBL_RESULT (*GblMarshalFn) (GblClosure* pClosure,
51 GblVariant* pRetValue,
52 size_t argCount,
53 GblVariant* pArgs,
54 GblPtr pMarshalData);
55
56//! Unimplemented, but mirror of GblMarshalFn using a va_list to hold args instead of GblVariant
57typedef GBL_RESULT (*GblMarshalVaFn)(GblClosure* pClosure,
58 GblVariant* pRetValue,
59 void* pInstance,
60 va_list args,
61 void* pMarshalData,
62 size_t argCount,
63 const GblType* pParamTypes);
64
65/*! \name Builtin Marshals
66 * \brief Marshals which come pregenerated with libGimbal
67 * @{
68 */
69//!< GblMarshalFn which takes nothing and returns nothing
70GBL_EXPORT GBL_RESULT GblMarshal_CClosure_VOID__VOID (GblClosure* pClosure,
71 GblVariant* pRetValue,
72 size_t argCount,
73 GblVariant* pArgs,
74 GblPtr pMarshalData) GBL_NOEXCEPT;
75//!< GblMarshalFn to be used as the meta marshal for GblClassClosure
76GBL_EXPORT GBL_RESULT GblMarshal_ClassClosureMeta (GblClosure* pClosure,
77 GblVariant* pRetValue,
78 size_t argCount,
79 GblVariant* pArgs,
80 GblPtr pMarshalData) GBL_NOEXCEPT;
81//!< GblMarshalFn to be used as the marshal for GblSignalClosure
82GBL_EXPORT GBL_RESULT GblMarshal_SignalForwarder (GblClosure* pClosure,
83 GblVariant* pRetValue,
84 size_t argCount,
85 GblVariant* pArgs,
86 GblPtr pMarshalData) GBL_NOEXCEPT;
87
88#define GBL_DECL_CCLOSURE_MARSHAL_VOID___(postFix)
89 GBL_EXPORT GBL_RESULT
90 GblMarshal_CClosure_VOID__##postFix(GblClosure* pClosure,
91 GblVariant* pRetValue,
92 size_t argCount,
93 GblVariant* pArgs,
94 GblPtr pMarshalData) GBL_NOEXCEPT
95
97
101GBL_DECL_CCLOSURE_MARSHAL_VOID__(INSTANCE_UINT16);
103GBL_DECL_CCLOSURE_MARSHAL_VOID__(INSTANCE_UINT32);
105GBL_DECL_CCLOSURE_MARSHAL_VOID__(INSTANCE_UINT64);
109GBL_DECL_CCLOSURE_MARSHAL_VOID__(INSTANCE_DOUBLE);
110GBL_DECL_CCLOSURE_MARSHAL_VOID__(INSTANCE_STRING);
113GBL_DECL_CCLOSURE_MARSHAL_VOID__(INSTANCE_POINTER);
114GBL_DECL_CCLOSURE_MARSHAL_VOID__(INSTANCE_OPAQUE);
115GBL_DECL_CCLOSURE_MARSHAL_VOID__(INSTANCE_INSTANCE);
116
117GBL_DECL_CCLOSURE_MARSHAL_VOID__(INSTANCE_INSTANCE_SIZE);
118
119//! @}
120
122
123#define GBL_DEFINE_CCLOSURE_MARSHAL_VOID___(paramsPostfix, paramCount, paramList, argList)
124 GBL_EXPORT GBL_RESULT GblMarshal_CClosure_VOID__##paramsPostfix(GblClosure* pClosure,
125 GblVariant* pRetValue,
126 size_t argCount,
127 GblVariant* pArgs,
128 GblPtr pMarshalData)
130 GBL_UNUSED(pRetValue, argCount);
131 typedef void (*CFunction)(GBL_EVAL paramList);
132 GBL_ASSERT(argCount >= paramCount);
133 GBL_ASSERT(!pRetValue || GblVariant_typeOf(pRetValue) == GBL_INVALID_TYPE);
134 GblCClosure* pCClosure = (GblCClosure*)pClosure;
135 CFunction pFnPtr = (CFunction)((pMarshalData.pFunc)?
136 pMarshalData.pFunc : GBL_PRIV_REF(pCClosure).pFnCallback);
137 pFnPtr(GBL_EVAL argList);
138 return GBL_RESULT_SUCCESS;
139 }
140
141#endif // GIMBAL_MARSHAL_H
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_UNUSED(...)
#define GBL_FORWARD_DECLARE_STRUCT(S)
#define GBL_PRIV_REF(a)
#define GBL_EXPORT
#define GBL_EVAL(...)
#define GBL_ASSERT(...)
#define GBL_DEFINE_CCLOSURE_MARSHAL_VOID___(paramsPostfix, paramCount, paramList, argList)
GBL_RESULT GblMarshal_ClassClosureMeta(GblClosure *pClosure, GblVariant *pRetValue, size_t argCount, GblVariant *pArgs, GblPtr pMarshalData)
GblMarshalFn to be used as the marshal for GblSignalClosure.
#define GBL_DECL_CCLOSURE_MARSHAL_VOID__(postFix)
Declares a GblMarshalFn for a GblCClosure which returns nothing and has the given name postfix (usual...
#define GBL_DECL_CCLOSURE_MARSHAL_VOID___(postFix)
GBL_RESULT GblMarshal_CClosure_VOID__VOID(GblClosure *pClosure, GblVariant *pRetValue, size_t argCount, GblVariant *pArgs, GblPtr pMarshalData)
< GblMarshalFn which takes nothing and returns nothing
#define GBL_RESULT_SUCCESS(value)
#define GBL_INVALID_TYPE
GblType UUID of the invalid type.
Definition gimbal_type.h:31
uintptr_t GblType
Meta Type UUID.
Definition gimbal_type.h:51