Skip to content

Commit

Permalink
Merge branch '1050' of github.com:Patel-Kamalkumar/pldm into AIO
Browse files Browse the repository at this point in the history
  • Loading branch information
Patel-Kamalkumar committed Oct 5, 2023
2 parents b6aca03 + d7e0cb9 commit 39d7dc5
Show file tree
Hide file tree
Showing 104 changed files with 3,280 additions and 1,975 deletions.
13 changes: 7 additions & 6 deletions common/flight_recorder.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#pragma once

#include <config.h>

#include <common/utils.hpp>
#include <phosphor-logging/lg2.hpp>

#include <fstream>
#include <iomanip>
#include <iostream>
#include <vector>

PHOSPHOR_LOG2_USING;

namespace pldm
{
namespace flightrecorder
{

using ReqOrResponse = bool;
using FlightRecorderData = std::vector<uint8_t>;
using FlightRecorderTimeStamp = std::string;
Expand Down Expand Up @@ -91,8 +92,8 @@ class FlightRecorder
if (flightRecorderPolicy)
{
std::ofstream recorderOutputFile(flightRecorderDumpPath);
std::cout << "Dumping the flight recorder into : "
<< flightRecorderDumpPath << "\n";
info("Dumping the flight recorder into : {FLIGHT_REC_DUMP}",
"FLIGHT_REC_DUMP", flightRecorderDumpPath);

for (const auto& message : tapeRecorder)
{
Expand All @@ -117,7 +118,7 @@ class FlightRecorder
}
else
{
std::cerr << "Fight recorder policy is disabled\n";
error("Fight recorder policy is disabled");
}
}
};
Expand Down
1 change: 1 addition & 0 deletions common/test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ foreach t : tests
libpldm_dep,
nlohmann_json,
phosphor_dbus_interfaces,
phosphor_logging_dep,
libpldmutils,
sdbusplus]),
workdir: meson.current_source_dir())
Expand Down
107 changes: 66 additions & 41 deletions common/utils.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "config.h"

#include "utils.hpp"

#include "libpldm/pdr.h"
#include "libpldm/pldm_types.h"

#include <sys/time.h>

#include <phosphor-logging/lg2.hpp>
#include <xyz/openbmc_project/Common/error.hpp>

#include <algorithm>
Expand All @@ -20,6 +19,8 @@
#include <string>
#include <vector>

PHOSPHOR_LOG2_USING;

namespace pldm
{
namespace utils
Expand Down Expand Up @@ -75,8 +76,8 @@ std::vector<std::vector<uint8_t>> findStateEffecterPDR(uint8_t /*tid*/,
}
catch (const std::exception& e)
{
std::cerr << " Failed to obtain a record. ERROR =" << e.what()
<< std::endl;
error(" Failed to obtain a record. ERROR = {ERR_EXCEP}", "ERR_EXCEP",
e.what());
}

return pdrs;
Expand Down Expand Up @@ -129,8 +130,8 @@ std::vector<std::vector<uint8_t>> findStateSensorPDR(uint8_t /*tid*/,
}
catch (const std::exception& e)
{
std::cerr << " Failed to obtain a record. ERROR =" << e.what()
<< std::endl;
error(" Failed to obtain a record. ERROR = {ERR_EXCEP}", "ERR_EXCEP",
e.what());
}

return pdrs;
Expand All @@ -142,7 +143,8 @@ uint8_t readHostEID()
std::ifstream eidFile{HOST_EID_PATH};
if (!eidFile.good())
{
std::cerr << "Could not open host EID file: " << HOST_EID_PATH << "\n";
error("Could not open host EID file: {HOST_EID_PATH}", "HOST_EID_PATH",
std::string(HOST_EID_PATH));
}
else
{
Expand All @@ -154,8 +156,7 @@ uint8_t readHostEID()
}
else
{
std::cerr << "Host EID file was empty"
<< "\n";
error("Host EID file was empty");
}
}

Expand Down Expand Up @@ -235,7 +236,9 @@ std::string DBusHandler::getService(const char* path,
mapper.append(path, DbusInterfaceList({}));
}

