imgtools/romtools/rofsbuild/src/cache/cacheentry.cpp
author Zheng Shen <zheng.shen@nokia.com>
Tue, 26 Oct 2010 11:12:31 +0800
changeset 654 7c11c3d8d025
parent 600 6d08f4a05d93
permissions -rw-r--r--
romtools 13.2.0.1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
600
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     1
/*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     2
* Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     3
* All rights reserved.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     4
* This component and the accompanying materials are made available
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     6
* which accompanies this distribution, and is available
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     8
*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     9
* Initial Contributors:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    11
*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    12
* Contributors:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    13
*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    14
* Description: 
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    15
*
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    16
*/
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
#include <new>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
#include <cstring>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
#include <string>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
#include <queue>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
#include <time.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
#include <stdio.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
#include <stdlib.h>
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
#include "cache/cacheexception.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
#include "cache/cacheentry.hpp"
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
CacheEntry::CacheEntry(void)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
	this->next                 = (CacheEntry*)0;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
	this->cachedfilebuffer     = (char*)0      ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
	this->cachedfilebuffersize = 0             ;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
void CacheEntry::SetOriginalFilename(const char* OriginalFilename)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
	this->originalfile.clear();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
	this->originalfile.assign(OriginalFilename);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
const char* CacheEntry::GetOriginalFilename(void) const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
	return this->originalfile.c_str();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
void CacheEntry::SetCachedFilename(const char* CachedFilename)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
	this->cachedfile.clear();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
	this->cachedfile.assign(CachedFilename);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
const char* CacheEntry::GetCachedFilename(void) const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
	return this->cachedfile.c_str();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
void CacheEntry::SetOriginalFileCreateTime(time_t* CreateRawTime)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
	this->originalfilecreatetime.clear();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
	this->originalfilecreatetime.assign(ctime(CreateRawTime));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
	size_t newlinepos = this->originalfilecreatetime.find("\n");
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
	while(newlinepos != std::string::npos)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
		this->originalfilecreatetime.erase(newlinepos, 1);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
		newlinepos = this->originalfilecreatetime.find(("\n"));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
void CacheEntry::SetOriginalFileCreateTime(const char* CreateRawTime)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
	this->originalfilecreatetime.clear();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
	this->originalfilecreatetime.assign(CreateRawTime);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    90
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    91
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    92
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    94
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
const char* CacheEntry::GetOriginalFileCreateTime(void) const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
	return this->originalfilecreatetime.c_str();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   100
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   101
void CacheEntry::SetOriginalFileCompression(const char* CompressionMethodID)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   102
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   103
	this->originalfilecompression.clear();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   104
	this->originalfilecompression.assign(CompressionMethodID);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   105
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   106
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   107
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   108
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   109
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   110
void CacheEntry::SetOriginalFileCompression(unsigned int CompressionMethodID)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   111
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   112
	char methodid[30];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   113
	memset(methodid, 0, sizeof(methodid));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   114
	sprintf(methodid, "%d", CompressionMethodID);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   115
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   116
	this->originalfilecompression.clear();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   117
	this->originalfilecompression.assign(methodid);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   118
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   119
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   120
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   121
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   122
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   123
const char* CacheEntry::GetOriginalFileCompressionID(void) const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   124
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   125
	return this->originalfilecompression.c_str();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   126
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   127
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   128
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   129
void CacheEntry::SetCachedFileCompression(const char* CompressionMethodID)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   130
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   131
	this->cachedfilecompression.clear();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   132
	this->cachedfilecompression.assign(CompressionMethodID);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   133
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   134
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   135
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   136
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   137
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   138
void CacheEntry::SetCachedFileCompression(unsigned int CompressionMethodID)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   139
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   140
	char methodid[128];
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   141
	memset(methodid, 0, sizeof(methodid));
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   142
	sprintf(methodid, "%d", CompressionMethodID);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   143
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   144
	this->cachedfilecompression.clear();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   145
	this->cachedfilecompression.assign(methodid);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   146
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   147
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   148
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   149
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   150
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   151
const char* CacheEntry::GetCachedFileCompressionID(void) const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   152
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   153
	return this->cachedfilecompression.c_str();
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   154
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   155
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   156
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   157
void CacheEntry::SetCachedFileBuffer(char* FileBuffer, int FileBufferLen)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   158
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   159
	this->cachedfilebuffer     = (char*)malloc(sizeof(char)*FileBufferLen);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   160
	memcpy(this->cachedfilebuffer, FileBuffer, FileBufferLen);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   161
	this->cachedfilebuffersize = FileBufferLen;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   162
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   163
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   164
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   165
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   166
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   167
const char* CacheEntry::GetCachedFileBuffer(void) const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   168
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   169
	return this->cachedfilebuffer;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   170
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   171
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   172
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   173
int CacheEntry::GetCachedFileBufferLen(void) const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   174
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   175
	return this->cachedfilebuffersize;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   176
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   177
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   178
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   179
void CacheEntry::AppendEntry(CacheEntry* EntryRef)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   180
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   181
	//the parameter EntryRef must be valid, should be verified by the caller.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   182
	this->next = EntryRef;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   183
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   184
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   185
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   186
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   187
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   188
CacheEntry* CacheEntry::GetNextEntry(void) const
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   189
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   190
	return this->next;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   191
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   192
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   193
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   194
void CacheEntry::SetNextEntry(CacheEntry* EntryRef)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   195
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   196
	this->next = EntryRef;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   197
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   198
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   199
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   200
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   201
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   202
bool CacheEntry::Equals(CacheEntry* EntryRef)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   203
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   204
	if( (this->originalfile.compare(EntryRef->GetOriginalFilename())==0) &&
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   205
	    (this->originalfilecreatetime.compare(EntryRef->GetOriginalFileCreateTime())==0) &&
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   206
	    (this->originalfilecompression.compare(EntryRef->GetOriginalFileCompressionID())==0) &&
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   207
	    (this->cachedfile.compare(EntryRef->GetCachedFilename())==0) &&
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   208
	    (this->cachedfilecompression.compare(EntryRef->GetCachedFileCompressionID())==0)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   209
	  )
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   210
		return true;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   211
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   212
	return false;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   213
}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   214
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   215
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   216
CacheEntry::~CacheEntry(void)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   217
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   218
	if(this->cachedfilebuffer)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   219
	{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   220
		free(this->cachedfilebuffer);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   221
		this->cachedfilebuffer = NULL;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   222
	}
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   223
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   224
	return;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
   225
}