1 /*
2  * Copyright (c) 2023-2024 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 COOPERATE_FREE_H
17 #define COOPERATE_FREE_H
18 
19 #include "nocopyable.h"
20 
21 #include "i_cooperate_state.h"
22 
23 namespace OHOS {
24 namespace Msdp {
25 namespace DeviceStatus {
26 namespace Cooperate {
27 class CooperateFree final : public ICooperateState {
28 public:
29     CooperateFree(IStateMachine &parent, IContext *env);
30     ~CooperateFree();
31     DISALLOW_COPY_AND_MOVE(CooperateFree);
32 
33     void OnEvent(Context &context, const CooperateEvent &event) override;
34     void OnEnterState(Context &context) override;
35     void OnLeaveState(Context &context) override;
GetDeviceManager()36     IDeviceManager& GetDeviceManager()
37     {
38         return env_->GetDeviceManager();
39     }
40 
41 private:
42     class Initial final : public ICooperateStep {
43     public:
44         Initial(CooperateFree &parent);
45         ~Initial() = default;
46 
47         void OnProgress(Context &context, const CooperateEvent &event) override;
48         void OnReset(Context &context, const CooperateEvent &event) override;
49 
50         static void BuildChains(std::shared_ptr<Initial> initial, CooperateFree &parent);
51         static void RemoveChains(std::shared_ptr<Initial> initial);
52 
53     private:
54         void OnStart(Context &context, const CooperateEvent &event);
55         void OnStop(Context &context, const CooperateEvent &event);
56         void OnAppClosed(Context &context, const CooperateEvent &event);
57         void OnRemoteStart(Context &context, const CooperateEvent &event);
58 
59         CooperateFree &parent_;
60     };
61 
62     bool HasLocalPointerDevice() const;
63     bool HasLocalKeyboardDevice() const;
64     void UnchainConnections(Context &context, const StopCooperateEvent &event) const;
65 
66     IContext *env_ { nullptr };
67     std::shared_ptr<Initial> initial_ { nullptr };
68 };
69 } // namespace Cooperate
70 } // namespace DeviceStatus
71 } // namespace Msdp
72 } // namespace OHOS
73 #endif // COOPERATE_FREE_H
74