auto mapperResponseMsg = bus.call(mapper);
auto mapperResponseMsg = bus.call(
mapper,
std::chrono::duration_cast<microsec>(sec(DBUS_TIMEOUT)).count());
mapperResponseMsg.read(mapperResponse);
return mapperResponse.begin()->first;
}
Expand All @@ -251,13 +254,16 @@ GetSubTreeResponse
auto method = bus.new_method_call(mapperBusName, mapperPath,
mapperInterface, "GetSubTree");
method.append(searchPath, depth, ifaceList);
auto reply = bus.call(method);
auto reply = bus.call(
method,
std::chrono::duration_cast<microsec>(sec(DBUS_TIMEOUT)).count());
reply.read(response);
}
catch (const std::exception& e)
{
std::cerr << "failed GetSubTree query for interface " << ifaceList[0]
<< " with ERROR=" << e.what() << "\n";
error(
"failed GetSubTree query for interface {FACE_LIST} with ERROR = {ERR_EXCEP}",
"FACE_LIST", ifaceList[0], "ERR_EXCEP", e.what());
}
return response;
}
Expand All @@ -284,12 +290,15 @@ void reportError(const char* errorMsg, const Severity& sev)
}
std::map<std::string, std::string> addlData{};
method.append(errorMsg, severity, addlData);
bus.call_noreply(method);
bus.call_noreply(
method,
std::chrono::duration_cast<microsec>(sec(DBUS_TIMEOUT)).count());
}
catch (const std::exception& e)
{
std::cerr << "failed to make a d-bus call to create error log, ERROR="
<< e.what() << "\n";
error(
"failed to make a d-bus call to create error log, ERROR={ERR_EXCEP}",
"ERR_EXCEP", e.what());
}
}

Expand Down Expand Up @@ -318,7 +327,9 @@ void DBusHandler::setDbusProperty(const DBusMapping& dBusMap,
service.c_str(), "/xyz/openbmc_project/inventory",
"xyz.openbmc_project.Inventory.Manager", "Notify");
method.append(std::move(objectValueTree));
bus.call_noreply(method);
bus.call_noreply(
method, std::chrono::duration_cast<microsec>(sec(DBUS_TIMEOUT))
.count());
}
else
{
Expand All @@ -330,14 +341,16 @@ void DBusHandler::setDbusProperty(const DBusMapping& dBusMap,
dBusMap.objectPath ==
"/xyz/openbmc_project/network/hypervisor/eth1/ipv4/addr0")
{
std::cout << " ,service :" << service.c_str()
<< " , interface : " << dBusMap.interface.c_str()
<< " , path : " << dBusMap.objectPath.c_str()
<< std::endl;
info(
" service :{SERV} , interface : {INTF} , path : {DBUS_OBJ_PATH}",
"SERV", service.c_str(), "INTF", dBusMap.interface.c_str(),
"DBUS_OBJ_PATH", dBusMap.objectPath.c_str());
}
method.append(dBusMap.interface.c_str(),
dBusMap.propertyName.c_str(), variant);
bus.call_noreply(method);
bus.call_noreply(
method, std::chrono::duration_cast<microsec>(sec(DBUS_TIMEOUT))
.count());
}
};

Expand All @@ -354,16 +367,16 @@ void DBusHandler::setDbusProperty(const DBusMapping& dBusMap,
dBusMap.objectPath ==
"/xyz/openbmc_project/network/hypervisor/eth1/ipv4/addr0")
{
std::cout << " value : " << std::get<bool>(value);
info(" value : {VAL}", "VAL", std::get<bool>(value));
}
if (strstr(dBusMap.objectPath.c_str(), "dimm") &&
(dBusMap.interface ==
"xyz.openbmc_project.State.Decorator.OperationalStatus"))
{
if (!std::get<bool>(value))
{
std::cerr << "Guard event on DIMM : [ "
<< dBusMap.objectPath.c_str() << " ] \n";
error("Guard event on DIMM : [ {DBUS_OBJ_PATH} ]",
"DBUS_OBJ_PATH", dBusMap.objectPath.c_str());
}
}

