xref: /openbmc/entity-manager/src/devicetree_vpd_parser/machine_context.cpp (revision 4e1142d6f418f48ea260132ebb5a4995b2310c90)
1*4e1142d6SAlexander Hansen // SPDX-License-Identifier: Apache-2.0
2*4e1142d6SAlexander Hansen // SPDX-FileCopyrightText: Copyright 2024 Hewlett Packard Enterprise
3cfc7f4f4SChristopher Meis 
4cfc7f4f4SChristopher Meis #include "machine_context.hpp"
5cfc7f4f4SChristopher Meis 
6cfc7f4f4SChristopher Meis #include <filesystem>
7cfc7f4f4SChristopher Meis #include <fstream>
8cfc7f4f4SChristopher Meis 
populateFromDeviceTree()9cfc7f4f4SChristopher Meis void MachineContext::populateFromDeviceTree()
10cfc7f4f4SChristopher Meis {
11cfc7f4f4SChristopher Meis     std::string nodeVal;
12cfc7f4f4SChristopher Meis     std::ifstream vpdStream(nodeBasePath + std::string("model"));
13cfc7f4f4SChristopher Meis     if (vpdStream && std::getline(vpdStream, nodeVal))
14cfc7f4f4SChristopher Meis     {
15cfc7f4f4SChristopher Meis         MachineContext::Asset::model(nodeVal);
16cfc7f4f4SChristopher Meis         vpdStream.close();
17cfc7f4f4SChristopher Meis     }
18cfc7f4f4SChristopher Meis 
19cfc7f4f4SChristopher Meis     vpdStream.open(nodeBasePath + std::string("serial-number"));
20cfc7f4f4SChristopher Meis     if (vpdStream && std::getline(vpdStream, nodeVal))
21cfc7f4f4SChristopher Meis     {
22cfc7f4f4SChristopher Meis         MachineContext::Asset::serial_number(nodeVal);
23cfc7f4f4SChristopher Meis         vpdStream.close();
24cfc7f4f4SChristopher Meis     }
25cfc7f4f4SChristopher Meis };
26cfc7f4f4SChristopher Meis 
keyNodeExists()27cfc7f4f4SChristopher Meis bool MachineContext::keyNodeExists()
28cfc7f4f4SChristopher Meis {
29cfc7f4f4SChristopher Meis     std::filesystem::path nodePath{nodeBasePath + std::string("model")};
30cfc7f4f4SChristopher Meis 
31cfc7f4f4SChristopher Meis     return std::filesystem::exists(nodePath);
32cfc7f4f4SChristopher Meis };
33