• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 INTERFACES_INNERKITS_NATIVE_INCLUDE_FETCH_RESULT_H_
17 #define INTERFACES_INNERKITS_NATIVE_INCLUDE_FETCH_RESULT_H_
18 
19 #include <variant>
20 #include "abs_shared_result_set.h"
21 #include "album_asset.h"
22 #include "album_order.h"
23 #include "datashare_result_set.h"
24 #include "file_asset.h"
25 #include "medialibrary_type_const.h"
26 #include "medialibrary_db_const.h"
27 #include "rdb_errno.h"
28 #include "photo_album.h"
29 #include "smart_album_asset.h"
30 #include "userfile_manager_types.h"
31 #include "photo_asset_custom_record.h"
32 #include "custom_records_column.h"
33 
34 namespace OHOS {
35 namespace Media {
36 #define EXPORT __attribute__ ((visibility ("default")))
37 /**
38  * @brief Class for returning the data cursor to application.
39  *
40  * @since 1.0
41  * @version 1.0
42  */
43 template <class T>
44 class FetchResult {
45 public:
46     EXPORT explicit FetchResult(const std::shared_ptr<DataShare::DataShareResultSet> &resultset);
47     EXPORT FetchResult();
48     EXPORT virtual ~FetchResult();
49 
50     EXPORT void Close();
51     EXPORT int32_t GetCount();
52     EXPORT bool IsAtLastRow();
53     EXPORT void SetInfo(const unique_ptr<FetchResult<T>> &fetch);
54     EXPORT void SetNetworkId(const string &networkId);
55     EXPORT void SetResultNapiType(const ResultNapiType napiType);
56     EXPORT void SetFetchResType(const FetchResType resType);
57     EXPORT void SetHiddenOnly(const bool hiddenOnly);
58     EXPORT void SetLocationOnly(const bool locationOnly);
59 
60     EXPORT const std::string& GetNetworkId() const;
61     EXPORT ResultNapiType GetResultNapiType();
62     EXPORT std::shared_ptr<DataShare::DataShareResultSet> &GetDataShareResultSet();
63     EXPORT FetchResType GetFetchResType();
64     EXPORT bool GetHiddenOnly() const;
65     EXPORT bool GetLocationOnly() const;
66 
67     EXPORT std::unique_ptr<T> GetObjectAtPosition(int32_t index);
68     EXPORT std::unique_ptr<T> GetFirstObject();
69     EXPORT std::unique_ptr<T> GetObjectFromRdb(std::shared_ptr<NativeRdb::ResultSet> &resultSet, int idx);
70     EXPORT std::unique_ptr<T> GetNextObject();
71     EXPORT std::unique_ptr<T> GetLastObject();
72     EXPORT std::unique_ptr<T> GetObject();
73     EXPORT void SetUserId(int32_t userId);
74     EXPORT int32_t GetUserId();
75 
76 private:
77     EXPORT std::unique_ptr<T> GetObject(std::shared_ptr<NativeRdb::ResultSet> &resultSet);
78     EXPORT std::variant<int32_t, int64_t, std::string, double> GetRowValFromColumn(std::string columnName,
79         ResultSetDataType dataType, std::shared_ptr<NativeRdb::ResultSet> &resultSet);
80     std::variant<int32_t, int64_t, std::string, double> GetValByIndex(int32_t index, ResultSetDataType dataType,
81         std::shared_ptr<NativeRdb::ResultSet> &resultSet);
82 
83     void SetFileAsset(FileAsset *fileAsset, std::shared_ptr<NativeRdb::ResultSet> &resultSet);
84     void SetAlbumAsset(AlbumAsset* albumData, std::shared_ptr<NativeRdb::ResultSet> &resultSet);
85     void SetPhotoAlbum(PhotoAlbum* photoAlbumData, std::shared_ptr<NativeRdb::ResultSet> &resultSet);
86     void SetSmartAlbumAsset(SmartAlbumAsset* smartAlbumData, std::shared_ptr<NativeRdb::ResultSet> &resultSet);
87     void SetPhotoAssetCustomRecordAsset(PhotoAssetCustomRecord* smartAlbumData,
88         std::shared_ptr<NativeRdb::ResultSet> &resultSet);
89     void SetAssetUri(FileAsset *fileAsset);
90     void SetAlbumOrder(AlbumOrder *albumOrderData, std::shared_ptr<NativeRdb::ResultSet> &resultSet);
91 
92     void GetObjectFromResultSet(FileAsset *asset, shared_ptr<NativeRdb::ResultSet> &resultSet);
93     void GetObjectFromResultSet(AlbumAsset *asset, shared_ptr<NativeRdb::ResultSet> &resultSet);
94     void GetObjectFromResultSet(PhotoAlbum *asset, shared_ptr<NativeRdb::ResultSet> &resultSet);
95     void GetObjectFromResultSet(SmartAlbumAsset *asset, shared_ptr<NativeRdb::ResultSet> &resultSet);
96     void GetObjectFromResultSet(PhotoAssetCustomRecord *asset, shared_ptr<NativeRdb::ResultSet> &resultSet);
97     void GetObjectFromResultSet(AlbumOrder *asset, shared_ptr<NativeRdb::ResultSet> &resultSet);
98 
99     std::string networkId_;
100     ResultNapiType resultNapiType_;
101     std::shared_ptr<DataShare::DataShareResultSet> resultset_ = nullptr;
102     FetchResType fetchResType_;
103     int32_t userId_ = -1;
104     bool hiddenOnly_ = false;
105     bool locationOnly_ = false;
106 };
107 } // namespace Media
108 } // namespace OHOS
109 
110 #endif  // INTERFACES_INNERKITS_NATIVE_INCLUDE_FETCH_RESULT_H_