• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 DAEMON_H
17 #define DAEMON_H
18 
19 #include <mutex>
20 
21 #include "daemon_stub.h"
22 #include "i_daemon.h"
23 #include "iremote_stub.h"
24 #include "multiuser/os_account_observer.h"
25 #include "system_ability.h"
26 
27 namespace OHOS {
28 namespace Storage {
29 namespace DistributedFile {
30 enum class ServiceRunningState { STATE_NOT_START, STATE_RUNNING };
31 
32 class Daemon final : public SystemAbility, public DaemonStub, protected NoCopyable {
33     DECLARE_SYSTEM_ABILITY(Daemon);
34 
35 public:
SystemAbility(saID,runOnCreate)36     explicit Daemon(int32_t saID, bool runOnCreate = true) : SystemAbility(saID, runOnCreate) {};
37     virtual ~Daemon() = default;
38 
39     void OnStart() override;
40     void OnStop() override;
QueryServiceState()41     ServiceRunningState QueryServiceState() const
42     {
43         return state_;
44     }
45 
46     int32_t EchoServerDemo(const std::string &echoStr) override;
47 
48 private:
49     Daemon();
50     ServiceRunningState state_ { ServiceRunningState::STATE_NOT_START };
51     static sptr<Daemon> instance_;
52     static std::mutex instanceLock_;
53     bool registerToService_ { false };
54     std::shared_ptr<OsAccountObserver> subScriber_;
55     void PublishSA();
56     void RegisterOsAccount();
57 };
58 } // namespace DistributedFile
59 } // namespace Storage
60 } // namespace OHOS
61 #endif // DAEMON_H