tahoma2d/toonz/sources/include/tcacheresourcepool.h

119 lines
2.7 KiB
C
Raw Normal View History

2016-05-17 03:04:11 +12:00
#pragma once
2016-03-19 06:57:51 +13:00
#ifndef TCACHERESOURCEPOOL_INCLUDED
#define TCACHERESOURCEPOOL_INCLUDED
#include "tcommon.h"
#include "tfilepath.h"
#include "tcacheresource.h"
#include <QString>
#include <QSettings>
#include <QMutex>
#undef DVAPI
#undef DVVAR
#ifdef TFX_EXPORTS
#define DVAPI DV_EXPORT_API
#define DVVAR DV_EXPORT_VAR
#else
#define DVAPI DV_IMPORT_API
#define DVVAR DV_IMPORT_VAR
#endif
//============================================================================
class THDCacheResourcePool;
class TCacheResource;
class TFilePath;
//============================================================================
class DVAPI TCacheResourcePool final : public QObject {
2016-06-15 18:43:10 +12:00
Q_OBJECT
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
THDCacheResourcePool *m_hdPool;
TFilePath m_path;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
typedef std::map<std::string, TCacheResource *> MemResources;
MemResources m_memResources;
QMutex m_memMutex;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
unsigned int m_searchCount;
bool m_foundIterator;
MemResources::iterator m_searchIterator;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TCacheResourcePool();
~TCacheResourcePool();
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
// General functions
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
static TCacheResourcePool *instance();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setPath(QString cacheRoot, QString projectName, QString sceneName);
const TFilePath &getPath() const;
void reset();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void beginCachedSearch();
void endCachedSearch();
2016-03-19 06:57:51 +13:00
public:
2016-06-15 18:43:10 +12:00
// Pool management functions
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void flushResources();
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
unsigned int getCurrentSize() const;
unsigned int getSizeAccessedAfterDays(int days) const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void clear();
void clear(QString cacheRoot, QString projectName, QString sceneName);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void clearKeyword(const std::string &keyword);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void addReference(TCacheResourceP resource, QString flag);
void releaseReference(TCacheResourceP resource, QString flag);
void releaseReferences(QString flag);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void clearFxResources(std::wstring fxId);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void clearAccessedUpToSize(int MB);
void clearAccessedAfterDays(int days);
void clearAccessedAfterSessions(int sessionsCount);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// Automatic management functions
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setMaximumSize(int MB);
int getMaximumSize() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void setResourcesAccessTimeOut(int days);
int getResourcesAccessTimeOut() const;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
// void setAutomaticCleanupInterval(int days, int minutes);
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
// Resources interaction functions
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
friend class TCacheResource;
friend class TCacheResourceP;
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
TCacheResource *getResource(const std::string &name, bool createIfNone);
void releaseResource(TCacheResource *resource);
2016-03-19 06:57:51 +13:00
2016-06-15 18:43:10 +12:00
void invalidateAll();
2016-03-19 06:57:51 +13:00
private:
2016-06-15 18:43:10 +12:00
// HD Pool functions
bool isHDActive();
void startBacking(TCacheResource *resource);
void saveResourceInfos(TCacheResource *resource);
void touchBackingPath(TCacheResource *resource);
QString getPoolRoot(QString cacheRoot, QString projectName,
QString sceneName);
void clearResource(QString path);
2016-03-19 06:57:51 +13:00
};
2016-06-15 18:43:10 +12:00
#endif // TCACHERESOURCEPOOL_INCLUDED