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