2014-11-15 15:16:18 +01:00
|
|
|
#pragma once
|
|
|
|
#ifndef FUSEPP_FUSEOPENFILELIST_H_
|
|
|
|
#define FUSEPP_FUSEOPENFILELIST_H_
|
|
|
|
|
2014-11-15 23:47:38 +01:00
|
|
|
#include <fusepp/fs_interface/File.h>
|
|
|
|
#include <fusepp/fs_interface/OpenFile.h>
|
2014-11-15 17:24:07 +01:00
|
|
|
#include "fusepp/utils/macros.h"
|
2014-11-15 15:16:18 +01:00
|
|
|
#include "IdList.h"
|
|
|
|
|
|
|
|
namespace fusepp {
|
|
|
|
|
|
|
|
class FuseOpenFileList {
|
|
|
|
public:
|
|
|
|
FuseOpenFileList();
|
|
|
|
virtual ~FuseOpenFileList();
|
|
|
|
|
2014-11-15 23:47:38 +01:00
|
|
|
int open(const File &rhs, int flags);
|
|
|
|
OpenFile *get(int descriptor);
|
2014-11-15 15:16:18 +01:00
|
|
|
void close(int descriptor);
|
|
|
|
|
|
|
|
private:
|
2014-11-15 23:47:38 +01:00
|
|
|
IdList<OpenFile> _open_files;
|
2014-11-15 15:16:18 +01:00
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(FuseOpenFileList);
|
|
|
|
};
|
|
|
|
|
2014-11-15 16:33:24 +01:00
|
|
|
inline FuseOpenFileList::FuseOpenFileList()
|
|
|
|
:_open_files() {
|
|
|
|
}
|
|
|
|
|
2014-11-15 23:47:38 +01:00
|
|
|
inline int FuseOpenFileList::open(const File &file, int flags) {
|
2014-11-15 16:33:24 +01:00
|
|
|
return _open_files.add(file.open(flags));
|
|
|
|
}
|
|
|
|
|
2014-11-15 23:47:38 +01:00
|
|
|
inline OpenFile *FuseOpenFileList::get(int descriptor) {
|
2014-11-15 16:33:24 +01:00
|
|
|
return _open_files.get(descriptor);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void FuseOpenFileList::close(int descriptor) {
|
|
|
|
//The destructor of the stored FuseOpenFile closes the file
|
|
|
|
_open_files.remove(descriptor);
|
|
|
|
}
|
|
|
|
|
2014-11-15 15:16:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* FUSEPP_FUSEOPENFILELIST_H_ */
|