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