Optim Data Privacy Providers  11.3.0
 All Data Structures Files Functions Variables Macros Groups Pages
Example for Init()

In the following example, the Service Provider is initialized.

ODPP_WCHAR *pDestColName = NULL; // Destination column name
DP_MYCTRL_DEF *pMyCtrlBlk = NULL; // DP_MYCTRL_DEF is my service Provider control block
DP_INIT_OP_DEF_X *pParams = NULL; // DP_INIT_OP_DEF structure which contains provider initialization parametes
DP_FIELD_DEF_X *pFieldDef = NULL; // Contains Columns provided
RETVAL retval = 0;
short sPrmCount = 0; // to loop through parameter list
short sFldCnt = 0; // to loop through field list
short sDstColType = 0; // To search dest col by index or name
DP_SRCCOL_DEF_X *pSrcCols = NULL;
//Allocate the Service Provider Control Block and assign it to framework control block
//This would be service provider local storage that will presist between the calls to
//this service provider from ODPP service manager
pMyCtrlBlk = (DP_MYCTRL_DEF *) malloc(sizeof(DP_MYCTRL_DEF));
if(NULL == pMyCtrlBlk)
{
//malloc failed, Capture the error and go to errorclean. You need to allocate your error codes in ODPPCmnErrCodes.h file,
//Check the next range to allocate in ODPPCmnErrCodes10.h file and
//allocate the eror code range for your provider
retval = MY_ERR_CTRLBLK_MALLOC_FAILED;
goto OnErrorClean;
}
//Allocation of my control block is successful, initialize the memory with zeros
memset(pMyCtrlBlk, 0, sizeof(DP_MYCTRL_DEF));
//Initialize the Srvice Provider control block from the parameters provided in DP_INIT_OP_DEF
pParams = pSvcDef->pParams; // pParams contains Parameters
//Search for My Service Provider specific parameter from the list of parameters supplied.
//sPrmCount of DP_SVC_DEF structure contains count of initialization parameter Provided
for(sPrmCount = 0; sPrmCount < pSvcDef->sParamCount; sPrmCount ++)
{
switch(pParams->usParameterID)
{
//usParameterID contains parameter name
case PARAM_SRC1_COLINDEX:
{
pMyCtrlBlk->sSrc1ColIndex = (short)pParams->uiVal;
}
break;
case PARAM_SRC2_COLINDEX:
{
pMyCtrlBlk->sSrc2ColIndex = (short)pParams->uiVal;
}
break;
case PARAM_DEST_COLINDEX:
{
pMyCtrlBlk->sDestColIndex = (short)pParams->uiVal;
sDstColType = DEST_COL_TYPE_INDEX;
}
break;
case PARAM_DEST_COLNAME:
{
pDestColName = pParams->pVal;
sDstColType = DEST_COL_TYPE_NAME;
//pDestColName = pDestColName;
}
break;
case PARAM_OPERATOR:
{
pMyCtrlBlk->iOperator = (int) pParams->uiVal;
}
break;
}//End of switch(pParams->usParameterID)
MOVENEXT(pParams)
}//End of for(sPrmCount = 0; sPrmCount < pSvcDef->sPrmCount; sPrmCount ++)
//Check if source1 and source2 column indexes are in range
if((pMyCtrlBlk->sSrc1ColIndex > pCtrlBlk->sSrcColCount) ||
(pMyCtrlBlk->sSrc2ColIndex > pCtrlBlk->sSrcColCount) ||
(pMyCtrlBlk->sSrc1ColIndex < 0)||
(pMyCtrlBlk->sSrc2ColIndex < 0))
{
retval = MY_ERR_SRC_INDEX_OUT_OF_RANGE;
goto OnErrorClean;
}
//Find the destinatin column in the list of columns supplied
switch(sDstColType)
{
//Search Destination ColName into the list of Columns(Fields) sent by the caller
case DEST_COL_TYPE_NAME:
{
//Check if destination column name is provided
if(pDestColName == NULL)
{
retval = MY_ERR_DESTCOL_NULL;
goto OnErrorClean;
}
//Search dest col name in list of fields
pFieldDef = pCtrlBlk->pFldDef;
for(sFldCnt = 0; sFldCnt < pSvcDef->sFldCount; sFldCnt++)
{
if(memcmp(pFieldDef->pColNameW, pDestColName, pFieldDef->iColNameWBytes) == 0)
break;
MOVENEXT(pFieldDef)
}
//If we failed to find the field in the supplied list of fields throw an error
if(sFldCnt >= pSvcDef->sFldCount)
{
retval = MY_ERR_INVALID_DEST_COLNAME;
goto OnErrorClean;
}
pMyCtrlBlk->sDestColIndex = sFldCnt;
}
break;
case DEST_COL_TYPE_INDEX :
{
//Search dest col index in list of fields
pFieldDef = pCtrlBlk-> pFldDef;
if((pMyCtrlBlk->sDestColIndex > pSvcDef->sFldCount) ||
(pMyCtrlBlk->sDestColIndex < 0))
{
retval = MY_ERR_DST_INDEX_OUT_OF_RANGE;
goto OnErrorClean;
}
for(sFldCnt = 0; sFldCnt < pMyCtrlBlk->sDestColIndex ; sFldCnt++)
{
MOVENEXT(pFieldDef)
}
}
break;
default :
retval = MY_ERR_INVALID_DEST_COLUMN;
goto OnErrorClean;
}//End switch(sDstColType)
//Save the destination column supplied by the caller in our control block
pMyCtrlBlk->pDstCol = pFieldDef;
//Check for source columns details like datatype, length/precesion, scale etc
pSrcCols = &pCtrlBlk->SrcCol;
while(NULL != pSrcCols)
{
switch(pSrcCols->pSrcFldDef->sDatatype)
{
break;
default:
//Data type not supported
retval = MY_ERR_SRC_COL_DATATYPE_NOTSUPPORTED;
goto OnErrorClean;
}
pSrcCols = pSrcCols->pNext;
}
switch(pMyCtrlBlk->pDstCol->sDatatype)
{
break;
default:
//Data type not supported
retval = MY_ERR_DST_COL_DATATYPE_NOTSUPPORTED;
goto OnErrorClean;
}
//We have successfully initialized the Service Provider control block now assign it to the framework control block
//pExt of framework control block holds the provider specific control block
pCtrlBlk->pExt = (void *)pMyCtrlBlk;
return ODPPSUCCESS;
OnErrorClean:
//Clear all the allocation on failure
if(NULL != pMyCtrlBlk)
{
//Free my control block
free(pMyCtrlBlk);
pMyCtrlBlk = NULL;
}//end of if(NULL != pMyCtrlBlk)
return retval;
}