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 31 namespace OHOS { 32 namespace FileManagement { 33 namespace CloudFile { 34 enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING }; 35 36 class CloudDaemon final : public SystemAbility, public CloudDaemonStub, protected NoCopyable { 37 DECLARE_SYSTEM_ABILITY(CloudDaemon); 38 39 public: SystemAbility(saID,runOnCreate)40 explicit CloudDaemon(int32_t saID, bool runOnCreate = true) : SystemAbility(saID, runOnCreate) {}; 41 virtual ~CloudDaemon() = default; 42 43 void OnStart() override; 44 void OnStop() override; QueryServiceState()45 ServiceRunningState QueryServiceState() const 46 { 47 return state_; 48 } 49 int32_t StartFuse(int32_t userId, int32_t deviceFd, const std::string &path) override; 50 51 private: 52 CloudDaemon(); 53 ServiceRunningState state_ { ServiceRunningState::STATE_NOT_START }; 54 static sptr<CloudDaemon> instance_; 55 static std::mutex instanceLock_; 56 bool registerToService_ { false }; 57 void PublishSA(); 58 }; 59 } // namespace CloudFile 60 } // namespace FileManagement 61 } // namespace OHOS 62 #endif // CLOUD_DAEMON_H 63