• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 OHOS_ROSEN_FOLD_SCREEN_STATE_MACHINE_H
17 #define OHOS_ROSEN_FOLD_SCREEN_STATE_MACHINE_H
18 
19 #include <deque>
20 #include <memory>
21 #include <mutex>
22 #include <sstream>
23 
24 #include "refbase.h"
25 #include "ws_common.h"
26 
27 namespace OHOS {
28 namespace Rosen {
29 
30 enum class FoldScreenState : uint32_t {
31     UNKNOWN,
32     FOLDED,
33     HALF_FOLDED,
34     FULL
35 };
36 
37 class TransitionCallback {
38 public:
39     ~TransitionCallback() = default;
40 
OnTransitionEnter(FoldScreenState current,FoldScreenState next)41     virtual void OnTransitionEnter(FoldScreenState current, FoldScreenState next) { };
42 
OnTransitionExit(FoldScreenState previous,FoldScreenState current)43     virtual void OnTransitionExit(FoldScreenState previous, FoldScreenState current) { };
44 };
45 
46 
47 class FoldScreenStateMachine : public RefBase {
48 public:
49     FoldScreenStateMachine();
50 
51     ~FoldScreenStateMachine();
52 
53     void TransitionTo(FoldScreenState state);
54 
55     void RegistrationTransitionCallback(const std::shared_ptr<TransitionCallback>& callback);
56 
57     void UnRegistrationTransitionCallback(const std::shared_ptr<TransitionCallback>& callback);
58 
59     FoldScreenState GetCurrentState() const;
60 
61     std::string GenStateMachineInfo() const;
62 
63 private:
64     std::deque<std::shared_ptr<TransitionCallback>> callbacks_;
65     FoldScreenState currState_ = FoldScreenState::UNKNOWN;
66     std::recursive_mutex mutex_;
67 };
68 } // namespace Rosen
69 } // namespace OHOS
70 #endif