📄 cdevicecache.cpp
字号:
/*____________________________________________________________________________
Copyright (C) 2002 PGP Corporation
All rights reserved.
$Id: CDeviceCache.cpp,v 1.3 2002/08/06 20:09:31 dallen Exp $
____________________________________________________________________________*/
#include "pgpClassesConfig.h"
#include "CString.h"
#include "CDevice.h"
#include "CUnicodeString.h"
#include "CDeviceCache.h"
_USING_PGP
// Types
struct CDeviceCache::CachedCDeviceInfo :
public CListableObject<CDeviceCache::CachedCDeviceInfo>
{
CDevice *pDevice;
CString name;
CUnicodeString volId;
CUnicodeString curLink;
};
// Class CDeviceCache member functions
CDeviceCache::CDeviceCache()
{
Status() = mCDIAllocator.Status();
if (Status().IsntError())
Status() = mCDILock.Status();
}
PGPBoolean
CDeviceCache::DoesEntryExist(const char *name) const
{
pgpAssertStrValid(name);
PGPBoolean exists = FALSE;
mCDILock.StartReading();
exists = IsntNull(FindEntry(name));
mCDILock.StopReading();
return exists;
}
CComboError
CDeviceCache::CreateEntry(const char *name)
{
pgpAssertStrValid(name);
CComboError error;
mCDILock.StartWriting();
if (IsntNull(FindEntry(name)))
{
mCDILock.StopWriting();
return error;
}
CachedCDeviceInfo *pCDI;
error = mCDIAllocator.Allocate(pCDI);
if (error.IsntError())
{
pCDI->pDevice = NULL;
error = pCDI->name.Status();
if (error.IsntError())
error = pCDI->curLink.Status();
if (error.IsntError())
error = pCDI->name.Assign(name);
if (error.IsntError())
mCDIList.AddHead(pCDI);
if (error.IsError())
mCDIAllocator.Free(pCDI);
}
mCDILock.StopWriting();
return error;
}
void
CDeviceCache::DeleteEntry(const char *name)
{
pgpAssertStrValid(name);
mCDILock.StartWriting();
CachedCDeviceInfo *pCDI = FindEntry(name);
if (IsNull(pCDI))
{
mCDILock.StopWriting();
return;
}
if (IsNull(pCDI))
return;
if (IsntNull(pCDI->pDevice))
delete pCDI->pDevice;
mCDIList.Remove(pCDI);
mCDIAllocator.Free(pCDI);
mCDILock.StopWriting();
}
CComboError
CDeviceCache::SetEntryDevice(const char *name, CDevice *pDevice)
{
pgpAssertStrValid(name);
pgpAssertAddrValid(pDevice, CDevice);
mCDILock.StartWriting();
CComboError error;
CachedCDeviceInfo *pCDI = FindEntry(name);
if (IsNull(pCDI))
{
mCDILock.StopWriting();
error.pgpErr = kPGPError_ItemNotFound;
}
if (error.IsntError())
{
if (IsntNull(pCDI->pDevice))
delete pCDI->pDevice;
pCDI->pDevice = pDevice;
}
mCDILock.StopWriting();
return error;
}
CComboError
CDeviceCache::GetEntryDevice(const char *name, CDevice *&pDevice) const
{
pgpAssertStrValid(name);
mCDILock.StartReading();
CComboError error;
CachedCDeviceInfo *pCDI = FindEntry(name);
if (IsNull(pCDI))
error.pgpErr = kPGPError_ItemNotFound;
if (error.IsntError())
pDevice = pCDI->pDevice;
mCDILock.StopReading();
return error;
}
CComboError
CDeviceCache::SetEntryVolId(const char *name, const CUnicodeString& volId)
{
pgpAssertStrValid(name);
mCDILock.StartWriting();
CComboError error;
CachedCDeviceInfo *pCDI = FindEntry(name);
if (IsNull(pCDI))
{
mCDILock.StopWriting();
error.pgpErr = kPGPError_ItemNotFound;
}
if (error.IsntError())
error = pCDI->volId.Assign(volId);
mCDILock.StopWriting();
return error;
}
CComboError
CDeviceCache::GetEntryVolId(const char *name, CUnicodeString& volId) const
{
pgpAssertStrValid(name);
mCDILock.StartReading();
CComboError error;
CachedCDeviceInfo *pCDI = FindEntry(name);
if (IsNull(pCDI))
error.pgpErr = kPGPError_ItemNotFound;
if (error.IsntError())
error = volId.Assign(pCDI->volId);
mCDILock.StopReading();
return error;
}
CComboError
CDeviceCache::SetEntryCurLink(const char *name, const UNICODE_STRING& curLink)
{
pgpAssertStrValid(name);
mCDILock.StartWriting();
CComboError error;
CachedCDeviceInfo *pCDI = FindEntry(name);
if (IsNull(pCDI))
{
mCDILock.StopWriting();
error.pgpErr = kPGPError_ItemNotFound;
}
if (error.IsntError())
error = pCDI->curLink.Assign(curLink);
mCDILock.StopWriting();
return error;
}
CComboError
CDeviceCache::GetEntryCurLink(const char *name, CUnicodeString& curLink) const
{
pgpAssertStrValid(name);
mCDILock.StartReading();
CComboError error;
CachedCDeviceInfo *pCDI = FindEntry(name);
if (IsNull(pCDI))
error.pgpErr = kPGPError_ItemNotFound;
if (error.IsntError())
error = curLink.Assign(pCDI->curLink);
mCDILock.StopReading();
return error;
}
CDeviceCache::CachedCDeviceInfo *
CDeviceCache::FindEntry(const char *name) const
{
pgpAssertStrValid(name);
CachedCDeviceInfo *pCDI = mCDIList.Head();
while (IsntNull(pCDI))
{
if (pCDI->name.Compare(name))
break;
pCDI = mCDIList.Next(pCDI);
}
return pCDI;
}
void
CDeviceCache::Shutdown()
{
mCDILock.StartWriting();
CachedCDeviceInfo *pCDI = mCDIList.Head();
while (IsntNull(pCDI))
{
CachedCDeviceInfo *pNext = mCDIList.Next(pCDI);
if (IsntNull(pCDI->pDevice))
delete pCDI->pDevice;
mCDIList.Remove(pCDI);
mCDIAllocator.Free(pCDI);
pCDI = pNext;
}
mCDILock.StopWriting();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -