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_SERVICE_H 17 #define MDNS_SERVICE_H 18 19 #include <cstdint> 20 #include <iosfwd> 21 #include <memory> 22 #include <string> 23 #include <vector> 24 25 #include "refbase.h" 26 #include "singleton.h" 27 #include "system_ability.h" 28 29 #include "i_mdns_event.h" 30 #include "mdns_service_stub.h" 31 #include "mdns_manager.h" 32 #include "net_interface_callback.h" 33 34 namespace OHOS { 35 namespace NetManagerStandard { 36 37 class MDnsService : public SystemAbility, public MDnsServiceStub { 38 DECLARE_DELAYED_SINGLETON(MDnsService) 39 DECLARE_SYSTEM_ABILITY(MDnsService) 40 41 public: 42 enum ServiceRunningState { 43 STATE_STOPPED = 0, 44 STATE_RUNNING, 45 }; 46 47 int32_t RegisterService(const MDnsServiceInfo &serviceInfo, const sptr<IRegistrationCallback> &cb) override; 48 int32_t UnRegisterService(const sptr<IRegistrationCallback> &cb) override; 49 50 int32_t StartDiscoverService(const std::string &serviceType, const sptr<IDiscoveryCallback> &cb) override; 51 int32_t StopDiscoverService(const sptr<IDiscoveryCallback> &cb) override; 52 53 int32_t ResolveService(const MDnsServiceInfo &serviceInfo, const sptr<IResolveCallback> &cb) override; 54 55 int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override; 56 57 protected: 58 void OnStart() override; 59 void OnStop() override; 60 61 private: 62 bool Init(); 63 64 bool isRegistered_; 65 ServiceRunningState state_; 66 sptr<INetInterfaceStateCallback> netStateCallback_; 67 }; 68 } // namespace NetManagerStandard 69 } // namespace OHOS 70 71 #endif // MDNS_SERVICE_H