GATE
objects.h File Reference

C object class definition functions and macros. More...

#include "gate/gate_core_api.h"
#include "gate/gatetypes.h"
#include "gate/memalloc.h"

Macros

#define GATE_STRIP_PARENTHESES(...)   __VA_ARGS__
 
#define GATE_METHOD0(rettype, methodname)   rettype ( * methodname ) ( void * thisptr)
 
#define GATE_METHOD1(rettype, methodname, a1)   rettype ( * methodname ) ( void* thisptr, a1)
 
#define GATE_METHOD2(rettype, methodname, a1, a2)   rettype ( * methodname ) ( void* thisptr, a1, a2)
 
#define GATE_METHOD3(rettype, methodname, a1, a2, a3)   rettype ( * methodname ) ( void* thisptr, a1, a2, a3)
 
#define GATE_METHOD4(rettype, methodname, a1, a2, a3, a4)   rettype ( * methodname ) ( void* thisptr, a1, a2, a3, a4)
 
#define GATE_METHOD5(rettype, methodname, a1, a2, a3, a4, a5)   rettype ( * methodname ) ( void* thisptr, a1, a2, a3, a4, a5)
 
#define GATE_METHOD6(rettype, methodname, a1, a2, a3, a4, a5, a6)   rettype ( * methodname ) ( void* thisptr, a1, a2, a3, a4, a5, a6)
 
#define GATE_METHOD7(rettype, methodname, a1, a2, a3, a4, a5, a6, a7)   rettype ( * methodname ) ( void* thisptr, a1, a2, a3, a4, a5, a6, a7)
 
#define GATE_METHOD8(rettype, methodname, a1, a2, a3, a4, a5, a6, a7, a8)   rettype ( * methodname ) ( void* thisptr, a1, a2, a3, a4, a5, a6, a7, a8)
 
#define GATE_METHOD9(rettype, methodname, a1, a2, a3, a4, a5, a6, a7, a8, a9)   rettype ( * methodname ) ( void* thisptr, a1, a2, a3, a4, a5, a6, a7, a8, a9)
 
#define GATE_METHOD(rettype, methodname, args)   rettype ( * methodname ) ( void* thisptr, GATE_STRIP_PARENTHESES(args) )
 
#define GATE_INTERFACE_NAME_SEPARATOR_CHAR   '/'
 
#define GATE_INTERFACE_NAME_SEPARATOR   "/"
 
#define GATE_INTERFACE_VTBL(ifacename)   ifacename ## _vtbl_t
 
#define GATE_INTERFACE_STRUCT(ifacename)   struct ifacename ## _interface
 
#define GATE_INTERFACE(ifacename)
 
#define GATE_OBJECT_CALL(obj, method, params)    (obj)->vtbl-> method ((obj), GATE_STRIP_PARENTHESES params)
 
#define GOCALL(obj, method, params)   GATE_OBJECT_CALL(obj, method, params)
 
#define GOCALL0(obj, method)   (obj)->vtbl-> method ((obj))
 
#define GATE_INTERFACE_NAME_OBJECT   "object"
 
#define gate_object_get_interface_name(obj)   ((gate_object_ptr_t)(obj))->vtbl->get_interface_name((obj))
 See gate_object_t::get_interface_name.
 
#define gate_object_release(obj)   ((gate_object_ptr_t)(obj))->vtbl->release((obj))
 See gate_object_t::release.
 
#define gate_object_retain(obj)   ((gate_object_ptr_t)(obj))->vtbl->retain((obj))
 See gate_object_t::retain.
 
#define GATE_INTERFACE_NAME_RUNNABLE   GATE_INTERFACE_NAME_OBJECT GATE_INTERFACE_NAME_SEPARATOR "runnable"
 
#define gate_runnable_run(obj)   ((gate_runnable_t*)(obj))->vtbl->run((obj))
 See gate_runnable_t::run.
 
#define GATE_INTERFACE_NAME_CLONEABLE   GATE_INTERFACE_NAME_OBJECT GATE_INTERFACE_NAME_SEPARATOR "cloneable"
 
#define gate_cloneable_clone(obj, ptrnewclone)   ((gate_cloneable_t*)(obj))->vtbl->clone((obj), (ptrnewclone))
 See gate_clonable_t::clone.
 
#define GATE_INTERFACE_NAME_STARTABLE   GATE_INTERFACE_NAME_OBJECT GATE_INTERFACE_NAME_SEPARATOR "startable"
 
#define gate_startable_start(obj)   ((gate_startable_t*)(obj))->vtbl->start((obj))
 See gate_startable_t::start.
 
