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 16 #ifndef FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_MTP_PACKET_H_ 17 #define FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_MTP_PACKET_H_ 18 19 #include <memory> 20 #include <stdint.h> 21 #include <vector> 22 23 #include "header_data.h" 24 #include "mtp_driver.h" 25 #include "payload_data.h" 26 27 namespace OHOS { 28 namespace Media { 29 class MtpPacket { 30 public: 31 explicit MtpPacket(std::shared_ptr<MtpOperationContext> &context); 32 MtpPacket(std::shared_ptr<MtpOperationContext> &context, const std::shared_ptr<MtpDriver> &mtpDriver); 33 ~MtpPacket(); 34 int Parser(); 35 int Maker(bool isPayload); 36 37 int Read(); 38 int Write(); 39 void Init(std::shared_ptr<HeaderData> &headerData); 40 void Init(std::shared_ptr<HeaderData> &headerData, std::shared_ptr<PayloadData> &payloadData); 41 void Reset(); 42 43 uint16_t GetOperationCode(); 44 uint32_t GetTransactionId(); 45 uint32_t GetSessionID(); 46 47 static bool IsNeedDataPhase(uint16_t operationCode); 48 static bool IsI2R(uint16_t operationCode); 49 private: 50 int ParserHead(); 51 int ParserPayload(); 52 int ParserPayloaddata(); 53 int MakeHead(); 54 int MakerPayload(); 55 56 std::shared_ptr<MtpOperationContext> context_; 57 uint32_t readSize_ {0}; 58 uint32_t readBufSize_ {0}; 59 uint32_t writeSize_ {0}; 60 std::shared_ptr<HeaderData> headerData_; 61 std::shared_ptr<PayloadData> payloadData_; 62 std::shared_ptr<MtpDriver> mtpDriver_; 63 std::vector<uint8_t> readBuffer_; 64 std::vector<uint8_t> writeBuffer_; 65 }; 66 } // namespace Media 67 } // namespace OHOS 68 69 #endif // FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_MTP_PACKET_H_ 70