1 /* 2 * Copyright (c) 2022-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 OHOS_DISTRIBUTED_INPUT_SOURCE_SA_CLI_MGR_H 17 #define OHOS_DISTRIBUTED_INPUT_SOURCE_SA_CLI_MGR_H 18 19 #include <map> 20 #include <memory> 21 #include <mutex> 22 #include <string> 23 24 #include "event_handler.h" 25 26 #include "i_distributed_source_input.h" 27 #include "single_instance.h" 28 29 namespace OHOS { 30 namespace DistributedHardware { 31 namespace DistributedInput { 32 class DInputSourceSACliMgr { 33 DECLARE_SINGLE_INSTANCE_BASE(DInputSourceSACliMgr); 34 public: 35 DInputSourceSACliMgr(); 36 virtual ~DInputSourceSACliMgr(); 37 38 sptr<IDistributedSourceInput> GetRemoteCli(const std::string &deviceId); 39 40 private: 41 class RemoteCliDeathRecipient : public IRemoteObject::DeathRecipient { 42 public: 43 void OnRemoteDied(const wptr<IRemoteObject> &remote) override; 44 }; 45 sptr<RemoteCliDeathRecipient> remoteCliDeathRcv; 46 sptr<IDistributedSourceInput> GetRemoteCliFromCache(const std::string &devId); 47 void AddRemoteCli(const std::string &devId, sptr<IRemoteObject> object); 48 void DeleteRemoteCli(const std::string &devId); 49 void DeleteRemoteCli(const sptr<IRemoteObject> remote); 50 void ProcRemoteCliDied(const sptr<IRemoteObject> &remote); 51 52 private: 53 std::mutex remoteCliLock; 54 std::map<std::string, sptr<IDistributedSourceInput>> remoteCliMap; 55 std::shared_ptr<AppExecFwk::EventHandler> dinputMgrHandler_; 56 }; 57 } 58 } 59 } 60 #endif