Page Speed Optimization Libraries  1.2.24.1
net/instaweb/util/public/stdio_file_system.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00018 
00019 #ifndef NET_INSTAWEB_UTIL_PUBLIC_STDIO_FILE_SYSTEM_H_
00020 #define NET_INSTAWEB_UTIL_PUBLIC_STDIO_FILE_SYSTEM_H_
00021 
00022 #include "net/instaweb/util/public/basictypes.h"
00023 #include "net/instaweb/util/public/file_system.h"
00024 #include "net/instaweb/util/public/string_util.h"
00025 
00026 struct stat;
00027 
00028 namespace net_instaweb {
00029 
00030 class MessageHandler;
00031 class Timer;
00032 
00033 class StdioFileSystem : public FileSystem {
00034  public:
00036   explicit StdioFileSystem(Timer* timer) : timer_(timer) {}
00037   virtual ~StdioFileSystem();
00038 
00039   virtual int MaxPathLength(const StringPiece& base) const;
00040 
00041   virtual InputFile* OpenInputFile(const char* filename,
00042                                    MessageHandler* message_handler);
00043   virtual OutputFile* OpenOutputFileHelper(const char* filename,
00044                                            bool append,
00045                                            MessageHandler* message_handler);
00046   virtual OutputFile* OpenTempFileHelper(const StringPiece& prefix_name,
00047                                          MessageHandler* message_handle);
00048 
00049   virtual bool ListContents(const StringPiece& dir, StringVector* files,
00050                             MessageHandler* handler);
00051   virtual bool MakeDir(const char* directory_path, MessageHandler* handler);
00052   virtual bool RemoveDir(const char* directory_path, MessageHandler* handler);
00053   virtual bool RemoveFile(const char* filename, MessageHandler* handler);
00054   virtual bool RenameFileHelper(const char* old_file, const char* new_file,
00055                                 MessageHandler* handler);
00056 
00057   virtual bool Atime(const StringPiece& path, int64* timestamp_sec,
00058                      MessageHandler* handler);
00059   virtual bool Mtime(const StringPiece& path, int64* timestamp_sec,
00060                      MessageHandler* handler);
00064   virtual bool Size(const StringPiece& path, int64* size,
00065                     MessageHandler* handler);
00066   virtual BoolOrError Exists(const char* path, MessageHandler* handler);
00067   virtual BoolOrError IsDir(const char* path, MessageHandler* handler);
00068 
00069   virtual BoolOrError TryLock(const StringPiece& lock_name,
00070                               MessageHandler* handler);
00071   virtual BoolOrError TryLockWithTimeout(const StringPiece& lock_name,
00072                                          int64 timeout_ms,
00073                                          MessageHandler* handler);
00074 
00075   virtual bool Unlock(const StringPiece& lock_name, MessageHandler* handler);
00076 
00077   InputFile* Stdin();
00078   OutputFile* Stdout();
00079   OutputFile* Stderr();
00080 
00081  private:
00083   bool Stat(const StringPiece& path, struct stat* statbuf,
00084             MessageHandler* handler);
00085 
00086   Timer* timer_;
00087   DISALLOW_COPY_AND_ASSIGN(StdioFileSystem);
00088 };
00089 
00090 }  
00091 
00092 #endif  ///< NET_INSTAWEB_UTIL_PUBLIC_STDIO_FILE_SYSTEM_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines