• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_MTP_OPERATION_UTILS_H_
16 #define FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_MTP_OPERATION_UTILS_H_
17 #include <memory>
18 #include <vector>
19 #include "mtp_operation_context.h"
20 #include "payload_data.h"
21 namespace OHOS {
22 namespace Media {
23 class MtpOperationUtils {
24 public:
25     explicit MtpOperationUtils(const std::shared_ptr<MtpOperationContext> &context, bool isInit = false);
26     ~MtpOperationUtils();
27 
28     uint16_t GetRespCommonData(std::shared_ptr<PayloadData> &data, int errorCode);
29     uint16_t GetDeviceInfo(std::shared_ptr<PayloadData> &data, uint16_t containerType, int &errorCode);
30     uint16_t GetNumObjects(std::shared_ptr<PayloadData> &data);
31     uint16_t GetObjectHandles(std::shared_ptr<PayloadData> &data, uint16_t containerType, int &errorCode);
32     uint16_t GetObjectInfo(std::shared_ptr<PayloadData> &data, uint16_t containerType, int &errorCode);
33     uint16_t GetObjectPropDesc(std::shared_ptr<PayloadData> &data, uint16_t containerType, int &errorCode);
34     uint16_t GetObjectPropValue(std::shared_ptr<PayloadData> &data, uint16_t containerType, int &errorCode);
35     void DoSetObjectPropValue(int &errorCode);
36     uint16_t GetObjectPropList(std::shared_ptr<PayloadData> &data, uint16_t containerType, int &errorCode);
37     uint16_t GetObjectReferences(std::shared_ptr<PayloadData> &data, uint16_t containerType, int &errorCode);
38     uint16_t SetObjectReferences(std::shared_ptr<PayloadData> &data);
39     uint16_t GetObjectDataDeal();
40     uint16_t GetObject(std::shared_ptr<PayloadData> &data, int errorCode);
41     int32_t DoRecevieSendObject();
42     uint16_t GetThumb(std::shared_ptr<PayloadData> &data, uint16_t containerType, int &errorCode);
43     uint16_t SendObjectInfo(std::shared_ptr<PayloadData> &data, int &errorCode);
44     uint16_t GetPartialObject(std::shared_ptr<PayloadData> &data);
45     uint16_t GetObjectPropsSupported(std::shared_ptr<PayloadData> &data);
46     uint16_t DeleteObject(std::shared_ptr<PayloadData> &data, int &errorCode);
47     uint16_t MoveObject(std::shared_ptr<PayloadData> &data, int &errorCode);
48     uint16_t CopyObject(std::shared_ptr<PayloadData> &data, int &errorCode);
49     uint16_t GetStorageIDs(std::shared_ptr<PayloadData> &data, uint16_t containerType, int &errorCode);
50     uint16_t GetStorageInfo(std::shared_ptr<PayloadData> &data, uint16_t containerType, int &errorCode);
51     uint16_t GetOpenSession(std::shared_ptr<PayloadData> &data, int errorCode);
52     uint16_t GetCloseSession(std::shared_ptr<PayloadData> &data);
53     uint16_t GetPropDesc(std::shared_ptr<PayloadData> &data, uint16_t containerType, int &errorCode);
54     uint16_t GetPropValue(std::shared_ptr<PayloadData> &data, uint16_t containerType, int &errorCode);
55     uint16_t SetDevicePropValueResp(std::shared_ptr<PayloadData> &data);
56     uint16_t ResetDevicePropResp(std::shared_ptr<PayloadData> &data);
57     uint16_t ObjectEvent(std::shared_ptr<PayloadData> &data, const int32_t payload);
58     uint16_t GetPathByHandle(const uint32_t &handle, std::string &path, std::string &realPath);
59     int32_t GetHandleByPaths(std::string path, uint32_t &handle);
60     bool TryAddExternalStorage(const std::string &fsUuid, uint32_t &storageId);
61     bool TryRemoveExternalStorage(const std::string &fsUuid, uint32_t &storageId);
62     static int32_t GetBatteryLevel();
63     static std::string GetPropertyInner(const std::string &property, const std::string &defValue);
64     static bool SetPropertyInner(const std::string &property, const std::string &value);
65     static void SetIsDevicePropSet();
66 
67 private:
68     uint16_t CheckErrorCode(int errorCode);
69     void PreDealFd(const bool deal, const int fd);
70     void SendEventPacket(uint32_t objectHandle, uint16_t eventCode);
71     uint16_t HasStorage(int &errorCode);
72     int32_t RecevieSendObject(MtpFileRange &object, int fd);
73     void ModifyObjectInfo();
74 
75     std::shared_ptr<MtpOperationContext> context_;
76 };
77 } // namespace Media
78 } // namespace OHOS
79 #endif  // FRAMEWORKS_SERVICES_MEDIA_MTP_INCLUDE_MTP_OPERATION_UTILS_H_
80