1cb7eb8c9Sopenharmony_ci/*
2cb7eb8c9Sopenharmony_ci * Copyright (c) 2023 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#ifndef CLOUD_DAEMON_H
17cb7eb8c9Sopenharmony_ci#define CLOUD_DAEMON_H
18cb7eb8c9Sopenharmony_ci
19cb7eb8c9Sopenharmony_ci#include <memory>
20cb7eb8c9Sopenharmony_ci#include <mutex>
21cb7eb8c9Sopenharmony_ci#include <string>
22cb7eb8c9Sopenharmony_ci
23cb7eb8c9Sopenharmony_ci#include "iremote_stub.h"
24cb7eb8c9Sopenharmony_ci#include "nocopyable.h"
25cb7eb8c9Sopenharmony_ci#include "refbase.h"
26cb7eb8c9Sopenharmony_ci#include "system_ability.h"
27cb7eb8c9Sopenharmony_ci
28cb7eb8c9Sopenharmony_ci#include "cloud_daemon_stub.h"
29cb7eb8c9Sopenharmony_ci#include "i_cloud_daemon.h"
30cb7eb8c9Sopenharmony_ci#include "account_status_listener.h"
31cb7eb8c9Sopenharmony_ci
32cb7eb8c9Sopenharmony_cinamespace OHOS {
33cb7eb8c9Sopenharmony_cinamespace FileManagement {
34cb7eb8c9Sopenharmony_cinamespace CloudFile {
35cb7eb8c9Sopenharmony_cienum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING };
36cb7eb8c9Sopenharmony_ci
37cb7eb8c9Sopenharmony_ciclass CloudDaemon final : public SystemAbility, public CloudDaemonStub, protected NoCopyable {
38cb7eb8c9Sopenharmony_ci    DECLARE_SYSTEM_ABILITY(CloudDaemon);
39cb7eb8c9Sopenharmony_ci
40cb7eb8c9Sopenharmony_cipublic:
41cb7eb8c9Sopenharmony_ci    explicit CloudDaemon(int32_t saID, bool runOnCreate = true);
42cb7eb8c9Sopenharmony_ci    virtual ~CloudDaemon() = default;
43cb7eb8c9Sopenharmony_ci
44cb7eb8c9Sopenharmony_ci    void OnStart() override;
45cb7eb8c9Sopenharmony_ci    void OnStop() override;
46cb7eb8c9Sopenharmony_ci    ServiceRunningState QueryServiceState() const
47cb7eb8c9Sopenharmony_ci    {
48cb7eb8c9Sopenharmony_ci        return state_;
49cb7eb8c9Sopenharmony_ci    }
50cb7eb8c9Sopenharmony_ci    int32_t StartFuse(int32_t userId, int32_t deviceFd, const std::string &path) override;
51cb7eb8c9Sopenharmony_ci
52cb7eb8c9Sopenharmony_ciprivate:
53cb7eb8c9Sopenharmony_ci    CloudDaemon();
54cb7eb8c9Sopenharmony_ci    ServiceRunningState state_ { ServiceRunningState::STATE_NOT_START };
55cb7eb8c9Sopenharmony_ci    static sptr<CloudDaemon> instance_;
56cb7eb8c9Sopenharmony_ci    static std::mutex instanceLock_;
57cb7eb8c9Sopenharmony_ci    bool registerToService_ { false };
58cb7eb8c9Sopenharmony_ci    void PublishSA();
59cb7eb8c9Sopenharmony_ci    void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override;
60cb7eb8c9Sopenharmony_ci    std::shared_ptr<CloudDisk::AccountStatusListener> accountStatusListener_ = nullptr;
61cb7eb8c9Sopenharmony_ci};
62cb7eb8c9Sopenharmony_ci} // namespace CloudFile
63cb7eb8c9Sopenharmony_ci} // namespace FileManagement
64cb7eb8c9Sopenharmony_ci} // namespace OHOS
65cb7eb8c9Sopenharmony_ci#endif // CLOUD_DAEMON_H
66