1 /* 2 * Copyright (c) 2022 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 DINPUT_SA_MANAGER_H 17 #define DINPUT_SA_MANAGER_H 18 19 #include <atomic> 20 #include <mutex> 21 22 #include "i_distributed_source_input.h" 23 #include "i_distributed_sink_input.h" 24 #include "single_instance.h" 25 #include "system_ability_status_change_stub.h" 26 27 #include "idistributed_hardware_source.h" 28 #include "idistributed_hardware_sink.h" 29 #include "event_handler.h" 30 31 namespace OHOS { 32 namespace DistributedHardware { 33 namespace DistributedInput { 34 const uint32_t DINPUT_CLIENT_CHECK_SOURCE_CALLBACK_REGISTER_MSG = 1; 35 const uint32_t DINPUT_CLIENT_CHECK_SINK_CALLBACK_REGISTER_MSG = 2; 36 const uint32_t DINPUT_CLIENT_CLEAR_SOURCE_CALLBACK_REGISTER_MSG = 3; 37 const uint32_t DINPUT_CLIENT_CLEAR_SINK_CALLBACK_REGISTER_MSG = 4; 38 class DInputSAManager { 39 DECLARE_SINGLE_INSTANCE_BASE(DInputSAManager); 40 public: 41 void Init(); 42 bool GetDInputSourceProxy(); 43 bool HasDInputSourceProxy(); 44 bool SetDInputSourceProxy(const sptr<IRemoteObject> &remoteObject); 45 bool GetDInputSinkProxy(); 46 bool HasDInputSinkProxy(); 47 bool SetDInputSinkProxy(const sptr<IRemoteObject> &remoteObject); 48 void RegisterEventHandler(std::shared_ptr<AppExecFwk::EventHandler> handler); 49 50 public: 51 class SystemAbilityListener : public SystemAbilityStatusChangeStub { 52 public: 53 void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 54 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; 55 }; 56 57 private: 58 DInputSAManager() = default; 59 ~DInputSAManager() = default; 60 61 public: 62 std::atomic<bool> dInputSourceSAOnline = false; 63 std::atomic<bool> dInputSinkSAOnline = false; 64 std::atomic<bool> isSubscribeSrcSAChangeListener = false; 65 std::atomic<bool> isSubscribeSinkSAChangeListener = false; 66 std::mutex sinkMutex_; 67 std::mutex sourceMutex_; 68 std::mutex handlerMutex_; 69 70 sptr<IDistributedSourceInput> dInputSourceProxy_ = nullptr; 71 sptr<IDistributedSinkInput> dInputSinkProxy_ = nullptr; 72 sptr<SystemAbilityListener> saListenerCallback = nullptr; 73 74 std::shared_ptr<AppExecFwk::EventHandler> eventHandler_; 75 }; 76 } // namespace DistributedInput 77 } // namespace DistributedHardware 78 } // namespace OHOS 79 80 #endif // DINPUT_SA_MANAGER_H