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