LCOV - code coverage report
Current view: top level - DCPS - LogAddr.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 4 38 10.5 %
Date: 2023-04-30 01:32:43 Functions: 1 6 16.7 %

          Line data    Source code
       1             : #include "DCPS/DdsDcps_pch.h"
       2             : 
       3             : #include "LogAddr.h"
       4             : #include "Definitions.h"
       5             : #include "SafetyProfileStreams.h"
       6             : #include "debug.h"
       7             : 
       8             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
       9             : 
      10             : namespace OpenDDS {
      11             : namespace DCPS {
      12             : 
      13             : const size_t LogAddr::BufSize = AddrToStringSize;
      14             : 
      15           0 : const String LogAddr::ip(const ACE_INET_Addr& addr)
      16             : {
      17           0 :   char s[BufSize] = {'\0'};
      18           0 :   return String(addr.get_host_addr(s, BufSize));
      19             : }
      20             : 
      21           0 : const String LogAddr::port(const ACE_INET_Addr& addr)
      22             : {
      23           0 :   return to_dds_string(addr.get_port_number());
      24             : }
      25             : 
      26           5 : const String LogAddr::host(const ACE_INET_Addr& addr)
      27             : {
      28           5 :   char s[BufSize] = {'\0'};
      29           5 :   if (addr.get_host_name(s, BufSize) < 0 && log_level >= LogLevel::Warning) {
      30           0 :     ACE_ERROR((LM_WARNING, "(%P|%t) WARNING: LogAddr::host: "
      31             :                "could not get hostname: %m\n"));
      32             :   }
      33           5 :   return String(s);
      34             : }
      35             : 
      36           0 : LogAddr::LogAddr(const ACE_INET_Addr& addr, Option opt)
      37             : {
      38           0 :   init_addr(addr, opt);
      39           0 : }
      40             : 
      41           0 : LogAddr::LogAddr(const NetworkAddress& addr, Option opt)
      42             : {
      43           0 :   init_addr(addr.to_addr(), opt);
      44           0 : }
      45             : 
      46           0 : void LogAddr::init_addr(const ACE_INET_Addr& addr, Option opt)
      47             : {
      48           0 :   switch (opt) {
      49           0 :     case IpPort:
      50           0 :       addr_ = ip(addr) + ':' + port(addr);
      51           0 :       break;
      52           0 :     case HostPort:
      53           0 :       addr_ = host(addr) + ':' + port(addr);
      54           0 :       break;
      55           0 :     case Ip:
      56           0 :       addr_ = ip(addr);
      57           0 :       break;
      58           0 :     case Port:
      59           0 :       addr_ = port(addr);
      60           0 :       break;
      61           0 :     case Host:
      62           0 :       addr_ = host(addr);
      63           0 :       break;
      64           0 :     case IpPortHost:
      65           0 :       addr_ = ip(addr) + ':' + port(addr) + " (" + host(addr) + ')';
      66           0 :     default:
      67           0 :       break;
      68             :   }
      69           0 : }
      70             : 
      71             : } // namespace DCPS
      72             : } // namespace OpenDDS
      73             : 
      74             : OPENDDS_END_VERSIONED_NAMESPACE_DECL

Generated by: LCOV version 1.16