edk2/RedfishPkg/Include/Library/RedfishDebugLib.h
Michael Kubacki 6181c85fa9 RedfishPkg: Replace include guards with #pragma once
Replace traditional `#ifndef`/`#define`/`#endif` include guards with
`#pragma` once.

`#pragma once` is a widely supported preprocessor directive that
prevents header files from being included multiple times. It is
supported by all toolchains used to build edk2: GCC, Clang/LLVM, and
MSVC.

Compared to macro-based include guards, `#pragma once`:

- Eliminates the risk of macro name collisions or copy/paste errors
  where two headers inadvertently use the same guard macro.
- Eliminate inconsistency in the way include guard macros are named
  (e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.).
- Reduces boilerplate (three lines replaced by one).
- Avoids polluting the macro namespace with guard symbols.
- Can improve build times as the preprocessor can skip re-opening the
  file entirely, rather than re-reading it to find the matching
  `#endif` ("multiple-include optimization").
  - Note that some compilers may already optimize traditional include
    guards, by recognzining the idiomatic pattern.

This change is made acknowledging that overall portability of the
code will technically be reduced, as `#pragma once` is not part of the
C/C++ standards.

However, this is considered acceptable given:

1. edk2 already defines a subset of supported compilers in
   BaseTools/Conf/tools_def.template, all of which have supported
   `#pragma once` for over two decades.
2. There have been concerns raised to the project about inconsistent
   include guard naming and potential macro collisions.

Approximate compiler support dates:

- MSVC: Supported since Visual C++ 4.2 (1996)
- GCC: Supported since 3.4 (2004)
  (http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html)
- Clang (LLVM based): Since initial release in 2007

Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-02-23 21:01:28 +00:00

177 lines
4.9 KiB
C

/** @file
This file defines the Redfish debug library interface.
Copyright (c) 2023-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#pragma once
#include <Uefi.h>
#include <Library/DebugLib.h>
#include <RedfishServiceData.h>
#include <Library/HiiUtilityLib.h>
#include <Library/JsonLib.h>
#include <Protocol/EdkIIRedfishPlatformConfig.h>
// Used with MdePKg DEBUG macro.
#define DEBUG_REDFISH_NETWORK DEBUG_MANAGEABILITY ///< Debug error level for Redfish networking function
#define DEBUG_REDFISH_HOST_INTERFACE DEBUG_MANAGEABILITY ///< Debug error level for Redfish Host INterface
#define DEBUG_REDFISH_PLATFORM_CONFIG DEBUG_MANAGEABILITY ///< Debug error level for Redfish Platform Configure Driver
//
// Definitions of Redfish debug capability in Redfish component scope, used with DEBUG_REDFISH macro
// For example, Redfish Platform Config Driver
// DEBUG_REDFISH(DEBUG_REDFISH_PLATFORM_CONFIG_DXE, ...)
//
#define DEBUG_REDFISH_COMPONENT_PLATFORM_CONFIG_DXE 0x00000001
#define DEBUG_REDFISH(DebugCategory, ...) \
do { \
if (!DebugPrintEnabled()) { \
break; \
} \
if (!DebugRedfishComponentEnabled (DebugCategory)) { \
break; \
} \
DEBUG ((DEBUG_MANAGEABILITY, ##__VA_ARGS__)); \
} while (FALSE)
/**
Determine whether the Redfish debug category is enabled in
gEfiRedfishPkgTokenSpaceGuid.PcdRedfishDebugCategory.
@param[in] DebugCategory Redfish debug category.
@retval TRUE This debug category is enabled.
@retval FALSE This debug category is disabled..
**/
BOOLEAN
DebugRedfishComponentEnabled (
IN UINT64 DebugCategory
);
/**
Debug print the value of RedfishValue.
@param[in] ErrorLevel DEBUG macro error level.
@param[in] RedfishValue The statement value to print.
@retval EFI_SUCCESS RedfishValue is printed.
@retval EFI_INVALID_PARAMETER RedfishValue is NULL.
**/
EFI_STATUS
DumpRedfishValue (
IN UINTN ErrorLevel,
IN EDKII_REDFISH_VALUE *RedfishValue
);
/**
This function dump the Json string in given error level.
@param[in] ErrorLevel DEBUG macro error level
@param[in] JsonValue Json value to dump.
@retval EFI_SUCCESS Json string is printed.
@retval Others Errors occur.
**/
EFI_STATUS
DumpJsonValue (
IN UINTN ErrorLevel,
IN EDKII_JSON_VALUE JsonValue
);
/**
This function dump the status code, header and body in given
Redfish payload.
@param[in] ErrorLevel DEBUG macro error level
@param[in] Payload Redfish payload to dump
@retval EFI_SUCCESS Redfish payload is printed.
@retval Others Errors occur.
**/
EFI_STATUS
DumpRedfishPayload (
IN UINTN ErrorLevel,
IN REDFISH_PAYLOAD Payload
);
/**
This function dump the status code, header and body in given
Redfish response.
@param[in] Message Message string
@param[in] ErrorLevel DEBUG macro error level
@param[in] Response Redfish response to dump
@retval EFI_SUCCESS Redfish response is printed.
@retval Others Errors occur.
**/
EFI_STATUS
DumpRedfishResponse (
IN CONST CHAR8 *Message,
IN UINTN ErrorLevel,
IN REDFISH_RESPONSE *Response
);
/**
This function dump the HTTP status code.
@param[in] ErrorLevel DEBUG macro error level
@param[in] HttpStatusCode HTTP status code
@retval EFI_SUCCESS HTTP status code is printed
**/
EFI_STATUS
DumpHttpStatusCode (
IN UINTN ErrorLevel,
IN EFI_HTTP_STATUS_CODE HttpStatusCode
);
/**
This function dump the IPv4 address in given error level.
@param[in] ErrorLevel DEBUG macro error level
@param[in] Ipv4Address IPv4 address to dump
@retval EFI_SUCCESS IPv4 address string is printed.
@retval Others Errors occur.
**/
EFI_STATUS
DumpIpv4Address (
IN UINTN ErrorLevel,
IN EFI_IPv4_ADDRESS *Ipv4Address
);
/**
Debug output raw data buffer.
@param[in] ErrorLevel DEBUG macro error level
@param[in] Buffer Debug output data buffer.
@param[in] BufferSize The size of Buffer in byte.
@retval EFI_SUCCESS Debug dump finished.
@retval EFI_INVALID_PARAMETER Buffer is NULL.
**/
EFI_STATUS
DumpBuffer (
IN UINTN ErrorLevel,
IN UINT8 *Buffer,
IN UINTN BufferSize
);