Implementing the PODSPodNew( ) function

Every POD must have a PODSPodNew() function that M-Business Client calls to initialize the POD. This is the only external function to the PODS object structure. If PODSPod were a C++ class, PODSPodNew() would be comparable to the constructor for your derived class.

There is no default implementation of this function; you must write your own. PODSPodNew() has the following prototype:

PODSPod* PODSPodNew(PODSAvantGo* podsavantgo);

PODSPodNew() receives a pointer to a PODSAvantGo object. The PODSAvantGo interface is defined in the podsavantgo.h header file. PODSAvantGo is the object that manages PODs; its methods provide access to the objects associated with a POD. There is a single PODSAvantGo object. See PODSAvantGo object for details.

PODSPodNew() must return a pointer to an object that implements the PODSPod interface. When you write a POD, you can implement a PODSPod object using code similar to the code presented in Implementing a PODS interface in C.

Note

In writing the code that implements your POD, be sure that you allocate any vtables with calloc. Alternatively, you may allocate vtables with malloc and then memset them to zero. Failure to do so may leave unassigned vtable entries undefined. This can cause unpredictable behavior.

Below is a complete definition of a PODSPodNew() function:

PODSPod *PODSPodNew(PODSAvantGo *avantgo)
{
   ObjectSrcPod *self = (ObjectSrcPod *)malloc(sizeof(ObjectSrcPod));
   PODSObjectMgr *objMgr = PODSgetObjectMgr(avantgo);
   PODSObjectSrc *objSrc = (PODSObjectSrc *)ObjectSrcNew(objMgr);

   self->podsPod.avantgo = avantgo;
   self->podsPod.vtable = (PODSPodVTable *)calloc(1, sizeof(PODSPodVTable));
   self->podsPod.vtable->m_getVersion = getVersion;
   self->podsPod.vtable->m_getPodDescription = ObjectSrcPodGetPodDescription;
   self->podsPod.vtable->m_getPodVersion = ObjectSrcPodGetPodVersion;
   self->podsPod.vtable->m_destroy = ObjectSrcPodDestroy;

   PODSregisterObjectSrc(objMgr, objSrc);

   return (PODSPod *)self;
}

For more examples of PODSPodNew() implementations, see the sample code listings in PODS Code Samples.