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