blob: 10038b44438bfbff1e48473b88cc7c24aa8d3c37 [file] [log] [blame]
Sampa Misra032bd502019-03-06 05:03:22 -06001#pragma once
2
Sampa Misraaea5dde2020-08-31 08:33:47 -05003#include "types.hpp"
4
George Liuc453e162022-12-21 17:16:23 +08005#include <libpldm/base.h>
6#include <libpldm/bios.h>
George Liudf9a6d32020-12-22 16:27:16 +08007#include <libpldm/entity.h>
8#include <libpldm/pdr.h>
George Liuc453e162022-12-21 17:16:23 +08009#include <libpldm/platform.h>
10#include <libpldm/utils.h>
Sampa Misra032bd502019-03-06 05:03:22 -060011#include <stdint.h>
12#include <systemd/sd-bus.h>
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050013#include <unistd.h>
Sampa Misra032bd502019-03-06 05:03:22 -060014
George Liu6492f522020-06-16 10:34:05 +080015#include <nlohmann/json.hpp>
16#include <sdbusplus/server.hpp>
Riya Dixit754041d2024-02-20 06:15:49 -060017#include <xyz/openbmc_project/Inventory/Manager/client.hpp>
George Liu6492f522020-06-16 10:34:05 +080018#include <xyz/openbmc_project/Logging/Entry/server.hpp>
Gilbert Chen44524a52022-02-14 12:12:25 +000019#include <xyz/openbmc_project/ObjectMapper/client.hpp>
George Liu6492f522020-06-16 10:34:05 +080020
George Liudf9a6d32020-12-22 16:27:16 +080021#include <deque>
Sampa Misraa2fa0702019-05-31 01:28:55 -050022#include <exception>
Deepak Kodihalli3cd61812020-03-10 06:38:45 -050023#include <filesystem>
Sampa Misraaa8ae722019-12-12 03:20:40 -060024#include <iostream>
George Liudf9a6d32020-12-22 16:27:16 +080025#include <map>
Sampa Misra032bd502019-03-06 05:03:22 -060026#include <string>
Sampa Misraa2fa0702019-05-31 01:28:55 -050027#include <variant>
28#include <vector>
Sampa Misra032bd502019-03-06 05:03:22 -060029
vkaverap@in.ibm.com5b71b862023-08-21 05:19:04 +000030constexpr uint64_t dbusTimeout =
31 std::chrono::duration_cast<std::chrono::microseconds>(
32 std::chrono::seconds(DBUS_TIMEOUT))
33 .count();
34
Sampa Misra032bd502019-03-06 05:03:22 -060035namespace pldm
36{
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050037namespace utils
38{
Deepak Kodihalli3cd61812020-03-10 06:38:45 -050039namespace fs = std::filesystem;
Tom Joseph250c4752020-04-15 10:32:45 +053040using Json = nlohmann::json;
Tom Josephe5268cd2021-09-07 13:04:03 +053041constexpr bool Tx = true;
42constexpr bool Rx = false;
Deepak Kodihalli3cd61812020-03-10 06:38:45 -050043
George Liudf9a6d32020-12-22 16:27:16 +080044using EntityName = std::string;
45using EntityType = uint16_t;
46
47using Entities = std::vector<pldm_entity_node*>;
48using EntityAssociations = std::vector<Entities>;
49using ObjectPathMaps = std::map<fs::path, pldm_entity_node*>;
Gilbert Chen44524a52022-02-14 12:12:25 +000050using ObjectMapper = sdbusplus::client::xyz::openbmc_project::ObjectMapper<>;
51
52using inventoryManager =
53 sdbusplus::client::xyz::openbmc_project::inventory::Manager<>;
54
55constexpr auto dbusProperties = "org.freedesktop.DBus.Properties";
56constexpr auto mapperService = ObjectMapper::default_service;
57constexpr auto inventoryPath = "/xyz/openbmc_project/inventory";
George Liudf9a6d32020-12-22 16:27:16 +080058
59const std::map<EntityType, EntityName> entityMaps = {
60 {PLDM_ENTITY_SYSTEM_CHASSIS, "chassis"},
61 {PLDM_ENTITY_BOARD, "io_board"},
62 {PLDM_ENTITY_SYS_BOARD, "motherboard"},
63 {PLDM_ENTITY_POWER_SUPPLY, "powersupply"},
64 {PLDM_ENTITY_PROC, "cpu"},
65 {PLDM_ENTITY_SYSTEM_CHASSIS | 0x8000, "system"},
66 {PLDM_ENTITY_PROC_MODULE, "dcm"},
67 {PLDM_ENTITY_PROC | 0x8000, "core"},
68 {PLDM_ENTITY_IO_MODULE, "io_module"},
69 {PLDM_ENTITY_FAN, "fan"},
70 {PLDM_ENTITY_SYS_MGMT_MODULE, "system_management_module"},
71 {PLDM_ENTITY_POWER_CONVERTER, "power_converter"},
72 {PLDM_ENTITY_SLOT, "slot"},
73 {PLDM_ENTITY_CONNECTOR, "connector"}};
74
75/** @brief Vector a entity name to pldm_entity from entity association tree
76 * @param[in] entityAssoc - Vector of associated pldm entities
77 * @param[in] entityTree - entity association tree
78 * @param[out] objPathMap - maps an object path to pldm_entity from the
79 * BMC's entity association tree
80 * @return
81 */
82void updateEntityAssociation(const EntityAssociations& entityAssoc,
83 pldm_entity_association_tree* entityTree,
84 ObjectPathMaps& objPathMap);
85
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050086/** @struct CustomFD
87 *
88 * RAII wrapper for file descriptor.
89 */
90struct CustomFD
91{
92 CustomFD(const CustomFD&) = delete;
93 CustomFD& operator=(const CustomFD&) = delete;
94 CustomFD(CustomFD&&) = delete;
95 CustomFD& operator=(CustomFD&&) = delete;
96
Patrick Williams6da4f912023-05-10 07:50:53 -050097 CustomFD(int fd) : fd(fd) {}
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050098
99 ~CustomFD()
100 {
101 if (fd >= 0)
102 {
103 close(fd);
104 }
105 }
106
107 int operator()() const
108 {
109 return fd;
110 }
111
112 private:
113 int fd = -1;
114};
115
Sampa Misrab37be312019-07-03 02:26:41 -0500116/** @brief Calculate the pad for PLDM data
117 *
118 * @param[in] data - Length of the data
119 * @return - uint8_t - number of pad bytes
120 */
121uint8_t getNumPadBytes(uint32_t data);
122
George Liu83409572019-12-24 18:42:54 +0800123/** @brief Convert uint64 to date
124 *
125 * @param[in] data - time date of uint64
126 * @param[out] year - year number in dec
127 * @param[out] month - month number in dec
128 * @param[out] day - day of the month in dec
129 * @param[out] hour - number of hours in dec
130 * @param[out] min - number of minutes in dec
131 * @param[out] sec - number of seconds in dec
132 * @return true if decode success, false if decode faild
133 */
134bool uintToDate(uint64_t data, uint16_t* year, uint8_t* month, uint8_t* day,
135 uint8_t* hour, uint8_t* min, uint8_t* sec);
136
137/** @brief Convert effecter data to structure of set_effecter_state_field
138 *
139 * @param[in] effecterData - the date of effecter
George Liuba4c1fb2020-02-05 14:13:30 +0800140 * @param[in] effecterCount - the number of individual sets of effecter
141 * information
142 * @return[out] parse success and get a valid set_effecter_state_field
143 * structure, return nullopt means parse failed
George Liu83409572019-12-24 18:42:54 +0800144 */
George Liuba4c1fb2020-02-05 14:13:30 +0800145std::optional<std::vector<set_effecter_state_field>>
146 parseEffecterData(const std::vector<uint8_t>& effecterData,
147 uint8_t effecterCount);
Sampa Misra032bd502019-03-06 05:03:22 -0600148
149/**
Sampa Misraaa8ae722019-12-12 03:20:40 -0600150 * @brief creates an error log
151 * @param[in] errorMsg - the error message
152 */
Manojkiran Eda92fb0b52024-04-17 10:48:17 +0530153void reportError(const char* errorMsg);
Sampa Misraaa8ae722019-12-12 03:20:40 -0600154
Sampa Misra032bd502019-03-06 05:03:22 -0600155/** @brief Convert any Decimal number to BCD
156 *
157 * @tparam[in] decimal - Decimal number
158 * @return Corresponding BCD number
159 */
160template <typename T>
161T decimalToBcd(T decimal)
162{
163 T bcd = 0;
164 T rem = 0;
165 auto cnt = 0;
166
167 while (decimal)
168 {
169 rem = decimal % 10;
170 bcd = bcd + (rem << cnt);
171 decimal = decimal / 10;
172 cnt += 4;
173 }
174
175 return bcd;
176}
177
George Liu1e44c732020-02-28 20:20:06 +0800178struct DBusMapping
179{
180 std::string objectPath; //!< D-Bus object path
181 std::string interface; //!< D-Bus interface
182 std::string propertyName; //!< D-Bus property name
183 std::string propertyType; //!< D-Bus property type
184};
185
186using PropertyValue =
187 std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t,
Riya Dixit754041d2024-02-20 06:15:49 -0600188 uint64_t, double, std::string, std::vector<uint8_t>,
189 std::vector<std::string>>;
Deepak Kodihalli6b1d1ca2020-04-27 07:24:51 -0500190using DbusProp = std::string;
191using DbusChangedProps = std::map<DbusProp, PropertyValue>;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500192using DBusInterfaceAdded = std::vector<
193 std::pair<pldm::dbus::Interface,
194 std::vector<std::pair<pldm::dbus::Property,
195 std::variant<pldm::dbus::Property>>>>>;
Manojkiran Eda1ef62c32021-04-24 07:23:18 +0530196using ObjectPath = std::string;
197using ServiceName = std::string;
198using Interfaces = std::vector<std::string>;
199using MapperServiceMap = std::vector<std::pair<ServiceName, Interfaces>>;
200using GetSubTreeResponse = std::vector<std::pair<ObjectPath, MapperServiceMap>>;
Sridevi Ramesheefe49b2022-06-27 11:51:02 -0500201using PropertyMap = std::map<std::string, PropertyValue>;
202using InterfaceMap = std::map<std::string, PropertyMap>;
Riya Dixit754041d2024-02-20 06:15:49 -0600203using ObjectValueTree = std::map<sdbusplus::message::object_path, InterfaceMap>;
George Liu1e44c732020-02-28 20:20:06 +0800204
205/**
206 * @brief The interface for DBusHandler
207 */
208class DBusHandlerInterface
209{
210 public:
211 virtual ~DBusHandlerInterface() = default;
212
George Liu36e81352020-07-01 14:40:30 +0800213 virtual std::string getService(const char* path,
214 const char* interface) const = 0;
Manojkiran Eda1ef62c32021-04-24 07:23:18 +0530215 virtual GetSubTreeResponse
216 getSubtree(const std::string& path, int depth,
217 const std::vector<std::string>& ifaceList) const = 0;
George Liu36e81352020-07-01 14:40:30 +0800218
George Liu1e44c732020-02-28 20:20:06 +0800219 virtual void setDbusProperty(const DBusMapping& dBusMap,
220 const PropertyValue& value) const = 0;
John Wang9e242422020-03-05 08:37:50 +0800221
222 virtual PropertyValue
223 getDbusPropertyVariant(const char* objPath, const char* dbusProp,
224 const char* dbusInterface) const = 0;
Gilbert Chen44524a52022-02-14 12:12:25 +0000225
226 virtual PropertyMap
227 getDbusPropertiesVariant(const char* serviceName, const char* objPath,
228 const char* dbusInterface) const = 0;
George Liu1e44c732020-02-28 20:20:06 +0800229};
230
Sampa Misraa2fa0702019-05-31 01:28:55 -0500231/**
232 * @class DBusHandler
233 *
234 * Wrapper class to handle the D-Bus calls
235 *
236 * This class contains the APIs to handle the D-Bus calls
237 * to cater the request from pldm requester.
238 * A class is created to mock the apis in the test cases
239 */
George Liu1e44c732020-02-28 20:20:06 +0800240class DBusHandler : public DBusHandlerInterface
Sampa Misraa2fa0702019-05-31 01:28:55 -0500241{
242 public:
George Liu0e02c322020-01-01 09:41:51 +0800243 /** @brief Get the bus connection. */
244 static auto& getBus()
245 {
246 static auto bus = sdbusplus::bus::new_default();
247 return bus;
248 }
249
250 /**
251 * @brief Get the DBUS Service name for the input dbus path
John Wang9e242422020-03-05 08:37:50 +0800252 *
George Liu0e02c322020-01-01 09:41:51 +0800253 * @param[in] path - DBUS object path
254 * @param[in] interface - DBUS Interface
John Wang9e242422020-03-05 08:37:50 +0800255 *
George Liu0e02c322020-01-01 09:41:51 +0800256 * @return std::string - the dbus service name
John Wang9e242422020-03-05 08:37:50 +0800257 *
Patrick Williams84b790c2022-07-22 19:26:56 -0500258 * @throw sdbusplus::exception_t when it fails
George Liu0e02c322020-01-01 09:41:51 +0800259 */
George Liu36e81352020-07-01 14:40:30 +0800260 std::string getService(const char* path,
261 const char* interface) const override;
George Liu0e02c322020-01-01 09:41:51 +0800262
Manojkiran Eda1ef62c32021-04-24 07:23:18 +0530263 /**
264 * @brief Get the Subtree response from the mapper
265 *
266 * @param[in] path - DBUS object path
267 * @param[in] depth - Search depth
268 * @param[in] ifaceList - list of the interface that are being
269 * queried from the mapper
270 *
271 * @return GetSubTreeResponse - the mapper subtree response
272 *
Patrick Williams84b790c2022-07-22 19:26:56 -0500273 * @throw sdbusplus::exception_t when it fails
Manojkiran Eda1ef62c32021-04-24 07:23:18 +0530274 */
275 GetSubTreeResponse
276 getSubtree(const std::string& path, int depth,
277 const std::vector<std::string>& ifaceList) const override;
278
John Wang9e242422020-03-05 08:37:50 +0800279 /** @brief Get property(type: variant) from the requested dbus
280 *
281 * @param[in] objPath - The Dbus object path
282 * @param[in] dbusProp - The property name to get
283 * @param[in] dbusInterface - The Dbus interface
284 *
285 * @return The value of the property(type: variant)
286 *
Patrick Williams84b790c2022-07-22 19:26:56 -0500287 * @throw sdbusplus::exception_t when it fails
John Wang9e242422020-03-05 08:37:50 +0800288 */
289 PropertyValue
290 getDbusPropertyVariant(const char* objPath, const char* dbusProp,
291 const char* dbusInterface) const override;
George Liu0e02c322020-01-01 09:41:51 +0800292
Gilbert Chen44524a52022-02-14 12:12:25 +0000293 /** @brief Get All properties(type: variant) from the requested dbus
294 *
295 * @param[in] serviceName - The Dbus service name
296 * @param[in] objPath - The Dbus object path
297 * @param[in] dbusInterface - The Dbus interface
298 *
299 * @return The values of the properties(type: variant)
300 *
301 * @throw sdbusplus::exception_t when it fails
302 */
303 PropertyMap
304 getDbusPropertiesVariant(const char* serviceName, const char* objPath,
305 const char* dbusInterface) const override;
306
John Wang9e242422020-03-05 08:37:50 +0800307 /** @brief The template function to get property from the requested dbus
308 * path
309 *
310 * @tparam Property - Excepted type of the property on dbus
311 *
312 * @param[in] objPath - The Dbus object path
313 * @param[in] dbusProp - The property name to get
314 * @param[in] dbusInterface - The Dbus interface
315 *
316 * @return The value of the property
317 *
Patrick Williams84b790c2022-07-22 19:26:56 -0500318 * @throw sdbusplus::exception_t when dbus request fails
John Wang9e242422020-03-05 08:37:50 +0800319 * std::bad_variant_access when \p Property and property on dbus do
320 * not match
321 */
John Wang92b3c972019-10-17 11:06:41 +0800322 template <typename Property>
323 auto getDbusProperty(const char* objPath, const char* dbusProp,
324 const char* dbusInterface)
325 {
Patrick Williams6da4f912023-05-10 07:50:53 -0500326 auto VariantValue = getDbusPropertyVariant(objPath, dbusProp,
327 dbusInterface);
John Wang92b3c972019-10-17 11:06:41 +0800328 return std::get<Property>(VariantValue);
329 }
George Liu1e44c732020-02-28 20:20:06 +0800330
331 /** @brief Set Dbus property
332 *
333 * @param[in] dBusMap - Object path, property name, interface and property
334 * type for the D-Bus object
335 * @param[in] value - The value to be set
John Wang9e242422020-03-05 08:37:50 +0800336 *
Patrick Williams84b790c2022-07-22 19:26:56 -0500337 * @throw sdbusplus::exception_t when it fails
George Liu1e44c732020-02-28 20:20:06 +0800338 */
339 void setDbusProperty(const DBusMapping& dBusMap,
340 const PropertyValue& value) const override;
Riya Dixit754041d2024-02-20 06:15:49 -0600341
342 /** @brief This function retrieves the properties of an object managed
343 * by the specified D-Bus service located at the given object path.
344 *
345 * @param[in] service - The D-Bus service providing the managed object
346 * @param[in] value - The object path of the managed object
347 *
348 * @return A hierarchical structure representing the properties of the
349 * managed object.
Patrick Williams897b0f82024-04-14 02:31:48 -0500350 * @throw sdbusplus::exception_t when it fails
Riya Dixit754041d2024-02-20 06:15:49 -0600351 */
352 static ObjectValueTree getManagedObj(const char* service, const char* path);
353
354 /** @brief Retrieve the inventory objects managed by a specified class.
355 * The retrieved inventory objects are cached statically
356 * and returned upon subsequent calls to this function.
357 *
358 * @tparam ClassType - The class type that manages the inventory objects.
359 *
360 * @return A reference to the cached inventory objects.
361 */
362 template <typename ClassType>
363 static auto& getInventoryObjects()
364 {
365 static ObjectValueTree object = ClassType::getManagedObj(
366 inventoryManager::interface, inventoryPath);
367 return object;
368 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500369};
370
Deepak Kodihalli3cd61812020-03-10 06:38:45 -0500371/** @brief Fetch parent D-Bus object based on pathname
372 *
373 * @param[in] dbusObj - child D-Bus object
374 *
375 * @return std::string - the parent D-Bus object path
376 */
377inline std::string findParent(const std::string& dbusObj)
378{
379 fs::path p(dbusObj);
380 return p.parent_path().string();
381}
382
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500383/** @brief Read (static) MCTP EID of host firmware from a file
384 *
385 * @return uint8_t - MCTP EID
386 */
387uint8_t readHostEID();
Tom Joseph250c4752020-04-15 10:32:45 +0530388
TOM JOSEPHd4d97a52020-03-23 14:36:34 +0530389/** @brief Convert a value in the JSON to a D-Bus property value
390 *
391 * @param[in] type - type of the D-Bus property
392 * @param[in] value - value in the JSON file
393 *
394 * @return PropertyValue - the D-Bus property value
395 */
396PropertyValue jsonEntryToDbusVal(std::string_view type,
397 const nlohmann::json& value);
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500398
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500399/** @brief Find State Effecter PDR
400 * @param[in] tid - PLDM terminus ID.
401 * @param[in] entityID - entity that can be associated with PLDM State set.
402 * @param[in] stateSetId - value that identifies PLDM State set.
403 * @param[in] repo - pointer to BMC's primary PDR repo.
404 * @return array[array[uint8_t]] - StateEffecterPDRs
405 */
406std::vector<std::vector<uint8_t>> findStateEffecterPDR(uint8_t tid,
407 uint16_t entityID,
408 uint16_t stateSetId,
409 const pldm_pdr* repo);
Chicago Duan738e4d82020-05-28 16:39:19 +0800410/** @brief Find State Sensor PDR
411 * @param[in] tid - PLDM terminus ID.
412 * @param[in] entityID - entity that can be associated with PLDM State set.
413 * @param[in] stateSetId - value that identifies PLDM State set.
414 * @param[in] repo - pointer to BMC's primary PDR repo.
415 * @return array[array[uint8_t]] - StateSensorPDRs
416 */
417std::vector<std::vector<uint8_t>> findStateSensorPDR(uint8_t tid,
418 uint16_t entityID,
419 uint16_t stateSetId,
420 const pldm_pdr* repo);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500421
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500422/** @brief Find sensor id from a state sensor PDR
423 *
424 * @param[in] pdrRepo - PDR repository
425 * @param[in] tid - terminus id
426 * @param[in] entityType - entity type
427 * @param[in] entityInstance - entity instance number
428 * @param[in] containerId - container id
429 * @param[in] stateSetId - state set id
430 *
431 * @return uint16_t - the sensor id
432 */
433uint16_t findStateSensorId(const pldm_pdr* pdrRepo, uint8_t tid,
434 uint16_t entityType, uint16_t entityInstance,
435 uint16_t containerId, uint16_t stateSetId);
436
Tom Joseph250c4752020-04-15 10:32:45 +0530437/** @brief Find effecter id from a state effecter pdr
438 * @param[in] pdrRepo - PDR repository
439 * @param[in] entityType - entity type
440 * @param[in] entityInstance - entity instance number
441 * @param[in] containerId - container id
442 * @param[in] stateSetId - state set id
Sampa Misraa4a96162020-07-14 05:33:46 -0500443 * @param[in] localOrRemote - true for checking local repo and false for remote
444 * repo
Tom Joseph250c4752020-04-15 10:32:45 +0530445 *
446 * @return uint16_t - the effecter id
447 */
448uint16_t findStateEffecterId(const pldm_pdr* pdrRepo, uint16_t entityType,
449 uint16_t entityInstance, uint16_t containerId,
Sampa Misraa4a96162020-07-14 05:33:46 -0500450 uint16_t stateSetId, bool localOrRemote);
Tom Joseph250c4752020-04-15 10:32:45 +0530451
Chicago Duanfe4d88b2020-06-12 16:44:13 +0800452/** @brief Emit the sensor event signal
453 *
454 * @param[in] tid - the terminus id
455 * @param[in] sensorId - sensorID value of the sensor
456 * @param[in] sensorOffset - Identifies which state sensor within a
457 * composite state sensor the event is being returned for
458 * @param[in] eventState - The event state value from the state change that
459 * triggered the event message
460 * @param[in] previousEventState - The event state value for the state from
461 * which the present event state was entered.
462 * @return PLDM completion code
463 */
464int emitStateSensorEventSignal(uint8_t tid, uint16_t sensorId,
465 uint8_t sensorOffset, uint8_t eventState,
466 uint8_t previousEventState);
467
Sridevi Rameshae28bc72020-12-10 07:21:16 -0600468/** @brief Print the buffer
469 *
Tom Josephe5268cd2021-09-07 13:04:03 +0530470 * @param[in] isTx - True if the buffer is an outgoing PLDM message, false if
471 the buffer is an incoming PLDM message
472 * @param[in] buffer - Buffer to print
Sridevi Rameshae28bc72020-12-10 07:21:16 -0600473 *
474 * @return - None
475 */
Tom Josephe5268cd2021-09-07 13:04:03 +0530476void printBuffer(bool isTx, const std::vector<uint8_t>& buffer);
Sridevi Rameshae28bc72020-12-10 07:21:16 -0600477
Tom Joseph54922072021-06-19 02:45:46 -0700478/** @brief Convert the buffer to std::string
479 *
480 * If there are characters that are not printable characters, it is replaced
481 * with space(0x20).
482 *
483 * @param[in] var - pointer to data and length of the data
484 *
485 * @return std::string equivalent of variable field
486 */
487std::string toString(const struct variable_field& var);
488
George Liu872f0f62021-11-25 16:26:16 +0800489/** @brief Split strings according to special identifiers
490 *
491 * We can split the string according to the custom identifier(';', ',', '&' or
492 * others) and store it to vector.
493 *
494 * @param[in] srcStr - The string to be split
495 * @param[in] delim - The custom identifier
496 * @param[in] trimStr - The first and last string to be trimmed
497 *
498 * @return std::vector<std::string> Vectors are used to store strings
499 */
500std::vector<std::string> split(std::string_view srcStr, std::string_view delim,
501 std::string_view trimStr = "");
Manojkiran Edaef773052021-07-29 09:29:28 +0530502/** @brief Get the current system time in readable format
503 *
504 * @return - std::string equivalent of the system time
505 */
506std::string getCurrentSystemTime();
George Liu872f0f62021-11-25 16:26:16 +0800507
Sridevi Ramesheefe49b2022-06-27 11:51:02 -0500508/** @brief checks if the FRU is actually present.
509 * @param[in] objPath - FRU object path.
510 *
511 * @return bool to indicate presence or absence of FRU.
512 */
513bool checkForFruPresence(const std::string& objPath);
514
Sagar Srinivas5db6e872023-12-01 10:03:30 -0600515/** @brief Method to check if the logical bit is set
516 *
517 * @param[containerId] - container id of the entity
518 *
519 * @return true or false based on the logic bit set
520 */
521bool checkIfLogicalBitSet(const uint16_t& containerId);
Pavithra Barithaya5e542be2021-08-13 00:33:31 -0500522
523/** @brief setting the present property
524 *
525 * @param[in] objPath - the object path of the fru
526 * @param[in] present - status to set either true/false
527 */
528void setFruPresence(const std::string& fruObjPath, bool present);
George Liu83409572019-12-24 18:42:54 +0800529} // namespace utils
Sampa Misra032bd502019-03-06 05:03:22 -0600530} // namespace pldm