commit | d35c85239a85a101e866a7bd60aff4f40bf77401 | [log] [tgz] |
---|---|---|
author | Lei YU <mine260309@gmail.com> | Fri Dec 13 14:48:03 2019 +0800 |
committer | Lei YU <mine260309@gmail.com> | Wed Jan 15 14:57:52 2020 +0800 |
tree | a52ad1f50a9c26338316457bcf37f20ac87f0f9c | |
parent | 4212292bcf136d04b38ba5116aa568b0fa312798 [diff] |
Fix vtable CI error The CI reports failure in VtableTest.SameContent, where the case is comparing the binary of example vtables constructed from sdbusplus and macros defined in systemd. The root cause has two parts. Part I: When systemd is updated, the members in struct sd_bus_vtable is updated, e.g. * From v239 to v242, sd_bus_vtable.x.start is updated from struct { size_t element_size; } start; to: struct { size_t element_size; uint64_t features; } start; and sd_bus_vtable.x.method is updated from struct { const char *member; const char *signature; const char *result; sd_bus_message_handler_t handler; size_t offset; } method; to: struct { const char *member; const char *signature; const char *result; sd_bus_message_handler_t handler; size_t offset; const char *names; } method; * From v242 to v243, sd_bus_vtable.x.start is updated to struct { size_t element_size; uint64_t features; const unsigned *vtable_format_reference; } start; The code in vtable.hpp only assign the members in v239, the new members are intialized with 0, so it differs from the vtable constructed from macros defined by systemd. The fix is to use macros from systemd in vtable.hpp as well, which is suggested by systemd: > Please do not initialize this structure directly, use the > macros below instead Part II: The `const char *names` in struct method and signal introduced between systemd v239 and v242 is a pointer to const strings. By default they are "empty" strings, but there is no guarantee that the compiler will use the same pointer for the same string. So the test case can not assume the binaries are the same for two vtables even they are constructed with the same parameters. Update the test case to use real `const char*` and handler/get/set functions and check each member of the struct instead of comparing the binary data by memcmp. Tested: Verify the CI passes. Change-Id: I9e94ff16075dd3f12d73e96438c0d864203bdcf4 Signed-off-by: Lei YU <mine260309@gmail.com>
sdbusplus contains two parts:
The sdbusplus library requires sd-bus, which is contained in libsystemd.
The sdbus++ application requires python and the python libraries mako and py-inflection.
The sdbusplus library builds on top of the sd-bus library to create a modern C++ API for D-Bus. The library attempts to be as lightweight as possible, usually compiling to exactly the sd-bus API calls that would have been necessary, while also providing compile-time type-safety and memory leak protection afforded by modern C++ practices.
Consider the following code:
auto b = bus::new_default_system(); auto m = b.new_method_call("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "ListUsers"); auto reply = b.call(m); std::vector<std::tuple<uint32_t, std::string, message::object_path>> users; reply.read(users);
In a few, relatively succinct, C++ lines this snippet will create a D-Bus connection to the system bus, and call the systemd login manager to get a list of active users. The message and bus objects are automatically freed when they leave scope and the message format strings are generated at compile time based on the types being read. Compare this to the corresponding server code within logind.
In general, the library attempts to mimic the naming conventions of the sd-bus library: ex. sd_bus_call
becomes sdbusplus::bus::call
, sd_bus_get_unique_name
becomes sdbusplus::bus::get_unique_name
, sd_bus_message_get_signature
becomes sdbusplus::message::get_signature
, etc. This allows a relatively straight-forward translation back to the sd-bus functions for looking up the manpage details.
sdbusplus also contains a bindings generator tool: sdbus++
. The purpose of a bindings generator is to reduce the boilerplate associated with creating D-Bus server or client applications. When creating a server application, rather than creating sd-bus vtables and writing C-style functions to handle each vtable callback, you can create a small YAML file to define your D-Bus interface and the sdbus++
tool will create a C++ class that implements your D-Bus interface. This class has a set of virtual functions for each method and property, which you can overload to create your own customized behavior for the interface.
There are currently two types of YAML files: interface and error. Interfaces are used to create server and client D-Bus interfaces. Errors are used to define C++ exceptions which can be thrown and will automatically turn into D-Bus error responses.
[[ D-Bus client bindings are not yet implemented. See openbmc/openbmc#851. ]]
The path of your file will be the interface name. For example, for an interface org.freedesktop.Example
, you would create the files org/freedesktop/Example.interface.yaml
and org/freedesktop/Example.errors.yaml]
for interfaces and errors respectively. These can then be used to generate the server and error bindings:
sdbus++ interface server-header org.freedesktop.Example > \ org/freedesktop/Example/server.hpp sdbus++ interface server-cpp org.freedesktop.Example > \ org/freedesktop/Example/server.cpp sdbus++ error exception-header org.freedesktop.Example > \ org/freedesktop/Example/error.hpp \ sdbus++ error exception-cpp org.freedesktop.Example > \ org/freedesktop/Example/error.cpp
Markdown-based documentation can also be generated from the interface and exception files:
sdbus++ interface markdown org.freedesktop.Example > \ org/freedesktop/Example.md sdbus++ error markdown org.freedesktop.Example >> \ org/freedesktop/Example.md
See the example/Makefile.am
for more details.
Installation of sdbusplus bindings on a custom distribution requires a few packages to be installed prior. Although these packages are the same for several distributions the names of these packages do differ. Below are the packages needed for Ubuntu and Fedora.
sudo apt install git autoconf libtool pkg-config g++ autoconf-archive libsystemd-dev python python-yaml python-mako python-inflection
sudo dnf install git autoconf libtool gcc-c++ pkgconfig autoconf-archive systemd-devel python python-pip python-yaml python-mako
Install the inflection package using the pip utility (on Fedora)
pip install inflection