This commit is contained in:
gagan 1998-05-06 20:29:20 +00:00
Родитель c389b52b5b
Коммит 9efa1ae251
12 изменённых файлов: 150 добавлений и 55 удалений

19
network/cache/nu/include/nsCacheTrace.h поставляемый
Просмотреть файл

@ -28,23 +28,8 @@
# define CRLF "\r\n"
#endif
#include <stdlib.h>
#include <string.h>
#define APPEND(x) \
if (total) { \
total = (char*) realloc (total, strlen(total) + strlen(x) +1); \
if (total == 0) \
return 0; \
strcat(total, x); \
} \
else { \
total = (char*) malloc (strlen(x)+1); \
if (total == 0) \
return 0; \
strcpy(total, x); }
#include <stdio.h>
#include <xp_core.h>
#include <xp_str.h>
class nsCacheTrace
{

3
network/cache/nu/nsGeneric.h поставляемый
Просмотреть файл

@ -38,6 +38,7 @@ protected:
private:
nsGeneric(const nsGeneric& o);
nsGeneric& operator=(const nsGeneric& o);
}
};
#endif // nsGeneric_h__

30
network/cache/nu/public/nsCacheManager.h поставляемый
Просмотреть файл

@ -32,31 +32,53 @@
#include "nsCacheModule.h"
#include "nsCacheObject.h"
class nsMemModule;
class nsDiskModule;
class nsCachePref;
class nsCacheManager //: public nsISupports
{
/* Change entries from 32 to 16 bit */
public:
nsCacheManager();
~nsCacheManager();
PRInt32 AddModule(nsCacheModule* i_cacheModule);
PRBool Contains(const char* i_url) const;
/* Number of modules in the cache manager */
PRInt32 Entries() const;
/* Singleton */
/* Singleton */
static nsCacheManager*
GetInstance();
nsCacheObject* GetObject(const char* i_url) const;
nsCacheModule* GetModule(PRInt32 i_index) const;
nsMemModule* GetMemModule() const;
nsDiskModule* GetDiskModule() const;
const char* Trace() const;
/* Performance measure- microseconds */
PRUint32 WorstCaseTime() const;
PRUint32 WorstCaseTime() const;
protected:
nsCacheModule*
void Init();
nsCacheModule*
LastModule() const;
enum modules
{
MEM =0,
DISK=1
};
private:
nsCacheModule* m_pFirstModule;
nsCachePref* m_pPref;
nsCacheManager(const nsCacheManager& cm);
nsCacheManager& operator=(const nsCacheManager& cm);

15
network/cache/nu/public/nsCacheObject.h поставляемый
Просмотреть файл

@ -70,6 +70,9 @@ public:
LastModified(void) const;
void LastModified(PRIntervalTime i_lastModified);
PRInt16 Module(void) const;
void Module(PRUint16 i_m);
PRUint32 Size(void) const;
void Size(PRUint32 s);
@ -93,6 +96,8 @@ protected:
PRUint32 m_Size;
char* m_Url;
PRInt16 m_Module;
private:
nsCacheObject& operator=(const nsCacheObject& x);
};
@ -148,6 +153,16 @@ inline void nsCacheObject::LastModified(PRIntervalTime i_LastModified)
m_LastModified = i_LastModified;
}
inline PRInt16 nsCacheObject::Module(void) const
{
return m_Module;
}
inline void nsCacheObject::Module(PRUint16 i_Module)
{
m_Module = i_Module;
}
inline PRUint32 nsCacheObject::Size(void) const
{
return m_Size;

13
network/cache/nu/src/makefile.win поставляемый
Просмотреть файл

@ -23,10 +23,10 @@ DLL = .\$(OBJDIR)\$(DLLNAME).dll
LIBRARY_NAME=cachelib
MISCDEP = \
MISCDEP = \
$(LIBNSPR) \
$(DIST)\lib\xpcom32.lib \
$(LIBNSPR) \
$(NULL)
$(NULL)
MODULE = cache
@ -37,6 +37,7 @@ OBJS = \
.\$(OBJDIR)\nsDiskModule.obj \
.\$(OBJDIR)\nsCacheTrace.obj \
.\$(OBJDIR)\nsCacheManager.obj \
.\$(OBJDIR)\nsCachePref.obj \
.\$(OBJDIR)\nsMemCacheObject.obj \
$(NULL)
@ -51,9 +52,9 @@ LCFLAGS = \
-DNS_DLLNAME=$(DLLNAME).dll \
$(NULL)
LLIBS = \
$(DIST)\lib\xpcom32.lib \
$(LIBNSPR) \
LLIBS = \
$(DIST)\lib\xpcom32.lib \
$(LIBNSPR) \
$(NULL)
include <$(DEPTH)\config\rules.mak>

50
network/cache/nu/src/nsCacheManager.cpp поставляемый
Просмотреть файл

@ -23,17 +23,23 @@
#include <prtypes.h>
#include <prinrval.h>
#include <xp_core.h>
#include <xpassert.h>
#include <xp_str.h>
#include "nsCacheManager.h"
#include "nsCacheTrace.h"
#include "nsCachePref.h"
#include "nsCacheModule.h"
#include <assert.h> // TODO change
#include <time.h> //TODO change to PR_
#include "nsMemModule.h"
#include "nsDiskModule.h"
static nsCacheManager TheManager;
nsCacheManager::nsCacheManager(): m_pFirstModule(0)
nsCacheManager::nsCacheManager(): m_pFirstModule(0), m_pPref(new nsCachePref())
{
Init();
}
nsCacheManager::~nsCacheManager()
@ -43,6 +49,7 @@ nsCacheManager::~nsCacheManager()
if (m_pFirstModule)
delete m_pFirstModule;
#endif
delete m_pPref;
}
nsCacheManager* nsCacheManager::GetInstance()
@ -50,15 +57,17 @@ nsCacheManager* nsCacheManager::GetInstance()
return &TheManager;
}
/* Caller must free returned char* */
const char* nsCacheManager::Trace() const
{
char linebuffer[128];
char* total = 0;
sprintf(linebuffer, "nsCacheManager: Modules = %d\n", Entries());
APPEND(linebuffer);
char* total;
sprintf(linebuffer, "nsCacheManager: Modules = %d\n", Entries());
total = new char[strlen(linebuffer) + 1];
strcpy(total, linebuffer);
return total;
}
@ -133,12 +142,31 @@ nsCacheModule* nsCacheManager::GetModule(PRInt32 i_index) const
nsCacheModule* pModule = m_pFirstModule;
for (PRInt32 i=0; i<=i_index; pModule = pModule->Next())
i++;
#ifdef DEBUG
assert(pModule);
#endif
PR_ASSERT(pModule);
return pModule;
}
nsMemModule* nsCacheManager::GetMemModule() const
{
return (nsMemModule*) m_pFirstModule;
}
nsDiskModule* nsCacheManager::GetDiskModule() const
{
return (m_pFirstModule) ? (nsDiskModule*) m_pFirstModule->Next() : NULL;
}
void nsCacheManager::Init()
{
if (m_pFirstModule)
delete m_pFirstModule;
m_pFirstModule = new nsMemModule(m_pPref->MemCacheSize());
// m_pFirstModule->Next((new nsDiskModule(m_pPref->DiskCacheSize()));
}
nsCacheModule* nsCacheManager::LastModule() const
{
if (m_pFirstModule)

10
network/cache/nu/src/nsCacheModule.cpp поставляемый
Просмотреть файл

@ -16,9 +16,13 @@
* Reserved.
*/
#include <xp_core.h>
#include <xp_str.h>
#include "nsCacheModule.h"
#include "nsCacheTrace.h"
/*
* nsCacheModule
*
@ -55,10 +59,12 @@ nsCacheModule::~nsCacheModule()
const char* nsCacheModule::Trace() const
{
char linebuffer[128];
char* total = 0;
char* total;
sprintf(linebuffer, "nsCacheModule: Objects = %d\n", Entries());
APPEND(linebuffer);
total = new char[strlen(linebuffer) + 1];
strcpy(total, linebuffer);
return total;
}

21
network/cache/nu/src/nsCacheObject.cpp поставляемый
Просмотреть файл

@ -15,8 +15,9 @@
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include <string.h>
#include <assert.h>
#include <xp_core.h>
#include <xp_str.h>
#include <xpassert.h>
#include "nsCacheObject.h"
#include "nsCacheTrace.h"
@ -33,7 +34,8 @@ static const PRIntervalTime DEFAULT_EXPIRES = PR_SecondsToInterval(86400);
nsCacheObject::nsCacheObject():
m_Flags(INIT),
m_Url(new char[1]),
m_Etag(new char[1])
m_Etag(new char[1]),
m_Module(-1)
{
Init();
*m_Url = '\0';
@ -67,14 +69,14 @@ nsCacheObject::nsCacheObject(const char* i_url):
m_Etag(new char[1])
{
Init();
assert(i_url);
PR_ASSERT(i_url);
strcpy(m_Url, i_url);
*m_Etag = '\0';
}
void nsCacheObject::Address(const char* i_url)
{
assert(i_url);
PR_ASSERT(i_url && *i_url);
if (m_Url)
delete[] m_Url;
m_Url = new char[strlen(i_url) + 1];
@ -83,7 +85,7 @@ void nsCacheObject::Address(const char* i_url)
void nsCacheObject::Etag(const char* i_etag)
{
assert(i_etag && *i_etag);
PR_ASSERT(i_etag && *i_etag);
if (m_Etag)
delete[] m_Etag;
m_Etag = new char[strlen(i_etag) + 1];
@ -96,10 +98,11 @@ void nsCacheObject::Init()
m_Hits = 0;
}
/* Caller must free returned string */
const char* nsCacheObject::Trace() const
{
char linebuffer[256];
char* total = 0;
char* total;
sprintf(linebuffer, "nsCacheObject:URL=%s,SIZE=%d,ET=%s,\n\tLM=%d,LA=%d,EXP=%d,HITS=%d\n",
m_Url,
@ -109,7 +112,9 @@ const char* nsCacheObject::Trace() const
m_LastAccessed,
m_Expires,
m_Hits);
APPEND(linebuffer);
total = new char[strlen(linebuffer) +1];
strcpy(total, linebuffer);
return total;
}

1
network/cache/nu/src/nsMemModule.cpp поставляемый
Просмотреть файл

@ -50,6 +50,7 @@ nsMemModule::~nsMemModule()
}
}
/* TODO dont make copies */
PRBool nsMemModule::AddObject(nsCacheObject* i_pObject)
{
if (i_pObject)

16
network/cache/nu/tests/cb/cb.mak поставляемый
Просмотреть файл

@ -380,6 +380,16 @@ SOURCE=.\cbView.cpp
!IF "$(CFG)" == "cb - Win32 Release"
DEP_CPP_CBVIE=\
"..\..\..\..\..\dist\public\cache\nsCacheManager.h"\
"..\..\..\..\..\dist\public\cache\nsCacheModule.h"\
"..\..\..\..\..\dist\public\cache\nsCacheObject.h"\
"..\..\..\..\..\dist\public\cache\nsDiskModule.h"\
"..\..\..\..\..\dist\public\cache\nsMemCacheObject.h"\
"..\..\..\..\..\dist\public\cache\nsMemModule.h"\
"..\..\..\..\..\dist\win32_d.obj\include\obsolete\protypes.h"\
"..\..\..\..\..\dist\win32_d.obj\include\prcpucfg.h"\
"..\..\..\..\..\dist\win32_d.obj\include\prinrval.h"\
"..\..\..\..\..\dist\win32_d.obj\include\prtypes.h"\
".\cb.h"\
".\cbDoc.h"\
".\cbView.h"\
@ -387,10 +397,8 @@ DEP_CPP_CBVIE=\
".\StdAfx.h"\
NODEP_CPP_CBVIE=\
".\nsCacheManager.h"\
".\nsCacheObject.h"\
".\nsDiskModule.h"\
".\nsMemModule.h"\
"..\..\..\..\..\dist\public\cache\nsISupports.h"\
"..\..\..\..\..\dist\win32_d.obj\include\protypes.h"\
"$(INTDIR)\cbView.obj" : $(SOURCE) $(DEP_CPP_CBVIE) "$(INTDIR)"\

Двоичные данные
network/cache/nu/tests/cb/cb.mdp поставляемый

Двоичный файл не отображается.

27
network/cache/nu/tests/cb/cbView.cpp поставляемый
Просмотреть файл

@ -13,6 +13,7 @@
#include "nsMemModule.h"
#include "nsDiskModule.h"
#include "nsCacheObject.h"
#include "nsTimeIt.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@ -58,9 +59,11 @@ void CCbView::OnDraw(CDC* pDC)
{
CRect rect;
GetClientRect(&rect);
pDC->SetBkColor(RGB(192,192,192));
pDC->FillSolidRect(rect, RGB(192,192,192));
rect.DeflateRect(10,10);
rect.DeflateRect(10,10);
pDC->DrawText(m_Mesg.GetBuffer(m_Mesg.GetLength()), -1, rect, DT_WORDBREAK | DT_EXPANDTABS);
}
@ -123,6 +126,13 @@ void CCbView::OnInitialUpdate()
pCO->Size(1230);
pCO->Etag("Another");
int j = 1000;
char tmpBuff[10];
while (j--)
{
pMM->AddObject(pCO);
pCO->Address(itoa(j,tmpBuff,10));
}
if (pMM->AddObject(pCO))
{
char buffer[10];
@ -137,17 +147,30 @@ void CCbView::OnInitialUpdate()
m_Mesg += pMM->Trace();
m_Mesg += "-----------------\n";
for (int i = pMM->Entries(); i>0 ; i--)
/*
for (int i = pMM->Entries(); i>0 ; i--)
{
m_Mesg += pMM->GetObject(i-1)->Trace();
}
m_Mesg += "-----------------\n";
*/
char buffer[10];
m_Mesg += "Worst case time= ";
m_Mesg += itoa(pCM->WorstCaseTime(), buffer, 10);
m_Mesg += " microsec.\n";
PRUint32 t;
{
nsTimeIt tmp(t);
if (pMM->Contains("999"))
m_Mesg += "!";
}
m_Mesg += "-----------------\n";
m_Mesg += "Found in ";
m_Mesg += itoa(t, buffer, 10);
m_Mesg += " microsec.\n";
delete pMM;
pMM = 0;
delete pCO;