ANSC_STATUS
AnscDstoPoEngineCloseUp
    (
        ANSC_HANDLE                 hThisObject,
        ANSC_HANDLE                 hForm,
        ULONG                       ulIndex
    )
{
    ANSC_STATUS                     returnStatus = ANSC_STATUS_SUCCESS;
    PANSC_DAEMON_SERVER_TCP_OBJECT  pMyObject    = (PANSC_DAEMON_SERVER_TCP_OBJECT)hThisObject;
    PANSC_DSTO_CLOSE_UP_FORM        pCloseUpForm = (PANSC_DSTO_CLOSE_UP_FORM      )hForm;
    PANSC_DAEMON_ENGINE_TCP_OBJECT  pEngine      = NULL;
    PSINGLE_LINK_ENTRY              pSLinkEntry  = NULL;

    AnscAcquireLock(&pMyObject->EngineQueueLock);
    pSLinkEntry = AnscQueueSearchEntryByIndex(&pMyObject->EngineQueue, ulIndex);
    AnscReleaseLock(&pMyObject->EngineQueueLock);

    if ( !pSLinkEntry )
    {
        return  ANSC_STATUS_UNAPPLICABLE;
    }
    else
    {
        pEngine = ACCESS_ANSC_DAEMON_ENGINE_TCP_OBJECT(pSLinkEntry);
    }

    returnStatus =
        pEngine->CloseUp
            (
                (ANSC_HANDLE)pEngine,
                (ANSC_HANDLE)pCloseUpForm
            );

    pCloseUpForm->EngineIndex = ulIndex;

    return  returnStatus;
}
int
CcspTableHelperRefreshCache
	(
        ANSC_HANDLE                 hThisObject
	)
{
	PCCSP_TABLE_HELPER_OBJECT       pThisObject     = (PCCSP_TABLE_HELPER_OBJECT)hThisObject;
	char*							pDMString       = pThisObject->pStrSampleDM;
	char*							pDestComp       = NULL;
	char*							pDestPath       = NULL;
	PCCSP_MIB_MAPPING				pMibMap			= (PCCSP_MIB_MAPPING)NULL;
	PCCSP_INDEX_MAPPING				pIndexMap		= (PCCSP_INDEX_MAPPING)NULL;
	PSINGLE_LINK_ENTRY              pSLinkEntry     = (PSINGLE_LINK_ENTRY)NULL;
	char                            pTemp[256]      = { 0 };
	netsnmp_tdata*					table			= (netsnmp_tdata *)pThisObject->mibMagic.pTableData;
    netsnmp_tdata_row*				row				= NULL;
	PCCSP_TABLE_ENTRY				pEntry          = NULL;
	ULONG							indexes[6]      = { 0 };
	int							    indexCount      = pThisObject->IndexMapQueue.Depth;
	int								i				= 0;
	int								j				= 0;
	int								k				= 0;
	char*							pFind           = NULL;
	unsigned int*				    insArray1       = NULL;
	unsigned int					insCount1       = 32;
	unsigned int*					insArray2       = NULL;
	unsigned int					insCount2       = 32;
	unsigned int*					insArray3       = NULL;
	unsigned int					insCount3       = 32;
	unsigned int					subDMIns[3] = {0,0,0};
    int                             status          = 0;

    if (pThisObject->RefreshCacheCallback != NULL)
    {
        int (*TableRefreshCache)(netsnmp_tdata *);

        TableRefreshCache = pThisObject->RefreshCacheCallback;
        status = TableRefreshCache(table);
    }

    if(pThisObject->bCacheSkip == TRUE)
    {
        return status;
    }

#if 0

	for( i = 0; i < 3; i ++)
	{
		for( j = 0; j < indexCount; j ++)
 		{
			indexes[j] = 5 + i + j; 
		}

        row = CcspUtilCreateMibEntry(table, indexes, indexCount, TRUE);
		
        if (row == NULL)  continue;

		pEntry = (PCCSP_TABLE_ENTRY)row->data;

		/* init the value array */
		CcspUtilInitMibValueArray(&pThisObject->MibObjQueue, &pEntry->MibValueQueue);
    }


#else

	/* first time we need to figure out which component to talk with */
	if( !pThisObject->pCcspComp || !pThisObject->pCcspPath)
	{
		if( pDMString == NULL)
		{
			AnscTraceWarning(("No one DM param name is configured, no way to cache.\n"));

			return -1;
		}
		else
		{
			/* remove the chars after '%d' */
			pFind = _ansc_strstr(pDMString, "%d");

			if( pFind != NULL)
			{
				pDMString[(ULONG)(pFind - pDMString)] = '\0';
			}

			AnscTraceInfo(("Try to find the CCSP component who supports '%s'\n", pDMString));
		}

		if( !Cosa_FindDestComp(pDMString, &pThisObject->pCcspComp, &pThisObject->pCcspPath) )
		{
			AnscTraceWarning(("Failed to find the CCSP component who supports '%s'\n", pDMString));

			return -1;
		}
	}

	if( pThisObject->MibObjQueue.Depth == 0 || pThisObject->IndexMapQueue.Depth == 0)
	{
		AnscTraceError(("No one mib or index is loaded in the mib table, cache failed.\n"));

		return -1;
	}

	if( pThisObject->IndexMapQueue.Depth == 1)
	{
		pSLinkEntry = AnscQueueGetFirstEntry(&pThisObject->IndexMapQueue);

		pIndexMap   = ACCESS_CCSP_INDEX_MAPPING(pSLinkEntry);

		if( pIndexMap != NULL)
		{
			if(pIndexMap->uMapType >= CCSP_MIB_MAP_TO_DM)
			{
				AnscCopyString(pTemp, pIndexMap->Mapping.DMMappingInfo.pDMName);
		
				/* get the ins count */
				if( !Cosa_GetInstanceNums(pThisObject->pCcspComp, pThisObject->pCcspPath, pTemp, &insArray1, &insCount1))
				{
					AnscTraceWarning(("Failed to GetInstanceNums of '%s'\n", pTemp));
                    insArray1 = NULL;
                    insCount1 = 0;
				}

				for( i = 0; i < insCount1; i ++)
				{
					indexCount = 1;
                                        if (pIndexMap->uMapType == CCSP_MIB_MAP_TO_INSNUMBER) {
						indexes[0] = CcspUtilLookforInsNumMapping(&pIndexMap->IndexQueue, insArray1[i], FALSE);
						if( indexes[0] == 0 && pIndexMap->IndexQueue.Depth > 0)
						{
							AnscTraceError(("Unable to find the insNumber to index mapping for '%d'\n", insArray1[i]));
						}
					} else if (pIndexMap->uMapType == CCSP_MIB_MAP_TO_SUBDM) {
						subDMIns[0] = insArray1[i];
						indexes[0] = tableGroupGetSubDMMapping(pThisObject, pIndexMap->Mapping.SubDMMappingInfo.pSubDMName, subDMIns);
						if( indexes[0] == 0 )
						{
							AnscTraceError(("Unable to find the sub DM value to index mapping for '%d'\n", insArray1[i]));
						}
					}

					if( indexes[0] == 0)
						indexes[0] = insArray1[i];

					row = CcspUtilCreateMibEntry(table, indexes, indexCount, TRUE);
		
					if (row == NULL)  continue;

					pEntry = (PCCSP_TABLE_ENTRY)row->data;

					/* don't forget to set back the actual instance number at back-end */
					pEntry->IndexValue[0].Value.iValue = insArray1[i];
					pEntry->IndexCount = 1;

					/* init the value array */
					CcspUtilInitMibValueArray(&pThisObject->MibObjQueue, &pEntry->MibValueQueue);

					/* retrieve values from back-end Component */
					if(!tableGroupGetCosaValues(pThisObject, pEntry))
					{
						AnscTraceError(("Failed to get COSA values.\n"));
					}
				}

                if (insArray1)
                    free(insArray1);
			}
			else
			{
				AnscTraceInfo(("Unsupported MIB index mapping type: %lu\n", pIndexMap->uMapType));
			}
		}
	}
	else if(pThisObject->IndexMapQueue.Depth == 2)
	{
		pSLinkEntry = AnscQueueGetFirstEntry(&pThisObject->IndexMapQueue);
		pIndexMap   = ACCESS_CCSP_INDEX_MAPPING(pSLinkEntry);

		if( pIndexMap != NULL)
		{
			if(pIndexMap->uMapType >= CCSP_MIB_MAP_TO_DM)
			{
				AnscCopyString(pTemp, pIndexMap->Mapping.DMMappingInfo.pDMName);
		
				/* get the ins count */
				if( !Cosa_GetInstanceNums(pThisObject->pCcspComp, pThisObject->pCcspPath, pTemp, &insArray1, &insCount1))
				{
					AnscTraceWarning(("Failed to GetInstanceNums of '%s'\n", pTemp));
                    insArray1 = NULL;
                    insCount1 = 0;
				}

				for( i = 0; i < insCount1; i ++)
				{
					indexes[0] = CcspUtilLookforInsNumMapping(&pIndexMap->IndexQueue, insArray1[i], FALSE);
					indexCount = 1;

					if( indexes[0] == 0)
					{
						if( pIndexMap->IndexQueue.Depth > 0)
						{
							AnscTraceError(("Unable to find the insNumber to index mapping for '%d'\n", insArray1[i]));
						}

						indexes[0] = insArray1[i];
					}

					/* get the second index */
					pSLinkEntry = AnscQueueSearchEntryByIndex(&pThisObject->IndexMapQueue,1);
					pIndexMap   = ACCESS_CCSP_INDEX_MAPPING(pSLinkEntry);

					if( pIndexMap != NULL)
					{
						if(pIndexMap->uMapType >= CCSP_MIB_MAP_TO_DM)
						{
							/* AnscCopyString(pTemp, pIndexMap->Mapping.DMMappingInfo.pDMName); */
							_ansc_sprintf(pTemp, pIndexMap->Mapping.DMMappingInfo.pDMName, insArray1[i]);
		
							/* get the ins count */
							if( !Cosa_GetInstanceNums(pThisObject->pCcspComp, pThisObject->pCcspPath, pTemp, &insArray2, &insCount2))
							{
								AnscTraceWarning(("Failed to GetInstanceNums of '%s'\n", pTemp));
                                insArray2 = NULL;
                                insCount2 = 0;
							}

							for( j = 0; j < insCount2; j ++)
							{
								indexes[1] = CcspUtilLookforInsNumMapping(&pIndexMap->IndexQueue, insArray2[j], FALSE);
								indexCount = 2;

								if( indexes[1] == 0)
								{
									if( pIndexMap->IndexQueue.Depth > 0)
									{
										AnscTraceError(("Unable to find the insNumber to index mapping for '%d'\n", insArray2[j]));
									}

									indexes[1] = insArray2[j];
								}

								/* create the entry */
								row = CcspUtilCreateMibEntry(table, indexes, indexCount, TRUE);
		
								if (row == NULL)  continue;

								pEntry = (PCCSP_TABLE_ENTRY)row->data;

								/* don't forget to set back the actual instance number at back-end */
								pEntry->IndexValue[0].Value.iValue = insArray1[i];
								pEntry->IndexValue[1].Value.iValue = insArray2[j];
								pEntry->IndexCount = 2;

								/* init the value array */
								CcspUtilInitMibValueArray(&pThisObject->MibObjQueue, &pEntry->MibValueQueue);

								/* retrieve values from back-end Component */
								if(!tableGroupGetCosaValues(pThisObject, pEntry))
								{
									AnscTraceError(("Failed to get COSA values.\n"));
								}
							}
                            
                            

                            if (insArray2)
                                free(insArray2);
						}
					}
                    /*Reset mapping to first level index*/
                    pSLinkEntry = AnscQueueGetFirstEntry(&pThisObject->IndexMapQueue);
                    pIndexMap   = ACCESS_CCSP_INDEX_MAPPING(pSLinkEntry);
				}

                if (insArray1)
                    free(insArray1);
			}
			else
			{
				AnscTraceInfo(("Unsupported MIB index mapping type: %lu\n", pIndexMap->uMapType));
			}
		}
	}
	else if(pThisObject->IndexMapQueue.Depth == 3)
	{
		pSLinkEntry = AnscQueueGetFirstEntry(&pThisObject->IndexMapQueue);
		pIndexMap   = ACCESS_CCSP_INDEX_MAPPING(pSLinkEntry);

		if( pIndexMap != NULL)
		{
			if(pIndexMap->uMapType >= CCSP_MIB_MAP_TO_DM)
			{
				AnscCopyString(pTemp, pIndexMap->Mapping.DMMappingInfo.pDMName);
		
				/* get the ins count */
				if( !Cosa_GetInstanceNums(pThisObject->pCcspComp, pThisObject->pCcspPath, pTemp, &insArray1, &insCount1))
				{
					AnscTraceWarning(("Failed to GetInstanceNums of '%s'\n", pTemp));
                    insArray1 = NULL;
                    insCount1 = 0;
				}

				for( i = 0; i < insCount1; i ++)
				{
					indexes[0] = CcspUtilLookforInsNumMapping(&pIndexMap->IndexQueue, insArray1[i], FALSE);
					indexCount = 1;

					if( indexes[0] == 0)
					{
						if( pIndexMap->IndexQueue.Depth > 0)
						{
							AnscTraceError(("Unable to find the insNumber to index mapping for '%d'\n", insArray1[i]));
						}

						indexes[0] = insArray1[i];
					}

					/* get the second index */
					pSLinkEntry = AnscQueueSearchEntryByIndex(&pThisObject->IndexMapQueue,1);
					pIndexMap   = ACCESS_CCSP_INDEX_MAPPING(pSLinkEntry);

					if( pIndexMap != NULL)
					{
						if(pIndexMap->uMapType >= CCSP_MIB_MAP_TO_DM)
						{
							/* AnscCopyString(pTemp, pIndexMap->Mapping.DMMappingInfo.pDMName); */
							_ansc_sprintf(pTemp, pIndexMap->Mapping.DMMappingInfo.pDMName, insArray1[i]);
		
							/* get the ins count */
							if( !Cosa_GetInstanceNums(pThisObject->pCcspComp, pThisObject->pCcspPath, pTemp, &insArray2, &insCount2))
							{
								AnscTraceWarning(("Failed to GetInstanceNums of '%s'\n", pTemp));
                                insArray2 = NULL;
                                insCount2 = 0;
							}

							for( j = 0; j < insCount2; j ++)
							{
								indexes[1] = CcspUtilLookforInsNumMapping(&pIndexMap->IndexQueue, insArray2[j], FALSE);
								indexCount = 2;

								if( indexes[1] == 0)
								{
									if( pIndexMap->IndexQueue.Depth > 0)
									{
										AnscTraceError(("Unable to find the insNumber to index mapping for '%d'\n", insArray2[j]));
									}

									indexes[1] = insArray2[j];
								}

								/* get the third index */
								pSLinkEntry = AnscQueueSearchEntryByIndex(&pThisObject->IndexMapQueue,2);
								pIndexMap   = ACCESS_CCSP_INDEX_MAPPING(pSLinkEntry);

								if( pIndexMap != NULL)
								{
									if(pIndexMap->uMapType >= CCSP_MIB_MAP_TO_DM)
									{
										/* AnscCopyString(pTemp, pIndexMap->Mapping.DMMappingInfo.pDMName); */
										_ansc_sprintf(pTemp, pIndexMap->Mapping.DMMappingInfo.pDMName, insArray1[i], insArray2[j]);
		
										/* get the ins count */
										if( !Cosa_GetInstanceNums(pThisObject->pCcspComp, pThisObject->pCcspPath, pTemp, &insArray3, &insCount3))
										{
											AnscTraceWarning(("Failed to GetInstanceNums of '%s'\n", pTemp));
                                            insArray3 = NULL;
                                            insCount3 = 0;
										}

										for( k = 0; k < insCount3; k ++)
										{
											indexes[2] = CcspUtilLookforInsNumMapping(&pIndexMap->IndexQueue, insArray3[k], FALSE);
											indexCount = 3;

											if( indexes[2] == 0)
											{
												if( pIndexMap->IndexQueue.Depth > 0)
												{
													AnscTraceError(("Unable to find the insNumber to index mapping for '%d'\n", insArray3[k]));
												}

												indexes[2] = insArray3[k];
											}

											/* create the entry */
											row = CcspUtilCreateMibEntry(table, indexes, indexCount, TRUE);
		
											if (row == NULL)  continue;

											pEntry = (PCCSP_TABLE_ENTRY)row->data;

											/* don't forget to set back the actual instance number at back-end */
											pEntry->IndexValue[0].Value.iValue = insArray1[i];
											pEntry->IndexValue[1].Value.iValue = insArray2[j];
											pEntry->IndexValue[2].Value.iValue = insArray3[k];
											pEntry->IndexCount = 3;

											/* init the value array */
											CcspUtilInitMibValueArray(&pThisObject->MibObjQueue, &pEntry->MibValueQueue);

											/* retrieve values from back-end Component */
											if(!tableGroupGetCosaValues(pThisObject, pEntry))
											{
												AnscTraceError(("Failed to get COSA values.\n"));
											}
										}

                                        if (insArray3)
                                            free(insArray3);
									}
								}
                                pSLinkEntry = AnscQueueSearchEntryByIndex(&pThisObject->IndexMapQueue,1);
                                pIndexMap   = ACCESS_CCSP_INDEX_MAPPING(pSLinkEntry);
							}

                            if (insArray2)
                                free(insArray2);
						}
					}
                    pSLinkEntry = AnscQueueGetFirstEntry(&pThisObject->IndexMapQueue);
                    pIndexMap   = ACCESS_CCSP_INDEX_MAPPING(pSLinkEntry);
				}

                if (insArray1)
                    free(insArray1);
			}
			else
			{
				AnscTraceInfo(("Unsupported MIB index mapping type: %ld\n", pIndexMap->uMapType));
			}
		}
	}

#endif

	return 0;
}