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 #include "payload_data/resp_common_data.h"
17 #include "media_mtp_utils.h"
18 #include "mtp_constants.h"
19 #include "mtp_packet_tools.h"
20 using namespace std;
21
22 namespace OHOS {
23 namespace Media {
24 const int DATA_SIZE = 4;
25 // these numbers are defined by protocol, have no exact meaning
26 const int PARAM_INDEX_1 = 1;
27 const int PARAM_INDEX_2 = 2;
28 const int PARAM_INDEX_3 = 3;
29 const int PARAM_INDEX_4 = 4;
30 const int PARAM_INDEX_5 = 5;
RespCommonData(shared_ptr<MtpOperationContext> & context)31 RespCommonData::RespCommonData(shared_ptr<MtpOperationContext> &context)
32 :PayloadData(context)
33 {
34 }
35
RespCommonData()36 RespCommonData::RespCommonData()
37 {
38 }
39
~RespCommonData()40 RespCommonData::~RespCommonData()
41 {
42 }
43
Parser(const vector<uint8_t> & buffer,int32_t readSize)44 int RespCommonData::Parser(const vector<uint8_t> &buffer, int32_t readSize)
45 {
46 return MTP_SUCCESS;
47 }
48
Maker(vector<uint8_t> & outBuffer)49 int RespCommonData::Maker(vector<uint8_t> &outBuffer)
50 {
51 if (param1_ > 0) {
52 MtpPacketTool::PutUInt32(outBuffer, param1_);
53 } else {
54 return MTP_SUCCESS;
55 }
56
57 if (param2_ > 0) {
58 MtpPacketTool::PutUInt32(outBuffer, param2_);
59 } else {
60 return MTP_SUCCESS;
61 }
62
63 if (param3_ > 0) {
64 MtpPacketTool::PutUInt32(outBuffer, param3_);
65 } else {
66 return MTP_SUCCESS;
67 }
68
69 if (param4_ > 0) {
70 MtpPacketTool::PutUInt32(outBuffer, param4_);
71 } else {
72 return MTP_SUCCESS;
73 }
74
75 if (param5_ > 0) {
76 MtpPacketTool::PutUInt32(outBuffer, param5_);
77 } else {
78 return MTP_SUCCESS;
79 }
80
81 return MTP_SUCCESS;
82 }
83
CalculateSize()84 uint32_t RespCommonData::CalculateSize()
85 {
86 int dataSize = 0;
87 if (param1_ > 0) {
88 dataSize += DATA_SIZE;
89 }
90
91 if (param2_ > 0) {
92 dataSize += DATA_SIZE;
93 }
94
95 if (param3_ > 0) {
96 dataSize += DATA_SIZE;
97 }
98
99 if (param4_ > 0) {
100 dataSize += DATA_SIZE;
101 }
102
103 if (param5_ > 0) {
104 dataSize += DATA_SIZE;
105 }
106 return dataSize;
107 }
108
SetParam(int paramIndex,uint32_t value)109 void RespCommonData::SetParam(int paramIndex, uint32_t value)
110 {
111 switch (paramIndex) {
112 case PARAM_INDEX_1:
113 param1_ = value;
114 break;
115 case PARAM_INDEX_2:
116 param2_ = value;
117 break;
118 case PARAM_INDEX_3:
119 param3_ = value;
120 break;
121 case PARAM_INDEX_4:
122 param4_ = value;
123 break;
124 case PARAM_INDEX_5:
125 param5_ = value;
126 break;
127 default:
128 break;
129 }
130 }
131 } // namespace Media
132 } // namespace OHOS