Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
stdio_file_system.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef PAGESPEED_KERNEL_BASE_STDIO_FILE_SYSTEM_H_
20 #define PAGESPEED_KERNEL_BASE_STDIO_FILE_SYSTEM_H_
21 
26 
27 struct stat;
28 
29 namespace net_instaweb {
30 
31 class MessageHandler;
32 class Timer;
33 
34 class StdioFileSystem : public FileSystem {
35  public:
37  virtual ~StdioFileSystem();
38 
39  virtual int MaxPathLength(const StringPiece& base) const;
40 
41  virtual InputFile* OpenInputFile(const char* filename,
42  MessageHandler* message_handler);
43  virtual OutputFile* OpenOutputFileHelper(const char* filename,
44  bool append,
45  MessageHandler* message_handler);
46  virtual OutputFile* OpenTempFileHelper(const StringPiece& prefix_name,
47  MessageHandler* message_handle);
48 
49  virtual bool ListContents(const StringPiece& dir, StringVector* files,
50  MessageHandler* handler);
51  virtual bool MakeDir(const char* directory_path, MessageHandler* handler);
52  virtual bool RemoveDir(const char* directory_path, MessageHandler* handler);
53  virtual bool RemoveFile(const char* filename, MessageHandler* handler);
54  virtual bool RenameFileHelper(const char* old_file, const char* new_file,
55  MessageHandler* handler);
56 
57  virtual bool Atime(const StringPiece& path, int64* timestamp_sec,
58  MessageHandler* handler);
59  virtual bool Mtime(const StringPiece& path, int64* timestamp_sec,
60  MessageHandler* handler);
64  virtual bool Size(const StringPiece& path, int64* size,
65  MessageHandler* handler) const;
66  virtual BoolOrError Exists(const char* path, MessageHandler* handler);
67  virtual BoolOrError IsDir(const char* path, MessageHandler* handler);
68 
69  virtual BoolOrError TryLock(const StringPiece& lock_name,
70  MessageHandler* handler);
71  virtual BoolOrError TryLockWithTimeout(const StringPiece& lock_name,
72  int64 timeout_ms,
73  const Timer* timer,
74  MessageHandler* handler);
75  virtual bool BumpLockTimeout(const StringPiece& lock_name,
76  MessageHandler* handler);
77 
78  virtual bool Unlock(const StringPiece& lock_name, MessageHandler* handler);
79 
80  InputFile* Stdin();
81  OutputFile* Stdout();
82  OutputFile* Stderr();
83 
84  static void InitStats(Statistics* stats);
85  void TrackTiming(int64 slow_file_latency_threshold_us, Timer* timer,
86  Statistics* stats, MessageHandler* handler);
87 
88  int64 StartTimer();
89  void EndTimer(const char* filename, const char* operation, int64 start_us);
90 
91  private:
93  bool Stat(const StringPiece& path, struct stat* statbuf,
94  MessageHandler* handler) const;
95 
96  int64 slow_file_latency_threshold_us_;
97  Timer* timer_;
98  Statistics* statistics_;
99  UpDownCounter* outstanding_ops_;
100  Variable* slow_ops_;
101  Variable* total_ops_;
102  MessageHandler* message_handler_;
103 
104 
105 };
106 
107 }
108 
109 #endif
virtual bool RemoveFile(const char *filename, MessageHandler *handler)
Like POSIX 'rm'.
virtual bool Unlock(const StringPiece &lock_name, MessageHandler *handler)
virtual bool MakeDir(const char *directory_path, MessageHandler *handler)
Definition: file_system.h:35
Definition: statistics.h:43
virtual bool RemoveDir(const char *directory_path, MessageHandler *handler)
Like POSIX 'rmdir', remove a directory only if it is empty.
virtual int MaxPathLength(const StringPiece &base) const
Definition: stdio_file_system.h:34
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
virtual bool Atime(const StringPiece &path, int64 *timestamp_sec, MessageHandler *handler)
virtual BoolOrError TryLock(const StringPiece &lock_name, MessageHandler *handler)
virtual bool Size(const StringPiece &path, int64 *size, MessageHandler *handler) const
virtual bool BumpLockTimeout(const StringPiece &lock_name, MessageHandler *handler)
virtual BoolOrError TryLockWithTimeout(const StringPiece &lock_name, int64 timeout_ms, const Timer *timer, MessageHandler *handler)
Definition: file_system.h:76
virtual BoolOrError IsDir(const char *path, MessageHandler *handler)
Like POSIX 'test -d', checks if path exists and refers to a directory.
Definition: file_system.h:96
virtual bool Mtime(const StringPiece &path, int64 *timestamp_sec, MessageHandler *handler)
Modified time. Time the file contents were modified.
Definition: statistics.h:73
Definition: message_handler.h:39
virtual BoolOrError Exists(const char *path, MessageHandler *handler)
Like POSIX 'test -e', checks if path exists (is a file, directory, etc.).
virtual OutputFile * OpenOutputFileHelper(const char *filename, bool append, MessageHandler *message_handler)
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
virtual bool ListContents(const StringPiece &dir, StringVector *files, MessageHandler *handler)
Definition: file_system.h:113