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_device_prop_desc_data.h" 16 #include "media_log.h" 17 #include "media_mtp_utils.h" 18 #include "mtp_operation_utils.h" 19 #include "mtp_packet_tools.h" 20 using namespace std; 21 namespace OHOS { 22 namespace Media { GetDevicePropDescData(std::shared_ptr<MtpOperationContext> & context)23GetDevicePropDescData::GetDevicePropDescData(std::shared_ptr<MtpOperationContext> &context) 24 :PayloadData(context) 25 { 26 } 27 GetDevicePropDescData()28GetDevicePropDescData::GetDevicePropDescData() 29 { 30 } 31 ~GetDevicePropDescData()32GetDevicePropDescData::~GetDevicePropDescData() 33 { 34 } 35 Parser(const std::vector<uint8_t> & buffer,int32_t readSize)36int GetDevicePropDescData::Parser(const std::vector<uint8_t> &buffer, int32_t readSize) 37 { 38 if (context_ == nullptr) { 39 return MTP_ERROR_CONTEXT_IS_NULL; 40 } 41 42 size_t offset = MTP_CONTAINER_HEADER_SIZE; 43 context_->property = MtpPacketTool::GetUInt32(buffer, offset); 44 return MTP_SUCCESS; 45 } 46 Maker(std::vector<uint8_t> & outBuffer)47int GetDevicePropDescData::Maker(std::vector<uint8_t> &outBuffer) 48 { 49 if (result_ == nullptr) { 50 MEDIA_ERR_LOG("property id NULL"); 51 return MTP_ERROR_DEVICEPROP_NOT_SUPPORTED; 52 } 53 result_->Write(outBuffer); 54 55 return MTP_SUCCESS; 56 } 57 CalculateSize()58uint32_t GetDevicePropDescData::CalculateSize() 59 { 60 std::vector<uint8_t> tmpVar; 61 62 int res = Maker(tmpVar); 63 if (res != MTP_SUCCESS) { 64 return res; 65 } 66 67 uint32_t size = tmpVar.size(); 68 return size; 69 } 70 SetProperty(std::shared_ptr<Property> & property)71void GetDevicePropDescData::SetProperty(std::shared_ptr<Property> &property) 72 { 73 result_ = property; 74 } 75 } // namespace Media 76 } // namespace OHOS