imgtools/romtools/rofsbuild/inc/cache/cache.hpp
author Ross Qin <ross.qin@nokia.com>
Tue, 02 Nov 2010 16:47:21 +0800
changeset 672 bc9ef8cca9ec
parent 600 6d08f4a05d93
permissions -rw-r--r--
revert the change to rofsbuild image format, but add checking codes to prevent address overflow
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
 * @file cache.hpp
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     3
 */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     4
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     5
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     6
#ifndef ROM_TOOLS_ROFSBUILD_CACHE_CACHE_H_
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     7
#define ROM_TOOLS_ROFSBUILD_CACHE_CACHE_H_
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     8
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     9
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    10
#define BOOST_FILESYSTEM_NO_DEPRECATED
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    11
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    12
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    13
/**
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    14
 * @class Cache
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    15
 * @brief Cache
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    16
 */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
class Cache
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
public:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
	/**
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
	 * @fn static Cache* Cache::GetInstance(void)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
	 * @brief Retrieve singleton instance of class Cache.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
	 * @return The singleton instance.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
	 */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
	static Cache* GetInstance(void) throw (CacheException);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
	/**
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    28
	 * @fn void Cache::Initialize(path* CacheRoot)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    29
	 * @brief Load Cache meta data file and initialize inner structures.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    30
	 * @exception CacheException I/O operation failures or resource allocation failures.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
	 */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
	void Initialize(void) throw (CacheException);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
	/**
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
	 * @fn CacheEntry Cache::GetEntryList(const char* OriginalFilename)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
	 * @param OriginalFilename The filename of original executable which is being cached.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    37
	 * @return A list of cached items for the original executables or NULL if there's no entries match the original filename.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    38
	 */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    39
	CacheEntry* GetEntryList(const char* OriginalFilaname);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
	/**
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
	 * @fn void Cache::SetEntry(const char* OriginalFilename, CacheEntry* EntryRef)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
	 * @brief Add a new cache entry into cache or update an existing cache entry.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
	 * @param OriginalFilename The filename of the original executable file.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
	 * @param EntryRef The address pointing to an instance of class CacheEntry, must be valid, verified by the caller.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
	 */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
	void AddEntry(const char* OriginalFilename, CacheEntry* EntryRef);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
	/**
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
	 * @fn void Cache::CloseCache(void)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
	 * @brief Update cache with all cache entries.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
	 * @exception CacheException Catch errors occurring when the Cache gets updated.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
	 */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
	void CloseCache(void) throw (CacheException);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
protected:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
	bool ValidateEntry(std::string& EntryRawText);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
	static Cache* Only;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
	std::string metafile;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    61
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    62
	boost::mutex cachemutex;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    63
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
	std::map<std::string, CacheEntry*> entrymap;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
private:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
	Cache(void);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    68
	Cache(const Cache&);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    69
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    70
	Cache& operator = (const Cache&);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
};
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
#endif  /* defined ROM_TOOLS_ROFSBUILD_CACHE_CACHE_H_ */