1 /* 2 * Copyright (c) 2021-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 DISTRIBUTED_INPUT_SOURCE_HANDLER_H 17 #define DISTRIBUTED_INPUT_SOURCE_HANDLER_H 18 19 #include <condition_variable> 20 #include <mutex> 21 #include <string> 22 23 #include "idistributed_hardware_source.h" 24 #include "iservice_registry.h" 25 #include "single_instance.h" 26 #include "system_ability_load_callback_stub.h" 27 #include "system_ability_definition.h" 28 29 #include "distributed_input_client.h" 30 #include "distributed_input_source_manager.h" 31 #include "i_distributed_source_input.h" 32 #include "load_d_input_source_callback.h" 33 34 namespace OHOS { 35 namespace DistributedHardware { 36 namespace DistributedInput { 37 class DistributedInputSourceHandler : public IDistributedHardwareSource { 38 DECLARE_SINGLE_INSTANCE_BASE(DistributedInputSourceHandler); 39 public: 40 int32_t InitSource(const std::string ¶ms) override; 41 int32_t ReleaseSource() override; 42 int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId, 43 const EnableParam ¶m, std::shared_ptr<RegisterCallback> callback) override; 44 int32_t UnregisterDistributedHardware(const std::string &devId, const std::string &dhId, 45 std::shared_ptr<UnregisterCallback> callback) override; 46 int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &key, 47 const std::string &value) override; 48 void FinishStartSA(const std::string ¶ms, const sptr<IRemoteObject> &remoteObject); 49 void OnRemoteSourceSvrDied(const wptr<IRemoteObject> &remote); 50 51 public: 52 53 class SALoadSourceCb : public OHOS::SystemAbilityLoadCallbackStub { 54 public: 55 void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, 56 const OHOS::sptr<IRemoteObject> &remoteObject) override; 57 58 void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; 59 GetSystemAbilityId()60 int32_t GetSystemAbilityId() const 61 { 62 return currSystemAbilityId; 63 } 64 GetRemoteObject()65 OHOS::sptr<IRemoteObject> GetRemoteObject() const 66 { 67 return currRemoteObject; 68 } 69 private: 70 int32_t currSystemAbilityId = 0; 71 OHOS::sptr<OHOS::IRemoteObject> currRemoteObject; 72 }; 73 private: 74 DistributedInputSourceHandler(); 75 ~DistributedInputSourceHandler() = default; 76 class DInputSourceSvrRecipient : public IRemoteObject::DeathRecipient { 77 public: 78 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 79 }; 80 OHOS::sptr<OHOS::ISystemAbilityLoadCallback> sysSourceCallback = nullptr; 81 82 std::mutex proxyMutex_; 83 std::condition_variable proxyConVar_; 84 sptr<IDistributedSourceInput> dInputSourceProxy_ = nullptr; 85 sptr<LoadDInputSourceCallback> dInputSourceCallback_ = nullptr; 86 sptr<DInputSourceSvrRecipient> sourceSvrRecipient_ = nullptr; 87 }; 88 89 #ifdef __cplusplus 90 extern "C" { 91 #endif // __cplusplus 92 __attribute__((visibility("default"))) IDistributedHardwareSource *GetSourceHardwareHandler(); 93 #ifdef __cplusplus 94 } 95 #endif // __cplusplus 96 } // namespace DistributedInput 97 } // namespace DistributedHardware 98 } // namespace OHOS 99 100 #endif // DISTRIBUTED_INPUT_SOURCE_HANDLER_H 101