1 /*
2 * Copyright (C) 2024 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 #define MLOG_TAG "RingtoneAsset"
16
17 #include "ringtone_asset.h"
18
19 #include "ringtone_db_const.h"
20 #include "ringtone_errno.h"
21 #include "ringtone_log.h"
22 #include "ringtone_type.h"
23
24 namespace OHOS {
25 namespace Media {
26 using namespace std;
27
RingtoneAsset()28 RingtoneAsset::RingtoneAsset()
29 {
30 }
31
GetId() const32 int32_t RingtoneAsset::GetId() const
33 {
34 return GetInt32Member(RINGTONE_COLUMN_TONE_ID);
35 }
36
SetId(int32_t id)37 void RingtoneAsset::SetId(int32_t id)
38 {
39 member_[RINGTONE_COLUMN_TONE_ID] = id;
40 }
41
GetSize() const42 int64_t RingtoneAsset::GetSize() const
43 {
44 return GetInt64Member(RINGTONE_COLUMN_SIZE);
45 }
46
SetSize(int64_t size)47 void RingtoneAsset::SetSize(int64_t size)
48 {
49 member_[RINGTONE_COLUMN_SIZE] = size;
50 }
51
GetPath() const52 const string &RingtoneAsset::GetPath() const
53 {
54 return GetStrMember(RINGTONE_COLUMN_DATA);
55 }
56
SetPath(const string & path)57 void RingtoneAsset::SetPath(const string &path)
58 {
59 member_[RINGTONE_COLUMN_DATA] = path;
60 }
61
GetDisplayName() const62 const string &RingtoneAsset::GetDisplayName() const
63 {
64 return GetStrMember(RINGTONE_COLUMN_DISPLAY_NAME);
65 }
66
SetDisplayName(const string & displayName)67 void RingtoneAsset::SetDisplayName(const string &displayName)
68 {
69 member_[RINGTONE_COLUMN_DISPLAY_NAME] = displayName;
70 }
71
GetTitle() const72 const string &RingtoneAsset::GetTitle() const
73 {
74 return GetStrMember(RINGTONE_COLUMN_TITLE);
75 }
76
SetTitle(const string & title)77 void RingtoneAsset::SetTitle(const string &title)
78 {
79 member_[RINGTONE_COLUMN_TITLE] = title;
80 }
81
GetMediaType() const82 int32_t RingtoneAsset::GetMediaType() const
83 {
84 return GetInt32Member(RINGTONE_COLUMN_MEDIA_TYPE);
85 }
86
SetMediaType(int32_t mediaType)87 void RingtoneAsset::SetMediaType(int32_t mediaType)
88 {
89 member_[RINGTONE_COLUMN_MEDIA_TYPE] = mediaType;
90 }
91
GetMimeType() const92 const string &RingtoneAsset::GetMimeType() const
93 {
94 return GetStrMember(RINGTONE_COLUMN_MIME_TYPE);
95 }
96
SetMimeType(const string & mimeType)97 void RingtoneAsset::SetMimeType(const string &mimeType)
98 {
99 member_[RINGTONE_COLUMN_MIME_TYPE] = mimeType;
100 }
101
GetToneType() const102 int32_t RingtoneAsset::GetToneType() const
103 {
104 return GetInt32Member(RINGTONE_COLUMN_TONE_TYPE);
105 }
106
SetToneType(int32_t toneType)107 void RingtoneAsset::SetToneType(int32_t toneType)
108 {
109 member_[RINGTONE_COLUMN_TONE_TYPE] = toneType;
110 }
111
GetSourceType() const112 int32_t RingtoneAsset::GetSourceType() const
113 {
114 return GetInt32Member(RINGTONE_COLUMN_SOURCE_TYPE);
115 }
116
SetSourceType(int32_t type)117 void RingtoneAsset::SetSourceType(int32_t type)
118 {
119 member_[RINGTONE_COLUMN_SOURCE_TYPE] = type;
120 }
121
GetDateAdded() const122 int64_t RingtoneAsset::GetDateAdded() const
123 {
124 return GetInt64Member(RINGTONE_COLUMN_DATE_ADDED);
125 }
126
SetDateAdded(int64_t dateAdded)127 void RingtoneAsset::SetDateAdded(int64_t dateAdded)
128 {
129 member_[RINGTONE_COLUMN_DATE_ADDED] = dateAdded;
130 }
131
GetDateModified() const132 int64_t RingtoneAsset::GetDateModified() const
133 {
134 return GetInt64Member(RINGTONE_COLUMN_DATE_MODIFIED);
135 }
136
SetDateModified(int64_t dateModified)137 void RingtoneAsset::SetDateModified(int64_t dateModified)
138 {
139 member_[RINGTONE_COLUMN_DATE_MODIFIED] = dateModified;
140 }
141
142
GetDateTaken() const143 int64_t RingtoneAsset::GetDateTaken() const
144 {
145 return GetInt64Member(RINGTONE_COLUMN_DATE_TAKEN);
146 }
147
SetDateTaken(int64_t dataTaken)148 void RingtoneAsset::SetDateTaken(int64_t dataTaken)
149 {
150 member_[RINGTONE_COLUMN_DATE_TAKEN] = dataTaken;
151 }
152
GetDuration() const153 int32_t RingtoneAsset::GetDuration() const
154 {
155 return GetInt32Member(RINGTONE_COLUMN_DURATION);
156 }
157
SetDuration(int32_t duration)158 void RingtoneAsset::SetDuration(int32_t duration)
159 {
160 member_[RINGTONE_COLUMN_DURATION] = duration;
161 }
162
GetShottoneType() const163 int32_t RingtoneAsset::GetShottoneType() const
164 {
165 return GetInt32Member(RINGTONE_COLUMN_SHOT_TONE_TYPE);
166 }
167
SetShottoneType(int32_t type)168 void RingtoneAsset::SetShottoneType(int32_t type)
169 {
170 member_[RINGTONE_COLUMN_SHOT_TONE_TYPE] = type;
171 }
172
GetShottoneSourceType() const173 int32_t RingtoneAsset::GetShottoneSourceType() const
174 {
175 return GetInt32Member(RINGTONE_COLUMN_SHOT_TONE_SOURCE_TYPE);
176 }
177
SetShottoneSourceType(int32_t type)178 void RingtoneAsset::SetShottoneSourceType(int32_t type)
179 {
180 member_[RINGTONE_COLUMN_SHOT_TONE_SOURCE_TYPE] = type;
181 }
182
GetNotificationtoneType() const183 int32_t RingtoneAsset::GetNotificationtoneType() const
184 {
185 return GetInt32Member(RINGTONE_COLUMN_NOTIFICATION_TONE_TYPE);
186 }
187
SetNotificationtoneType(int32_t type)188 void RingtoneAsset::SetNotificationtoneType(int32_t type)
189 {
190 member_[RINGTONE_COLUMN_NOTIFICATION_TONE_TYPE] = type;
191 }
192
GetNotificationtoneSourceType() const193 int32_t RingtoneAsset::GetNotificationtoneSourceType() const
194 {
195 return GetInt32Member(RINGTONE_COLUMN_NOTIFICATION_TONE_SOURCE_TYPE);
196 }
197
SetNotificationtoneSourceType(int32_t type)198 void RingtoneAsset::SetNotificationtoneSourceType(int32_t type)
199 {
200 member_[RINGTONE_COLUMN_NOTIFICATION_TONE_SOURCE_TYPE] = type;
201 }
202
GetRingtoneType() const203 int32_t RingtoneAsset::GetRingtoneType() const
204 {
205 return GetInt32Member(RINGTONE_COLUMN_RING_TONE_TYPE);
206 }
207
SetRingtoneType(int32_t type)208 void RingtoneAsset::SetRingtoneType(int32_t type)
209 {
210 member_[RINGTONE_COLUMN_RING_TONE_TYPE] = type;
211 }
212
GetRingtoneSourceType() const213 int32_t RingtoneAsset::GetRingtoneSourceType() const
214 {
215 return GetInt32Member(RINGTONE_COLUMN_RING_TONE_SOURCE_TYPE);
216 }
217
SetRingtoneSourceType(int32_t type)218 void RingtoneAsset::SetRingtoneSourceType(int32_t type)
219 {
220 member_[RINGTONE_COLUMN_RING_TONE_SOURCE_TYPE] = type;
221 }
222
GetAlarmtoneType() const223 int32_t RingtoneAsset::GetAlarmtoneType() const
224 {
225 return GetInt32Member(RINGTONE_COLUMN_ALARM_TONE_TYPE);
226 }
227
SetAlarmtoneType(int32_t type)228 void RingtoneAsset::SetAlarmtoneType(int32_t type)
229 {
230 member_[RINGTONE_COLUMN_ALARM_TONE_TYPE] = type;
231 }
232
GetAlarmtoneSourceType() const233 int32_t RingtoneAsset::GetAlarmtoneSourceType() const
234 {
235 return GetInt32Member(RINGTONE_COLUMN_ALARM_TONE_SOURCE_TYPE);
236 }
237
SetAlarmtoneSourceType(int32_t type)238 void RingtoneAsset::SetAlarmtoneSourceType(int32_t type)
239 {
240 member_[RINGTONE_COLUMN_ALARM_TONE_SOURCE_TYPE] = type;
241 }
242
GetScannerFlag() const243 int32_t RingtoneAsset::GetScannerFlag() const
244 {
245 return GetInt32Member(RINGTONE_COLUMN_SCANNER_FLAG);
246 }
247
SetScannerFlag(int32_t flag)248 void RingtoneAsset::SetScannerFlag(int32_t flag)
249 {
250 member_[RINGTONE_COLUMN_SCANNER_FLAG] = flag;
251 }
252
SetOpenStatus(int32_t fd,int32_t openStatus)253 void RingtoneAsset::SetOpenStatus(int32_t fd, int32_t openStatus)
254 {
255 lock_guard<mutex> lock(openStatusMapMutex_);
256 if (openStatusMap_ == nullptr) {
257 openStatusMap_ = make_shared<unordered_map<int32_t, int32_t>>();
258 }
259 openStatusMap_->insert({fd, openStatus});
260 }
261
RemoveOpenStatus(int32_t fd)262 void RingtoneAsset::RemoveOpenStatus(int32_t fd)
263 {
264 lock_guard<mutex> lock(openStatusMapMutex_);
265 if (openStatusMap_ == nullptr) {
266 return;
267 }
268 openStatusMap_->erase(fd);
269 }
270
GetOpenStatus(int32_t fd)271 int32_t RingtoneAsset::GetOpenStatus(int32_t fd)
272 {
273 lock_guard<mutex> lock(openStatusMapMutex_);
274 if (openStatusMap_ == nullptr) {
275 return E_INVALID_VALUES;
276 }
277 if (openStatusMap_->find(fd) != openStatusMap_->end()) {
278 return openStatusMap_->at(fd);
279 } else {
280 RINGTONE_ERR_LOG("can not find this fd: [%{public}d]", fd);
281 return E_INVALID_VALUES;
282 }
283 }
284
GetMemberMap()285 unordered_map<string, variant<int32_t, int64_t, string, double>> &RingtoneAsset::GetMemberMap()
286 {
287 return member_;
288 }
289
GetMemberValue(const string & name)290 variant<int32_t, int64_t, string, double> &RingtoneAsset::GetMemberValue(const string &name)
291 {
292 return member_[name];
293 }
294
GetStrMember(const string & name) const295 const string &RingtoneAsset::GetStrMember(const string &name) const
296 {
297 return (member_.count(name) > 0) ? get<string>(member_.at(name)) : RINGTONE_DEFAULT_STR;
298 }
299
GetInt32Member(const string & name) const300 int32_t RingtoneAsset::GetInt32Member(const string &name) const
301 {
302 return (member_.count(name) > 0) ? get<int32_t>(member_.at(name)) : RINGTONE_DEFAULT_INT32;
303 }
304
GetInt64Member(const string & name) const305 int64_t RingtoneAsset::GetInt64Member(const string &name) const
306 {
307 return (member_.count(name) > 0) ? get<int64_t>(member_.at(name)) : RINGTONE_DEFAULT_INT64;
308 }
309 } // namespace Media
310 } // namespace OHOS
311