• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "mtpfs_type_file.h"
17 
MtpFsTypeFile()18 MtpFsTypeFile::MtpFsTypeFile() : MtpFsTypeBasic(), size_(0), modifyDate_(0) {}
19 
MtpFsTypeFile(uint32_t id,uint32_t parentId,uint32_t storageId,const std::string & name,uint64_t size,time_t modifyDate)20 MtpFsTypeFile::MtpFsTypeFile(uint32_t id, uint32_t parentId, uint32_t storageId, const std::string &name, uint64_t size,
21     time_t modifyDate)
22     : MtpFsTypeBasic(id, parentId, storageId, name), size_(size), modifyDate_(modifyDate)
23 {}
24 
MtpFsTypeFile(LIBMTP_file_t * file)25 MtpFsTypeFile::MtpFsTypeFile(LIBMTP_file_t *file)
26     : MtpFsTypeBasic(file->item_id, file->parent_id, file->storage_id, std::string(file->filename)),
27       size_(file->filesize),
28       modifyDate_(file->modificationdate)
29 {}
30 
MtpFsTypeFile(const MtpFsTypeFile & copy)31 MtpFsTypeFile::MtpFsTypeFile(const MtpFsTypeFile &copy)
32     : MtpFsTypeBasic(copy), size_(copy.size_), modifyDate_(copy.modifyDate_)
33 {}
34 
ToLIBMTPFile() const35 LIBMTP_file_t *MtpFsTypeFile::ToLIBMTPFile() const
36 {
37     LIBMTP_file_t *f = static_cast<LIBMTP_file_t *>(malloc(sizeof(LIBMTP_file_t)));
38     if (f == nullptr) {
39         return nullptr;
40     }
41     f->item_id = id_;
42     f->parent_id = parentId_;
43     f->storage_id = storageId_;
44     f->filename = strdup(name_.c_str());
45     f->filesize = size_;
46     f->modificationdate = modifyDate_;
47     f->filetype = LIBMTP_FILETYPE_UNKNOWN;
48     f->next = nullptr;
49     return f;
50 }
51 
operator =(const MtpFsTypeFile & rhs)52 MtpFsTypeFile &MtpFsTypeFile::operator = (const MtpFsTypeFile &rhs)
53 {
54     MtpFsTypeBasic::operator = (rhs);
55     size_ = rhs.size_;
56     modifyDate_ = rhs.modifyDate_;
57     return *this;
58 }
59