1 /*
2 * Copyright (c) 2025 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 "exit_dfwk_task.h"
17
18 #include <pthread.h>
19 #include <thread>
20
21 #include "ffrt.h"
22
23 #include "anonymous_string.h"
24 #include "distributed_hardware_errno.h"
25 #include "distributed_hardware_log.h"
26 #include "distributed_hardware_manager_factory.h"
27 #include "task_board.h"
28
29 namespace OHOS {
30 namespace DistributedHardware {
31
32 #undef DH_LOG_TAG
33 #define DH_LOG_TAG "ExitDfwkTask"
34
35 namespace {
36 constexpr int32_t WAIT_TIME_SEC = 5;
37 }
38
ExitDfwkTask(const std::string & networkId,const std::string & uuid,const std::string & udid,const std::string & dhId,const DHType dhType)39 ExitDfwkTask::ExitDfwkTask(const std::string &networkId, const std::string &uuid, const std::string &udid,
40 const std::string &dhId, const DHType dhType) : Task(networkId, uuid, udid, dhId, dhType)
41 {
42 SetTaskType(TaskType::EXIT_DFWK);
43 DHLOGD("ExitDfwkTask id: %{public}s", GetId().c_str());
44 }
45
~ExitDfwkTask()46 ExitDfwkTask::~ExitDfwkTask()
47 {
48 DHLOGD("id = %{public}s", GetId().c_str());
49 }
50
DoTask()51 void ExitDfwkTask::DoTask()
52 {
53 ffrt::submit([this]() { this->DoTaskInner(); });
54 }
55
DoTaskInner()56 void ExitDfwkTask::DoTaskInner()
57 {
58 DHLOGI("do exit dfwk task bebin!");
59 std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME_SEC));
60 DistributedHardwareManagerFactory::GetInstance().CheckExitSAOrNot();
61 DHLOGI("do exit dfwk task end!");
62 }
63 } // namespace DistributedHardware
64 } // namespace OHOS
65