adbncfs  0.9.1
fileInfoCache.h
Go to the documentation of this file.
1 /*
2  * $Id: fileInfoCache.h 2 2015-12-03 19:46:25Z wejaeger $
3  *
4  * File: fileInfoCche.h
5  * Author: Werner Jaeger
6  *
7  * Created on November 19, 2015, 5:15 PM
8  *
9  * Copyright 2015 Werner Jaeger.
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
25 #ifndef FILEINFOCACHE_H
26 #define FILEINFOCACHE_H
27 
28 #include <string>
29 #include <queue>
30 #include <map>
31 #include <unistd.h>
32 
33 using namespace std;
34 
38 class FileCache
39 {
40 public:
42  FileCache() : m_Entries() {}
43 
45  virtual ~FileCache() {}
46 
47  // setters
48  void putStat(const char *pcPath, const deque<string>& statOutput);
49  void putReadLink(const char *pcPath, const deque<string>& readLinkOutput);
50 
51  // getters
52  const deque<string>* getStat(const char *pcPath) const ;
53  const deque<string>* getReadLink(const char *pcPath) const;
54 
55  //operations
56  void invalidate(const char *pcPath);
57 
58 private:
62  class Entry
63  {
64  public:
66  Entry() : m_Timestamp(::time(NULL)), m_pStatOutput(NULL), m_pReadLinkOutput(NULL) {}
67  Entry(const Entry& orig);
68  Entry& operator=(const Entry& orig);
69  virtual ~Entry();
70 
76  void timeStamp(const time_t& time) { m_Timestamp = time; }
77  void statOutput(const deque<string>& output);
78  void readLinkOutput(const deque<string>& output);
79 
80  // getters
81  const time_t timeStamp() const { return(m_Timestamp); }
82  const deque<string> *statOutput() const { return(m_pStatOutput); }
83  const deque<string> *readLinkOutput() const { return(m_pReadLinkOutput); }
84 
85  private:
86  time_t m_Timestamp;
87  deque<string> *m_pStatOutput;
88  deque<string> *m_pReadLinkOutput;
89  };
90 
92  FileCache(const FileCache& orig);
93 
95  FileCache operator=(const FileCache& orig);
96 
97  bool isValid(const Entry& entry) const;
98 
99  map<string, Entry> m_Entries;
100 };
101 
106 {
107 public:
109  FileStatus() : m_Entries() {}
110 
112  virtual ~FileStatus() {}
113 
114  // setters
115  void pendingOpen(const char *pcPath, const bool fPendingOpen, const bool fForWrite);
116  void pendingOpen(const char *pcPath, const string& strRenamedFromLocal);
117  void truncated(const char *pcPath, const bool fTruncated);
118 
119  // getters
120  bool pendingOpen(const char *pcPath) const;
121  bool truncated(const char *pcPath) const;
122 
123  // operations
124  int flush(const char *pcPath, const string& strFromLocalPath);
125  int release(const char *pcPath, const int iFh);
126 
127 private:
131  class Entry
132  {
133  public:
135  Entry() : m_fPendingOpen(false), m_fForWrite(false), m_fTruncated(false), m_strRenamedFromLocal() {}
136 
138  virtual ~Entry() {}
139 
140  // setters
141  void pendingOpen(const bool fPendingOpen, const bool fForWrite) { m_fPendingOpen = fPendingOpen; m_fForWrite = fForWrite; }
142  void pendingOpen(const string& strRenamedFromLocal) { m_fPendingOpen = true; m_strRenamedFromLocal.assign(strRenamedFromLocal); }
143  void truncated(const bool fTruncated) { m_fTruncated = fTruncated; }
144 
145  // getters
146  const bool pendingOpen() const { return(m_fPendingOpen); }
147  const bool truncated() const { return(m_fTruncated); }
148 
149  // ops
150  int release(const int iFh);
151  int flush(const string& strFromLocalPath, const string& strToPat);
152 
153  private:
158  };
159 
161  FileStatus(const FileStatus& orig);
162 
164  FileStatus operator=(const FileStatus& orig);
165 
166  map<string, Entry> m_Entries;
167 };
168 
169 
170 #endif /* FILEINFOCACHE_H */
171 
FileStatus()
Default constructor.
deque< string > * m_pStatOutput
Definition: fileInfoCache.h:87
Keep track of files opened and truncated files.
deque< string > * m_pReadLinkOutput
Definition: fileInfoCache.h:88
const bool pendingOpen() const
Entry()
Default constructor.
Definition: fileInfoCache.h:66
const deque< string > * statOutput() const
Definition: fileInfoCache.h:82
A cache for file attributes and resolved links.
Definition: fileInfoCache.h:38
const time_t timeStamp() const
Definition: fileInfoCache.h:81
void truncated(const bool fTruncated)
FileCache()
Default constructor.
Definition: fileInfoCache.h:42
Entry()
Default constructor.
virtual ~FileCache()
Virtual destructor.
Definition: fileInfoCache.h:45
virtual ~Entry()
Virtual destructor.
void timeStamp(const time_t &time)
Set the entries time stamp.
Definition: fileInfoCache.h:76
void pendingOpen(const string &strRenamedFromLocal)
Represents an entry of FileStatus.
const bool truncated() const
Represents an entry of FileCache.
Definition: fileInfoCache.h:62
map< string, Entry > m_Entries
string m_strRenamedFromLocal
const deque< string > * readLinkOutput() const
Definition: fileInfoCache.h:83
void pendingOpen(const bool fPendingOpen, const bool fForWrite)
virtual ~FileStatus()
Virtual destructor.
map< string, Entry > m_Entries
Definition: fileInfoCache.h:99