1*a31ceb91SManojkiran Eda #include "collect_slot_vpd.hpp"
2*a31ceb91SManojkiran Eda 
3*a31ceb91SManojkiran Eda #include "oem_ibm_handler.hpp"
4*a31ceb91SManojkiran Eda 
5*a31ceb91SManojkiran Eda #include <phosphor-logging/lg2.hpp>
6*a31ceb91SManojkiran Eda 
7*a31ceb91SManojkiran Eda PHOSPHOR_LOG2_USING;
8*a31ceb91SManojkiran Eda 
9*a31ceb91SManojkiran Eda namespace pldm
10*a31ceb91SManojkiran Eda {
11*a31ceb91SManojkiran Eda namespace responder
12*a31ceb91SManojkiran Eda {
13*a31ceb91SManojkiran Eda using namespace oem_ibm_platform;
14*a31ceb91SManojkiran Eda void SlotHandler::timeOutHandler()
15*a31ceb91SManojkiran Eda {
16*a31ceb91SManojkiran Eda     info(
17*a31ceb91SManojkiran Eda         "Timer expired waiting for Event from Inventory on following pldm_entity: [ {ENTITY_TYP}, {ENTITY_NUM}, {ENTITY_ID} ]",
18*a31ceb91SManojkiran Eda         "ENTITY_TYP",
19*a31ceb91SManojkiran Eda         static_cast<unsigned>(currentOnGoingSlotEntity.entity_type),
20*a31ceb91SManojkiran Eda         "ENTITY_NUM",
21*a31ceb91SManojkiran Eda         static_cast<unsigned>(currentOnGoingSlotEntity.entity_instance_num),
22*a31ceb91SManojkiran Eda         "ENTITY_ID",
23*a31ceb91SManojkiran Eda         static_cast<unsigned>(currentOnGoingSlotEntity.entity_container_id));
24*a31ceb91SManojkiran Eda     // Disable the timer
25*a31ceb91SManojkiran Eda     timer.setEnabled(false);
26*a31ceb91SManojkiran Eda 
27*a31ceb91SManojkiran Eda     // obtain the sensor Id
28*a31ceb91SManojkiran Eda     auto sensorId = pldm::utils::findStateSensorId(
29*a31ceb91SManojkiran Eda         pdrRepo, 0, PLDM_ENTITY_SLOT,
30*a31ceb91SManojkiran Eda         currentOnGoingSlotEntity.entity_instance_num,
31*a31ceb91SManojkiran Eda         currentOnGoingSlotEntity.entity_container_id,
32*a31ceb91SManojkiran Eda         PLDM_OEM_IBM_PCIE_SLOT_SENSOR_STATE);
33*a31ceb91SManojkiran Eda 
34*a31ceb91SManojkiran Eda     // send the sensor event to host with error state
35*a31ceb91SManojkiran Eda     sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0,
36*a31ceb91SManojkiran Eda                          PLDM_OEM_IBM_PCIE_SLOT_SENSOR_STATE_ERROR,
37*a31ceb91SManojkiran Eda                          PLDM_OEM_IBM_PCIE_SLOT_SENSOR_STATE_UNKOWN);
38*a31ceb91SManojkiran Eda }
39*a31ceb91SManojkiran Eda 
40*a31ceb91SManojkiran Eda void SlotHandler::enableSlot(uint16_t effecterId,
41*a31ceb91SManojkiran Eda                              const AssociatedEntityMap& fruAssociationMap,
42*a31ceb91SManojkiran Eda                              uint8_t stateFileValue)
43*a31ceb91SManojkiran Eda 
44*a31ceb91SManojkiran Eda {
45*a31ceb91SManojkiran Eda     info("CM: slot enable effecter id: {EFFECTER_ID}", "EFFECTER_ID",
46*a31ceb91SManojkiran Eda          effecterId);
47*a31ceb91SManojkiran Eda     const pldm_entity entity = getEntityIDfromEffecterID(effecterId);
48*a31ceb91SManojkiran Eda 
49*a31ceb91SManojkiran Eda     for (const auto& [key, value] : fruAssociationMap)
50*a31ceb91SManojkiran Eda     {
51*a31ceb91SManojkiran Eda         if (entity.entity_instance_num == value.entity_instance_num &&
52*a31ceb91SManojkiran Eda             entity.entity_type == value.entity_type &&
53*a31ceb91SManojkiran Eda             entity.entity_container_id == value.entity_container_id)
54*a31ceb91SManojkiran Eda         {
55*a31ceb91SManojkiran Eda             this->currentOnGoingSlotEntity.entity_type = value.entity_type;
56*a31ceb91SManojkiran Eda             this->currentOnGoingSlotEntity.entity_instance_num =
57*a31ceb91SManojkiran Eda                 value.entity_instance_num;
58*a31ceb91SManojkiran Eda             this->currentOnGoingSlotEntity.entity_container_id =
59*a31ceb91SManojkiran Eda                 value.entity_container_id;
60*a31ceb91SManojkiran Eda             processSlotOperations(key, value, stateFileValue);
61*a31ceb91SManojkiran Eda         }
62*a31ceb91SManojkiran Eda     }
63*a31ceb91SManojkiran Eda }
64*a31ceb91SManojkiran Eda 
65*a31ceb91SManojkiran Eda void SlotHandler::processSlotOperations(const std::string& slotObjectPath,
66*a31ceb91SManojkiran Eda                                         const pldm_entity& entity,
67*a31ceb91SManojkiran Eda                                         uint8_t stateFieldValue)
68*a31ceb91SManojkiran Eda {
69*a31ceb91SManojkiran Eda     info("CM: processing the slot operations, SlotObject: {SLOT_OBJ}",
70*a31ceb91SManojkiran Eda          "SLOT_OBJ", slotObjectPath);
71*a31ceb91SManojkiran Eda 
72*a31ceb91SManojkiran Eda     std::string adapterObjPath;
73*a31ceb91SManojkiran Eda     try
74*a31ceb91SManojkiran Eda     {
75*a31ceb91SManojkiran Eda         // get the adapter dbus object path from the slot dbus object path
76*a31ceb91SManojkiran Eda         adapterObjPath = getAdapterObjPath(slotObjectPath).value();
77*a31ceb91SManojkiran Eda     }
78*a31ceb91SManojkiran Eda     catch (const std::bad_optional_access& e)
79*a31ceb91SManojkiran Eda     {
80*a31ceb91SManojkiran Eda         error("Failed to get the adapter dbus object ERROR={ERROR}", "ERROR",
81*a31ceb91SManojkiran Eda               e);
82*a31ceb91SManojkiran Eda         return;
83*a31ceb91SManojkiran Eda     }
84*a31ceb91SManojkiran Eda 
85*a31ceb91SManojkiran Eda     info(
86*a31ceb91SManojkiran Eda         "CM: Found an adapter under the slot, adapter object:{ADAPTER_OBJ_PATH}",
87*a31ceb91SManojkiran Eda         "ADAPTER_OBJ_PATH", adapterObjPath);
88*a31ceb91SManojkiran Eda     // create a presence match for the adpter present property
89*a31ceb91SManojkiran Eda     createPresenceMatch(adapterObjPath, entity, stateFieldValue);
90*a31ceb91SManojkiran Eda 
91*a31ceb91SManojkiran Eda     // call the VPD Manager to collect/remove VPD objects
92*a31ceb91SManojkiran Eda     callVPDManager(adapterObjPath, stateFieldValue);
93*a31ceb91SManojkiran Eda 
94*a31ceb91SManojkiran Eda     // start the 1 min timer
95*a31ceb91SManojkiran Eda     timer.restart(std::chrono::seconds(60));
96*a31ceb91SManojkiran Eda }
97*a31ceb91SManojkiran Eda 
98*a31ceb91SManojkiran Eda void SlotHandler::callVPDManager(const std::string& adapterObjPath,
99*a31ceb91SManojkiran Eda                                  uint8_t stateFieldValue)
100*a31ceb91SManojkiran Eda {
101*a31ceb91SManojkiran Eda     static constexpr auto VPDObjPath = "/com/ibm/VPD/Manager";
102*a31ceb91SManojkiran Eda     static constexpr auto VPDInterface = "com.ibm.VPD.Manager";
103*a31ceb91SManojkiran Eda     auto& bus = pldm::utils::DBusHandler::getBus();
104*a31ceb91SManojkiran Eda     try
105*a31ceb91SManojkiran Eda     {
106*a31ceb91SManojkiran Eda         auto service =
107*a31ceb91SManojkiran Eda             pldm::utils::DBusHandler().getService(VPDObjPath, VPDInterface);
108*a31ceb91SManojkiran Eda         if (stateFieldValue == PLDM_OEM_IBM_PCIE_SLOT_EFFECTER_ADD)
109*a31ceb91SManojkiran Eda         {
110*a31ceb91SManojkiran Eda             auto method = bus.new_method_call(service.c_str(), VPDObjPath,
111*a31ceb91SManojkiran Eda                                               VPDInterface, "CollectFRUVPD");
112*a31ceb91SManojkiran Eda             method.append(
113*a31ceb91SManojkiran Eda                 static_cast<sdbusplus::message::object_path>(adapterObjPath));
114*a31ceb91SManojkiran Eda             bus.call_noreply(method, dbusTimeout);
115*a31ceb91SManojkiran Eda         }
116*a31ceb91SManojkiran Eda         else if (stateFieldValue == PLDM_OEM_IBM_PCIE_SLOT_EFFECTER_REMOVE ||
117*a31ceb91SManojkiran Eda                  stateFieldValue == PLDM_OEM_IBM_PCIE_SLOT_EFFECTER_REPLACE)
118*a31ceb91SManojkiran Eda         {
119*a31ceb91SManojkiran Eda             auto method = bus.new_method_call(service.c_str(), VPDObjPath,
120*a31ceb91SManojkiran Eda                                               VPDInterface, "deleteFRUVPD");
121*a31ceb91SManojkiran Eda             method.append(
122*a31ceb91SManojkiran Eda                 static_cast<sdbusplus::message::object_path>(adapterObjPath));
123*a31ceb91SManojkiran Eda             bus.call_noreply(method, dbusTimeout);
124*a31ceb91SManojkiran Eda         }
125*a31ceb91SManojkiran Eda     }
126*a31ceb91SManojkiran Eda     catch (const std::exception& e)
127*a31ceb91SManojkiran Eda     {
128*a31ceb91SManojkiran Eda         error(
129*a31ceb91SManojkiran Eda             "failed to make a d-bus call to VPD Manager , Operation = {STATE_FILED_VAL}, ERROR={ERROR}",
130*a31ceb91SManojkiran Eda             "STATE_FILED_VAL", (unsigned)stateFieldValue, "ERROR", e);
131*a31ceb91SManojkiran Eda     }
132*a31ceb91SManojkiran Eda }
133*a31ceb91SManojkiran Eda 
134*a31ceb91SManojkiran Eda std::optional<std::string>
135*a31ceb91SManojkiran Eda     SlotHandler::getAdapterObjPath(const std::string& slotObjPath)
136*a31ceb91SManojkiran Eda {
137*a31ceb91SManojkiran Eda     static constexpr auto searchpath = "/xyz/openbmc_project/inventory";
138*a31ceb91SManojkiran Eda     int depth = 0;
139*a31ceb91SManojkiran Eda     std::vector<std::string> pcieAdapterInterface = {
140*a31ceb91SManojkiran Eda         "xyz.openbmc_project.Inventory.Item.PCIeDevice"};
141*a31ceb91SManojkiran Eda     pldm::utils::GetSubTreeResponse response =
142*a31ceb91SManojkiran Eda         pldm::utils::DBusHandler().getSubtree(searchpath, depth,
143*a31ceb91SManojkiran Eda                                               pcieAdapterInterface);
144*a31ceb91SManojkiran Eda     for (const auto& [objPath, serviceMap] : response)
145*a31ceb91SManojkiran Eda     {
146*a31ceb91SManojkiran Eda         // An adapter is a child of a PCIe Slot Object
147*a31ceb91SManojkiran Eda         if (objPath.contains(slotObjPath))
148*a31ceb91SManojkiran Eda         {
149*a31ceb91SManojkiran Eda             // Found the Adapter under the slot
150*a31ceb91SManojkiran Eda             return objPath;
151*a31ceb91SManojkiran Eda         }
152*a31ceb91SManojkiran Eda     }
153*a31ceb91SManojkiran Eda     return std::nullopt;
154*a31ceb91SManojkiran Eda }
155*a31ceb91SManojkiran Eda 
156*a31ceb91SManojkiran Eda void SlotHandler::createPresenceMatch(const std::string& adapterObjectPath,
157*a31ceb91SManojkiran Eda                                       const pldm_entity& entity,
158*a31ceb91SManojkiran Eda                                       uint8_t stateFieldValue)
159*a31ceb91SManojkiran Eda {
160*a31ceb91SManojkiran Eda     fruPresenceMatch = std::make_unique<sdbusplus::bus::match_t>(
161*a31ceb91SManojkiran Eda         pldm::utils::DBusHandler::getBus(),
162*a31ceb91SManojkiran Eda         propertiesChanged(adapterObjectPath,
163*a31ceb91SManojkiran Eda                           "xyz.openbmc_project.Inventory.Item"),
164*a31ceb91SManojkiran Eda         [this, adapterObjectPath, stateFieldValue,
165*a31ceb91SManojkiran Eda          entity](sdbusplus::message::message& msg) {
166*a31ceb91SManojkiran Eda             pldm::utils::DbusChangedProps props{};
167*a31ceb91SManojkiran Eda             std::string intf;
168*a31ceb91SManojkiran Eda             msg.read(intf, props);
169*a31ceb91SManojkiran Eda             const auto itr = props.find("Present");
170*a31ceb91SManojkiran Eda             if (itr != props.end())
171*a31ceb91SManojkiran Eda             {
172*a31ceb91SManojkiran Eda                 bool value = std::get<bool>(itr->second);
173*a31ceb91SManojkiran Eda                 // Present Property is found
174*a31ceb91SManojkiran Eda                 this->processPresentPropertyChange(value, stateFieldValue,
175*a31ceb91SManojkiran Eda                                                    entity);
176*a31ceb91SManojkiran Eda             }
177*a31ceb91SManojkiran Eda         });
178*a31ceb91SManojkiran Eda }
179*a31ceb91SManojkiran Eda 
180*a31ceb91SManojkiran Eda void SlotHandler::processPresentPropertyChange(
181*a31ceb91SManojkiran Eda     bool presentValue, uint8_t stateFiledvalue, const pldm_entity& entity)
182*a31ceb91SManojkiran Eda {
183*a31ceb91SManojkiran Eda     // irrespective of true->false or false->true change, we should stop the
184*a31ceb91SManojkiran Eda     // timer
185*a31ceb91SManojkiran Eda     timer.setEnabled(false);
186*a31ceb91SManojkiran Eda 
187*a31ceb91SManojkiran Eda     // remove the prence match so that it does not monitor the change
188*a31ceb91SManojkiran Eda     // even after we captured the property changed signal
189*a31ceb91SManojkiran Eda     fruPresenceMatch = nullptr;
190*a31ceb91SManojkiran Eda 
191*a31ceb91SManojkiran Eda     // obtain the sensor id attached with this slot
192*a31ceb91SManojkiran Eda     auto sensorId = pldm::utils::findStateSensorId(
193*a31ceb91SManojkiran Eda         pdrRepo, 0, PLDM_ENTITY_SLOT, entity.entity_instance_num,
194*a31ceb91SManojkiran Eda         entity.entity_container_id, PLDM_OEM_IBM_PCIE_SLOT_SENSOR_STATE);
195*a31ceb91SManojkiran Eda 
196*a31ceb91SManojkiran Eda     uint8_t sensorOpState = PLDM_OEM_IBM_PCIE_SLOT_SENSOR_STATE_UNKOWN;
197*a31ceb91SManojkiran Eda     if (presentValue)
198*a31ceb91SManojkiran Eda     {
199*a31ceb91SManojkiran Eda         sensorOpState = PLDM_OEM_IBM_PCIE_SLOT_SENSOR_STATE_ENABLED;
200*a31ceb91SManojkiran Eda     }
201*a31ceb91SManojkiran Eda     else
202*a31ceb91SManojkiran Eda     {
203*a31ceb91SManojkiran Eda         if (stateFiledvalue == PLDM_OEM_IBM_PCIE_SLOT_EFFECTER_REPLACE)
204*a31ceb91SManojkiran Eda         {
205*a31ceb91SManojkiran Eda             sensorOpState = PLDM_OEM_IBM_PCIE_SLOT_SENSOR_STATE_UNKOWN;
206*a31ceb91SManojkiran Eda         }
207*a31ceb91SManojkiran Eda         else
208*a31ceb91SManojkiran Eda         {
209*a31ceb91SManojkiran Eda             sensorOpState = PLDM_OEM_IBM_PCIE_SLOT_SENSOR_STATE_DISABLED;
210*a31ceb91SManojkiran Eda         }
211*a31ceb91SManojkiran Eda     }
212*a31ceb91SManojkiran Eda     info(
213*a31ceb91SManojkiran Eda         "CM: processing the property change from VPD Present value and sensor opState: {CURR_VAL} and {SENSOR_OP_STATE}",
214*a31ceb91SManojkiran Eda         "CURR_VAL", presentValue, "SENSOR_OP_STATE", (unsigned)sensorOpState);
215*a31ceb91SManojkiran Eda     // set the sensor state based on the stateFieldValue
216*a31ceb91SManojkiran Eda     this->sendStateSensorEvent(sensorId, PLDM_STATE_SENSOR_STATE, 0,
217*a31ceb91SManojkiran Eda                                sensorOpState,
218*a31ceb91SManojkiran Eda                                PLDM_OEM_IBM_PCIE_SLOT_SENSOR_STATE_UNKOWN);
219*a31ceb91SManojkiran Eda }
220*a31ceb91SManojkiran Eda 
221*a31ceb91SManojkiran Eda pldm_entity SlotHandler::getEntityIDfromEffecterID(uint16_t effecterId)
222*a31ceb91SManojkiran Eda {
223*a31ceb91SManojkiran Eda     pldm_entity parentFruEntity{};
224*a31ceb91SManojkiran Eda     uint8_t* pdrData = nullptr;
225*a31ceb91SManojkiran Eda     uint32_t pdrSize{};
226*a31ceb91SManojkiran Eda     const pldm_pdr_record* record{};
227*a31ceb91SManojkiran Eda     do
228*a31ceb91SManojkiran Eda     {
229*a31ceb91SManojkiran Eda         record = pldm_pdr_find_record_by_type(pdrRepo, PLDM_STATE_EFFECTER_PDR,
230*a31ceb91SManojkiran Eda                                               record, &pdrData, &pdrSize);
231*a31ceb91SManojkiran Eda         if (record && !pldm_pdr_record_is_remote(record))
232*a31ceb91SManojkiran Eda         {
233*a31ceb91SManojkiran Eda             auto pdr = reinterpret_cast<pldm_state_effecter_pdr*>(pdrData);
234*a31ceb91SManojkiran Eda             auto compositeEffecterCount = pdr->composite_effecter_count;
235*a31ceb91SManojkiran Eda             auto possible_states_start = pdr->possible_states;
236*a31ceb91SManojkiran Eda 
237*a31ceb91SManojkiran Eda             for (auto effecters = 0x00; effecters < compositeEffecterCount;
238*a31ceb91SManojkiran Eda                  effecters++)
239*a31ceb91SManojkiran Eda             {
240*a31ceb91SManojkiran Eda                 auto possibleStates =
241*a31ceb91SManojkiran Eda                     reinterpret_cast<state_effecter_possible_states*>(
242*a31ceb91SManojkiran Eda                         possible_states_start);
243*a31ceb91SManojkiran Eda 
244*a31ceb91SManojkiran Eda                 if (possibleStates->state_set_id ==
245*a31ceb91SManojkiran Eda                         PLDM_OEM_IBM_PCIE_SLOT_EFFECTER_STATE &&
246*a31ceb91SManojkiran Eda                     effecterId == pdr->effecter_id)
247*a31ceb91SManojkiran Eda                 {
248*a31ceb91SManojkiran Eda                     parentFruEntity.entity_type = pdr->entity_type;
249*a31ceb91SManojkiran Eda                     parentFruEntity.entity_instance_num = pdr->entity_instance;
250*a31ceb91SManojkiran Eda                     parentFruEntity.entity_container_id = pdr->container_id;
251*a31ceb91SManojkiran Eda 
252*a31ceb91SManojkiran Eda                     return parentFruEntity;
253*a31ceb91SManojkiran Eda                 }
254*a31ceb91SManojkiran Eda             }
255*a31ceb91SManojkiran Eda         }
256*a31ceb91SManojkiran Eda     } while (record);
257*a31ceb91SManojkiran Eda 
258*a31ceb91SManojkiran Eda     return parentFruEntity;
259*a31ceb91SManojkiran Eda }
260*a31ceb91SManojkiran Eda 
261*a31ceb91SManojkiran Eda uint8_t SlotHandler::fetchSlotSensorState(const std::string& slotObjectPath)
262*a31ceb91SManojkiran Eda {
263*a31ceb91SManojkiran Eda     std::string adapterObjPath;
264*a31ceb91SManojkiran Eda     uint8_t sensorOpState = PLDM_OEM_IBM_PCIE_SLOT_SENSOR_STATE_UNKOWN;
265*a31ceb91SManojkiran Eda 
266*a31ceb91SManojkiran Eda     try
267*a31ceb91SManojkiran Eda     {
268*a31ceb91SManojkiran Eda         // get the adapter dbus object path from the slot dbus object path
269*a31ceb91SManojkiran Eda         adapterObjPath = getAdapterObjPath(slotObjectPath).value();
270*a31ceb91SManojkiran Eda     }
271*a31ceb91SManojkiran Eda     catch (const std::bad_optional_access& e)
272*a31ceb91SManojkiran Eda     {
273*a31ceb91SManojkiran Eda         error(
274*a31ceb91SManojkiran Eda             "Failed to get the adapterObjectPath from slotObjectPath : {SLOT_OBJ_PATH} with error ERROR={ERROR}",
275*a31ceb91SManojkiran Eda             "SLOT_OBJ_PATH", slotObjectPath, "ERROR", e);
276*a31ceb91SManojkiran Eda         return PLDM_OEM_IBM_PCIE_SLOT_SENSOR_STATE_UNKOWN;
277*a31ceb91SManojkiran Eda     }
278*a31ceb91SManojkiran Eda 
279*a31ceb91SManojkiran Eda     if (fetchSensorStateFromDbus(adapterObjPath))
280*a31ceb91SManojkiran Eda     {
281*a31ceb91SManojkiran Eda         sensorOpState = PLDM_OEM_IBM_PCIE_SLOT_SENSOR_STATE_ENABLED;
282*a31ceb91SManojkiran Eda     }
283*a31ceb91SManojkiran Eda     else
284*a31ceb91SManojkiran Eda     {
285*a31ceb91SManojkiran Eda         sensorOpState = PLDM_OEM_IBM_PCIE_SLOT_SENSOR_STATE_DISABLED;
286*a31ceb91SManojkiran Eda     }
287*a31ceb91SManojkiran Eda     return sensorOpState;
288*a31ceb91SManojkiran Eda }
289*a31ceb91SManojkiran Eda 
290*a31ceb91SManojkiran Eda void SlotHandler::setOemPlatformHandler(
291*a31ceb91SManojkiran Eda     pldm::responder::oem_platform::Handler* handler)
292*a31ceb91SManojkiran Eda {
293*a31ceb91SManojkiran Eda     oemPlatformHandler = handler;
294*a31ceb91SManojkiran Eda }
295*a31ceb91SManojkiran Eda 
296*a31ceb91SManojkiran Eda void SlotHandler::sendStateSensorEvent(
297*a31ceb91SManojkiran Eda     uint16_t sensorId, enum sensor_event_class_states sensorEventClass,
298*a31ceb91SManojkiran Eda     uint8_t sensorOffset, uint8_t eventState, uint8_t prevEventState)
299*a31ceb91SManojkiran Eda {
300*a31ceb91SManojkiran Eda     pldm::responder::oem_ibm_platform::Handler* oemIbmPlatformHandler =
301*a31ceb91SManojkiran Eda         dynamic_cast<pldm::responder::oem_ibm_platform::Handler*>(
302*a31ceb91SManojkiran Eda             oemPlatformHandler);
303*a31ceb91SManojkiran Eda     if (oemIbmPlatformHandler)
304*a31ceb91SManojkiran Eda     {
305*a31ceb91SManojkiran Eda         oemIbmPlatformHandler->sendStateSensorEvent(
306*a31ceb91SManojkiran Eda             sensorId, sensorEventClass, sensorOffset, eventState,
307*a31ceb91SManojkiran Eda             prevEventState);
308*a31ceb91SManojkiran Eda     }
309*a31ceb91SManojkiran Eda }
310*a31ceb91SManojkiran Eda 
311*a31ceb91SManojkiran Eda bool SlotHandler::fetchSensorStateFromDbus(const std::string& adapterObjectPath)
312*a31ceb91SManojkiran Eda {
313*a31ceb91SManojkiran Eda     static constexpr auto ItemInterface = "xyz.openbmc_project.Inventory.Item";
314*a31ceb91SManojkiran Eda 
315*a31ceb91SManojkiran Eda     try
316*a31ceb91SManojkiran Eda     {
317*a31ceb91SManojkiran Eda         auto presentProperty =
318*a31ceb91SManojkiran Eda             pldm::utils::DBusHandler().getDbusPropertyVariant(
319*a31ceb91SManojkiran Eda                 adapterObjectPath.c_str(), "Present", ItemInterface);
320*a31ceb91SManojkiran Eda         return std::get<bool>(presentProperty);
321*a31ceb91SManojkiran Eda     }
322*a31ceb91SManojkiran Eda     catch (const std::exception& e)
323*a31ceb91SManojkiran Eda     {
324*a31ceb91SManojkiran Eda         error(
325*a31ceb91SManojkiran Eda             "failed to make a d-bus call to Inventory manager from adapterObjectPath : {ADAPTER_OBJ_PATH} with error ERROR={ERROR}",
326*a31ceb91SManojkiran Eda             "ADAPTER_OBJ_PATH", adapterObjectPath, "ERROR", e);
327*a31ceb91SManojkiran Eda     }
328*a31ceb91SManojkiran Eda 
329*a31ceb91SManojkiran Eda     return false;
330*a31ceb91SManojkiran Eda }
331*a31ceb91SManojkiran Eda 
332*a31ceb91SManojkiran Eda } // namespace responder
333*a31ceb91SManojkiran Eda } // namespace pldm
334