ANSC_STATUS
BwrmPmoAddPage
    (
        ANSC_HANDLE                 hThisObject,
        char*                       root_path,
        char*                       file_path,
        ANSC_HANDLE                 hCookedPage
    )
{
    ANSC_STATUS                     returnStatus      = ANSC_STATUS_SUCCESS;
    PBWRM_PAGE_MANAGER_OBJECT       pMyObject         = (PBWRM_PAGE_MANAGER_OBJECT    )hThisObject;
    PBWRM_PAGE_MANAGER_PROPERTY     pProperty         = (PBWRM_PAGE_MANAGER_PROPERTY  )&pMyObject->Property;
    PANSC_TIMER_DESCRIPTOR_OBJECT   pCacheTimerObject = (PANSC_TIMER_DESCRIPTOR_OBJECT)pMyObject->hCacheTimerObject;
    PBWRM_COOKED_PAGE_OBJECT        pCookedPage       = (PBWRM_COOKED_PAGE_OBJECT     )hCookedPage;
    ULONG                           ulHashIndex       = (ULONG                        )AnscHashString(file_path, AnscSizeOfString(file_path), BWRM_PMO_CPO_TABLE_SIZE);
    ULONG                           ulPageCount       = 0;
    ULONG                           ulCurTime         = AnscGetTickInSeconds();

    pMyObject->Timestamp = ulCurTime;

    pCookedPage->SetRootPath ((ANSC_HANDLE)pCookedPage, root_path);
    pCookedPage->SetPagePath ((ANSC_HANDLE)pCookedPage, file_path);
    pCookedPage->SetTimestamp((ANSC_HANDLE)pCookedPage, ulCurTime);
    pCookedPage->IncRefCount ((ANSC_HANDLE)pCookedPage           );

    AnscAcquireLock   (&pMyObject->CpoTableLock);
    AnscSListPushEntry(&pMyObject->CpoTable[ulHashIndex], &pCookedPage->Linkage);
    AnscReleaseLock   (&pMyObject->CpoTableLock);

    if ( TRUE )
    {
        ulPageCount = pMyObject->GetPageCount((ANSC_HANDLE)pMyObject);

        if ( ulPageCount == 1 )
        {
            pCacheTimerObject->Start((ANSC_HANDLE)pCacheTimerObject);
        }
        else if ( ulPageCount > pProperty->CacheEntryCount )
        {
            pCookedPage = (PBWRM_COOKED_PAGE_OBJECT)pMyObject->GetOldestPage((ANSC_HANDLE)pMyObject);

            if ( pCookedPage && 0 == pCookedPage->GetRefCount((ANSC_HANDLE)pCookedPage) )
            {
                returnStatus =
                    pMyObject->DelPage
                        (
                            (ANSC_HANDLE)pMyObject,
                            pCookedPage->GetRootPath((ANSC_HANDLE)pCookedPage),
                            pCookedPage->GetPagePath((ANSC_HANDLE)pCookedPage)
                        );
            }
        }
    }

    return  ANSC_STATUS_SUCCESS;
}
ANSC_STATUS
BwrmPmoDelAllPages
    (
        ANSC_HANDLE                 hThisObject
    )
{
    ANSC_STATUS                     returnStatus      = ANSC_STATUS_SUCCESS;
    PBWRM_PAGE_MANAGER_OBJECT       pMyObject         = (PBWRM_PAGE_MANAGER_OBJECT    )hThisObject;
    PBWRM_PAGE_MANAGER_PROPERTY     pProperty         = (PBWRM_PAGE_MANAGER_PROPERTY  )&pMyObject->Property;
    PANSC_TIMER_DESCRIPTOR_OBJECT   pCacheTimerObject = (PANSC_TIMER_DESCRIPTOR_OBJECT)pMyObject->hCacheTimerObject;
    PBWRM_COOKED_PAGE_OBJECT        pCookedPage       = (PBWRM_COOKED_PAGE_OBJECT     )NULL;
    PSINGLE_LINK_ENTRY              pSLinkEntry       = (PSINGLE_LINK_ENTRY           )NULL;
    ULONG                           i                 = 0;
    ULONG                           ulPageInUse       = 0;

    AnscAcquireLock(&pMyObject->CpoTableLock);

    for ( i = 0; i < BWRM_PMO_CPO_TABLE_SIZE; i++ )
    {
        pSLinkEntry = AnscSListPopEntry(&pMyObject->CpoTable[i]);

        while ( pSLinkEntry )
        {
            pCookedPage = ACCESS_BWRM_COOKED_PAGE_OBJECT(pSLinkEntry);
            pSLinkEntry = AnscSListPopEntry(&pMyObject->CpoTable[i]);

            if ( 0 == pCookedPage->GetRefCount((ANSC_HANDLE)pCookedPage) )
            {
                pCookedPage->Remove((ANSC_HANDLE)pCookedPage);
            }
            else
            {
                ulPageInUse ++;
            }
        }
    }

    AnscReleaseLock(&pMyObject->CpoTableLock);

    if ( 0 == ulPageInUse )
    {
        pCacheTimerObject->Stop((ANSC_HANDLE)pCacheTimerObject);
    }

    return  ANSC_STATUS_SUCCESS;
}