-
Notifications
You must be signed in to change notification settings - Fork 6
CObjEBB programming model
#define COBJ_EBBType(TYPE)
CObject(TYPE);
typedef TYPE ## Ref *TYPE ## Id;
CObjectDefine(TYPE) {
CObjInterface(TYPE) *ft;
};
CObjInterface(TYPE)
To define a C Object and the variables contained with, you use the CObject() macro.
Here is the syntax:
CObject( Object_Name ){ int var1; char *var2;}
To setup this CObject as an EBB, you initiate a local and root reference and bind the root reference to an registered EBBid.
To create an instance of the CObject in memory and bind it to a local reference with the EBBPrimMalloc() function, found in /l0/MemMgrPrim.h.
EBBPrimMalloc(sizeof( Object_Name ), &repRef, EBB_MEM_DEFAULT);
CObject(Console)
{
COBJ_EBBFuncTbl(AnEbbType);
lrt_pic_src in;
lrt_pic_src out;
uintptr_t inEvent;
uintptr_t outEvent;
};
To make calls to a CObject, you must register it as an EBB by defining it root reference type and binding that reference to established EBBid. The CObjEBBBind() function is used to bind an CObject's root reference and EBBId.
static inline EBBRC
CObjEBBBind(EBBId id, void *root){ return EBBBindPrimId(id, CObjEBBMissFunc, (EBBMissArg) root);}
AllocAndBind(EBBId *id, EBBRepRef repRef)
{
EBBRC rc;
// define root reference type
CObjEBBRootSharedRef rootRef;
rc = CObjEBBRootSharedCreate(&rootRef, repRef);
// Get a fresh EBBId
rc = EBBAllocPrimId((EBBId *)id);
// Bind id and reference
rc = CObjEBBBind((EBBId)*id, rootRef);
return EBBRC_OK;
}
CObjInterface macro inserts an named struct used for defining the interface (function tables) of CObjects.
#define CObjIfName(name) name ## _if
#define CObjInterface(name) struct CObjIfName(name)
CObjInterface(OBJ_NAME)
produces the following code: struct OBJ_NAME_if
CObjInterface() can initialize statically:
CObjInterface(CharStream) Console_ftable = {
.putChar = Console_putChar,
.getChar = Console_getChar,
.inEvent = (GenericEventFunc)Console_inEvent,
.outEvent = (GenericEventFunc)Console_outEvent
};
or, within another object:
CObject(ConsTst) {
CObjInterface(App) *ft;
};
COBJ_EBBFuncTbl is a simple macro for declaring a function table interface.
#define COBJ_EBBFuncTbl(TYPE) CObjInterface(TYPE) *ft;
COBJ_EBBFuncTbl(OBJ_NAME)
produces the following code: struct OBJ_NAME_if *ft;
TO setup event handeling of an EBB, a few steps are required.
#define COBJ_EBBCALL(id, method, ...) \
(EBBId_DREF(id)->ft->method(EBBId_DREF(id), ##__VA_ARGS__))
First, message the Event Manager to allocate a new event number.
rc = COBJ_EBBCALL(theEventMgrPrimId, allocEventNo, &(myRef->myEventNum));
Next, register that event number with a PIC source and a function within your EBBs function table.
rc = COBJ_EBBCALL(theEventMgrPrimId, registerHandler, myRef->myEventNum, *MyEBBid, COBJ_FUNCNUM(myRef, myEventFunc), &pic_src);
Finally, enable that event handle as we are ready to roll
rc = COBJ_EBBCALL(theEventMgrPrimId, eventEnable, myRef->myEventNum);
A macro that returns the function number from the reference's function table.
#define COBJ_FUNCNUM(ref, funcName) \ ( __builtin_offsetof( typeof(*(ref->ft)), funcName)/sizeof(COBJFunc) )
#TODO:
- describe pic source setup & binding
- EVENTFUNC()