imgtools/romtools/rofsbuild/inc/cache/cachemanager.hpp
author jjkang
Thu, 01 Jul 2010 14:58:06 +0800
changeset 609 f76e0f94b7ab
parent 600 6d08f4a05d93
permissions -rw-r--r--
Minor change: update package_definition.xml
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 cachemanager.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_CACHEMANAGER_H_
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
     7
#define ROM_TOOLS_ROFSBUILD_CACHE_CACHEMANAGER_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 CacheManager
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    15
 * @brief Managing cache content and the processing of generating/updating cache.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    16
 * @note CacheManager will accept forward slashes as file separators and all input filenames will be normalized.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    17
 */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    18
class CacheManager
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    19
{
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    20
public:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    21
	/**
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    22
	 * @fn static CacheManager* CacheManager::GetInstance(void)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    23
	 * @brief This method is thread-safe as it's using double-check pattern for singleton creation.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    24
	 * @exception CacheException Catch initialization failures.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    25
	 * @return Retrieve the singleton instance of class CacheManager.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    26
	 */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    27
	static CacheManager* GetInstance(void) throw (CacheException);
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
	 * @fn E32ImageFile* CacheManager::GetE32ImageFile(char* Filename, int CurrentCompressionID)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    31
	 * @brief Retrieve an instance of class E32ImageFile.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    32
	 * @param OriginalFilename The filename of the original file.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    33
	 * @param CurrentCompressionID The ID of compression method used over current image build.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    34
	 * @return Instance of class E32ImageFile or NULL if the original file has not been cached yet.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    35
	 */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    36
	E32ImageFile* GetE32ImageFile(char* OriginalFilename, int CurrentCompressionID);
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
	 * @fn CacheEntry* CacheManager::GetE32ImageFileRepresentation(char* OriginalFilename, int CurrentCompressionID, int FileFlags)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    40
	 * @param OriginalFilename The filename of the original executable file.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    41
	 * @param CurrentCompressionID
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    42
	 * @return A valid cached entry or NULL if the original file has not been cached yet.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    43
	 */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    44
	CacheEntry* GetE32ImageFileRepresentation(char* OriginalFilename, int CurrentCompressionID);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    45
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    46
	/**
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    47
	 * @fn void CacheManager::Invalidate(const char* Filename)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    48
	 * @brief Add an invalidated cache entry into the cacheable list.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    49
	 * @param Filename The filename of the original file.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    50
	 * @param EntryRef The reference of newly created CacheEntry instance.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    51
	 * @exception CacheException Catch resource allocation failures.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    52
	 */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    53
	void Invalidate(char* Filename, CacheEntry* EntryRef) throw (CacheException);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    54
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    55
	/**
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    56
	 * @fn void CacheManager::CleanCache(void)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    57
	 * @brief Remove all cache content from hard drive.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    58
	 * @exception CacheException Catch I/O failures on deletion.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    59
	 */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    60
	void CleanCache(void) throw (CacheException);
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
	 * @fn const char* CacheManager::GetCacheRoot(void)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    64
	 * @brief Retrieve the root directory of cache.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    65
	 * @return The absolute path of root directory.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    66
	 */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    67
	const char* GetCacheRoot(void);
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
	 * @fn CacheManager::~CacheManager(void)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    71
	 * @brief Clean up allocated resources and writes Cache class back in the cache.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    72
	 * @note It's important to delete CacheManager instance if you created it with new operation.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    73
	 */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    74
	virtual ~CacheManager(void);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    75
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    76
	/**
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    77
	 * @fn void CacheManager::NormalizeFilename(char* Filename)
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    78
	 * @brief Convert back slashes into forward slashes and remove redundant slashes.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    79
	 * @param Filename The filename which will be normalized when this function gets returned.
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    80
	 */
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    81
	void NormalizeFilename(char* Filename);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    82
protected:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    83
	void InitializeCache(void) throw (CacheException);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    84
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    85
	char* cacheroot;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    86
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    87
	static boost::mutex creationlock;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    88
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    89
	static CacheManager* Only;
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    90
private:
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    91
	CacheManager(void);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    92
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    93
	CacheManager(const CacheManager&);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    94
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    95
	CacheManager& operator = (const CacheManager&);
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    96
};
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    97
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    98
6d08f4a05d93 add deprecated files
jjkang
parents:
diff changeset
    99
#endif  /* defined ROM_TOOLS_ROFSBUILD_CACHE_CACHEMANAGER_H_ */