1 /*
2 * Copyright (C) 2022 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 #include "payload_data/get_storage_ids_data.h"
16 #include "media_mtp_utils.h"
17 #include "mtp_packet_tools.h"
18 #include "media_log.h"
19 using namespace std;
20 
21 namespace OHOS {
22 namespace Media {
GetStorageIdsData(shared_ptr<MtpOperationContext> & context)23 GetStorageIdsData::GetStorageIdsData(shared_ptr<MtpOperationContext> &context)
24     :PayloadData(context)
25 {
26 }
27 
GetStorageIdsData()28 GetStorageIdsData::GetStorageIdsData()
29 {
30 }
31 
~GetStorageIdsData()32 GetStorageIdsData::~GetStorageIdsData()
33 {
34 }
35 
Parser(const vector<uint8_t> & buffer,int32_t readSize)36 int GetStorageIdsData::Parser(const vector<uint8_t> &buffer, int32_t readSize)
37 {
38     return MTP_SUCCESS;
39 }
40 
Maker(vector<uint8_t> & outBuffer)41 int GetStorageIdsData::Maker(vector<uint8_t> &outBuffer)
42 {
43     MtpPacketTool::PutUInt32(outBuffer, storages_.size());
44     for (auto storage : storages_) {
45         MtpPacketTool::PutUInt32(outBuffer, storage->GetStorageID());
46     }
47     return MTP_SUCCESS;
48 }
49 
CalculateSize()50 uint32_t GetStorageIdsData::CalculateSize()
51 {
52     std::vector<uint8_t> tmpVar;
53     int res = Maker(tmpVar);
54     if (res != MTP_SUCCESS) {
55         return res;
56     }
57 
58     return tmpVar.size();
59 }
60 
SetStorages(const std::vector<std::shared_ptr<Storage>> & storages)61 void GetStorageIdsData::SetStorages(const std::vector<std::shared_ptr<Storage>> &storages)
62 {
63     storages_ = storages;
64 }
65 } // namespace Media
66 } // namespace OHOS