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 32 namespace OHOS { 33 namespace DistributedHardware { 34 namespace DistributedInput { 35 class DistributedInputSourceHandler : public IDistributedHardwareSource { 36 DECLARE_SINGLE_INSTANCE_BASE(DistributedInputSourceHandler); 37 public: 38 int32_t InitSource(const std::string ¶ms) override; 39 int32_t ReleaseSource() override; 40 int32_t RegisterDistributedHardware(const std::string &devId, const std::string &dhId, 41 const EnableParam ¶m, std::shared_ptr<RegisterCallback> callback) override; 42 int32_t UnregisterDistributedHardware(const std::string &devId, const std::string &dhId, 43 std::shared_ptr<UnregisterCallback> callback) override; 44 int32_t ConfigDistributedHardware(const std::string &devId, const std::string &dhId, const std::string &key, 45 const std::string &value) override; 46 void FinishStartSA(const std::string ¶ms, const sptr<IRemoteObject> &remoteObject); 47 48 public: 49 50 class SALoadSourceCb : public OHOS::SystemAbilityLoadCallbackStub { 51 public: 52 void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, 53 const OHOS::sptr<IRemoteObject> &remoteObject) override; 54 55 void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; 56 GetSystemAbilityId()57 int32_t GetSystemAbilityId() const 58 { 59 return currSystemAbilityId; 60 } 61 GetRemoteObject()62 OHOS::sptr<IRemoteObject> GetRemoteObject() const 63 { 64 return currRemoteObject; 65 } 66 private: 67 int32_t currSystemAbilityId = 0; 68 OHOS::sptr<OHOS::IRemoteObject> currRemoteObject; 69 }; 70 private: 71 DistributedInputSourceHandler() = default; 72 ~DistributedInputSourceHandler(); 73 OHOS::sptr<OHOS::ISystemAbilityLoadCallback> sysSourceCallback = nullptr; 74 75 std::mutex proxyMutex_; 76 std::condition_variable proxyConVar_; 77 }; 78 79 #ifdef __cplusplus 80 extern "C" { 81 #endif // __cplusplus 82 __attribute__((visibility("default"))) IDistributedHardwareSource *GetSourceHardwareHandler(); 83 #ifdef __cplusplus 84 } 85 #endif // __cplusplus 86 } // namespace DistributedInput 87 } // namespace DistributedHardware 88 } // namespace OHOS 89 90 #endif // DISTRIBUTED_INPUT_SOURCE_HANDLER_H 91