LCOV - code coverage report
Current view: top level - lib/dnssd - MinimalMdnsServer.cpp (source / functions) Hit Total Coverage
Test: lcov_final.info Lines: 15 15 100.0 %
Date: 2024-02-15 08:20:41 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  *    Copyright (c) 2021 Project CHIP Authors
       4             :  *
       5             :  *    Licensed under the Apache License, Version 2.0 (the "License");
       6             :  *    you may not use this file except in compliance with the License.
       7             :  *    You may obtain a copy of the License at
       8             :  *
       9             :  *        http://www.apache.org/licenses/LICENSE-2.0
      10             :  *
      11             :  *    Unless required by applicable law or agreed to in writing, software
      12             :  *    distributed under the License is distributed on an "AS IS" BASIS,
      13             :  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      14             :  *    See the License for the specific language governing permissions and
      15             :  *    limitations under the License.
      16             :  */
      17             : #include "MinimalMdnsServer.h"
      18             : 
      19             : #include <lib/dnssd/minimal_mdns/AddressPolicy.h>
      20             : 
      21             : #ifndef CHIP_MINMDNS_DEFAULT_POLICY
      22             : #define CHIP_MINMDNS_DEFAULT_POLICY 0
      23             : #endif
      24             : 
      25             : #ifndef CHIP_MINMDNS_LIBNL_POLICY
      26             : #define CHIP_MINMDNS_LIBNL_POLICY 0
      27             : #endif
      28             : 
      29             : #if CHIP_MINMDNS_DEFAULT_POLICY
      30             : #include <lib/dnssd/minimal_mdns/AddressPolicy_DefaultImpl.h> // nogncheck
      31             : #endif
      32             : 
      33             : #if CHIP_MINMDNS_LIBNL_POLICY
      34             : #include <lib/dnssd/minimal_mdns/AddressPolicy_LibNlImpl.h> // nogncheck
      35             : #endif
      36             : 
      37             : namespace chip {
      38             : namespace Dnssd {
      39             : 
      40             : using namespace mdns::Minimal;
      41             : using chip::Platform::UniquePtr;
      42             : 
      43          30 : GlobalMinimalMdnsServer::GlobalMinimalMdnsServer()
      44             : {
      45          30 :     mServer.SetDelegate(this);
      46             : 
      47             : #if CHIP_MINMDNS_DEFAULT_POLICY
      48          30 :     mdns::Minimal::SetDefaultAddressPolicy();
      49             : #endif
      50             : 
      51             : #if CHIP_MINMDNS_LIBNL_POLICY
      52             :     mdns::Minimal::LibNl::SetAddressPolicy();
      53             : #endif
      54          30 : }
      55             : 
      56         230 : GlobalMinimalMdnsServer & GlobalMinimalMdnsServer::Instance()
      57             : {
      58         230 :     static GlobalMinimalMdnsServer _instance;
      59         230 :     return _instance;
      60             : }
      61             : 
      62          17 : CHIP_ERROR GlobalMinimalMdnsServer::StartServer(chip::Inet::EndPointManager<chip::Inet::UDPEndPoint> * udpEndPointManager,
      63             :                                                 uint16_t port)
      64             : {
      65          17 :     GlobalMinimalMdnsServer::Server().ShutdownEndpoints();
      66             : 
      67          17 :     UniquePtr<ListenIterator> endpoints = GetAddressPolicy()->GetListenEndpoints();
      68             : 
      69          17 :     return GlobalMinimalMdnsServer::Server().Listen(udpEndPointManager, endpoints.get(), port);
      70          17 : }
      71             : 
      72           1 : void GlobalMinimalMdnsServer::ShutdownServer()
      73             : {
      74           1 :     GlobalMinimalMdnsServer::Server().Shutdown();
      75           1 : }
      76             : 
      77             : } // namespace Dnssd
      78             : } // namespace chip

Generated by: LCOV version 1.14