• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     MDnsManager();
36     ~MDnsManager() = default;
37     int32_t RegisterService(const MDnsServiceInfo &serviceInfo, const sptr<IRegistrationCallback> &cb);
38     int32_t UnRegisterService(const sptr<IRegistrationCallback> &cb);
39 
40     int32_t StartDiscoverService(const std::string &serviceType, const sptr<IDiscoveryCallback> &cb);
41     int32_t StopDiscoverService(const sptr<IDiscoveryCallback> &cb);
42 
43     int32_t ResolveService(const MDnsServiceInfo &serviceInfo, const sptr<IResolveCallback> &cb);
44 
45     void GetDumpMessage(std::string &message);
46 
47 private:
48     void InitHandler();
49     void ReceiveResult(const MDnsProtocolImpl::Result &result, int32_t error);
50     MDnsServiceInfo ConvertResultToInfo(const MDnsProtocolImpl::Result &result);
51     void ReceiveRegister(const MDnsProtocolImpl::Result &result, int32_t error);
52     void ReceiveDiscover(const MDnsProtocolImpl::Result &result, int32_t error);
53     void ReceiveInstanceResolve(const MDnsProtocolImpl::Result &result, int32_t error);
54     void ReceiveResolve(const MDnsProtocolImpl::Result &result, int32_t error);
55 
56     struct CompareSmartPointer {
operatorCompareSmartPointer57         template <class T> bool operator()(const T &lhs, const T &rhs) const
58         {
59             return lhs.GetRefPtr() < rhs.GetRefPtr();
60         }
61     };
62 
63     MDnsProtocolImpl impl;
64     std::vector<std::pair<sptr<IRegistrationCallback>, std::string>> registerMap_;
65     std::vector<std::pair<sptr<IDiscoveryCallback>, std::string>> discoveryMap_;
66     std::vector<std::pair<sptr<IResolveCallback>, std::string>> resolveMap_;
67     std::list<MDnsProtocolImpl::Result> resolvResults_;
68     std::mutex mutex_;
69 };
70 
71 } // namespace NetManagerStandard
72 } // namespace OHOS
73 
74 #endif