• 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 
16 #ifndef OHOS_MEDIALIBRARY_COMMAND_PARSE_H
17 #define OHOS_MEDIALIBRARY_COMMAND_PARSE_H
18 
19 #include <string>
20 #include <unordered_map>
21 #include <vector>
22 
23 #include "abs_rdb_predicates.h"
24 #include "datashare_predicates.h"
25 #include "dir_asset.h"
26 #include "medialibrary_db_const.h"
27 #include "medialibrary_operation.h"
28 #include "uri.h"
29 #include "values_bucket.h"
30 
31 namespace OHOS {
32 namespace Media {
33 #define EXPORT __attribute__ ((visibility ("default")))
34 class MediaLibraryCommand {
35 public:
36     EXPORT explicit MediaLibraryCommand(const Uri &uri);
37     EXPORT MediaLibraryCommand(const Uri &uri, const NativeRdb::ValuesBucket &value);
38     EXPORT MediaLibraryCommand(const Uri &uri, const OperationType &oprnType);
39     EXPORT MediaLibraryCommand(const OperationObject &oprnObject, const OperationType &oprnType,
40         MediaLibraryApi api = MediaLibraryApi::API_OLD);
41     EXPORT MediaLibraryCommand(const OperationObject &oprnObject, const OperationType &oprnType,
42         const NativeRdb::ValuesBucket &value, MediaLibraryApi api = MediaLibraryApi::API_OLD);
43     EXPORT MediaLibraryCommand(const OperationObject &oprnObject, const OperationType &oprnType,
44         const std::string &networkId, MediaLibraryApi api = MediaLibraryApi::API_OLD);
45     MediaLibraryCommand(const std::string &tableName, MediaLibraryApi api = MediaLibraryApi::API_OLD);
46     EXPORT MediaLibraryCommand(const NativeRdb::ValuesBucket &value, MediaLibraryApi api = MediaLibraryApi::API_OLD);
47     MediaLibraryCommand(const DataShare::DataSharePredicates &pred, MediaLibraryApi api = MediaLibraryApi::API_OLD);
48     EXPORT MediaLibraryCommand() = delete;
49     EXPORT ~MediaLibraryCommand();
50     EXPORT MediaLibraryCommand(const MediaLibraryCommand &) = delete;
51     EXPORT MediaLibraryCommand &operator=(const MediaLibraryCommand &) = delete;
52     EXPORT MediaLibraryCommand(MediaLibraryCommand &&) = delete;
53     EXPORT MediaLibraryCommand &operator=(MediaLibraryCommand &&) = delete;
54 
55     EXPORT OperationObject GetOprnObject() const;
56     EXPORT OperationType GetOprnType() const;
57     EXPORT const std::string &GetTableName();
58     EXPORT NativeRdb::ValuesBucket &GetValueBucket();
59     EXPORT NativeRdb::AbsRdbPredicates *GetAbsRdbPredicates();
60     EXPORT const std::string &GetOprnFileId();
61     EXPORT const std::string &GetOprnDevice();
62     EXPORT const Uri &GetUri() const;
63     EXPORT const std::string &GetBundleName();
64     EXPORT const std::string &GetDeviceName();
65     EXPORT std::string GetUriStringWithoutSegment() const;
66     EXPORT MediaLibraryApi GetApi();
67     EXPORT std::string GetQuerySetParam(const std::string &key);
68     EXPORT void SetDataSharePred(const DataShare::DataSharePredicates &pred);
69     EXPORT const DataShare::DataSharePredicates &GetDataSharePred() const;
70     EXPORT const std::string &GetResult();
71 
72     EXPORT void SetApiParam(const std::string &key, const std::string &param);
73     EXPORT void SetOprnObject(OperationObject object);
74     EXPORT void SetOprnAssetId(const std::string &oprnId);
75     EXPORT void SetValueBucket(const NativeRdb::ValuesBucket &value);
76     EXPORT void SetTableName(const std::string &tableName);
77     EXPORT void SetBundleName(const std::string &bundleName);
78     EXPORT void SetDeviceName(const std::string &deviceName);
79     EXPORT void SetResult(const std::string &result);
80     EXPORT bool IsDataSharePredNull() const;
81 
82 private:
83     void ParseOprnObjectFromUri();
84     void ParseOprnTypeFromUri();
85     void ParseTableName();
86     void InitAbsRdbPredicates();
87     void ParseFileId();
88     void ParseQuerySetMapFromUri();
89     void SetApiFromQuerySetMap();
90     void ParseOprnObjectFromFileUri();
91 
92     Uri uri_ {""};
93     NativeRdb::ValuesBucket insertValue_;
94     std::unique_ptr<NativeRdb::AbsRdbPredicates> absRdbPredicates_;
95     std::unique_ptr<const DataShare::DataSharePredicates> datasharePred_;
96     OperationObject oprnObject_ {OperationObject::UNKNOWN_OBJECT};
97     OperationType oprnType_ {OperationType::UNKNOWN_TYPE};
98     std::string oprnFileId_;
99     std::string oprnDevice_;
100     std::string tableName_;
101     std::string bundleName_;
102     std::string deviceName_;
103     std::unordered_map<std::string, std::string> querySetMap_;
104     std::string result_ = "";
105     MediaLibraryApi api_;
106 };
107 
108 } // namespace Media
109 } // namespace OHOS
110 
111 #endif // OHOS_MEDIALIBRARY_COMMAND_PARSE_H
112