12d4d9a4dSopenharmony_ci/* 22d4d9a4dSopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd. 32d4d9a4dSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 42d4d9a4dSopenharmony_ci * you may not use this file except in compliance with the License. 52d4d9a4dSopenharmony_ci * You may obtain a copy of the License at 62d4d9a4dSopenharmony_ci * 72d4d9a4dSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 82d4d9a4dSopenharmony_ci * 92d4d9a4dSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 102d4d9a4dSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 112d4d9a4dSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 122d4d9a4dSopenharmony_ci * See the License for the specific language governing permissions and 132d4d9a4dSopenharmony_ci * limitations under the License. 142d4d9a4dSopenharmony_ci */ 152d4d9a4dSopenharmony_ci 162d4d9a4dSopenharmony_ci#ifndef DISTRIBUTED_INPUT_SINK_HANDLER_H 172d4d9a4dSopenharmony_ci#define DISTRIBUTED_INPUT_SINK_HANDLER_H 182d4d9a4dSopenharmony_ci 192d4d9a4dSopenharmony_ci#include <condition_variable> 202d4d9a4dSopenharmony_ci#include <mutex> 212d4d9a4dSopenharmony_ci#include <string> 222d4d9a4dSopenharmony_ci 232d4d9a4dSopenharmony_ci#include "idistributed_hardware_sink.h" 242d4d9a4dSopenharmony_ci#include "iservice_registry.h" 252d4d9a4dSopenharmony_ci#include "single_instance.h" 262d4d9a4dSopenharmony_ci#include "system_ability_definition.h" 272d4d9a4dSopenharmony_ci#include "system_ability_load_callback_stub.h" 282d4d9a4dSopenharmony_ci 292d4d9a4dSopenharmony_ci#include "distributed_input_client.h" 302d4d9a4dSopenharmony_ci#include "i_distributed_sink_input.h" 312d4d9a4dSopenharmony_ci 322d4d9a4dSopenharmony_cinamespace OHOS { 332d4d9a4dSopenharmony_cinamespace DistributedHardware { 342d4d9a4dSopenharmony_cinamespace DistributedInput { 352d4d9a4dSopenharmony_ciclass DistributedInputSinkHandler : public IDistributedHardwareSink { 362d4d9a4dSopenharmony_ciDECLARE_SINGLE_INSTANCE_BASE(DistributedInputSinkHandler); 372d4d9a4dSopenharmony_cipublic: 382d4d9a4dSopenharmony_ci int32_t InitSink(const std::string ¶ms) override; 392d4d9a4dSopenharmony_ci int32_t ReleaseSink() override; 402d4d9a4dSopenharmony_ci int32_t SubscribeLocalHardware(const std::string &dhId, const std::string ¶ms) override; 412d4d9a4dSopenharmony_ci int32_t UnsubscribeLocalHardware(const std::string &dhId) override; 422d4d9a4dSopenharmony_ci void OnRemoteSinkSvrDied(const wptr<IRemoteObject> &remote); 432d4d9a4dSopenharmony_ci void FinishStartSA(const std::string ¶ms, const sptr<IRemoteObject> &remoteObject); 442d4d9a4dSopenharmony_ci int32_t RegisterPrivacyResources(std::shared_ptr<PrivacyResourcesListener> listener) override; 452d4d9a4dSopenharmony_ci int32_t PauseDistributedHardware(const std::string &networkId) override; 462d4d9a4dSopenharmony_ci int32_t ResumeDistributedHardware(const std::string &networkId) override; 472d4d9a4dSopenharmony_ci int32_t StopDistributedHardware(const std::string &networkId) override; 482d4d9a4dSopenharmony_ci 492d4d9a4dSopenharmony_cipublic: 502d4d9a4dSopenharmony_ci class SALoadSinkCb : public OHOS::SystemAbilityLoadCallbackStub { 512d4d9a4dSopenharmony_ci public: 522d4d9a4dSopenharmony_ci void OnLoadSystemAbilitySuccess(int32_t systemAbilityId, 532d4d9a4dSopenharmony_ci const OHOS::sptr<IRemoteObject> &remoteObject) override; 542d4d9a4dSopenharmony_ci 552d4d9a4dSopenharmony_ci void OnLoadSystemAbilityFail(int32_t systemAbilityId) override; 562d4d9a4dSopenharmony_ci 572d4d9a4dSopenharmony_ci int32_t GetSystemAbilityId() const 582d4d9a4dSopenharmony_ci { 592d4d9a4dSopenharmony_ci return currSystemAbilityId; 602d4d9a4dSopenharmony_ci } 612d4d9a4dSopenharmony_ci 622d4d9a4dSopenharmony_ci OHOS::sptr<IRemoteObject> GetRemoteObject() const 632d4d9a4dSopenharmony_ci { 642d4d9a4dSopenharmony_ci return currRemoteObject; 652d4d9a4dSopenharmony_ci } 662d4d9a4dSopenharmony_ci private: 672d4d9a4dSopenharmony_ci int32_t currSystemAbilityId = 0; 682d4d9a4dSopenharmony_ci OHOS::sptr<OHOS::IRemoteObject> currRemoteObject; 692d4d9a4dSopenharmony_ci }; 702d4d9a4dSopenharmony_ci 712d4d9a4dSopenharmony_ciprivate: 722d4d9a4dSopenharmony_ci class DInputSinkSvrRecipient : public IRemoteObject::DeathRecipient { 732d4d9a4dSopenharmony_ci public: 742d4d9a4dSopenharmony_ci void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 752d4d9a4dSopenharmony_ci }; 762d4d9a4dSopenharmony_ci DistributedInputSinkHandler(); 772d4d9a4dSopenharmony_ci ~DistributedInputSinkHandler(); 782d4d9a4dSopenharmony_ci OHOS::sptr<OHOS::ISystemAbilityLoadCallback> sysSinkCallback = nullptr; 792d4d9a4dSopenharmony_ci 802d4d9a4dSopenharmony_ci sptr<IDistributedSinkInput> dInputSinkProxy_ = nullptr; 812d4d9a4dSopenharmony_ci sptr<DInputSinkSvrRecipient> sinkSvrRecipient_ = nullptr; 822d4d9a4dSopenharmony_ci std::mutex proxyMutex_; 832d4d9a4dSopenharmony_ci std::condition_variable proxyConVar_; 842d4d9a4dSopenharmony_ci}; 852d4d9a4dSopenharmony_ci 862d4d9a4dSopenharmony_ci#ifdef __cplusplus 872d4d9a4dSopenharmony_ciextern "C" { 882d4d9a4dSopenharmony_ci#endif 892d4d9a4dSopenharmony_ci__attribute__((visibility("default"))) IDistributedHardwareSink *GetSinkHardwareHandler(); 902d4d9a4dSopenharmony_ci#ifdef __cplusplus 912d4d9a4dSopenharmony_ci} 922d4d9a4dSopenharmony_ci#endif 932d4d9a4dSopenharmony_ci} // namespace DistributedInput 942d4d9a4dSopenharmony_ci} // namespace DistributedHardware 952d4d9a4dSopenharmony_ci} // namespace OHOS 962d4d9a4dSopenharmony_ci 972d4d9a4dSopenharmony_ci#endif // DISTRIBUTED_INPUT_SINK_HANDLER_H 98