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
2 changes: 1 addition & 1 deletion .github/workflows/cpp-ci-serial-programs-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
cd Arduino-Source
sudo apt update
sudo apt upgrade
sudo apt install clang-tools libopencv-dev
sudo apt install clang-tools libopencv-dev libsystemd-dev

sudo apt install ./3rdPartyBinaries/libdpp-10.0.28-linux-x64.deb

Expand Down
152 changes: 152 additions & 0 deletions 3rdParty/sdbus-cpp/include/sdbus-c++/AdaptorInterfaces.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/**
* (C) 2016 - 2021 KISTLER INSTRUMENTE AG, Winterthur, Switzerland
* (C) 2016 - 2024 Stanislav Angelovic <stanislav.angelovic@protonmail.com>
*
* @file AdaptorInterfaces.h
*
* Created on: Nov 8, 2016
* Project: sdbus-c++
* Description: High-level D-Bus IPC C++ library based on sd-bus
*
* This file is part of sdbus-c++.
*
* sdbus-c++ is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* sdbus-c++ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with sdbus-c++. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef SDBUS_CXX_ADAPTORINTERFACES_H_
#define SDBUS_CXX_ADAPTORINTERFACES_H_

#include <sdbus-c++/IObject.h>
#include <cassert>
#include <string>
#include <memory>

// Forward declarations
namespace sdbus {
class IConnection;
}

namespace sdbus {

/********************************************//**
* @class ObjectHolder
*
* ObjectHolder is a helper that simply owns and provides
* access to an object to other classes in the inheritance
* hierarchy of an object based on generated interface classes.
*
***********************************************/
class ObjectHolder
{
protected:
ObjectHolder(std::unique_ptr<IObject>&& object)
: object_(std::move(object))
{
}

const IObject& getObject() const
{
assert(object_ != nullptr);
return *object_;
}

IObject& getObject()
{
assert(object_ != nullptr);
return *object_;
}

private:
std::unique_ptr<IObject> object_;
};

/********************************************//**
* @class AdaptorInterfaces
*
* AdaptorInterfaces is a helper template class that joins all interface classes of a remote
* D-Bus object generated by sdbus-c++-xml2cpp to be used on the server (the adaptor) side,
* including some auxiliary classes. AdaptorInterfaces is the class that native-like object
* implementation classes written by users should inherit from and implement all pure virtual
* methods. So the _Interfaces template parameter is a list of sdbus-c++-xml2cpp-generated
* adaptor-side interface classes representing interfaces (with methods, signals and properties)
* of the D-Bus object.
*
* In the final adaptor class inherited from AdaptorInterfaces, one needs to make sure:
* 1. to call `registerAdaptor();` in the class constructor, and, conversely,
* 2. to call `unregisterAdaptor();` in the class destructor,
* so that the object API vtable is registered and unregistered at the proper time.
*
***********************************************/
template <typename... _Interfaces>
class AdaptorInterfaces
: protected ObjectHolder
, public _Interfaces...
{
public:
/*!
* @brief Creates object instance
*
* @param[in] connection D-Bus connection where the object will publish itself
* @param[in] objectPath Path of the D-Bus object
*
* For more information, consult @ref createObject(sdbus::IConnection&,std::string)
*/
AdaptorInterfaces(IConnection& connection, ObjectPath objectPath)
: ObjectHolder(createObject(connection, std::move(objectPath)))
, _Interfaces(getObject())...
{
}

/*!
* @brief Adds object vtable (i.e. D-Bus API) definitions for all interfaces it implements
*
* This function must be called in the constructor of the final adaptor class that implements AdaptorInterfaces.
*
* See also @ref IObject::addVTable()
*/
void registerAdaptor()
{
(_Interfaces::registerAdaptor(), ...);
}

/*!
* @brief Unregisters adaptors's API and removes it from the bus
*
* This function must be called in the destructor of the final adaptor class that implements AdaptorInterfaces.
*
* For more information, see underlying @ref IObject::unregister()
*/
void unregisterAdaptor()
{
getObject().unregister();
}

/*!
* @brief Returns reference to the underlying IObject instance
*/
using ObjectHolder::getObject;

protected:
using base_type = AdaptorInterfaces;

AdaptorInterfaces(const AdaptorInterfaces&) = delete;
AdaptorInterfaces& operator=(const AdaptorInterfaces&) = delete;
AdaptorInterfaces(AdaptorInterfaces&&) = delete;
AdaptorInterfaces& operator=(AdaptorInterfaces&&) = delete;
~AdaptorInterfaces() = default;
};

}

#endif /* SDBUS_CXX_ADAPTORINTERFACES_H_ */
Loading
Loading