blob: 094c139db0f6434c4afcf3d48b739c36b04fe17c [file] [log] [blame]
Sunny Srivastava867ee752025-04-15 12:24:23 +05301#pragma once
2
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +05303#include "backup_restore.hpp"
4#include "gpio_monitor.hpp"
Anupama B Rc7565ed2025-06-19 02:08:39 -05005#include "listener.hpp"
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +05306#include "worker.hpp"
7
8#include <sdbusplus/asio/object_server.hpp>
9
10#include <memory>
11
Sunny Srivastava867ee752025-04-15 12:24:23 +053012namespace vpd
13{
14/**
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053015 * @brief Class to handle OEM specific use case.
Sunny Srivastava867ee752025-04-15 12:24:23 +053016 *
17 * Few pre-requisites needs to be taken case specifically, which will be
18 * encapsulated by this class.
19 */
20class IbmHandler
21{
22 public:
23 /**
24 * List of deleted methods.
25 */
26 IbmHandler(const IbmHandler&) = delete;
27 IbmHandler& operator=(const IbmHandler&) = delete;
28 IbmHandler(IbmHandler&&) = delete;
29
30 /**
31 * @brief Constructor.
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053032 *
33 * @param[in] o_worker - Reference to worker class object.
34 * @param[in] o_backupAndRestoreObj - Ref to back up and restore class
35 * object.
36 * @param[in] i_iFace - interface to implement.
37 * @param[in] i_ioCon - IO context.
38 * @param[in] i_asioConnection - Dbus Connection.
Sunny Srivastava867ee752025-04-15 12:24:23 +053039 */
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053040 IbmHandler(
41 std::shared_ptr<Worker>& o_worker,
42 std::shared_ptr<BackupAndRestore>& o_backupAndRestoreObj,
43 const std::shared_ptr<sdbusplus::asio::dbus_interface>& i_iFace,
44 const std::shared_ptr<boost::asio::io_context>& i_ioCon,
45 const std::shared_ptr<sdbusplus::asio::connection>& i_asioConnection);
46
47 private:
48 /**
Sunny Srivastava380efbb2025-04-25 10:28:30 +053049 * @brief API to register callback for Host state change.
50 */
51 void registerHostStateChangeCallback();
52
53 /**
54 * @brief API to process host state change callback.
55 *
56 * @param[in] i_msg - Callback message.
57 */
58 void hostStateChangeCallBack(sdbusplus::message_t& i_msg);
59
60 /**
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +053061 * @brief API to set timer to detect system VPD over D-Bus.
62 *
63 * System VPD is required before bus name for VPD-Manager is claimed. Once
64 * system VPD is published, VPD for other FRUs should be collected. This API
65 * detects id system VPD is already published on D-Bus and based on that
66 * triggers VPD collection for rest of the FRUs.
67 *
68 * Note: Throws exception in case of any failure. Needs to be handled by the
69 * caller.
70 */
71 void SetTimerToDetectSVPDOnDbus();
72
73 /**
74 * @brief Set timer to detect and set VPD collection status for the system.
75 *
76 * Collection of FRU VPD is triggered in a separate thread. Resulting in
77 * multiple threads at a given time. The API creates a timer which on
78 * regular interval will check if all the threads were collected back and
79 * sets the status of the VPD collection for the system accordingly.
80 *
81 * @throw std::runtime_error
82 */
83 void SetTimerToDetectVpdCollectionStatus();
84
85 /**
86 * @brief API to register callback for "AssetTag" property change.
87 */
88 void registerAssetTagChangeCallback();
89
90 /**
91 * @brief Callback API to be triggered on "AssetTag" property change.
92 *
93 * @param[in] i_msg - The callback message.
94 */
95 void processAssetTagChangeCallback(sdbusplus::message_t& i_msg);
96
97 /**
98 * @brief API to process VPD collection thread failed EEPROMs.
99 */
100 void processFailedEeproms();
101
102 /**
103 * @brief API to check and update PowerVS VPD.
104 *
105 * The API will read the existing data from the DBus and if found
106 * different than what has been read from JSON, it will update the VPD with
107 * JSON data on hardware and DBus both.
108 *
109 * @param[in] i_powerVsJsonObj - PowerVS JSON object.
110 * @param[out] o_failedPathList - List of path failed to update.
111 */
112 void checkAndUpdatePowerVsVpd(const nlohmann::json& i_powerVsJsonObj,
113 std::vector<std::string>& o_failedPathList);
114 /**
115 * @brief API to handle configuration w.r.t. PowerVS systems.
116 *
117 * Some FRUs VPD is specific to powerVS system. The API detects the
118 * powerVS configuration and updates the VPD accordingly.
119 */
120 void ConfigurePowerVsSystem();
121
Sunny Srivastava78a50422025-04-25 11:17:56 +0530122 /**
123 * @brief API to perform initial setup before manager claims Bus name.
124 *
125 * Before BUS name for VPD-Manager is claimed, fitconfig whould be set for
126 * corret device tree, inventory JSON w.r.t system should be linked and
127 * system VPD should be on DBus.
128 */
129 void performInitialSetup();
130
131 /**
132 * @brief API to prime system blueprint.
133 *
134 * The API will traverse the system config JSON and will prime all the FRU
135 * paths which qualifies for priming.
136 */
137 void primeSystemBlueprint();
138
139 /**
140 * @brief Function to enable and bring MUX out of idle state.
141 *
142 * This finds all the MUX defined in the system json and enables them by
143 * setting the holdidle parameter to 0.
144 *
145 * @throw std::runtime_error
146 */
147 void enableMuxChips();
148
Anupama B Rec7f8862025-05-23 01:21:01 -0500149 /**
150 * @brief API to check if priming is required.
151 *
152 * The API will traverse the system config JSON and counts the FRU
153 * paths which qualifies for priming and compares with count of object paths
154 * found under PIM which hosts the "com.ibm.VPD.Collection" interface. If
155 * the dbus count is equal to or greater than the count from JSON config
156 * consider as priming is not required.
157 *
158 * @return true if priming is required, false otherwise.
159 */
160 bool isPrimingRequired() const noexcept;
161
Sunny Srivastavac74c8ef2025-04-16 12:45:27 +0530162 // Parsed system config json object.
163 nlohmann::json m_sysCfgJsonObj{};
164
165 // Shared pointer to worker class
166 std::shared_ptr<Worker>& m_worker;
167
168 // Shared pointer to backup and restore object.
169 std::shared_ptr<BackupAndRestore>& m_backupAndRestoreObj;
170
171 // Shared pointer to GpioMonitor object.
172 std::shared_ptr<GpioMonitor> m_gpioMonitor;
173
174 // Shared pointer to Dbus interface class.
175 const std::shared_ptr<sdbusplus::asio::dbus_interface>& m_interface;
176
177 // Shared pointer to asio context object.
178 const std::shared_ptr<boost::asio::io_context>& m_ioContext;
179
180 // Shared pointer to bus connection.
181 const std::shared_ptr<sdbusplus::asio::connection>& m_asioConnection;
Anupama B Rc7565ed2025-06-19 02:08:39 -0500182
183 // Shared pointer to Listener object.
184 std::shared_ptr<Listener> m_eventListener;
Sunny Srivastava867ee752025-04-15 12:24:23 +0530185};
186} // namespace vpd