/* * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef DINPUT_SA_MANAGER_H #define DINPUT_SA_MANAGER_H #include #include #include #include "i_distributed_source_input.h" #include "i_distributed_sink_input.h" #include "single_instance.h" #include "system_ability_status_change_stub.h" #include "idistributed_hardware_source.h" #include "idistributed_hardware_sink.h" #include "event_handler.h" namespace OHOS { namespace DistributedHardware { namespace DistributedInput { const uint32_t DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG = 1; const uint32_t DINPUT_CLIENT_CHECK_SINK_CALLBACK_REGISTER_MSG = 2; const uint32_t DINPUT_CLIENT_CLEAR_SOURCE_CALLBACK_REGISTER_MSG = 3; const uint32_t DINPUT_CLIENT_CLEAR_SINK_CALLBACK_REGISTER_MSG = 4; class DInputSAManager { DECLARE_SINGLE_INSTANCE_BASE(DInputSAManager); public: void Init(); bool GetDInputSourceProxy(); bool HasDInputSourceProxy(); bool SetDInputSourceProxy(const sptr &remoteObject); bool GetDInputSinkProxy(); bool HasDInputSinkProxy(); bool SetDInputSinkProxy(const sptr &remoteObject); void RegisterEventHandler(std::shared_ptr handler); int32_t RestoreRegisterListenerAndCallback(); void AddSimEventListenerToCache(sptr listener); void RemoveSimEventListenerFromCache(sptr listener); void AddSessionStateCbToCache(sptr callback); void RemoveSessionStateCbFromCache(); public: class SystemAbilityListener : public SystemAbilityStatusChangeStub { public: void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; }; private: std::mutex simEventListenerCacheMtx_; std::set> simEventListenerCache_; std::mutex sessionStateCbCacheMtx_; std::set> sessionStateCbCache_; private: DInputSAManager() = default; ~DInputSAManager() = default; public: std::atomic dInputSourceSAOnline_ = false; std::atomic dInputSinkSAOnline_ = false; std::atomic isSubscribeSrcSAChangeListener_ = false; std::atomic isSubscribeSinkSAChangeListener_ = false; std::mutex sinkMutex_; std::mutex sourceMutex_; std::mutex handlerMutex_; sptr dInputSourceProxy_ = nullptr; sptr dInputSinkProxy_ = nullptr; sptr saListenerCallback = nullptr; std::shared_ptr eventHandler_; }; } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS #endif // DINPUT_SA_MANAGER_H