Connection instance overview

Instances of connection objects are created in the same way as adapter instances. When a new connection is required, a connection instance is created.

When an instance of a connection is required, the CreateConnectionInstance method is called. This method must call the mpiConnectionCreate method to create the physical object and associate the connection virtual table with the object.

The connection virtual table has the following structure:

struct MPI_CONNECTION_VTABLE
{
size_t nSize; /* size of this structure */
MPIRC     (*pfConnect)(HMPICONNECT hConnection,HMPIADAPT hAdapter);
MPIRC     (*pfDisconnect)(HMPICONNECT hConnection);
};
typedef struct MPI_CONNECTION_VTABLE MPI_CONNECTION_VTABLE;
CreateConnectionInstance example

The following code is an example of creating a connection instance.

MPI_CONNECTION_VTABLE ConnectionTable = { /* Initialize */ };

MPIRC CreateConnectionInstance(HMPICONNECT *phConnection)
{
MPIRC rc;
rc = mpiConnectionCreate(phConnection, &ConnectionTable);

if (rc == MPI_SUCCESS)
{   
/* Define the number and type of adapter properties */
rc = mpiObjectNewPropColl(*phConnection, 
MPI_PROPBASE_USER, 
NUM_CONNECTION_PROPERTIES, 
ConnectionProperties);

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

DestroyConnectionInstance example

The DestroyConnectionInstance method should do the reverse, that is, it should delete the connection object and free up any data structures that were created by the create method.

The following code is an example of deleting an object.

MPIRC 
DestroyConnectionInstance(HMPICONNECT hConnection)
{
/* Free up any memory or data structures used by the connection instance */

return (mpiObjectDestroy(hConnection));
}