Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions include/cm_object.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#pragma once

#include <sdbusplus/async/context.hpp>
#include <sdbusplus/bus.hpp>

#include <string>

namespace concurrent_maintenance
{

class CMObject
{
public:
CMObject(sdbusplus::async::context& ctx, const std::string& path);

CMObject(const CMObject&) = delete;
CMObject& operator=(const CMObject&) = delete;
CMObject(CMObject&&) = delete;
CMObject& operator=(CMObject&&) = delete;

~CMObject() = default;

// Get the object path
const std::string& getPath() const
{
return objectPath;
}

private:
std::string objectPath;

// TODO: Add progress interface when implementing progress tracking
// When adding the progress interface, use sdbusplus::server::object_t:
// Example:
// sdbusplus::server::object_t<xyz::openbmc_project::Common::Progress::server::Progress>
// dbusObject(bus, path.c_str(), action::defer_emit);
// Then call: dbusObject.emit_object_added();
};

} // namespace concurrent_maintenance
47 changes: 47 additions & 0 deletions include/cm_object_manager.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#pragma once

#include "cm_object.hpp"

#include <sdbusplus/async/context.hpp>

#include <memory>
#include <string>

namespace concurrent_maintenance
{

/**
* @brief Manages the creation and lifecycle of CM objects
*
* This class is responsible for:
* 1. CM type determination from inventory path
* 2. Creating objects for different types of CM (FSI, BMC, Switchboard).
* 3. Creating differnt handlers for each type of CM, and calling them
* based on the CM type
* Currently implements basic CM object creation [2].
*/
class CMObjectManager
{
public:
explicit CMObjectManager(sdbusplus::async::context& ctx);

CMObjectManager(const CMObjectManager&) = delete;
CMObjectManager& operator=(const CMObjectManager&) = delete;
CMObjectManager(CMObjectManager&&) = delete;
CMObjectManager& operator=(CMObjectManager&&) = delete;

~CMObjectManager() = default;

/**
* @brief Create a CM object for add or remove operation
*
* @param isRemove - true for remove operation, false for add operation
* @return std::unique_ptr<CMObject> - The created CM object
*/
std::unique_ptr<CMObject> createCMObject(bool isRemove);

private:
sdbusplus::async::context& ctx;
};

} // namespace concurrent_maintenance
23 changes: 23 additions & 0 deletions include/manager.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
#pragma once

#include "cm_object.hpp"
#include "cm_object_manager.hpp"

#include <sdbusplus/async/context.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/bus/match.hpp>

#include <memory>
#include <string>

namespace concurrent_maintenance
{
Expand All @@ -19,6 +27,21 @@ class Manager

private:
sdbusplus::async::context& ctx;

// "ReadyToRemove" Property change signal match
std::unique_ptr<sdbusplus::bus::match_t> readyToRemoveMatch;

// CM object manager
CMObjectManager cmObjectManager;

// Current CM object
std::unique_ptr<CMObject> currentCMObject;

// Callback for ReadyToRemove property change
void handleReadyToRemoveChange(sdbusplus::message_t& msg);

// Create/remove CM object based on ReadyToRemove value
void manageCMObject(bool readyToRemove);
};

} // namespace concurrent_maintenance
7 changes: 6 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ inc = include_directories('include')

