xref: /openbmc/entity-manager/src/machine_context.cpp (revision 2ab7341b7bd9467de10c8a6e6fdfd7f9801dc529)
1 /*
2 // Copyright (c) 2024 Hewlett Packard Enterprise
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16 
17 #include "machine_context.hpp"
18 
19 #include <filesystem>
20 #include <fstream>
21 
populateFromDeviceTree()22 void MachineContext::populateFromDeviceTree()
23 {
24     std::string nodeVal;
25     std::ifstream vpdStream(nodeBasePath + std::string("model"));
26     if (vpdStream && std::getline(vpdStream, nodeVal))
27     {
28         MachineContext::Asset::model(nodeVal);
29         vpdStream.close();
30     }
31 
32     vpdStream.open(nodeBasePath + std::string("serial-number"));
33     if (vpdStream && std::getline(vpdStream, nodeVal))
34     {
35         MachineContext::Asset::serial_number(nodeVal);
36         vpdStream.close();
37     }
38 };
39 
keyNodeExists()40 bool MachineContext::keyNodeExists()
41 {
42     std::filesystem::path nodePath{nodeBasePath + std::string("model")};
43 
44     return std::filesystem::exists(nodePath);
45 };
46