| OLD | NEW |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 const void* iov_base; | 37 const void* iov_base; |
| 38 | 38 |
| 39 //! \brief The size of the memory pointed to by #iov_base. | 39 //! \brief The size of the memory pointed to by #iov_base. |
| 40 size_t iov_len; | 40 size_t iov_len; |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 //! \brief An interface to write to files and other file-like objects with | 43 //! \brief An interface to write to files and other file-like objects with |
| 44 //! semantics matching the underlying platform (POSIX or Windows). | 44 //! semantics matching the underlying platform (POSIX or Windows). |
| 45 class FileWriterInterface : public virtual FileSeekerInterface { | 45 class FileWriterInterface : public virtual FileSeekerInterface { |
| 46 public: | 46 public: |
| 47 virtual ~FileWriterInterface() {} |
| 48 |
| 47 //! \brief Wraps LoggingWriteFile(), or provides an implementation with | 49 //! \brief Wraps LoggingWriteFile(), or provides an implementation with |
| 48 //! identical semantics. | 50 //! identical semantics. |
| 49 //! | 51 //! |
| 50 //! \return `true` if the operation succeeded, `false` if it failed, with an | 52 //! \return `true` if the operation succeeded, `false` if it failed, with an |
| 51 //! error message logged. | 53 //! error message logged. |
| 52 virtual bool Write(const void* data, size_t size) = 0; | 54 virtual bool Write(const void* data, size_t size) = 0; |
| 53 | 55 |
| 54 //! \brief Wraps `writev()` on POSIX or provides an alternate implementation | 56 //! \brief Wraps `writev()` on POSIX or provides an alternate implementation |
| 55 //! with identical semantics. This method will write entire buffers, | 57 //! with identical semantics. This method will write entire buffers, |
| 56 //! continuing after a short write or after being interrupted. On | 58 //! continuing after a short write or after being interrupted. On |
| 57 //! non-POSIX this is a simple wrapper around Write(). | 59 //! non-POSIX this is a simple wrapper around Write(). |
| 58 //! | 60 //! |
| 59 //! \return `true` if the operation succeeded, `false` if it failed, with an | 61 //! \return `true` if the operation succeeded, `false` if it failed, with an |
| 60 //! error message logged. | 62 //! error message logged. |
| 61 //! | 63 //! |
| 62 //! \note The contents of \a iovecs are undefined when this method returns. | 64 //! \note The contents of \a iovecs are undefined when this method returns. |
| 63 virtual bool WriteIoVec(std::vector<WritableIoVec>* iovecs) = 0; | 65 virtual bool WriteIoVec(std::vector<WritableIoVec>* iovecs) = 0; |
| 64 | |
| 65 protected: | |
| 66 ~FileWriterInterface() {} | |
| 67 }; | 66 }; |
| 68 | 67 |
| 69 //! \brief A file writer backed by a FileHandle. | 68 //! \brief A file writer backed by a FileHandle. |
| 70 //! | 69 //! |
| 71 //! FileWriter requires users to provide a FilePath to open, but this class | 70 //! FileWriter requires users to provide a FilePath to open, but this class |
| 72 //! accepts an already-open FileHandle instead. Like FileWriter, this class may | 71 //! accepts an already-open FileHandle instead. Like FileWriter, this class may |
| 73 //! write to a filesystem-based file, but unlike FileWriter, this class is not | 72 //! write to a filesystem-based file, but unlike FileWriter, this class is not |
| 74 //! responsible for creating or closing the file. Users of this class must | 73 //! responsible for creating or closing the file. Users of this class must |
| 75 //! ensure that the file handle is closed appropriately elsewhere. Objects of | 74 //! ensure that the file handle is closed appropriately elsewhere. Objects of |
| 76 //! this class may be used to write to file handles not associated with | 75 //! this class may be used to write to file handles not associated with |
| 77 //! filesystem-based files, although special attention should be paid to the | 76 //! filesystem-based files, although special attention should be paid to the |
| 78 //! Seek() method, which may not function on file handles that do not refer to | 77 //! Seek() method, which may not function on file handles that do not refer to |
| 79 //! disk-based files. | 78 //! disk-based files. |
| 80 //! | 79 //! |
| 81 //! This class is expected to be used when other code is responsible for | 80 //! This class is expected to be used when other code is responsible for |
| 82 //! creating files and already provides file handles. | 81 //! creating files and already provides file handles. |
| 83 class WeakFileHandleFileWriter : public FileWriterInterface { | 82 class WeakFileHandleFileWriter : public FileWriterInterface { |
| 84 public: | 83 public: |
| 85 explicit WeakFileHandleFileWriter(FileHandle file_handle); | 84 explicit WeakFileHandleFileWriter(FileHandle file_handle); |
| 86 ~WeakFileHandleFileWriter(); | 85 ~WeakFileHandleFileWriter() override; |
| 87 | 86 |
| 88 // FileWriterInterface: | 87 // FileWriterInterface: |
| 89 bool Write(const void* data, size_t size) override; | 88 bool Write(const void* data, size_t size) override; |
| 90 bool WriteIoVec(std::vector<WritableIoVec>* iovecs) override; | 89 bool WriteIoVec(std::vector<WritableIoVec>* iovecs) override; |
| 91 | 90 |
| 92 // FileSeekerInterface: | 91 // FileSeekerInterface: |
| 93 | 92 |
| 94 //! \copydoc FileWriterInterface::Seek() | 93 //! \copydoc FileWriterInterface::Seek() |
| 95 //! | 94 //! |
| 96 //! \note This method is only guaranteed to function on file handles referring | 95 //! \note This method is only guaranteed to function on file handles referring |
| (...skipping 13 matching lines...) Expand all Loading... |
| 110 friend class FileWriter; | 109 friend class FileWriter; |
| 111 | 110 |
| 112 DISALLOW_COPY_AND_ASSIGN(WeakFileHandleFileWriter); | 111 DISALLOW_COPY_AND_ASSIGN(WeakFileHandleFileWriter); |
| 113 }; | 112 }; |
| 114 | 113 |
| 115 //! \brief A file writer implementation that wraps traditional system file | 114 //! \brief A file writer implementation that wraps traditional system file |
| 116 //! operations on files accessed through the filesystem. | 115 //! operations on files accessed through the filesystem. |
| 117 class FileWriter : public FileWriterInterface { | 116 class FileWriter : public FileWriterInterface { |
| 118 public: | 117 public: |
| 119 FileWriter(); | 118 FileWriter(); |
| 120 ~FileWriter(); | 119 ~FileWriter() override; |
| 121 | 120 |
| 122 // FileWriterInterface: | 121 // FileWriterInterface: |
| 123 | 122 |
| 124 //! \brief Wraps LoggingOpenFileForWrite(). | 123 //! \brief Wraps LoggingOpenFileForWrite(). |
| 125 //! | 124 //! |
| 126 //! \return `true` if the operation succeeded, `false` if it failed, with an | 125 //! \return `true` if the operation succeeded, `false` if it failed, with an |
| 127 //! error message logged. | 126 //! error message logged. |
| 128 //! | 127 //! |
| 129 //! \note After a successful call, this method cannot be called again until | 128 //! \note After a successful call, this method cannot be called again until |
| 130 //! after Close(). | 129 //! after Close(). |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 private: | 163 private: |
| 165 ScopedFileHandle file_; | 164 ScopedFileHandle file_; |
| 166 WeakFileHandleFileWriter weak_file_handle_file_writer_; | 165 WeakFileHandleFileWriter weak_file_handle_file_writer_; |
| 167 | 166 |
| 168 DISALLOW_COPY_AND_ASSIGN(FileWriter); | 167 DISALLOW_COPY_AND_ASSIGN(FileWriter); |
| 169 }; | 168 }; |
| 170 | 169 |
| 171 } // namespace crashpad | 170 } // namespace crashpad |
| 172 | 171 |
| 173 #endif // CRASHPAD_UTIL_FILE_FILE_WRITER_H_ | 172 #endif // CRASHPAD_UTIL_FILE_FILE_WRITER_H_ |
| OLD | NEW |