#define gate_startable_stop(obj)   ((gate_startable_t*)(obj))->vtbl->stop((obj))
 See gate_startable_t::stop.
 
#define gate_startable_get_status(obj)   ((gate_startable_t*)(obj))->vtbl->get_status((obj))
 See gate_startable_t::get_status.
 
#define GATE_INTERFACE_NAME_MEMORYBLOCK   GATE_INTERFACE_NAME_OBJECT GATE_INTERFACE_NAME_SEPARATOR "memoryblock"
 
#define gate_memoryblock_get_size(obj)   (obj)->vtbl->get_size((obj))
 
#define gate_memoryblock_get_content(obj)   (obj)->vtbl->get_content((obj))
 
#define GATE_OBJECT_IMPLEMENTS(obj, interface_name)   gate_object_implements_interface((gate_object_t*)(obj), (interface_name))
 Macro that cast any obj pointer into gate_object_t* and invokes gate_object_implements_interface.
 

Typedefs

typedef gate_object_tgate_object_ptr_t
 

Functions

 GATE_INTERFACE (gate_object)
 
 GATE_INTERFACE (gate_runnable)
 
GATE_CORE_API gate_runnable_tgate_runnable_create (gate_entrypoint_t function, void *param, gate_size_t param_length, gate_mem_copyctor_t param_constructor, gate_mem_dtor_t param_destructor)
 Creates a gate_runnable_t interface covering an executable function and a user defined parameter.
 
 GATE_INTERFACE (gate_cloneable)
 
 GATE_INTERFACE (gate_startable)
 
 GATE_INTERFACE (gate_memoryblock)
 
GATE_CORE_API gate_memoryblock_tgate_memoryblock_create (size_t data_length)
 Creates a new memory block.
 
GATE_CORE_API gate_result_t gate_object_ptr_copyctor (void *dest, void const *src)
 Object-pointer copy constructor function.
 
GATE_CORE_API void gate_object_ptr_dtor (void *dest)
 Object-pointer destructor function.
 
GATE_CORE_API gate_bool_t gate_object_implements_interface (gate_object_t *obj, char const *interface_name)
 Evaluates if an object implements a specific interface.
 

Detailed Description

C object class definition functions and macros.

Macro Definition Documentation

◆ GATE_INTERFACE

#define GATE_INTERFACE ( ifacename)
Value:
typedef struct ifacename ## _vtbl GATE_INTERFACE_VTBL(ifacename); \
typedef struct ifacename ## _interface ifacename ## _t, ifacename ## _interface_t ; \
struct ifacename ## _interface \
{ \
GATE_INTERFACE_VTBL(ifacename) const * vtbl; \
}; \
struct ifacename ## _vtbl

Typedef Documentation

◆ gate_object_ptr_t

Pointer to gate_object_t interface

Function Documentation

◆ gate_object_implements_interface()

GATE_CORE_API gate_bool_t gate_object_implements_interface ( gate_object_t * obj,
char const * interface_name )

Evaluates if an object implements a specific interface.

Parameters
[in]objPointer to object to be evaluated
[in]interface_namePointer to object interface string name
Returns
true if object implements the interface specified in interface_name

◆ gate_object_ptr_copyctor()

GATE_CORE_API gate_result_t gate_object_ptr_copyctor ( void * dest,
void const * src )

Object-pointer copy constructor function.

Creates a copy of an object pointer and increases the object's reference count

Parameters
[out]destPointer to object-pointer (gate_object_t**) that receives the new object reference
[in]srcPointer to object-pointer (gate_object_t* const*) holding the source object reference
Returns
GATE_RESULT_* result code

◆ gate_object_ptr_dtor()

GATE_CORE_API void gate_object_ptr_dtor ( void * dest)

Object-pointer destructor function.

decreases the reference count of the referenced object and sets the pointer to NULL

Parameters
[out]destPointer to object-pointer (gate_object_t**) that will be released

◆ gate_runnable_create()

GATE_CORE_API gate_runnable_t * gate_runnable_create ( gate_entrypoint_t function,
void * param,
gate_size_t param_length,
gate_mem_copyctor_t param_constructor,
gate_mem_dtor_t param_destructor )

Creates a gate_runnable_t interface covering an executable function and a user defined parameter.

Parameters
[in]functionEntrypoint function pointer with code to be executed
[in]paramPointer to user defined parameter for entry point
[in]param_lengthLength of data in param in bytes
[in]param_constructorOptional copy-constructor function to copy user-defined data, NULL uses gate_mem_copy()
[in]param_destructorOptional destructor function to release user-defined data
Returns
New gate_runnable_t instance, or NULL in case of allocation error