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 bool IsSupportIpV6(); 51 52 private: 53 MDnsManager(); 54 ~MDnsManager() = default; 55 56 struct CompareSmartPointer { operator ()OHOS::NetManagerStandard::MDnsManager::CompareSmartPointer57 bool operator()(const sptr<IRemoteBroker> &lhs, const sptr<IRemoteBroker> &rhs) const 58 { 59 return lhs->AsObject().GetRefPtr() < rhs->AsObject().GetRefPtr(); 60 } 61 }; 62 void RestartDiscoverService(); 63 64 MDnsProtocolImpl impl; 65 std::map<sptr<IRegistrationCallback>, std::string, CompareSmartPointer> registerMap_; 66 std::map<sptr<IDiscoveryCallback>, std::string, CompareSmartPointer> discoveryMap_; 67 std::recursive_mutex registerMutex_; 68 std::recursive_mutex discoveryMutex_; 69 }; 70 71 } // namespace NetManagerStandard 72 } // namespace OHOS 73 74 #endif