bus: un-inline functions
Due to additional upstream error results, the bus creation functions
need better error handling. This will result in larger functions
that are no longer a direct sd-bus call and probably shouldn't be
inlined. Move the functions to the `bus.cpp` file.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: If141ef74a62fd04b3bbf58b0720da2a9410481a7
diff --git a/include/sdbusplus/bus.hpp b/include/sdbusplus/bus.hpp
index fe5253c..eb335ad 100644
--- a/include/sdbusplus/bus.hpp
+++ b/include/sdbusplus/bus.hpp
@@ -535,103 +535,6 @@
std::exception_ptr current_exception;
};
-inline bus::bus(busp_t b, sdbusplus::SdBusInterface* intf) :
- _intf(intf), _bus(_intf->sd_bus_ref(b), details::BusDeleter(intf))
-{
- // Emitting object added causes a message to get the properties
- // which can trigger a 'transaction' in the server bindings. If
- // the bus isn't up far enough, this causes an assert deep in
- // sd-bus code. Get the 'unique_name' to ensure the bus is up far
- // enough to avoid the assert.
- if (b != nullptr)
- {
- get_unique_name();
- }
-}
-
-inline bus::bus(busp_t b) :
- _intf(&sdbus_impl),
- _bus(_intf->sd_bus_ref(b), details::BusDeleter(&sdbus_impl))
-{
- // Emitting object added causes a message to get the properties
- // which can trigger a 'transaction' in the server bindings. If
- // the bus isn't up far enough, this causes an assert deep in
- // sd-bus code. Get the 'unique_name' to ensure the bus is up far
- // enough to avoid the assert.
- if (b != nullptr)
- {
- get_unique_name();
- }
-}
-
-inline bus::bus(busp_t b, std::false_type) :
- _intf(&sdbus_impl), _bus(b, details::BusDeleter(&sdbus_impl))
-{
- // Emitting object added causes a message to get the properties
- // which can trigger a 'transaction' in the server bindings. If
- // the bus isn't up far enough, this causes an assert deep in
- // sd-bus code. Get the 'unique_name' to ensure the bus is up far
- // enough to avoid the assert.
- if (b != nullptr)
- {
- get_unique_name();
- }
-}
-
-/* Create a new default connection: system bus if root, session bus if user. */
-inline bus new_default()
-{
- sd_bus* b = nullptr;
- sd_bus_default(&b);
- return bus(b, std::false_type());
-}
-
-/* Create a new default connection to the session bus. */
-inline bus new_default_user()
-{
- sd_bus* b = nullptr;
- sd_bus_default_user(&b);
- return bus(b, std::false_type());
-}
-
-/* Create a new default connection to the system bus. */
-inline bus new_default_system()
-{
- sd_bus* b = nullptr;
- sd_bus_default_system(&b);
- return bus(b, std::false_type());
-}
-
-/* Create a new connection: system bus if root, session bus if user. */
-inline bus new_bus()
-{
- sd_bus* b = nullptr;
- sd_bus_open(&b);
- bus bus(b, std::false_type());
- bus.set_should_close(true);
- return bus;
-}
-
-/* Create a new connection to the session bus. */
-inline bus new_user()
-{
- sd_bus* b = nullptr;
- sd_bus_open_user(&b);
- bus bus(b, std::false_type());
- bus.set_should_close(true);
- return bus;
-}
-
-/* Create a new connection to the system bus. */
-inline bus new_system()
-{
- sd_bus* b = nullptr;
- sd_bus_open_system(&b);
- bus bus(b, std::false_type());
- bus.set_should_close(true);
- return bus;
-}
-
namespace details
{
diff --git a/src/bus.cpp b/src/bus.cpp
index 6dc2309..7f96419 100644
--- a/src/bus.cpp
+++ b/src/bus.cpp
@@ -1,8 +1,6 @@
#include <sdbusplus/bus.hpp>
-namespace sdbusplus
-{
-namespace bus
+namespace sdbusplus::bus
{
void bus::emit_interfaces_added(const char* path,
@@ -21,5 +19,101 @@
static_cast<char**>(s));
}
-} // namespace bus
-} // namespace sdbusplus
+/* Create a new default connection: system bus if root, session bus if user. */
+bus new_default()
+{
+ sd_bus* b = nullptr;
+ sd_bus_default(&b);
+ return bus(b, std::false_type());
+}
+
+/* Create a new default connection to the session bus. */
+bus new_default_user()
+{
+ sd_bus* b = nullptr;
+ sd_bus_default_user(&b);
+ return bus(b, std::false_type());
+}
+
+/* Create a new default connection to the system bus. */
+bus new_default_system()
+{
+ sd_bus* b = nullptr;
+ sd_bus_default_system(&b);
+ return bus(b, std::false_type());
+}
+
+/* Create a new connection: system bus if root, session bus if user. */
+bus new_bus()
+{
+ sd_bus* b = nullptr;
+ sd_bus_open(&b);
+ bus bus(b, std::false_type());
+ bus.set_should_close(true);
+ return bus;
+}
+
+/* Create a new connection to the session bus. */
+bus new_user()
+{
+ sd_bus* b = nullptr;
+ sd_bus_open_user(&b);
+ bus bus(b, std::false_type());
+ bus.set_should_close(true);
+ return bus;
+}
+
+/* Create a new connection to the system bus. */
+bus new_system()
+{
+ sd_bus* b = nullptr;
+ sd_bus_open_system(&b);
+ bus bus(b, std::false_type());
+ bus.set_should_close(true);
+ return bus;
+}
+
+bus::bus(busp_t b, sdbusplus::SdBusInterface* intf) :
+ _intf(intf), _bus(_intf->sd_bus_ref(b), details::BusDeleter(intf))
+{
+ // Emitting object added causes a message to get the properties
+ // which can trigger a 'transaction' in the server bindings. If
+ // the bus isn't up far enough, this causes an assert deep in
+ // sd-bus code. Get the 'unique_name' to ensure the bus is up far
+ // enough to avoid the assert.
+ if (b != nullptr)
+ {
+ get_unique_name();
+ }
+}
+
+bus::bus(busp_t b) :
+ _intf(&sdbus_impl),
+ _bus(_intf->sd_bus_ref(b), details::BusDeleter(&sdbus_impl))
+{
+ // Emitting object added causes a message to get the properties
+ // which can trigger a 'transaction' in the server bindings. If
+ // the bus isn't up far enough, this causes an assert deep in
+ // sd-bus code. Get the 'unique_name' to ensure the bus is up far
+ // enough to avoid the assert.
+ if (b != nullptr)
+ {
+ get_unique_name();
+ }
+}
+
+bus::bus(busp_t b, std::false_type) :
+ _intf(&sdbus_impl), _bus(b, details::BusDeleter(&sdbus_impl))
+{
+ // Emitting object added causes a message to get the properties
+ // which can trigger a 'transaction' in the server bindings. If
+ // the bus isn't up far enough, this causes an assert deep in
+ // sd-bus code. Get the 'unique_name' to ensure the bus is up far
+ // enough to avoid the assert.
+ if (b != nullptr)
+ {
+ get_unique_name();
+ }
+}
+
+} // namespace sdbusplus::bus