BREW Extensions Demystified - Part II

Please see this post for the context before moving on.

The following files IMcbXML.c and IMcbXML.h needs to be created to convert the McbXML into a BREW Interface.

Creation of IMcbXML.h
The IMcbXML.h is the interface file for our extension, it is equivalent to AEEMenu.h or AEEText.h. To use the McbXML in a applet this header file must be included in the applet's source file.
The most important component of an extenstion is the VTBL (vector table or virtual table). The VTBL is a structure that stores a set of function pointers.
Lets create the VTBL structure for our extension.

typedef struct _IMcbXML IMcbXML;
QINTERFACE(IMcbXML)
{
  INHERIT_IBase(IMcbXML);
};
If you expand the macros, it will become

typedef struct _IMcbXML IMcbXML;
struct _IMcbXML {
  struct IMcbXMLVtbl *pvt;
};
typedef struct IMcbXMLVtbl IMcbXMLVtbl;
struct IMcbXMLVtbl
{
  uint32 (*AddRef) (IMcbXML*);
  uint32 (*Release) (IMcbXML*);
};
The structure IMcbXMLVtbl is our VTVL structure, the _IMcbXML is our interface class structure. The AddRef and Release function pointers are a must to any interface, they are used for reference counting and to decide when to unload the extension from the memory. Let's add the XML Parsing functionality to the extension, for now we will add 2 API which are supported by McbXML.

typedef struct _IMcbXML IMcbXML;
QINTERFACE(IMcbXML)
{
  INHERIT_IBase(IMcbXML);
  McbXMLElement* (*ParseXML)(IMcbXML *po, LPCTSTR lpszXML, McbXMLResults *pResults);
  McbXMLElement* (*FindElement)(IMcbXML *po, McbXMLElement *pHead, LPCTSTR lpszName);
  void (*DeleteRoot)(IMcbXML *po, McbXMLElement * pElement);
};
Finally, now we need to create macros to the function pointers of the interface VTBL.

#define IMCBXML_AddRef(p) GET_PVTBL(p,IMcbXML)->AddRef(p)
#define IMCBXML_Release(p) GET_PVTBL(p,IMcbXML)->Release(p)
#define IMCBXML_ParseXML(p, px, pr) GET_PVTBL(p,IMcbXML)->ParseXML(p, px, pr)
#define IMCBXML_FindElement(p, ph, pp) GET_PVTBL(p,IMcbXML)->FindElement(p, ph, pp)
#define IMCBXML_DeleteRoot(p, pe) GET_PVTBL(p,IMcbXML)->DeleteRoot(p, pe)
In the next post will we will continue creating the IMcbXML.c file.

0 Responses to "BREW Extensions Demystified - Part II"