LCOV - code coverage report
Current view: top level - DCPS - debug.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 22 22 100.0 %
Date: 2023-04-30 01:32:43 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Distributed under the OpenDDS License.
       3             :  * See: http://www.opendds.org/license.html
       4             :  */
       5             : 
       6             : #ifndef OPENDDS_DCPS_DEBUG_H
       7             : #define OPENDDS_DCPS_DEBUG_H
       8             : 
       9             : #include "dcps_export.h"
      10             : 
      11             : #ifndef OPENDDS_UTIL_BUILD
      12             : #include "transport/framework/TransportDebug.h"
      13             : #endif
      14             : 
      15             : #include <ace/ace_wchar.h>
      16             : 
      17             : #ifndef ACE_LACKS_PRAGMA_ONCE
      18             : #  pragma once
      19             : #endif
      20             : 
      21             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      22             : 
      23             : namespace OpenDDS {
      24             : namespace DCPS {
      25             : 
      26             : /**
      27             :  * General control for logging in OpenDDS.
      28             :  *
      29             :  * Access using the log_level global object.
      30             :  */
      31             : class OpenDDS_Dcps_Export LogLevel {
      32             : public:
      33             :   enum Value {
      34             :     None,
      35             :     Error,
      36             :     Warning,
      37             :     Notice,
      38             :     Info,
      39             :     Debug
      40             :   };
      41             : 
      42           1 :   LogLevel(Value value)
      43           1 :   {
      44           1 :     set(value);
      45           1 :   }
      46             : 
      47             :   void set(Value value);
      48             :   void set_from_string(const char* name);
      49             : 
      50         299 :   Value get() const
      51             :   {
      52         299 :     return level_;
      53             :   }
      54             :   const char* get_as_string() const;
      55             : 
      56             : private:
      57             :   Value level_;
      58             : };
      59             : extern OpenDDS_Dcps_Export LogLevel log_level;
      60             : 
      61         299 : inline bool operator>=(const LogLevel& ll, LogLevel::Value value)
      62             : {
      63         299 :   return ll.get() >= value;
      64             : }
      65             : 
      66             : /// Logging verbosity level.
      67             : /// set by Service_Participant
      68             : /// value guidelines:
      69             : /// 1 - logs that should happen once per process
      70             : /// 2 - logs that should happen once per DDS entity
      71             : /// 4 - logs that are related to administrative interfaces
      72             : /// 6 - logs that should happen every Nth sample write/read
      73             : /// 8 - logs that should happen once per sample write/read
      74             : /// 10 - logs that may happen more than once per sample write/read
      75             : extern OpenDDS_Dcps_Export unsigned int DCPS_debug_level;
      76             : 
      77             : /// The proper way to set the DCPS_debug_level.
      78             : /// This function allows for possible side-effects of setting the level.
      79             : extern void OpenDDS_Dcps_Export set_DCPS_debug_level(unsigned int lvl);
      80             : 
      81             : #ifndef OPENDDS_UTIL_BUILD
      82             : /// Transport Logging verbosity level.
      83             : // This needs to be initialized somewhere.
      84             : extern OpenDDS_Dcps_Export unsigned int Transport_debug_level;
      85             : extern OpenDDS_Dcps_Export TransportDebug transport_debug;
      86             : #endif
      87             : 
      88             : #ifdef OPENDDS_SECURITY
      89             : /**
      90             :  * Global Security Debug Settings
      91             :  */
      92             : class OpenDDS_Dcps_Export SecurityDebug {
      93             : public:
      94             :   SecurityDebug();
      95             : 
      96             :   /// Set all security debug message flags to this value
      97             :   void set_all_flags_to(bool value);
      98             : 
      99             :   /**
     100             :    * Parse a comma delimited string and set the corresponding flags.
     101             :    * Unknown ones are ignored and "all" enables all the flags.
     102             :    * Ex: "bookkeeping,showkeys"
     103             :    */
     104             :   void parse_flags(const ACE_TCHAR* flags);
     105             : 
     106             :   /**
     107             :    * Set debug level similarly to DCPSDebugLevel
     108             :    */
     109             :   void set_debug_level(unsigned level);
     110             : 
     111             :   /** @name SecurityFlags
     112             :    * These are the categories of Security Debug Messages
     113             :    */
     114             :   ///@{
     115             :   /// Encrypting and Decrypting
     116             :   bool encdec_error;
     117             :   bool encdec_warn;
     118             :   bool encdec_debug;
     119             : 
     120             :   /// Authentication and Handshake
     121             :   bool auth_debug;
     122             :   bool auth_warn;
     123             : 
     124             :   /// New entity creating
     125             :   bool new_entity_error;
     126             :   bool new_entity_warn;
     127             : 
     128             :   /// Cleanup
     129             :   bool cleanup_error;
     130             : 
     131             :   /// Permissions and Governance
     132             :   bool access_error;
     133             :   bool access_warn;
     134             : 
     135             :   /// Generation and Tracking of Crypto Handles and Keys
     136             :   bool bookkeeping;
     137             : 
     138             :   /// Print the Key when Generating it or Using It
     139             :   bool showkeys;
     140             : 
     141             :   /// Print Verbose Search Info About Getting the Crypto Handle from a Key id
     142             :   bool chlookup;
     143             :   ///@}
     144             : 
     145             :   /// Disable all encryption for security, even the required builtin encryption.
     146             :   bool fake_encryption;
     147             : 
     148             :   /**
     149             :    * Force role in authentication handshake. Like fake encryption this will
     150             :    * break everything if applied inconsistently.
     151             :    */
     152             :   enum ForceAuthRole {
     153             :     FORCE_AUTH_ROLE_NORMAL,
     154             :     FORCE_AUTH_ROLE_LEADER,
     155             :     FORCE_AUTH_ROLE_FOLLOWER
     156             :   } force_auth_role;
     157             : };
     158             : extern OpenDDS_Dcps_Export SecurityDebug security_debug;
     159             : #endif
     160             : 
     161             : #ifndef OPENDDS_UTIL_BUILD
     162             : class LogRestore {
     163             : public:
     164          12 :   LogRestore()
     165          12 :     : orig_log_level_(log_level)
     166          12 :     , orig_dcps_debug_level_(DCPS_debug_level)
     167          12 :     , orig_transport_debug_level_(Transport_debug_level)
     168          12 :     , orig_transport_debug_(transport_debug)
     169             : #ifdef OPENDDS_SECURITY
     170          12 :     , orig_security_debug_(security_debug)
     171             : #endif
     172             :   {
     173          12 :   }
     174             : 
     175          12 :   ~LogRestore()
     176             :   {
     177          12 :     log_level = orig_log_level_;
     178          12 :     DCPS_debug_level = orig_dcps_debug_level_;
     179          12 :     Transport_debug_level = orig_transport_debug_level_;
     180          12 :     transport_debug = orig_transport_debug_;
     181             : #ifdef OPENDDS_SECURITY
     182          12 :     security_debug = orig_security_debug_;
     183             : #endif
     184          12 :   }
     185             : 
     186             : private:
     187             :   LogLevel orig_log_level_;
     188             :   unsigned orig_dcps_debug_level_;
     189             :   unsigned orig_transport_debug_level_;
     190             :   TransportDebug orig_transport_debug_;
     191             : #ifdef OPENDDS_SECURITY
     192             :   SecurityDebug orig_security_debug_;
     193             : #endif
     194             : };
     195             : #endif // OPENDDS_UTIL_BUILD
     196             : 
     197             : } // namespace DCPS
     198             : } // namespace OpenDDS
     199             : 
     200             : OPENDDS_END_VERSIONED_NAMESPACE_DECL
     201             : 
     202             : #endif /* OPENDDS_DCPS_DEBUG_H */

Generated by: LCOV version 1.16