1f857971dSopenharmony_ci/* 2f857971dSopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3f857971dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4f857971dSopenharmony_ci * you may not use this file except in compliance with the License. 5f857971dSopenharmony_ci * You may obtain a copy of the License at 6f857971dSopenharmony_ci * 7f857971dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8f857971dSopenharmony_ci * 9f857971dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10f857971dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11f857971dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12f857971dSopenharmony_ci * See the License for the specific language governing permissions and 13f857971dSopenharmony_ci * limitations under the License. 14f857971dSopenharmony_ci */ 15f857971dSopenharmony_ci 16f857971dSopenharmony_ci#ifndef COOPERATE_STATE_MACHINE_H 17f857971dSopenharmony_ci#define COOPERATE_STATE_MACHINE_H 18f857971dSopenharmony_ci 19f857971dSopenharmony_ci#include "nocopyable.h" 20f857971dSopenharmony_ci 21f857971dSopenharmony_ci#include "accesstoken_kit.h" 22f857971dSopenharmony_ci#include "app_mgr_interface.h" 23f857971dSopenharmony_ci#include "application_state_observer_stub.h" 24f857971dSopenharmony_ci#include "iapplication_state_observer.h" 25f857971dSopenharmony_ci 26f857971dSopenharmony_ci#include "i_common_event_adapter.h" 27f857971dSopenharmony_ci#include "i_cooperate_state.h" 28f857971dSopenharmony_ci 29f857971dSopenharmony_cinamespace OHOS { 30f857971dSopenharmony_cinamespace Msdp { 31f857971dSopenharmony_cinamespace DeviceStatus { 32f857971dSopenharmony_cinamespace Cooperate { 33f857971dSopenharmony_ciclass StateMachine final : public IStateMachine { 34f857971dSopenharmony_cipublic: 35f857971dSopenharmony_ci StateMachine(IContext *env); 36f857971dSopenharmony_ci ~StateMachine() = default; 37f857971dSopenharmony_ci DISALLOW_COPY_AND_MOVE(StateMachine); 38f857971dSopenharmony_ci 39f857971dSopenharmony_ci void OnEvent(Context &context, const CooperateEvent &event); 40f857971dSopenharmony_ci bool IsCooperateEnable(); 41f857971dSopenharmony_ci 42f857971dSopenharmony_ciprivate: 43f857971dSopenharmony_ci class AppStateObserver final : public AppExecFwk::ApplicationStateObserverStub { 44f857971dSopenharmony_ci public: 45f857971dSopenharmony_ci AppStateObserver(Channel<CooperateEvent>::Sender sender, int32_t clientPid); 46f857971dSopenharmony_ci ~AppStateObserver() = default; 47f857971dSopenharmony_ci void UpdateClientPid(int32_t clientPid); 48f857971dSopenharmony_ci void OnProcessDied(const AppExecFwk::ProcessData &processData) override; 49f857971dSopenharmony_ci 50f857971dSopenharmony_ci private: 51f857971dSopenharmony_ci Channel<CooperateEvent>::Sender sender_; 52f857971dSopenharmony_ci int32_t clientPid_; 53f857971dSopenharmony_ci }; 54f857971dSopenharmony_ci 55f857971dSopenharmony_ciprivate: 56f857971dSopenharmony_ci void TransiteTo(Context &context, CooperateState state) override; 57f857971dSopenharmony_ci void AddHandler(CooperateEventType event, std::function<void(Context&, const CooperateEvent&)> handler); 58f857971dSopenharmony_ci void OnQuit(Context &context); 59f857971dSopenharmony_ci void AddObserver(Context &context, const CooperateEvent &event); 60f857971dSopenharmony_ci void RemoveObserver(Context &context, const CooperateEvent &event); 61f857971dSopenharmony_ci void RegisterListener(Context &context, const CooperateEvent &event); 62f857971dSopenharmony_ci void UnregisterListener(Context &context, const CooperateEvent &event); 63f857971dSopenharmony_ci void RegisterHotAreaListener(Context &context, const CooperateEvent &event); 64f857971dSopenharmony_ci void UnregisterHotAreaListener(Context &context, const CooperateEvent &event); 65f857971dSopenharmony_ci void EnableCooperate(Context &context, const CooperateEvent &event); 66f857971dSopenharmony_ci void DisableCooperate(Context &context, const CooperateEvent &event); 67f857971dSopenharmony_ci void StartCooperate(Context &context, const CooperateEvent &event); 68f857971dSopenharmony_ci void StopCooperate(Context &context, const CooperateEvent &event); 69f857971dSopenharmony_ci void GetCooperateState(Context &context, const CooperateEvent &event); 70f857971dSopenharmony_ci void RegisterEventListener(Context &context, const CooperateEvent &event); 71f857971dSopenharmony_ci void UnregisterEventListener(Context &context, const CooperateEvent &event); 72f857971dSopenharmony_ci void OnBoardOnline(Context &context, const CooperateEvent &event); 73f857971dSopenharmony_ci void OnBoardOffline(Context &context, const CooperateEvent &event); 74f857971dSopenharmony_ci void OnProfileChanged(Context &context, const CooperateEvent &event); 75f857971dSopenharmony_ci void OnPointerEvent(Context &context, const CooperateEvent &event); 76f857971dSopenharmony_ci void OnSoftbusSubscribeMouseLocation(Context &context, const CooperateEvent &event); 77f857971dSopenharmony_ci void OnProcessClientDied(Context &context, const CooperateEvent &event); 78f857971dSopenharmony_ci void OnSoftbusUnSubscribeMouseLocation(Context &context, const CooperateEvent &event); 79f857971dSopenharmony_ci void OnSoftbusReplySubscribeMouseLocation(Context &context, const CooperateEvent &event); 80f857971dSopenharmony_ci void OnSoftbusReplyUnSubscribeMouseLocation(Context &context, const CooperateEvent &event); 81f857971dSopenharmony_ci void OnSoftbusMouseLocation(Context &context, const CooperateEvent &event); 82f857971dSopenharmony_ci void OnSoftbusSessionClosed(Context &context, const CooperateEvent &event); 83f857971dSopenharmony_ci void OnSoftbusSessionOpened(Context &context, const CooperateEvent &event); 84f857971dSopenharmony_ci void OnHotPlugEvent(Context &context, const CooperateEvent &event); 85f857971dSopenharmony_ci void OnRemoteStart(Context &context, const CooperateEvent &event); 86f857971dSopenharmony_ci void OnRemoteHotPlug(Context &context, const CooperateEvent &event); 87f857971dSopenharmony_ci void OnRemoteInputDevice(Context &context, const CooperateEvent &event); 88f857971dSopenharmony_ci void Transfer(Context &context, const CooperateEvent &event); 89f857971dSopenharmony_ci sptr<AppExecFwk::IAppMgr> GetAppMgr(); 90f857971dSopenharmony_ci int32_t RegisterApplicationStateObserver(Channel<CooperateEvent>::Sender sender, const EnableCooperateEvent &event); 91f857971dSopenharmony_ci std::string GetPackageName(Security::AccessToken::AccessTokenID tokenId); 92f857971dSopenharmony_ci void UnregisterApplicationStateObserver(); 93f857971dSopenharmony_ci void UpdateApplicationStateObserver(int32_t clientPid); 94f857971dSopenharmony_ci void AddSessionObserver(Context &context, const EnableCooperateEvent &event); 95f857971dSopenharmony_ci void RemoveSessionObserver(Context &context, const DisableCooperateEvent &event); 96f857971dSopenharmony_ci void OnCommonEvent(Context &context, const std::string &commonEvent); 97f857971dSopenharmony_ci void AddMonitor(Context &context); 98f857971dSopenharmony_ci void RemoveMonitor(Context &context); 99f857971dSopenharmony_ci void RemoveWatches(Context &context); 100f857971dSopenharmony_ci 101f857971dSopenharmony_ci IContext *env_ { nullptr }; 102f857971dSopenharmony_ci std::map<CooperateEventType, std::function<void(Context&, const CooperateEvent&)>> handlers_; 103f857971dSopenharmony_ci size_t current_ { COOPERATE_STATE_FREE }; 104f857971dSopenharmony_ci std::array<std::shared_ptr<ICooperateState>, N_COOPERATE_STATES> states_; 105f857971dSopenharmony_ci std::set<std::string> onlineBoards_; 106f857971dSopenharmony_ci int32_t monitorId_ { -1 }; 107f857971dSopenharmony_ci int32_t screenEventTimer_ { -1 }; 108f857971dSopenharmony_ci std::vector<std::string> clientBundleNames_; 109f857971dSopenharmony_ci sptr<AppStateObserver> appStateObserver_ { nullptr }; 110f857971dSopenharmony_ci std::shared_ptr<ICommonEventObserver> observer_ { nullptr }; 111f857971dSopenharmony_ci bool isCooperateEnable_ { false }; 112f857971dSopenharmony_ci}; 113f857971dSopenharmony_ci} // namespace Cooperate 114f857971dSopenharmony_ci} // namespace DeviceStatus 115f857971dSopenharmony_ci} // namespace Msdp 116f857971dSopenharmony_ci} // namespace OHOS 117f857971dSopenharmony_ci#endif // COOPERATE_STATE_MACHINE_H 118