Skip to content

Instantly share code, notes, and snippets.

@mine260309
Created September 25, 2019 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mine260309/aff3c3c2d2cc94edc9d09d59256b61b7 to your computer and use it in GitHub Desktop.
Save mine260309/aff3c3c2d2cc94edc9d09d59256b61b7 to your computer and use it in GitHub Desktop.
# Put the binaries on BMC
### Test test_sdbusplus_emit_object
root@romulus:/tmp# ./test_sdbusplus_emit_object&
[1] 445
### By default, the object has 4 interfaces
root@romulus:/tmp# busctl call xyz.openbmc_project.ObjectMapper /xyz/openbmc_project/object_mapper xyz.openbmc_project.ObjectMapper GetObject sas /xyz/openbmc_project/leiyu 0
a{sas} 1 "xyz.openbmc_project.LeiYu.Test" 4 "org.freedesktop.DBus.Introspectable" "org.freedesktop.DBus.ObjectManager" "org.freedesktop.DBus.Peer" "org.freedesktop.DBus.Properties"
root@romulus:/tmp# kill -10 445
root@romulus:/tmp# Signal: 10
### Below is expected, the object now has 2 new interfaces created by our code
root@romulus:/tmp# busctl call xyz.openbmc_project.ObjectMapper /xyz/openbmc_project/object_mapper xyz.openbmc_project.ObjectMapper GetObject sas /xyz/openbmc_project/leiyu 0
a{sas} 1 "xyz.openbmc_project.LeiYu.Test" 6 "org.freedesktop.DBus.Introspectable" "org.freedesktop.DBus.ObjectManager" "org.freedesktop.DBus.Peer" "org.freedesktop.DBus.Properties" "xyz.openbmc_project.Software.ActivationBlocksTransition" "xyz.openbmc_project.Software.ActivationProgress"
root@romulus:/tmp# kill -12 445
root@romulus:/tmp# Signal: 12
test_sdbusplus.cpp:26:~ActivationBlocksTransition
test_sdbusplus.cpp:41:~ActivationProgress
### Now this is the problem, after sdbusplus::server::object::object is destructed,
### the object now only has 1 interface!
root@romulus:/tmp# busctl call xyz.openbmc_project.ObjectMapper /xyz/openbmc_project/object_mapper xyz.openbmc_project.ObjectMapper GetObject sas /xyz/openbmc_project/leiyu 0
a{sas} 1 "xyz.openbmc_project.LeiYu.Test" 1 "org.freedesktop.DBus.ObjectManager"
### Test test_sdbusplus_emit_interfaces
root@romulus:/tmp# ./test_sdbusplus_emit_interfaces&
[1] 449
root@romulus:/tmp# busctl call xyz.openbmc_project.ObjectMapper /xyz/openbmc_project/object_mapper xyz.openbmc_project.ObjectMapper GetObject sas /xyz/openbmc_project/leiyu 0
a{sas} 1 "xyz.openbmc_project.LeiYu.Test" 4 "org.freedesktop.DBus.Introspectable" "org.freedesktop.DBus.ObjectManager" "org.freedesktop.DBus.Peer" "org.freedesktop.DBus.Properties"
root@romulus:/tmp# kill -10 449
root@romulus:/tmp# Signal: 10
root@romulus:/tmp# busctl call xyz.openbmc_project.ObjectMapper /xyz/openbmc_project/object_mapper xyz.openbmc_project.ObjectMapper GetObject sas /xyz/openbmc_project/leiyu 0
a{sas} 1 "xyz.openbmc_project.LeiYu.Test" 6 "org.freedesktop.DBus.Introspectable" "org.freedesktop.DBus.ObjectManager" "org.freedesktop.DBus.Peer" "org.freedesktop.DBus.Properties" "xyz.openbmc_project.Software.ActivationBlocksTransition" "xyz.openbmc_project.Software.ActivationProgress"
root@romulus:/tmp# kill -12 449
root@romulus:/tmp# Signal: 12
test_sdbusplus.cpp:27:~ActivationBlocksTransition
test_sdbusplus.cpp:43:~ActivationProgress
### Now this is expected, after sdbusplus::server::object::object is destructed,
### the two interfaces are removed from DBus, the object remains as before.
root@romulus:/tmp# busctl call xyz.openbmc_project.ObjectMapper /xyz/openbmc_project/object_mapper xyz.openbmc_project.ObjectMapper GetObject sas /xyz/openbmc_project/leiyu 0
a{sas} 1 "xyz.openbmc_project.LeiYu.Test" 4 "org.freedesktop.DBus.Introspectable" "org.freedesktop.DBus.ObjectManager" "org.freedesktop.DBus.Peer" "org.freedesktop.DBus.Properties"
#include <csignal>
#include <cstdio>
#include <sdbusplus/bus.hpp>
#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
#include <xyz/openbmc_project/Software/ActivationProgress/server.hpp>
using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::Software::server::
ActivationBlocksTransition>;
using ActivationProgressInherit = sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
{
public:
ActivationBlocksTransition(sdbusplus::bus::bus& bus,
const std::string& path) :
ActivationBlocksTransitionInherit(bus, path.c_str(),
ActivationBlocksTransition::action::EMIT_INTERFACE_ADDED)
{
// Empty
}
~ActivationBlocksTransition()
{
printf("%s:%d:%s\n", __FILE__, __LINE__, __func__);
}
};
class ActivationProgress : public ActivationProgressInherit
{
public:
ActivationProgress(sdbusplus::bus::bus& bus,
const std::string& path) :
ActivationProgressInherit(bus, path.c_str(),
ActivationProgress::action::EMIT_INTERFACE_ADDED)
{
// Empty
}
~ActivationProgress()
{
printf("%s:%d:%s\n", __FILE__, __LINE__, __func__);
}
};
sdbusplus::bus::bus& getBus()
{
static auto bus = sdbusplus::bus::new_default();
return bus;
}
constexpr auto myService = "xyz.openbmc_project.LeiYu.Test";
constexpr auto objPath = "/xyz/openbmc_project/leiyu";
std::unique_ptr<ActivationBlocksTransitionInherit> block;
std::unique_ptr<ActivationProgressInherit> progress;
void signal_handler( int signal_num ) {
printf("Signal: %d\n", signal_num);
if (signal_num == SIGUSR1)
{
block = std::make_unique<ActivationBlocksTransition>(getBus(), objPath);
progress = std::make_unique<ActivationProgress>(getBus(), objPath);
}
else if(signal_num == SIGUSR2)
{
block.reset();
progress.reset();
}
}
int main(int, char**) {
signal(SIGUSR1, signal_handler);
signal(SIGUSR2, signal_handler);
auto& bus = getBus();
sdbusplus::server::manager::manager objManager(bus, objPath);
bus.request_name(myService);
while(true)
{
bus.process_discard();
bus.wait();
}
return 0;
}
#include <csignal>
#include <cstdio>
#include <sdbusplus/bus.hpp>
#include <xyz/openbmc_project/Software/ActivationBlocksTransition/server.hpp>
#include <xyz/openbmc_project/Software/ActivationProgress/server.hpp>
using ActivationBlocksTransitionInherit = sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::Software::server::
ActivationBlocksTransition>;
using ActivationProgressInherit = sdbusplus::server::object::object<
sdbusplus::xyz::openbmc_project::Software::server::ActivationProgress>;
class ActivationBlocksTransition : public ActivationBlocksTransitionInherit
{
public:
ActivationBlocksTransition(sdbusplus::bus::bus& bus,
const std::string& path) :
ActivationBlocksTransitionInherit(bus, path.c_str())
{
// Empty
}
~ActivationBlocksTransition()
{
printf("%s:%d:%s\n", __FILE__, __LINE__, __func__);
}
};
class ActivationProgress : public ActivationProgressInherit
{
public:
ActivationProgress(sdbusplus::bus::bus& bus,
const std::string& path) :
ActivationProgressInherit(bus, path.c_str())
{
// Empty
}
~ActivationProgress()
{
printf("%s:%d:%s\n", __FILE__, __LINE__, __func__);
}
};
sdbusplus::bus::bus& getBus()
{
static auto bus = sdbusplus::bus::new_default();
return bus;
}
constexpr auto myService = "xyz.openbmc_project.LeiYu.Test";
constexpr auto objPath = "/xyz/openbmc_project/leiyu";
std::unique_ptr<ActivationBlocksTransitionInherit> block;
std::unique_ptr<ActivationProgressInherit> progress;
void signal_handler( int signal_num ) {
printf("Signal: %d\n", signal_num);
if (signal_num == SIGUSR1)
{
block = std::make_unique<ActivationBlocksTransition>(getBus(), objPath);
progress = std::make_unique<ActivationProgress>(getBus(), objPath);
}
else if(signal_num == SIGUSR2)
{
block.reset();
progress.reset();
}
}
int main(int, char**) {
signal(SIGUSR1, signal_handler);
signal(SIGUSR2, signal_handler);
auto& bus = getBus();
sdbusplus::server::manager::manager objManager(bus, objPath);
bus.request_name(myService);
while(true)
{
bus.process_discard();
bus.wait();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment