• 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_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 
33 namespace OHOS {
34 namespace NetManagerStandard {
35 
36 class MDnsService : public SystemAbility, public MDnsServiceStub {
37     DECLARE_DELAYED_SINGLETON(MDnsService)
38     DECLARE_SYSTEM_ABILITY(MDnsService)
39 
40 public:
41     enum ServiceRunningState {
42         STATE_STOPPED = 0,
43         STATE_RUNNING,
44     };
45 
46     int32_t RegisterService(const MDnsServiceInfo &serviceInfo, const sptr<IRegistrationCallback> &cb) override;
47     int32_t UnRegisterService(const sptr<IRegistrationCallback> &cb) override;
48 
49     int32_t StartDiscoverService(const std::string &serviceType, const sptr<IDiscoveryCallback> &cb) override;
50     int32_t StopDiscoverService(const sptr<IDiscoveryCallback> &cb) override;
51 
52     int32_t ResolveService(const MDnsServiceInfo &serviceInfo, const sptr<IResolveCallback> &cb) override;
53 
54     int32_t Dump(int32_t fd, const std::vector<std::u16string> &args) override;
55 
56 protected:
57     void OnStart() override;
58     void OnStop() override;
59 
60 private:
61     bool Init();
62 
63     bool isRegistered_;
64     ServiceRunningState state_;
65     MDnsManager manager_;
66 };
67 } // namespace NetManagerStandard
68 } // namespace OHOS
69 
70 #endif // MDNS_SERVICE_H