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_SINK_HANDLER_H 17 #define DISTRIBUTED_INPUT_SINK_HANDLER_H 18 19 #include <condition_variable> 20 #include <mutex> 21 #include <string> 22 23 #include "idistributed_hardware_sink.h" 24 #include "iservice_registry.h" 25 #include "single_instance.h" 26 #include "system_ability_definition.h" 27 #include "system_ability_load_callback_stub.h" 28 29 #include "distributed_input_client.h" 30 31 namespace OHOS { 32 namespace DistributedHardware { 33 namespace DistributedInput { 34 class DistributedInputSinkHandler : public IDistributedHardwareSink { 35 DECLARE_SINGLE_INSTANCE_BASE(DistributedInputSinkHandler); 36 public: 37 int32_t InitSink(const std::string ¶ms) override; 38 int32_t ReleaseSink() override; 39 int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶ms) override; 40 int32_t UnsubscribeLocalHardware(const std::string &dhId) override; 41 void FinishStartSA(const std::string ¶ms, const sptr<IRemoteObject> &remoteObject); 42 43 public: 44 class SALoadSinkCb : public OHOS::SystemAbilityLoadCallbackStub { 45 public: 46 void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, 47 const OHOS::sptr<IRemoteObject> &remoteObject) override; 48 49 void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; 50 GetSystemAbilityId()51 int32_t GetSystemAbilityId() const 52 { 53 return currSystemAbilityId; 54 } 55 GetRemoteObject()56 OHOS::sptr<IRemoteObject> GetRemoteObject() const 57 { 58 return currRemoteObject; 59 } 60 private: 61 int32_t currSystemAbilityId = 0; 62 OHOS::sptr<OHOS::IRemoteObject> currRemoteObject; 63 }; 64 65 private: 66 DistributedInputSinkHandler() = default; 67 ~DistributedInputSinkHandler(); 68 OHOS::sptr<OHOS::ISystemAbilityLoadCallback> sysSinkCallback = nullptr; 69 70 std::mutex proxyMutex_; 71 std::condition_variable proxyConVar_; 72 }; 73 74 #ifdef __cplusplus 75 extern "C" { 76 #endif 77 __attribute__((visibility("default"))) IDistributedHardwareSink *GetSinkHardwareHandler(); 78 #ifdef __cplusplus 79 } 80 #endif 81 } // namespace DistributedInput 82 } // namespace DistributedHardware 83 } // namespace OHOS 84 85 #endif // DISTRIBUTED_INPUT_SINK_HANDLER_H 86