-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCacheManager.h
More file actions
81 lines (68 loc) · 2.28 KB
/
CacheManager.h
File metadata and controls
81 lines (68 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Copyright (c) 2024 Nils Zweiling
*
* This file is part of fusecache which is released under the MIT license.
* See file LICENSE or go to https://github.com/zwodev/fusecache/tree/master/LICENSE
* for full license details.
*/
#pragma once
#include <mutex>
#include <thread>
#include <string>
#include <map>
#include <vector>
#include <list>
#include "Log.h"
class CacheManager
{
public:
CacheManager(Log* log);
~CacheManager();
private:
bool canPartFileBeDeleted(const std::string& path);
int waitForFile(const char *path);
bool needsCopy(const std::string& path);
int copyFile(const char *from, const char *to);
int copyFileOnDemand(const char *from, const char *to);
public:
bool checkDependencies();
void createDirectories();
void run();
void start();
void stop();
int openFile(const char* filePath, int flags);
int closeFile(int id);
int readFile(int id, char* buf, size_t size, off_t offset);
int createFile(const char* filePath, mode_t mode, int flags);
int writeFile(int id, const char* buf, size_t size, off_t offset);
std::string origFilePath(const std::string& filePath);
std::string readCacheFilePath(const std::string& filePath);
std::string writeCacheFilePath(const std::string& filePath);
std::string partFilePath(const std::string& filePath);
const std::string& rootPath();
const std::string& readCacheDir();
const std::string& writeCacheDir();
const std::string& mountPoint();
void setRootPath(const std::string& rootPath);
void setReadCacheDir(const std::string& readCacheDir);
void setWriteCacheDir(const std::string& writeCacheDir);
void setMountPoint(const std::string& mountPoint);
void setName(const std::string& name);
void setReadCacheOnly(bool enabled);
void setMaxUpBandwidth(float mbPerSecond);
void setMaxDownBandwidth(float mbPerSecond);
private:
Log* m_log = nullptr;
std::mutex m_copyMutex;
std::thread m_syncThread;
std::string m_name;
bool m_readCacheOnly = false;
bool m_isRunning = false;
bool m_isCopying= false;
float m_maxUpBandwidth = 1.0f;
float m_maxDownBandwidth = 1.0f;
std::string m_rootPath;
std::string m_readCacheDir;
std::string m_writeCacheDir;
std::string m_mountPoint;
};