1 /* 2 * Copyright (C) 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 MDNS_MANDGER_H 17 #define MDNS_MANDGER_H 18 19 #include <cstdint> 20 #include <map> 21 #include <string> 22 23 #include "parcel.h" 24 25 #include "i_mdns_event.h" 26 #include "mdns_common.h" 27 #include "mdns_protocol_impl.h" 28 #include "mdns_service_info.h" 29 30 namespace OHOS { 31 namespace NetManagerStandard { 32 33 class MDnsManager { 34 public: 35 static MDnsManager &GetInstance(); 36 37 void RestartMDnsProtocolImpl(); 38 39 int32_t RegisterService(const MDnsServiceInfo &serviceInfo, const sptr<IRegistrationCallback> &cb); 40 int32_t UnRegisterService(const sptr<IRegistrationCallback> &cb); 41 42 int32_t StartDiscoverService(const std::string &serviceType, const sptr<IDiscoveryCallback> &cb); 43 int32_t StopDiscoverService(const sptr<IDiscoveryCallback> &cb); 44 45 int32_t ResolveService(const MDnsServiceInfo &serviceInfo, const sptr<IResolveCallback> &cb); 46 47 void GetDumpMessage(std::string &message); 48 bool IsAvailableCallback(const sptr<IDiscoveryCallback> &cb); 49 bool IsAvailableCallback(const sptr<IResolveCallback> &cb); 50 51 private: 52 MDnsManager(); 53 ~MDnsManager() = default; 54 55 struct CompareSmartPointer { operatorCompareSmartPointer56 bool operator()(const sptr<IRemoteBroker> &lhs, const sptr<IRemoteBroker> &rhs) const 57 { 58 return lhs->AsObject().GetRefPtr() < rhs->AsObject().GetRefPtr(); 59 } 60 }; 61 void RestartDiscoverService(); 62 63 MDnsProtocolImpl impl; 64 std::map<sptr<IRegistrationCallback>, std::string, CompareSmartPointer> registerMap_; 65 std::map<sptr<IDiscoveryCallback>, std::string, CompareSmartPointer> discoveryMap_; 66 std::recursive_mutex registerMutex_; 67 std::recursive_mutex discoveryMutex_; 68 }; 69 70 } // namespace NetManagerStandard 71 } // namespace OHOS 72 73 #endif