1cb7eb8c9Sopenharmony_ci/*
2cb7eb8c9Sopenharmony_ci* Copyright (c) 2024 Huawei Device Co., Ltd.
3cb7eb8c9Sopenharmony_ci* Licensed under the Apache License, Version 2.0 (the "License");
4cb7eb8c9Sopenharmony_ci* you may not use this file except in compliance with the License.
5cb7eb8c9Sopenharmony_ci* You may obtain a copy of the License at
6cb7eb8c9Sopenharmony_ci*
7cb7eb8c9Sopenharmony_ci*     http://www.apache.org/licenses/LICENSE-2.0
8cb7eb8c9Sopenharmony_ci*
9cb7eb8c9Sopenharmony_ci* Unless required by applicable law or agreed to in writing, software
10cb7eb8c9Sopenharmony_ci* distributed under the License is distributed on an "AS IS" BASIS,
11cb7eb8c9Sopenharmony_ci* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12cb7eb8c9Sopenharmony_ci* See the License for the specific language governing permissions and
13cb7eb8c9Sopenharmony_ci* limitations under the License.
14cb7eb8c9Sopenharmony_ci*/
15cb7eb8c9Sopenharmony_ci
16cb7eb8c9Sopenharmony_ci#include "daemon_eventhandler.h"
17cb7eb8c9Sopenharmony_ci
18cb7eb8c9Sopenharmony_ci#include "daemon.h"
19cb7eb8c9Sopenharmony_ci#include "utils_log.h"
20cb7eb8c9Sopenharmony_ci
21cb7eb8c9Sopenharmony_cinamespace OHOS {
22cb7eb8c9Sopenharmony_cinamespace Storage {
23cb7eb8c9Sopenharmony_cinamespace DistributedFile {
24cb7eb8c9Sopenharmony_ci
25cb7eb8c9Sopenharmony_ciDaemonEventHandler::DaemonEventHandler(const std::shared_ptr<AppExecFwk::EventRunner> &runner,
26cb7eb8c9Sopenharmony_ci                                       const std::shared_ptr<DaemonExecute> &daemonExecute)
27cb7eb8c9Sopenharmony_ci    : AppExecFwk::EventHandler(runner), daemonExecute_(daemonExecute)
28cb7eb8c9Sopenharmony_ci{
29cb7eb8c9Sopenharmony_ci    LOGI("daemon event handler create.");
30cb7eb8c9Sopenharmony_ci}
31cb7eb8c9Sopenharmony_ci
32cb7eb8c9Sopenharmony_ciDaemonEventHandler::~DaemonEventHandler()
33cb7eb8c9Sopenharmony_ci{
34cb7eb8c9Sopenharmony_ci    LOGI("daemon event handler delete.");
35cb7eb8c9Sopenharmony_ci}
36cb7eb8c9Sopenharmony_ci
37cb7eb8c9Sopenharmony_civoid DaemonEventHandler::ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event)
38cb7eb8c9Sopenharmony_ci{
39cb7eb8c9Sopenharmony_ci    if (event == nullptr) {
40cb7eb8c9Sopenharmony_ci        LOGE("event is nullptr.");
41cb7eb8c9Sopenharmony_ci        return;
42cb7eb8c9Sopenharmony_ci    }
43cb7eb8c9Sopenharmony_ci
44cb7eb8c9Sopenharmony_ci    std::shared_ptr<DaemonExecute> daemonExecute = daemonExecute_.lock();
45cb7eb8c9Sopenharmony_ci    if (daemonExecute == nullptr) {
46cb7eb8c9Sopenharmony_ci        LOGE("get DaemonExecute fail.");
47cb7eb8c9Sopenharmony_ci        return;
48cb7eb8c9Sopenharmony_ci    }
49cb7eb8c9Sopenharmony_ci    daemonExecute->ProcessEvent(event);
50cb7eb8c9Sopenharmony_ci}
51cb7eb8c9Sopenharmony_ci
52cb7eb8c9Sopenharmony_ci} // namespace DistributedFile
53cb7eb8c9Sopenharmony_ci} // namespace Storage
54cb7eb8c9Sopenharmony_ci} // namespace OHOS