• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "monitor_task_timer.h"
17 
18 #include "anonymous_string.h"
19 #include "capability_info.h"
20 #include "capability_info_manager.h"
21 #include "distributed_hardware_errno.h"
22 #include "dh_timer.h"
23 #include "task_board.h"
24 #include "task_executor.h"
25 #include "task_factory.h"
26 
27 namespace OHOS {
28 namespace DistributedHardware {
29 #undef DH_LOG_TAG
30 #define DH_LOG_TAG "MonitorTaskTimer"
MonitorTaskTimer(std::string timerId,int32_t delayTimeMs)31 MonitorTaskTimer::MonitorTaskTimer(std::string timerId, int32_t delayTimeMs) : DHTimer(timerId, delayTimeMs)
32 {
33     DHLOGI("MonitorTaskTimer ctor!");
34 }
35 
~MonitorTaskTimer()36 MonitorTaskTimer::~MonitorTaskTimer()
37 {
38     DHLOGI("MonitorTaskTimer dtor!");
39 }
40 
ExecuteInner()41 void MonitorTaskTimer::ExecuteInner()
42 {
43     DHLOGD("ExecuteInner!");
44     auto enabledDevices = TaskBoard::GetInstance().GetEnabledDevice();
45     std::shared_ptr<CapabilityInfo> capInfoPtr = nullptr;
46     TaskParam taskParam;
47     std::string capabilityKey;
48     for (auto item : enabledDevices) {
49         capabilityKey = item.first;
50         taskParam = item.second;
51         if (taskParam.dhType != DHType::INPUT) {
52             continue;
53         }
54         if (CapabilityInfoManager::GetInstance()->GetDataByKey(capabilityKey, capInfoPtr) != DH_FWK_SUCCESS) {
55             DHLOGI("CapabilityInfoManager can not find this key in DB, key: %s, networkId: %s, uuid: %s, dhId: %s",
56                 GetAnonyString(capabilityKey).c_str(), GetAnonyString(taskParam.networkId).c_str(),
57                 GetAnonyString(taskParam.uuid).c_str(), GetAnonyString(taskParam.dhId).c_str());
58             auto task = TaskFactory::GetInstance().CreateTask(TaskType::DISABLE, taskParam, nullptr);
59             TaskExecutor::GetInstance().PushTask(task);
60         }
61     }
62 
63     if (capInfoPtr != nullptr) {
64         capInfoPtr = nullptr;
65     }
66 }
67 
HandleStopTimer()68 void MonitorTaskTimer::HandleStopTimer()
69 {
70     DHLOGI("HandleStopTimer!");
71 }
72 } // namespace DistributedHardware
73 } // namespace OHOS
74