executable(
'ibm-concurrent-maintenance',
['src/main.cpp', 'src/manager.cpp'],
[
'src/main.cpp',
'src/manager.cpp',
'src/cm_object.cpp',
'src/cm_object_manager.cpp',
],
include_directories: inc,
dependencies: [sdbusplus_dep, phosphor_logging_dep],
install: true,
Expand Down
25 changes: 25 additions & 0 deletions src/cm_object.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "cm_object.hpp"

#include <phosphor-logging/lg2.hpp>

#include <chrono>

namespace concurrent_maintenance
{

CMObject::CMObject(sdbusplus::async::context& /*ctx*/,
const std::string& path) : objectPath(path)
{
lg2::info("Creating object at path: {PATH}", "PATH", path);

// TODO: When implementing progress interface, create the actual D-Bus
// object here Example: auto& bus = ctx.get_bus(); dbusObject =
// std::make_unique<sdbusplus::server::object_t<...>>(
// bus, path.c_str(),
// sdbusplus::server::object_t<...>::action::defer_emit);
// dbusObject->emit_object_added();

lg2::info("Object created at path: {PATH}", "PATH", path);
}

} // namespace concurrent_maintenance
26 changes: 26 additions & 0 deletions src/cm_object_manager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "cm_object_manager.hpp"

#include <phosphor-logging/lg2.hpp>

namespace concurrent_maintenance
{

constexpr auto cmRemoveObjectPath = "/com/ibm/ConcurrentMaintenance/remove";
constexpr auto cmAddObjectPath = "/com/ibm/ConcurrentMaintenance/add";

CMObjectManager::CMObjectManager(sdbusplus::async::context& ctx) : ctx(ctx)
{
lg2::info("CMObjectManager initialized");
}

std::unique_ptr<CMObject> CMObjectManager::createCMObject(bool isRemove)
{
const std::string cmObjectPath = isRemove ? cmRemoveObjectPath
: cmAddObjectPath;

lg2::info("CM object path: {PATH}", "PATH", cmObjectPath);

return std::make_unique<CMObject>(ctx, cmObjectPath);
}

} // namespace concurrent_maintenance
5 changes: 5 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

#include <phosphor-logging/lg2.hpp>
#include <sdbusplus/async/context.hpp>
#include <sdbusplus/server/manager.hpp>

int main()
{
sdbusplus::async::context ctx;

// Create ObjectManager for concurrent maintenance
constexpr auto objManagerPath = "/com/ibm/ConcurrentMaintenance";
sdbusplus::server::manager_t objManager(ctx, objManagerPath);

ctx.request_name("com.ibm.ConcurrentMaintenance");

concurrent_maintenance::Manager manager(ctx);
Expand Down
75 changes: 74 additions & 1 deletion src/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,85 @@

#include <phosphor-logging/lg2.hpp>

#include <string_view>

namespace concurrent_maintenance
{

Manager::Manager(sdbusplus::async::context& ctx) : ctx(ctx)
constexpr auto readyToRemoveProperty = "ReadyToRemove";

Manager::Manager(sdbusplus::async::context& ctx) :
ctx(ctx), cmObjectManager(ctx)
{
lg2::info("Concurrent Maintenance manager initialized");

// Create property change signal match for ReadyToRemove property
// This will match all child objects under /xyz/openbmc_project/inventory
// that implement xyz.openbmc_project.State.ReadyToRemove interface
auto& bus = ctx.get_bus();

readyToRemoveMatch = std::make_unique<sdbusplus::bus::match_t>(
bus,
sdbusplus::bus::match::rules::propertiesChangedNamespace(
"/xyz/openbmc_project/inventory",
"xyz.openbmc_project.State.ReadyToRemove"),
[this](sdbusplus::message_t& msg) { handleReadyToRemoveChange(msg); });

lg2::info(
"ReadyToRemove property watcher registered for all inventory objects");
}

void Manager::handleReadyToRemoveChange(sdbusplus::message_t& msg)
{
std::string interface;
std::map<std::string, std::variant<bool>> changedProperties;

try
{
msg.read(interface, changedProperties);

auto it = changedProperties.find(readyToRemoveProperty);
if (it != changedProperties.end())
{
bool readyToRemove = std::get<bool>(it->second);
const auto& objectPath = msg.get_path();
lg2::info("ReadyToRemove property changed on {PATH}: {VALUE}",
"PATH", objectPath, "VALUE", readyToRemove);

// Manage CM object based on property value
manageCMObject(readyToRemove);
}
}
catch (const std::exception& e)
{
lg2::error("Error handling ReadyToRemove property change: {ERROR}",
"ERROR", e);
}
}

void Manager::manageCMObject(bool readyToRemove)
{
try
{
// Check if a CM object already exists
if (currentCMObject)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to distinguish between the active CM object and the newly requested CM object so the new object can publish an error/status before being removed right? so we need to handle it here?

{
lg2::error(
"CM is already in progress. Object already exists at path: {PATH}.",
"PATH", currentCMObject->getPath());
return;
}

// Call CMObjectManager to create CM object
currentCMObject = cmObjectManager.createCMObject(readyToRemove);

lg2::info("CM object created at {PATH}", "PATH",
currentCMObject->getPath());
}
catch (const std::exception& e)
{
lg2::error("Error managing CM object: {ERROR}", "ERROR", e);
}
}

} // namespace concurrent_maintenance
7 changes: 6 additions & 1 deletion test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ gtest_dep = dependency('gtest', main: true, required: get_option('tests'))

test_manager = executable(
'test-manager',
['test_manager.cpp', '../src/manager.cpp'],
[
'test_manager.cpp',
'../src/manager.cpp',
'../src/cm_object.cpp',
'../src/cm_object_manager.cpp',
],
include_directories: inc,
dependencies: [gtest_dep, sdbusplus_dep, phosphor_logging_dep],
)
Expand Down