blob: b9611a36ae4fffed5300ac419e19e62c42d45b6f [file] [log] [blame]
#include "utils.hpp"
#include <phosphor-logging/log.hpp>
namespace utils
{
using namespace phosphor::logging;
std::string getService(sdbusplus::bus::bus& bus, const std::string& path,
const std::string& interface)
{
auto method = bus.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
MAPPER_BUSNAME, "GetObject");
method.append(path);
method.append(std::vector<std::string>({interface}));
std::vector<std::pair<std::string, std::vector<std::string>>> response;
try
{
auto reply = bus.call(method);
reply.read(response);
if (response.empty())
{
log<level::ERR>("Error in mapper response for getting service name",
entry("PATH=%s", path.c_str()),
entry("INTERFACE=%s", interface.c_str()));
return std::string{};
}
}
catch (const sdbusplus::exception::SdBusError& e)
{
log<level::ERR>("Error in mapper method call",
entry("ERROR=%s", e.what()),
entry("PATH=%s", path.c_str()),
entry("INTERFACE=%s", interface.c_str()));
return std::string{};
}
return response[0].first;
}
void mergeFiles(std::vector<std::string>& srcFiles, std::string& dstFile)
{
std::ofstream outFile(dstFile, std::ios::out);
for (auto& file : srcFiles)
{
std::ifstream inFile;
inFile.open(file, std::ios_base::in);
if (!inFile)
{
continue;
}
inFile.peek();
if (inFile.eof())
{
inFile.close();
continue;
}
outFile << inFile.rdbuf();
inFile.close();
}
outFile.close();
}
} // namespace utils