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