blob: 5561399e1dca2f300cbaf46c090036b3257430b6 [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;
Gilbert Chen44524a52022-02-14 12:12:25 +000043using ObjectMapper = sdbusplus::client::xyz::openbmc_project::ObjectMapper<>;
Gilbert Chen44524a52022-02-14 12:12:25 +000044using inventoryManager =
45 sdbusplus::client::xyz::openbmc_project::inventory::Manager<>;
46
47constexpr auto dbusProperties = "org.freedesktop.DBus.Properties";
48constexpr auto mapperService = ObjectMapper::default_service;
49constexpr auto inventoryPath = "/xyz/openbmc_project/inventory";
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050050/** @struct CustomFD
51 *
52 * RAII wrapper for file descriptor.
53 */
54struct CustomFD
55{
56 CustomFD(const CustomFD&) = delete;
57 CustomFD& operator=(const CustomFD&) = delete;
58 CustomFD(CustomFD&&) = delete;
59 CustomFD& operator=(CustomFD&&) = delete;
60
Patrick Williams6da4f912023-05-10 07:50:53 -050061 CustomFD(int fd) : fd(fd) {}
Jinu Joy Thomasf666db12019-05-29 05:22:31 -050062
63 ~CustomFD()
64 {
65 if (fd >= 0)
66 {
67 close(fd);
68 }
69 }
70
71 int operator()() const
72 {
73 return fd;
74 }
75
76 private:
77 int fd = -1;
78};
79
Sampa Misrab37be312019-07-03 02:26:41 -050080/** @brief Calculate the pad for PLDM data
81 *
82 * @param[in] data - Length of the data
83 * @return - uint8_t - number of pad bytes
84 */
85uint8_t getNumPadBytes(uint32_t data);
86
George Liu83409572019-12-24 18:42:54 +080087/** @brief Convert uint64 to date
88 *
89 * @param[in] data - time date of uint64
90 * @param[out] year - year number in dec
91 * @param[out] month - month number in dec
92 * @param[out] day - day of the month in dec
93 * @param[out] hour - number of hours in dec
94 * @param[out] min - number of minutes in dec
95 * @param[out] sec - number of seconds in dec
Manojkiran Eda2576aec2024-06-17 12:05:17 +053096 * @return true if decode success, false if decode failed
George Liu83409572019-12-24 18:42:54 +080097 */
98bool uintToDate(uint64_t data, uint16_t* year, uint8_t* month, uint8_t* day,
99 uint8_t* hour, uint8_t* min, uint8_t* sec);
100
101/** @brief Convert effecter data to structure of set_effecter_state_field
102 *
103 * @param[in] effecterData - the date of effecter
George Liuba4c1fb2020-02-05 14:13:30 +0800104 * @param[in] effecterCount - the number of individual sets of effecter
105 * information
106 * @return[out] parse success and get a valid set_effecter_state_field
107 * structure, return nullopt means parse failed
George Liu83409572019-12-24 18:42:54 +0800108 */
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400109std::optional<std::vector<set_effecter_state_field>> parseEffecterData(
110 const std::vector<uint8_t>& effecterData, uint8_t effecterCount);
Sampa Misra032bd502019-03-06 05:03:22 -0600111
112/**
Sampa Misraaa8ae722019-12-12 03:20:40 -0600113 * @brief creates an error log
114 * @param[in] errorMsg - the error message
115 */
Manojkiran Eda92fb0b52024-04-17 10:48:17 +0530116void reportError(const char* errorMsg);
Sampa Misraaa8ae722019-12-12 03:20:40 -0600117
Sampa Misra032bd502019-03-06 05:03:22 -0600118/** @brief Convert any Decimal number to BCD
119 *
120 * @tparam[in] decimal - Decimal number
121 * @return Corresponding BCD number
122 */
123template <typename T>
124T decimalToBcd(T decimal)
125{
126 T bcd = 0;
127 T rem = 0;
128 auto cnt = 0;
129
130 while (decimal)
131 {
132 rem = decimal % 10;
133 bcd = bcd + (rem << cnt);
134 decimal = decimal / 10;
135 cnt += 4;
136 }
137
138 return bcd;
139}
140
George Liu1e44c732020-02-28 20:20:06 +0800141struct DBusMapping
142{
143 std::string objectPath; //!< D-Bus object path
144 std::string interface; //!< D-Bus interface
145 std::string propertyName; //!< D-Bus property name
146 std::string propertyType; //!< D-Bus property type
147};
148
149using PropertyValue =
150 std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t,
Riya Dixit754041d2024-02-20 06:15:49 -0600151 uint64_t, double, std::string, std::vector<uint8_t>,
152 std::vector<std::string>>;
Deepak Kodihalli6b1d1ca2020-04-27 07:24:51 -0500153using DbusProp = std::string;
154using DbusChangedProps = std::map<DbusProp, PropertyValue>;
Sampa Misraaea5dde2020-08-31 08:33:47 -0500155using DBusInterfaceAdded = std::vector<
156 std::pair<pldm::dbus::Interface,
157 std::vector<std::pair<pldm::dbus::Property,
158 std::variant<pldm::dbus::Property>>>>>;
Kamalkumar Patel7d427f12024-05-16 03:44:00 -0500159
Manojkiran Eda1ef62c32021-04-24 07:23:18 +0530160using ObjectPath = std::string;
Kamalkumar Patel7d427f12024-05-16 03:44:00 -0500161using EntityName = std::string;
162using Entities = std::vector<pldm_entity_node*>;
163using EntityAssociations = std::vector<Entities>;
164using ObjectPathMaps = std::map<fs::path, pldm_entity_node*>;
165using EntityMaps = std::map<pldm::pdr::EntityType, EntityName>;
166
Manojkiran Eda1ef62c32021-04-24 07:23:18 +0530167using ServiceName = std::string;
168using Interfaces = std::vector<std::string>;
169using MapperServiceMap = std::vector<std::pair<ServiceName, Interfaces>>;
170using GetSubTreeResponse = std::vector<std::pair<ObjectPath, MapperServiceMap>>;
Pavithra Barithaya2ec82692024-04-29 06:31:10 -0500171using GetSubTreePathsResponse = std::vector<std::string>;
Sridevi Ramesheefe49b2022-06-27 11:51:02 -0500172using PropertyMap = std::map<std::string, PropertyValue>;
173using InterfaceMap = std::map<std::string, PropertyMap>;
Riya Dixit754041d2024-02-20 06:15:49 -0600174using ObjectValueTree = std::map<sdbusplus::message::object_path, InterfaceMap>;
George Liu1e44c732020-02-28 20:20:06 +0800175
176/**
177 * @brief The interface for DBusHandler
178 */
179class DBusHandlerInterface
180{
181 public:
182 virtual ~DBusHandlerInterface() = default;
183
George Liu36e81352020-07-01 14:40:30 +0800184 virtual std::string getService(const char* path,
185 const char* interface) const = 0;
Manojkiran Eda1ef62c32021-04-24 07:23:18 +0530186 virtual GetSubTreeResponse
187 getSubtree(const std::string& path, int depth,
188 const std::vector<std::string>& ifaceList) const = 0;
George Liu36e81352020-07-01 14:40:30 +0800189
Pavithra Barithaya2ec82692024-04-29 06:31:10 -0500190 virtual GetSubTreePathsResponse
191 getSubTreePaths(const std::string& objectPath, int depth,
192 const std::vector<std::string>& ifaceList) const = 0;
193
George Liu1e44c732020-02-28 20:20:06 +0800194 virtual void setDbusProperty(const DBusMapping& dBusMap,
195 const PropertyValue& value) const = 0;
John Wang9e242422020-03-05 08:37:50 +0800196
197 virtual PropertyValue
198 getDbusPropertyVariant(const char* objPath, const char* dbusProp,
199 const char* dbusInterface) const = 0;
Gilbert Chen44524a52022-02-14 12:12:25 +0000200
201 virtual PropertyMap
202 getDbusPropertiesVariant(const char* serviceName, const char* objPath,
203 const char* dbusInterface) const = 0;
George Liu1e44c732020-02-28 20:20:06 +0800204};
205
Sampa Misraa2fa0702019-05-31 01:28:55 -0500206/**
207 * @class DBusHandler
208 *
209 * Wrapper class to handle the D-Bus calls
210 *
211 * This class contains the APIs to handle the D-Bus calls
212 * to cater the request from pldm requester.
213 * A class is created to mock the apis in the test cases
214 */
George Liu1e44c732020-02-28 20:20:06 +0800215class DBusHandler : public DBusHandlerInterface
Sampa Misraa2fa0702019-05-31 01:28:55 -0500216{
217 public:
George Liu0e02c322020-01-01 09:41:51 +0800218 /** @brief Get the bus connection. */
219 static auto& getBus()
220 {
221 static auto bus = sdbusplus::bus::new_default();
222 return bus;
223 }
224
225 /**
226 * @brief Get the DBUS Service name for the input dbus path
John Wang9e242422020-03-05 08:37:50 +0800227 *
George Liu0e02c322020-01-01 09:41:51 +0800228 * @param[in] path - DBUS object path
229 * @param[in] interface - DBUS Interface
John Wang9e242422020-03-05 08:37:50 +0800230 *
George Liu0e02c322020-01-01 09:41:51 +0800231 * @return std::string - the dbus service name
John Wang9e242422020-03-05 08:37:50 +0800232 *
Patrick Williams84b790c2022-07-22 19:26:56 -0500233 * @throw sdbusplus::exception_t when it fails
George Liu0e02c322020-01-01 09:41:51 +0800234 */
George Liu36e81352020-07-01 14:40:30 +0800235 std::string getService(const char* path,
236 const char* interface) const override;
George Liu0e02c322020-01-01 09:41:51 +0800237
Manojkiran Eda1ef62c32021-04-24 07:23:18 +0530238 /**
239 * @brief Get the Subtree response from the mapper
240 *
241 * @param[in] path - DBUS object path
242 * @param[in] depth - Search depth
243 * @param[in] ifaceList - list of the interface that are being
244 * queried from the mapper
245 *
246 * @return GetSubTreeResponse - the mapper subtree response
247 *
Patrick Williams84b790c2022-07-22 19:26:56 -0500248 * @throw sdbusplus::exception_t when it fails
Manojkiran Eda1ef62c32021-04-24 07:23:18 +0530249 */
250 GetSubTreeResponse
251 getSubtree(const std::string& path, int depth,
252 const std::vector<std::string>& ifaceList) const override;
253
Pavithra Barithaya2ec82692024-04-29 06:31:10 -0500254 /** @brief Get Subtree path response from the mapper
255 *
256 * @param[in] path - DBUS object path
257 * @param[in] depth - Search depth
258 * @param[in] ifaceList - list of the interface that are being
259 * queried from the mapper
260 *
261 * @return std::vector<std::string> vector of subtree paths
262 */
263 GetSubTreePathsResponse getSubTreePaths(
264 const std::string& objectPath, int depth,
265 const std::vector<std::string>& ifaceList) const override;
266
John Wang9e242422020-03-05 08:37:50 +0800267 /** @brief Get property(type: variant) from the requested dbus
268 *
269 * @param[in] objPath - The Dbus object path
270 * @param[in] dbusProp - The property name to get
271 * @param[in] dbusInterface - The Dbus interface
272 *
273 * @return The value of the property(type: variant)
274 *
Patrick Williams84b790c2022-07-22 19:26:56 -0500275 * @throw sdbusplus::exception_t when it fails
John Wang9e242422020-03-05 08:37:50 +0800276 */
277 PropertyValue
278 getDbusPropertyVariant(const char* objPath, const char* dbusProp,
279 const char* dbusInterface) const override;
George Liu0e02c322020-01-01 09:41:51 +0800280
Gilbert Chen44524a52022-02-14 12:12:25 +0000281 /** @brief Get All properties(type: variant) from the requested dbus
282 *
283 * @param[in] serviceName - The Dbus service name
284 * @param[in] objPath - The Dbus object path
285 * @param[in] dbusInterface - The Dbus interface
286 *
287 * @return The values of the properties(type: variant)
288 *
289 * @throw sdbusplus::exception_t when it fails
290 */
291 PropertyMap
292 getDbusPropertiesVariant(const char* serviceName, const char* objPath,
293 const char* dbusInterface) const override;
294
John Wang9e242422020-03-05 08:37:50 +0800295 /** @brief The template function to get property from the requested dbus
296 * path
297 *
298 * @tparam Property - Excepted type of the property on dbus
299 *
300 * @param[in] objPath - The Dbus object path
301 * @param[in] dbusProp - The property name to get
302 * @param[in] dbusInterface - The Dbus interface
303 *
304 * @return The value of the property
305 *
Patrick Williams84b790c2022-07-22 19:26:56 -0500306 * @throw sdbusplus::exception_t when dbus request fails
John Wang9e242422020-03-05 08:37:50 +0800307 * std::bad_variant_access when \p Property and property on dbus do
308 * not match
309 */
John Wang92b3c972019-10-17 11:06:41 +0800310 template <typename Property>
311 auto getDbusProperty(const char* objPath, const char* dbusProp,
312 const char* dbusInterface)
313 {
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400314 auto VariantValue =
315 getDbusPropertyVariant(objPath, dbusProp, dbusInterface);
John Wang92b3c972019-10-17 11:06:41 +0800316 return std::get<Property>(VariantValue);
317 }
George Liu1e44c732020-02-28 20:20:06 +0800318
319 /** @brief Set Dbus property
320 *
321 * @param[in] dBusMap - Object path, property name, interface and property
322 * type for the D-Bus object
323 * @param[in] value - The value to be set
John Wang9e242422020-03-05 08:37:50 +0800324 *
Patrick Williams84b790c2022-07-22 19:26:56 -0500325 * @throw sdbusplus::exception_t when it fails
George Liu1e44c732020-02-28 20:20:06 +0800326 */
327 void setDbusProperty(const DBusMapping& dBusMap,
328 const PropertyValue& value) const override;
Riya Dixit754041d2024-02-20 06:15:49 -0600329
330 /** @brief This function retrieves the properties of an object managed
331 * by the specified D-Bus service located at the given object path.
332 *
333 * @param[in] service - The D-Bus service providing the managed object
334 * @param[in] value - The object path of the managed object
335 *
336 * @return A hierarchical structure representing the properties of the
337 * managed object.
Patrick Williams897b0f82024-04-14 02:31:48 -0500338 * @throw sdbusplus::exception_t when it fails
Riya Dixit754041d2024-02-20 06:15:49 -0600339 */
340 static ObjectValueTree getManagedObj(const char* service, const char* path);
341
342 /** @brief Retrieve the inventory objects managed by a specified class.
343 * The retrieved inventory objects are cached statically
344 * and returned upon subsequent calls to this function.
345 *
346 * @tparam ClassType - The class type that manages the inventory objects.
347 *
348 * @return A reference to the cached inventory objects.
349 */
350 template <typename ClassType>
351 static auto& getInventoryObjects()
352 {
353 static ObjectValueTree object = ClassType::getManagedObj(
354 inventoryManager::interface, inventoryPath);
355 return object;
356 }
Sampa Misraa2fa0702019-05-31 01:28:55 -0500357};
358
Deepak Kodihalli3cd61812020-03-10 06:38:45 -0500359/** @brief Fetch parent D-Bus object based on pathname
360 *
361 * @param[in] dbusObj - child D-Bus object
362 *
363 * @return std::string - the parent D-Bus object path
364 */
365inline std::string findParent(const std::string& dbusObj)
366{
367 fs::path p(dbusObj);
368 return p.parent_path().string();
369}
370
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500371/** @brief Read (static) MCTP EID of host firmware from a file
372 *
373 * @return uint8_t - MCTP EID
374 */
375uint8_t readHostEID();
Tom Joseph250c4752020-04-15 10:32:45 +0530376
Gilbert Chen6c7fed42022-02-22 15:40:17 +0000377/** @brief Validate the MCTP EID of MCTP endpoint
378 * In `Table 2 - Special endpoint IDs` of DSP0236. EID 0 is NULL_EID.
379 * EID from 1 to 7 is reserved EID. EID 0xFF is broadcast EID.
380 * Those are invalid EID of one MCTP Endpoint.
381 *
382 * @param[in] eid - MCTP EID
383 *
384 * @return true if the MCTP EID is valid otherwise return false.
385 */
386bool isValidEID(eid mctpEid);
387
TOM JOSEPHd4d97a52020-03-23 14:36:34 +0530388/** @brief Convert a value in the JSON to a D-Bus property value
389 *
390 * @param[in] type - type of the D-Bus property
391 * @param[in] value - value in the JSON file
392 *
393 * @return PropertyValue - the D-Bus property value
394 */
395PropertyValue jsonEntryToDbusVal(std::string_view type,
396 const nlohmann::json& value);
Pavithra Barithaya51efaf82020-04-02 02:42:27 -0500397
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500398/** @brief Find State Effecter PDR
399 * @param[in] tid - PLDM terminus ID.
400 * @param[in] entityID - entity that can be associated with PLDM State set.
401 * @param[in] stateSetId - value that identifies PLDM State set.
402 * @param[in] repo - pointer to BMC's primary PDR repo.
403 * @return array[array[uint8_t]] - StateEffecterPDRs
404 */
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400405std::vector<std::vector<uint8_t>> findStateEffecterPDR(
406 uint8_t tid, uint16_t entityID, uint16_t stateSetId, const pldm_pdr* repo);
Chicago Duan738e4d82020-05-28 16:39:19 +0800407/** @brief Find State Sensor PDR
408 * @param[in] tid - PLDM terminus ID.
409 * @param[in] entityID - entity that can be associated with PLDM State set.
410 * @param[in] stateSetId - value that identifies PLDM State set.
411 * @param[in] repo - pointer to BMC's primary PDR repo.
412 * @return array[array[uint8_t]] - StateSensorPDRs
413 */
Patrick Williams16c2a0a2024-08-16 15:20:59 -0400414std::vector<std::vector<uint8_t>> findStateSensorPDR(
415 uint8_t tid, uint16_t entityID, uint16_t stateSetId, const pldm_pdr* repo);
Pavithra Barithaya0f74c982020-04-27 02:17:10 -0500416
Sampa Misra3a0e3b92020-10-21 05:58:00 -0500417/** @brief Find sensor id from a state sensor PDR
418 *
419 * @param[in] pdrRepo - PDR repository
420 * @param[in] tid - terminus id
421 * @param[in] entityType - entity type
422 * @param[in] entityInstance - entity instance number
423 * @param[in] containerId - container id
424 * @param[in] stateSetId - state set id
425 *
426 * @return uint16_t - the sensor id
427 */
428uint16_t findStateSensorId(const pldm_pdr* pdrRepo, uint8_t tid,
429 uint16_t entityType, uint16_t entityInstance,
430 uint16_t containerId, uint16_t stateSetId);
431
Tom Joseph250c4752020-04-15 10:32:45 +0530432/** @brief Find effecter id from a state effecter pdr
433 * @param[in] pdrRepo - PDR repository
434 * @param[in] entityType - entity type
435 * @param[in] entityInstance - entity instance number
436 * @param[in] containerId - container id
437 * @param[in] stateSetId - state set id
Sampa Misraa4a96162020-07-14 05:33:46 -0500438 * @param[in] localOrRemote - true for checking local repo and false for remote
439 * repo
Tom Joseph250c4752020-04-15 10:32:45 +0530440 *
441 * @return uint16_t - the effecter id
442 */
443uint16_t findStateEffecterId(const pldm_pdr* pdrRepo, uint16_t entityType,
444 uint16_t entityInstance, uint16_t containerId,
Sampa Misraa4a96162020-07-14 05:33:46 -0500445 uint16_t stateSetId, bool localOrRemote);
Tom Joseph250c4752020-04-15 10:32:45 +0530446
Chicago Duanfe4d88b2020-06-12 16:44:13 +0800447/** @brief Emit the sensor event signal
448 *
449 * @param[in] tid - the terminus id
450 * @param[in] sensorId - sensorID value of the sensor
451 * @param[in] sensorOffset - Identifies which state sensor within a
452 * composite state sensor the event is being returned for
453 * @param[in] eventState - The event state value from the state change that
454 * triggered the event message
455 * @param[in] previousEventState - The event state value for the state from
456 * which the present event state was entered.
457 * @return PLDM completion code
458 */
459int emitStateSensorEventSignal(uint8_t tid, uint16_t sensorId,
460 uint8_t sensorOffset, uint8_t eventState,
461 uint8_t previousEventState);
462
Sridevi Rameshae28bc72020-12-10 07:21:16 -0600463/** @brief Print the buffer
464 *
Tom Josephe5268cd2021-09-07 13:04:03 +0530465 * @param[in] isTx - True if the buffer is an outgoing PLDM message, false if
466 the buffer is an incoming PLDM message
467 * @param[in] buffer - Buffer to print
Sridevi Rameshae28bc72020-12-10 07:21:16 -0600468 *
469 * @return - None
470 */
Tom Josephe5268cd2021-09-07 13:04:03 +0530471void printBuffer(bool isTx, const std::vector<uint8_t>& buffer);
Sridevi Rameshae28bc72020-12-10 07:21:16 -0600472
Tom Joseph54922072021-06-19 02:45:46 -0700473/** @brief Convert the buffer to std::string
474 *
475 * If there are characters that are not printable characters, it is replaced
476 * with space(0x20).
477 *
478 * @param[in] var - pointer to data and length of the data
479 *
480 * @return std::string equivalent of variable field
481 */
482std::string toString(const struct variable_field& var);
483
George Liu872f0f62021-11-25 16:26:16 +0800484/** @brief Split strings according to special identifiers
485 *
486 * We can split the string according to the custom identifier(';', ',', '&' or
487 * others) and store it to vector.
488 *
489 * @param[in] srcStr - The string to be split
490 * @param[in] delim - The custom identifier
491 * @param[in] trimStr - The first and last string to be trimmed
492 *
493 * @return std::vector<std::string> Vectors are used to store strings
494 */
495std::vector<std::string> split(std::string_view srcStr, std::string_view delim,
496 std::string_view trimStr = "");
Manojkiran Edaef773052021-07-29 09:29:28 +0530497/** @brief Get the current system time in readable format
498 *
499 * @return - std::string equivalent of the system time
500 */
501std::string getCurrentSystemTime();
George Liu872f0f62021-11-25 16:26:16 +0800502
Sridevi Ramesheefe49b2022-06-27 11:51:02 -0500503/** @brief checks if the FRU is actually present.
504 * @param[in] objPath - FRU object path.
505 *
506 * @return bool to indicate presence or absence of FRU.
507 */
508bool checkForFruPresence(const std::string& objPath);
509
Sagar Srinivas5db6e872023-12-01 10:03:30 -0600510/** @brief Method to check if the logical bit is set
511 *
512 * @param[containerId] - container id of the entity
513 *
514 * @return true or false based on the logic bit set
515 */
516bool checkIfLogicalBitSet(const uint16_t& containerId);
Pavithra Barithaya5e542be2021-08-13 00:33:31 -0500517
518/** @brief setting the present property
519 *
520 * @param[in] objPath - the object path of the fru
521 * @param[in] present - status to set either true/false
522 */
523void setFruPresence(const std::string& fruObjPath, bool present);
Thu Nguyenb8cf46b2024-06-15 02:44:35 +0000524
525/** @brief Trim `\0` in string and replace ` ` by `_` to use name in D-Bus
526 * object path
527 *
528 * @param[in] name - the input string
529 *
530 * @return the result string
531 */
532std::string_view trimNameForDbus(std::string& name);
533
George Liu83409572019-12-24 18:42:54 +0800534} // namespace utils
Sampa Misra032bd502019-03-06 05:03:22 -0600535} // namespace pldm