eo2: add comments end clean up

This commit is contained in:
Jérémy Zurcher 2013-07-18 07:10:07 +00:00 committed by Tom Hacohen
parent 23ae1fc453
commit bc6019c154
2 changed files with 50 additions and 34 deletions

View File

@ -601,65 +601,76 @@ EAPI Eina_Bool eo_init(void);
*/
EAPI Eina_Bool eo_shutdown(void);
/************************************ EO2 ************************************/
// computes size of Eo2_Op_Description[]
#define OP_DESC_SIZE(desc) (sizeof(desc)/sizeof(Eo2_Op_Description) -1 )
// sort Eo2_Op_Description[] by eapi_func then attribute OP ids
EAPI void
eo2_class_funcs_set(Eo_Class *klass_id, Eo2_Op_Description *op_descs, int n);
// opaque type used to pass object pointer to EAPI calls
typedef struct _Eo_Internal _Eo;
// to fetch internal function and object data at once
typedef struct _Eo2_Op_Call_Data
{
void *func;
void *data;
} Eo2_Op_Call_Data;
// EAPI function declaration first argument
#define eo2_a _Eo *obj, Eo *objid
// EAPI function call first argument
#define eo2_o _obj_, _objid_
// to pass the internal function call to EO_FUNC_BODY (as Func parameter)
#define EO_FUNC_CALL() func(objid, call.data)
#define EO_FUNC_CALLV(...) func(objid, call.data, __VA_ARGS__)
/* XXX: Essential, because we need to adjust objid for comp objects. */
#define EO_FUNC_BODY(Name, Ret, Func, DefRet, OpDescs) \
Ret \
Name(_Eo *obj, Eo *objid) \
{ \
// cache OP id, get real fct and object data then do the call
#define _EO_FUNC_COMMON(Name, Ret, Func, DefRet, OpDescs) \
static Eo_Op op = EO_NOOP; \
if ( op == EO_NOOP ) op = eo2_get_op_id(OpDescs, (void*)Name); \
typedef Ret (*__##Name##_func)(Eo *, void *obj_data); \
Eo2_Op_Call_Data call; \
if (!eo2_call_resolve(obj, op, &call)) return DefRet; \
__##Name##_func func = (__##Name##_func) call.func; \
return Func; \
/* XXX: Essential, because we need to adjust objid for comp objects. */
// to define an EAPI function
#define EO_FUNC_BODY(Name, Ret, Func, DefRet, OpDescs) \
Ret \
Name(_Eo *obj, Eo *objid) \
{ \
typedef Ret (*__##Name##_func)(Eo *, void *obj_data); \
_EO_FUNC_COMMON(Name, Ret, Func, DefRet, OpDescs) \
}
#define EO_FUNC_BODYV(Name, Ret, Func, DefRet, OpDescs, ...) \
Ret \
Name(_Eo *obj, Eo *objid, __VA_ARGS__) \
{ \
static Eo_Op op = EO_NOOP; \
if ( op == EO_NOOP ) op = eo2_get_op_id(OpDescs, (void*)Name); \
typedef Ret (*__##Name##_func)(Eo *, void *obj_data, __VA_ARGS__); \
Eo2_Op_Call_Data call; \
if (!eo2_call_resolve(obj, op, &call)) return DefRet; \
__##Name##_func func = (__##Name##_func) call.func; \
return Func; \
_EO_FUNC_COMMON(Name, Ret, Func, DefRet, OpDescs) \
}
EAPI _Eo * eo2_do_start(Eo *obj_id);
// returns the OP id corresponding to the given api_func
EAPI Eo_Op eo2_get_op_id(Eo2_Op_Description *op_descs, void *api_func);
// gets the real function pointer and the object data
#define eo2_call_resolve(obj_id, op, call) eo2_call_resolve_internal(obj_id, NULL, op, call)
EAPI Eina_Bool eo2_call_resolve_internal(_Eo *obj, const Eo_Class *klass, Eo_Op op, Eo2_Op_Call_Data *call);
EAPI Eo_Op eo2_get_op_id(Eo2_Op_Description *op_descs, void *api_func);
// start of eo2_do barrier, gets the object pointer and ref it
EAPI _Eo * eo2_do_start(Eo *obj_id);
#define OP_DESC_SIZE(desc) (sizeof(desc)/sizeof(Eo2_Op_Description) -1 )
EAPI void
eo2_class_funcs_set(Eo_Class *klass_id, Eo2_Op_Description *op_descs, int n);
/* FIXME: Don't use this unref, use an internal one. Reduce id resolution. */
EAPI void eo2_unref_internal(_Eo *obj);
#define eo2_do_end(obj) eo2_unref_internal(obj)
#define eo2_o _obj_, _objid_
#define eo2_a _Eo *obj, Eo *objid
// end of the eo2_do barrier, unref the obj
EAPI void eo2_do_end(_Eo *obj);
// eo object method calls batch,
// DO NOT use return statement in it, use break if necessary
#define eo2_do(objid, ...) \
do \
{ \
@ -670,12 +681,15 @@ EAPI void eo2_unref_internal(_Eo *obj);
eo2_do_end(_obj_); \
} while (0)
// FIXME
#define eo2_class_do(clsid, ...) \
do \
{ \
do { __VA_ARGS__ ; } while (0); \
} while (0)
/*****************************************************************************/
/**
* @def eo_do
* A convenience wrapper around eo_do_internal()

View File

@ -255,6 +255,8 @@ _eo_kls_itr_func_get(const _Eo_Class *cur_klass, Eo_Op op)
return NULL;
}
/************************************ EO2 ************************************/
EAPI _Eo *
eo2_do_start(Eo *obj_id)
{
@ -264,7 +266,7 @@ eo2_do_start(Eo *obj_id)
}
EAPI void
eo2_unref_internal(_Eo *obj)
eo2_do_end(_Eo *obj)
{
_eo_unref(obj);
}
@ -299,7 +301,7 @@ eo2_get_op_id(Eo2_Op_Description *op_descs, void *api_func)
{
Eo2_Op_Description *op_desc;
/* should do a binary search */
/* do a binary search, when it's swallowed by _Eo_Class_Description */
for (op_desc = op_descs; op_desc->op != EO_NOOP; op_desc++)
{
if (op_desc->api_func == api_func)
@ -310,7 +312,7 @@ eo2_get_op_id(Eo2_Op_Description *op_descs, void *api_func)
}
static int
eo2_fct_cmp(const void *p1, const void *p2)
eo2_api_funcs_cmp(const void *p1, const void *p2)
{
const Eo2_Op_Description *op1, *op2;
op1 = (Eo2_Op_Description *) p1;
@ -332,8 +334,8 @@ eo2_class_funcs_set(Eo_Class *klass_id, Eo2_Op_Description *op_descs, int n)
base_op_id = *klass->desc->ops.base_op_id;
/* so that eo2_get_op_id can do a binary search to get the OP from the api_func */
qsort((void*)op_descs, n, sizeof(Eo2_Op_Description), eo2_fct_cmp);
/* to speed up eo2_get_op_id */
qsort((void*)op_descs, n, sizeof(Eo2_Op_Description), eo2_api_funcs_cmp);
i = 0;
for (op_desc = op_descs; op_desc->op_type != EO_OP_TYPE_INVALID; op_desc++)
@ -346,12 +348,12 @@ eo2_class_funcs_set(Eo_Class *klass_id, Eo2_Op_Description *op_descs, int n)
}
/* printf("%d %p %p\n", op_desc->op, op_desc->api_func, op_desc->func); */
// no need to check func->op_type != op_desc->op_type
// as op_descs wourd replace op_desc
// what about func->op == EO_NOOP ??
_dich_func_set(klass, op_desc->op, op_desc->func);
}
}
/*****************************************************************************/
#define _EO_OP_ERR_NO_OP_PRINT(file, line, op, klass) \
do \
{ \