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 #ifndef FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_SET_OBJECT_PROP_VALUE_DATA_H_
16 #define FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_SET_OBJECT_PROP_VALUE_DATA_H_
17 #include <map>
18 #include "mtp_constants.h"
19 #include "payload_data.h"
20 namespace OHOS {
21 namespace Media {
22 class SetObjectPropValueData : public PayloadData {
23 public:
24     explicit SetObjectPropValueData(std::shared_ptr<MtpOperationContext> &context);
25     ~SetObjectPropValueData() override;
26 
27     int Parser(const std::vector<uint8_t> &buffer, int32_t readSize) override;
28     int Maker(std::vector<uint8_t> &outBuffer) override;
29     uint32_t CalculateSize() override;
30 
31     bool SetResult(uint16_t result);
32 
33 private:
34     bool hasSetResult_ {false};
35     uint16_t result_ {MTP_GENERAL_ERROR_CODE};
36 
37 private:
38     static bool ReadIntValue(const std::vector<uint8_t> &buffer, size_t &offset, int type, int64_t &int64Value);
39     static bool ReadInt8Value(const std::vector<uint8_t> &buffer, size_t &offset, int type, int64_t &int64Value);
40     static bool ReadInt16Value(const std::vector<uint8_t> &buffer, size_t &offset, int type, int64_t &int64Value);
41     static bool ReadInt32Value(const std::vector<uint8_t> &buffer, size_t &offset, int type, int64_t &int64Value);
42     static bool ReadInt64Value(const std::vector<uint8_t> &buffer, size_t &offset, int type, int64_t &int64Value);
43     static const std::map<uint16_t, int> objectPropertyMap_;
44 };
45 } // namespace Media
46 } // namespace OHOS
47 #endif  // FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_SET_OBJECT_PROP_VALUE_DATA_H_
48