Expand Down Expand Up @@ -411,7 +424,8 @@ void DBusHandler::setDbusProperty(const DBusMapping& dBusMap,
}
else
{
std::cerr << "Property Type is:" << dBusMap.propertyType << std::endl;
error("Property Type is: {DBUS_PROP_TYP} ", "DBUS_PROP_TYP",
dBusMap.propertyType);
throw std::invalid_argument("UnSpported Dbus Type");
}
}
Expand All @@ -425,7 +439,9 @@ PropertyValue DBusHandler::getDbusPropertyVariant(
"Get");
method.append(dbusInterface, dbusProp);
PropertyValue value{};
auto reply = bus.call(method);
auto reply = bus.call(
method,
std::chrono::duration_cast<microsec>(sec(DBUS_TIMEOUT)).count());
reply.read(value);
return value;
}
Expand All @@ -438,7 +454,9 @@ ObjectValueTree DBusHandler::getManagedObj(const char* service,
auto method = bus.new_method_call(service, rootPath,
"org.freedesktop.DBus.ObjectManager",
"GetManagedObjects");
auto reply = bus.call(method);
auto reply = bus.call(
method,
std::chrono::duration_cast<microsec>(sec(DBUS_TIMEOUT)).count());
reply.read(objects);
return objects;
}
Expand Down Expand Up @@ -489,7 +507,8 @@ PropertyValue jsonEntryToDbusVal(std::string_view type,
}
else
{
std::cerr << "Unknown D-Bus property type, TYPE=" << type << "\n";
error("Unknown D-Bus property type, TYPE={DBUS_PROP_TYP}",
"DBUS_PROP_TYP", type);
}

return propValue;
Expand Down Expand Up @@ -552,8 +571,8 @@ int emitStateSensorEventSignal(uint8_t tid, uint16_t sensorId,
}
catch (const std::exception& e)
{
std::cerr << "Error emitting pldm event signal:"
<< "ERROR=" << e.what() << "\n";
error("Error emitting pldm event signal:ERROR={ERR_EXCEP}", "ERR_EXCEP",
e.what());
return PLDM_ERROR;
}

Expand Down Expand Up @@ -671,14 +690,16 @@ std::string getBiosAttrValue(const std::string& dbusAttrName)
service.c_str(), biosConfigPath,
"xyz.openbmc_project.BIOSConfig.Manager", "GetAttribute");
method.append(dbusAttrName);
auto reply = bus.call(method);
auto reply = bus.call(
method,
std::chrono::duration_cast<microsec>(sec(DBUS_TIMEOUT)).count());
reply.read(var1, var2, var3);
}
catch (const sdbusplus::exception::SdBusError& e)
{
std::cout << "Error getting the bios attribute"
<< "ERROR=" << e.what() << "ATTRIBUTE=" << dbusAttrName
<< std::endl;
info(
"Error getting the bios attribute ERROR={ERR_EXCEP} ATTRIBUTE={BIOS_ATTR}",
"ERR_EXCEP", e.what(), "BIOS_ATTR", dbusAttrName);
return {};
}

Expand Down Expand Up @@ -713,13 +734,16 @@ void setBiosAttr(const BiosAttributeList& biosAttrList)
method.append(
biosConfigIntf, "PendingAttributes",
std::variant<PendingAttributesType>(pendingAttributes));
bus.call_noreply(method);
bus.call_noreply(
method, std::chrono::duration_cast<microsec>(sec(DBUS_TIMEOUT))
.count());
}
catch (const sdbusplus::exception::SdBusError& e)
{
std::cout << "Error setting the bios attribute"
<< "ERROR=" << e.what() << "ATTRIBUTE=" << dbusAttrName
<< "ATTRIBUTE VALUE=" << biosAttrStr << std::endl;
info(
"Error setting the bios attribute ERROR = {ERR_EXCEP} ATTRIBUTE= {DBUS_ATTR} ATTRIBUTE VALUE={BIOS_ATTR}",
"ERR_EXCEP", e.what(), "DBUS_ATTR", dbusAttrName.c_str(),
"BIOS_ATTR", biosAttrStr.c_str());
return;
}
}
Expand Down Expand Up @@ -928,8 +952,9 @@ bool checkForFruPresence(const std::string& objPath)
}
catch (const sdbusplus::exception::SdBusError& e)
{
std::cerr << "Failed to check for FRU presence for " << objPath
<< " ERROR =" << e.what() << std::endl;
error(
"Failed to check for FRU presence for {OBJ_PATH} ERROR = {ERR_EXCEP}",
"OBJ_PATH", objPath.c_str(), "ERR_EXCEP", e.what());
}
return isPresent;
}
Expand Down
3 changes: 3 additions & 0 deletions common/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include <variant>
#include <vector>

using microsec = std::chrono::microseconds;
using sec = std::chrono::seconds;

namespace pldm
{
using Severity = pldm::PelSeverity;
Expand Down
Loading

0 comments on commit 39d7dc5

Please sign in to comment.