Adapter instance overview

When a map executes, there are a number of objects created (for example, map and card). Each card has an associated adapter instance. The adapter instance contains a number of properties that determine the behavior of the adapter. The number and type of these properties are defined through the mpiObjectNewPropColl method.

When an instance of your adapter is required, the CreateAdapterInstance method is called. This method must call the mpiAdapterCreate method to create the physical object and associate the adapter virtual table with the object. The adapter virtual table has the following structure:

struct MPI_ADAPTER_VTABLE
{
size_t nSize; /* size of this structure */
MPIRC (*pfCompareWatches)(HMPIADAPT hAdapter1,HMPIADAPT hAdapter2,
				MPICOMP *peComp);
MPIRC (*pfCompareResources)(HMPIADAPT hAdapter1,HMPIADAPT hAdapter2,
				MPICOMP *peComp);
MPIRC (*pfGet)(HMPIADAPT hAdapter,HMPICONNECT hConnection);
MPIRC (*pfPut)(HMPIADAPT hAdapter,HMPICONNECT hConnection);
MPIRC (*pfBeginTransaction)(HMPIADAPT hAdapter,HMPICONNECT hConnection);
MPIRC (*pfEndTransaction)(HMPIADAPT hAdapter,HMPICONNECT hConnection,
				MPITRANS eAction);
MPIRC (*pfListen)(HMPIADAPT hAdapter,HMPICONNECT hConnection);
MPIRC (*pfValidateProperties)(HMPIADAPT hAdapter);
MPIRC (*pfValidateConnection)(HMPIADAPT hAdapter,HMPICONNECT hConnection);
MPIRC (*pfCompareConnection)(HMPIADAPT hAdapter,HMPICONNECT hConnection,
				MPICOMP *peComp);
MPIRC (*pfOnNotify)(HMPIOBJ hObject, int iId, int iParam, HMPIOBJ hParam);
};
typedef struct MPI_ADAPTER_VTABLE MPI_ADAPTER_VTABLE;

CreateAdapterInstance example

MPI_ADAPTER_VTABLE AdapterTable = { /* Initialize */ };
/* Define the adapter properties */
enum 
{
MYP_USERNAME = MPI_PROPBASE_USER,
MYP_PASSWORD,
MYP_SERVER
};

const static int AdapterProperties[] = 
{
MPI_PROP_TYPE_TEXT,  /* MYP_USERNAME */
MPI_PROP_TYPE_TEXT,  /* MYP_PASSWORD */
MPI_PROP_TYPE_TEXT   /* MYP_SERVER */ 
};   
#define NUM_ADAPTER_PROPERTIES (sizeof(AdapterProperties)/sizeof(int))

MPIRC CreateAdapterInstance(HMPIADAPT *phAdapter, HMPICARD hCard)
{
MPIRC rc;

rc = mpiAdapterCreate(phAdapter, hCard, &AdapterTable);

if (rc == MPI_SUCCESS)
{   
/* Define the number and type of adapter properties */
rc = mpiObjectNewPropColl(*phAdapter, 
MPI_PROPBASE_USER, 
NUM_ADAPTER_PROPERTIES, 
AdapterProperties);

/* Do any initialization of instance of adapter object */
}
return rc;
}

DestroyAdapterInstance example

The DestroyAdapterInstance method should do the reverse, that is, it should delete the adapter object and free up any data structures that were created by the create method. The following code example deletes an object.

MPIRC DestroyAdapterInstance(HMPIADAPT hAdapter)
{
/* Free up any memory or data structures use by the adapter instance */
return (mpiObjectDestroy(hAdapter));
}