• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_ACCURATE_COMMON_DATA_H
17 #define OHOS_MEDIALIBRARY_ACCURATE_COMMON_DATA_H
18 
19 #include <string>
20 #include "parcel.h"
21 
22 namespace OHOS {
23 namespace Media::AccurateRefresh {
24 
25 const std::string EMPTY_STR = "";
26 const int32_t INVALID_INT32_VALUE = -1;
27 const int64_t INVALID_INT64_VALUE = -1;
28 const std::size_t MAX_DATA_LENGTH = 1000;
29 const int32_t ACCURATE_REFRESH_RET_OK = 0;
30 
31 const int32_t ACCURATE_REFRESH_BASE = 0x10000;
32 
33 // 入参错误
34 const int32_t ACCURATE_REFRESH_INPUT_PARA_ERR = ACCURATE_REFRESH_BASE + 1;
35 
36 // rdb
37 const int32_t ACCURATE_REFRESH_RDB_NULL = ACCURATE_REFRESH_BASE + 2;
38 
39 // AssetDataManager/AlbumDataManager 类异常返回值
40 const int32_t ACCURATE_REFRESH_DATA_MGR_BASE = 0x20000;
41 // 查出变化数据为空
42 const int32_t ACCURATE_REFRESH_MODIFY_EMPTY = ACCURATE_REFRESH_DATA_MGR_BASE + 1;
43 
44 // 变化后数据存在,修改前数据不存在
45 const int32_t ACCURATE_REFRESH_MODIFY_ABNORMAL = ACCURATE_REFRESH_DATA_MGR_BASE + 2;
46 
47 // 变化前后不匹配
48 const int32_t ACCURATE_REFRESH_MODIFY_NO_MATCH = ACCURATE_REFRESH_DATA_MGR_BASE + 3;
49 
50 // 非ADD场景,initDatas为空
51 const int32_t ACCURATE_REFRESH_INIT_EMPTY = ACCURATE_REFRESH_DATA_MGR_BASE + 4;
52 
53 // 计算后的changeDatas数据为空
54 const int32_t ACCURATE_REFRESH_CHANGE_DATA_EMPTY = ACCURATE_REFRESH_DATA_MGR_BASE + 5;
55 
56 // dataManager为null,使用流程错误
57 const int32_t ACCURATE_REFRESH_DATA_MGR_NULL = ACCURATE_REFRESH_DATA_MGR_BASE + 6;
58 
59 // 待更新相册和查询出来的数据不一致
60 const int32_t ACCURATE_REFRESH_ALBUM_NO_MATCH = ACCURATE_REFRESH_DATA_MGR_BASE + 7;
61 
62 // 系统相册全量更新
63 const int32_t ACCURATE_REFRESH_ALBUM_ALL = ACCURATE_REFRESH_DATA_MGR_BASE + 8;
64 
65 // 插入Init数据重复
66 const int32_t ACCURATE_REFRESH_INIT_REPEAT = ACCURATE_REFRESH_DATA_MGR_BASE + 9;
67 
68 // 插入Modified数据重复
69 const int32_t ACCURATE_REFRESH_MODIFIED_REPEAT = ACCURATE_REFRESH_DATA_MGR_BASE + 10;
70 
71 // Add场景init已存在数据
72 const int32_t ACCURATE_REFRESH_MODIFIED_ADD_NO_MATCH = ACCURATE_REFRESH_DATA_MGR_BASE + 11;
73 
74 // Update/Del场景没有init数据
75 const int32_t ACCURATE_REFRESH_MODIFIED_NO_INIT = ACCURATE_REFRESH_DATA_MGR_BASE + 12;
76 
77 // 对同一key做operation处理,但是操作不匹配(除了增改和改改之外的操作)
78 const int32_t ACCURATE_REFRESH_OPERATION_NO_MATCH = ACCURATE_REFRESH_DATA_MGR_BASE + 13;
79 
80 // notifyExe_为null,使用流程错误
81 const int32_t ACCURATE_REFRESH_NOTIFY_EXE_NULL = ACCURATE_REFRESH_DATA_MGR_BASE + 14;
82 
83 // ForceUpdateAlbumInfo更新找不到数据
84 const int32_t ACCURATE_REFRESH_ALBUM_INFO_NULL = ACCURATE_REFRESH_DATA_MGR_BASE + 15;
85 
86 // 根据查询得到的前后数据更新公共参数失败
87 const int32_t ACCURATE_REFRESH_COMMON_DATAS_FAILED = ACCURATE_REFRESH_DATA_MGR_BASE + 16;
88 
89 // 数据数量超标
90 const int32_t ACCURATE_REFRESH_DATA_EXCEED = ACCURATE_REFRESH_DATA_MGR_BASE + 17;
91 
92 // 数据库类异常返回值
93 const int32_t ACCURATE_REFRESH_RDB_BASE = 0x40000;
94 const int32_t ACCURATE_REFRESH_RDB_INSERT_ERR = ACCURATE_REFRESH_RDB_BASE + 1;
95 
96 const int32_t ACCURATE_REFRESH_RDB_INVALITD_TABLE = ACCURATE_REFRESH_RDB_BASE + 2;
97 
98 const int32_t MAX_COST_TIME_REPORT = 1000;
99 
100 const int32_t MAX_COST_TIME_PRINT_LOG = 200;
101 
102 const size_t MAX_SQLSTR_SIZE = 210;
103 
104 const size_t MAX_ALBUM_ID_SIZE = 100;
105 
106 const size_t MAX_ALBUM_OPERATION_SIZE = 50;
107 
108 enum RdbOperation {
109     RDB_OPERATION_UNDEFINED,
110     RDB_OPERATION_ADD,
111     RDB_OPERATION_REMOVE,
112     RDB_OPERATION_UPDATE,
113 };
114 
115 template <typename ChangeInfo>
116 class AccurateRefreshChangeData : public Parcelable {
117 public:
118     virtual std::string ToString(bool isDetail = false) const
119     {
120         return "info before: " + infoBeforeChange_.ToString(isDetail) + "; info after: " +
121         infoAfterChange_.ToString((isDetail)) + ", isDelete_: " + std::to_string(isDelete_) +
122         ", operation_: " + std::to_string(operation_) + ", version_: " + std::to_string(version_);
123     }
Marshalling(Parcel & parcel)124     bool Marshalling(Parcel &parcel) const override
125     {
126         return Marshalling(parcel, false);
127     }
Marshalling(Parcel & parcel,bool isSystem)128     bool Marshalling(Parcel &parcel, bool isSystem) const
129     {
130         bool ret = infoBeforeChange_.Marshalling(parcel, isSystem);
131         ret = ret && infoAfterChange_.Marshalling(parcel, isSystem);
132         ret = ret && parcel.WriteBool(isDelete_);
133         ret = ret && parcel.WriteInt32(static_cast<int32_t>(operation_));
134         ret = ret && parcel.WriteBool(isSystem);
135         if (isSystem) {
136             ret = ret && parcel.WriteInt64(version_);
137         }
138         return ret;
139     }
140 
ReadFromParcel(Parcel & parcel)141     virtual bool ReadFromParcel(Parcel &parcel)
142     {
143         bool ret = infoBeforeChange_.ReadFromParcel(parcel);
144         ret = ret && infoAfterChange_.ReadFromParcel(parcel);
145         ret = ret && parcel.ReadBool(isDelete_);
146         int32_t operationNum;
147         if (ret && parcel.ReadInt32(operationNum)) {
148             operation_ = static_cast<RdbOperation>(operationNum);
149         } else {
150             return false;
151         }
152         ret = ret && parcel.ReadBool(isSystem_);
153         if (isSystem_) {
154             ret = ret && parcel.ReadInt64(version_);
155         }
156         return ret;
157     }
158 public:
159     ChangeInfo infoBeforeChange_;
160     ChangeInfo infoAfterChange_;
161     bool isDelete_ = false;
162     RdbOperation operation_ = RDB_OPERATION_UNDEFINED;
163     int64_t version_ = INVALID_INT64_VALUE;
164 
165 protected:
166     bool isSystem_ = false;
167 };
168 
169 class PendingInfo {
170 public:
PendingInfo()171     PendingInfo() : start_(INVALID_INT64_VALUE), end_(INVALID_INT64_VALUE) {}
PendingInfo(int64_t start)172     PendingInfo(int64_t start) : start_(start), end_(INVALID_INT64_VALUE) {}
PendingInfo(int64_t start,int64_t end)173     PendingInfo(int64_t start, int64_t end) : start_(start), end_(end) {}
174 public:
175     int64_t start_;
176     int64_t end_;
177 };
178 
179 } // namespace Media
180 } // namespace OHOS
181 
182 #endif