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 #include "recorder_profiles_ability_singleton.h"
17 #include "media_log.h"
18 #include "media_errors.h"
19
20 namespace {
21 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, LOG_DOMAIN_RECORDER,
22 "RecorderProfilesAbilitySingleton"};
23 }
24
25 namespace OHOS {
26 namespace Media {
GetInstance()27 RecorderProfilesAbilitySingleton& RecorderProfilesAbilitySingleton::GetInstance()
28 {
29 static RecorderProfilesAbilitySingleton instance;
30 bool ret = instance.ParseRecorderProfilesXml();
31 if (!ret) {
32 MEDIA_LOGD("ParseRecorderProfilesXml failed");
33 }
34 return instance;
35 }
36
RecorderProfilesAbilitySingleton()37 RecorderProfilesAbilitySingleton::RecorderProfilesAbilitySingleton()
38 {
39 MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances create", FAKE_POINTER(this));
40 }
41
~RecorderProfilesAbilitySingleton()42 RecorderProfilesAbilitySingleton::~RecorderProfilesAbilitySingleton()
43 {
44 MEDIA_LOGD("0x%{public}06" PRIXPTR " Instances destroy", FAKE_POINTER(this));
45 }
46
ParseRecorderProfilesXml()47 bool RecorderProfilesAbilitySingleton::ParseRecorderProfilesXml()
48 {
49 std::lock_guard<std::mutex> lock(mutex_);
50 if (isParsered_) {
51 return true;
52 }
53 capabilityDataArray_.clear();
54
55 std::shared_ptr<RecorderProfilesXmlParser> xmlParser = std::make_shared<RecorderProfilesXmlParser>();
56
57 bool ret = xmlParser->LoadConfiguration(MEDIA_PROFILE_CONFIG_FILE);
58 if (!ret) {
59 isParsered_ = false;
60 MEDIA_LOGE("RecorderProfiles LoadConfiguration failed");
61 return false;
62 }
63 ret = xmlParser->Parse();
64 if (!ret) {
65 isParsered_ = false;
66 MEDIA_LOGE("RecorderProfiles Parse failed.");
67 return false;
68 }
69 std::vector<RecorderProfilesData> data = xmlParser->GetRecorderProfileDataArray();
70 capabilityDataArray_.insert(capabilityDataArray_.end(), data.begin(), data.end());
71 isParsered_ = true;
72 return true;
73 }
74
GetCapabilityDataArray() const75 std::vector<RecorderProfilesData> RecorderProfilesAbilitySingleton::GetCapabilityDataArray() const
76 {
77 return capabilityDataArray_;
78 }
79 } // namespace Media
80 } // namespace OHOS
81