• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "settings_data_event_monitor.h"
17 
18 #include "dm_log.h"
19 
20 namespace OHOS {
21 namespace DistributedHardware {
SettingsDataEventMonitor(std::shared_ptr<LocalDeviceNameMgr> localDeviceNameMgr,SettingsDataMonitorType monitorType)22 SettingsDataEventMonitor::SettingsDataEventMonitor(std::shared_ptr<LocalDeviceNameMgr> localDeviceNameMgr,
23     SettingsDataMonitorType monitorType)
24     : localDeviceNameMgrWPtr_(localDeviceNameMgr), monitorType_(monitorType)
25 {
26     LOGI("Ctor SettingsDataEventMonitor, monitorType: %{public}d", (int32_t)monitorType);
27 }
28 
OnChange()29 void SettingsDataEventMonitor::OnChange()
30 {
31     if (localDeviceNameMgrWPtr_.expired()) {
32         LOGE("localDeviceNameMgrWPtr_ expired");
33         return;
34     }
35     LOGI("Settings OnChange type: %{public}d", (int32_t)monitorType_);
36     std::shared_ptr<LocalDeviceNameMgr> localDevNameSPtr = localDeviceNameMgrWPtr_.lock();
37     if (localDevNameSPtr == nullptr) {
38         LOGE("localDevNameSPtr is null!");
39         return;
40     }
41     switch (monitorType_) {
42         case SettingsDataMonitorType::USER_DEFINED_DEVICE_NAME_MONITOR:
43             localDevNameSPtr->QueryLocalDeviceName();
44             break;
45         case SettingsDataMonitorType::DISPLAY_DEVICE_NAME_MONITOR:
46             localDevNameSPtr->QueryLocalDisplayName();
47             break;
48         default:
49             LOGE("unknwon monitor type");
50             break;
51     }
52 }
53 } // DistributedHardware
54 } // OHOS