1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (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 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef MTPFS_TYPE_TMP_FILE_H 17 #define MTPFS_TYPE_TMP_FILE_H 18 19 #include <set> 20 #include <string> 21 #include "mtpfs_type_file.h" 22 23 class MtpFsTypeTmpFile { 24 public: 25 MtpFsTypeTmpFile(); 26 MtpFsTypeTmpFile(const MtpFsTypeTmpFile ©); 27 MtpFsTypeTmpFile(const std::string &pathDevice, const std::string &pathTmp, int fileDesc, bool modified = false); 28 PathDevice()29 std::string PathDevice() const 30 { 31 return pathDevice_; 32 } PathTmp()33 std::string PathTmp() const 34 { 35 return pathTmp_; 36 } 37 IsModified()38 bool IsModified() const 39 { 40 return modified_; 41 } 42 void SetModified(bool modified = true) 43 { 44 modified_ = modified; 45 } 46 FileDescriptors()47 std::set<int> FileDescriptors() const 48 { 49 return fileDescriptors_; 50 } AddFileDescriptor(int fd)51 void AddFileDescriptor(int fd) 52 { 53 fileDescriptors_.insert(fd); 54 } 55 bool HasFileDescriptor(int fd); 56 void RemoveFileDescriptor(int fd); RefCnt()57 int RefCnt() const 58 { 59 return fileDescriptors_.size(); 60 } 61 62 MtpFsTypeTmpFile &operator = (const MtpFsTypeTmpFile &rhs); 63 64 bool operator == (const MtpFsTypeTmpFile &rhs) const 65 { 66 return pathDevice_ == rhs.pathDevice_; 67 } 68 bool operator == (const std::string &path) const 69 { 70 return pathDevice_ == path; 71 } 72 bool operator < (const MtpFsTypeTmpFile &rhs) const 73 { 74 return pathDevice_ < rhs.pathDevice_; 75 } 76 bool operator < (const std::string &path) const 77 { 78 return pathDevice_ < path; 79 } 80 81 private: 82 std::string pathDevice_; 83 std::string pathTmp_; 84 std::set<int> fileDescriptors_; 85 bool modified_; 86 }; 87 88 #endif // MTPFS_TYPE_TMP_FILE_H 89