2017-11-27 14:13:55 +01:00
|
|
|
/**
|
2022-07-05 17:08:35 +02:00
|
|
|
* (C) 2016 - 2021 KISTLER INSTRUMENTE AG, Winterthur, Switzerland
|
2024-04-16 22:48:34 +02:00
|
|
|
* (C) 2016 - 2024 Stanislav Angelovic <stanislav.angelovic@protonmail.com>
|
2017-11-27 14:13:55 +01:00
|
|
|
*
|
|
|
|
|
* @file Object.cpp
|
|
|
|
|
*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "Object.h"
|
2019-06-10 21:38:30 +02:00
|
|
|
#include "MessageUtils.h"
|
2017-11-27 14:13:55 +01:00
|
|
|
#include <sdbus-c++/IConnection.h>
|
|
|
|
|
#include <sdbus-c++/Message.h>
|
|
|
|
|
#include <sdbus-c++/Error.h>
|
2018-07-02 11:22:00 +02:00
|
|
|
#include <sdbus-c++/MethodResult.h>
|
2019-01-10 08:47:59 +01:00
|
|
|
#include <sdbus-c++/Flags.h>
|
2021-06-02 15:17:20 +00:00
|
|
|
#include "ScopeGuard.h"
|
2017-11-27 14:13:55 +01:00
|
|
|
#include "IConnection.h"
|
2022-02-11 21:53:37 +01:00
|
|
|
#include "Utils.h"
|
2017-11-27 14:13:55 +01:00
|
|
|
#include "VTableUtils.h"
|
2023-09-16 14:28:58 +00:00
|
|
|
#include SDBUS_HEADER
|
2017-11-27 14:13:55 +01:00
|
|
|
#include <utility>
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
2020-02-01 22:47:04 +01:00
|
|
|
namespace sdbus::internal {
|
2017-11-27 14:13:55 +01:00
|
|
|
|
|
|
|
|
Object::Object(sdbus::internal::IConnection& connection, std::string objectPath)
|
|
|
|
|
: connection_(connection), objectPath_(std::move(objectPath))
|
|
|
|
|
{
|
2022-02-11 21:53:37 +01:00
|
|
|
SDBUS_CHECK_OBJECT_PATH(objectPath_);
|
2017-11-27 14:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
void Object::addVTable(std::string interfaceName, std::vector<VTableItem> vtable)
|
2020-01-27 07:57:38 +01:00
|
|
|
{
|
2023-12-30 19:22:45 +01:00
|
|
|
auto slot = Object::addVTable(std::move(interfaceName), std::move(vtable), return_slot);
|
2023-12-30 18:40:38 +01:00
|
|
|
|
|
|
|
|
vtables_.push_back(std::move(slot));
|
2020-01-27 07:57:38 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-30 19:22:45 +01:00
|
|
|
Slot Object::addVTable(std::string interfaceName, std::vector<VTableItem> vtable, return_slot_t)
|
2017-11-27 14:13:55 +01:00
|
|
|
{
|
2022-02-11 21:53:37 +01:00
|
|
|
SDBUS_CHECK_INTERFACE_NAME(interfaceName);
|
2017-11-27 14:13:55 +01:00
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
// 1st pass -- create vtable structure for internal sdbus-c++ purposes
|
|
|
|
|
auto internalVTable = std::make_unique<VTable>(createInternalVTable(std::move(interfaceName), std::move(vtable)));
|
2017-11-27 14:13:55 +01:00
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
// 2nd pass -- from internal sdbus-c++ vtable, create vtable structure in format expected by underlying sd-bus library
|
|
|
|
|
internalVTable->sdbusVTable = createInternalSdBusVTable(*internalVTable);
|
2017-11-27 14:13:55 +01:00
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
// 3rd step -- register the vtable with sd-bus
|
|
|
|
|
internalVTable->slot = connection_.addObjectVTable(objectPath_, internalVTable->interfaceName, &internalVTable->sdbusVTable[0], internalVTable.get());
|
2020-01-27 07:57:38 +01:00
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
// Return vtable wrapped in a Slot object
|
|
|
|
|
return {internalVTable.release(), [](void *ptr){ delete static_cast<VTable*>(ptr); }};
|
2017-11-27 14:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
2019-04-13 21:17:37 +02:00
|
|
|
void Object::unregister()
|
|
|
|
|
{
|
2023-12-30 18:40:38 +01:00
|
|
|
vtables_.clear();
|
2020-01-19 18:57:14 +01:00
|
|
|
removeObjectManager();
|
2019-04-13 21:17:37 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-02 11:22:00 +02:00
|
|
|
sdbus::Signal Object::createSignal(const std::string& interfaceName, const std::string& signalName)
|
2017-11-27 14:13:55 +01:00
|
|
|
{
|
|
|
|
|
return connection_.createSignal(objectPath_, interfaceName, signalName);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-02 11:22:00 +02:00
|
|
|
void Object::emitSignal(const sdbus::Signal& message)
|
2017-11-27 14:13:55 +01:00
|
|
|
{
|
2019-11-10 17:31:58 +01:00
|
|
|
SDBUS_THROW_ERROR_IF(!message.isValid(), "Invalid signal message provided", EINVAL);
|
|
|
|
|
|
2017-11-27 14:13:55 +01:00
|
|
|
message.send();
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-03 22:02:15 +02:00
|
|
|
void Object::emitPropertiesChangedSignal(const std::string& interfaceName, const std::vector<std::string>& propNames)
|
|
|
|
|
{
|
|
|
|
|
connection_.emitPropertiesChangedSignal(objectPath_, interfaceName, propNames);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::emitPropertiesChangedSignal(const std::string& interfaceName)
|
|
|
|
|
{
|
|
|
|
|
Object::emitPropertiesChangedSignal(interfaceName, {});
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-03 23:47:27 +02:00
|
|
|
void Object::emitInterfacesAddedSignal()
|
2019-04-04 20:39:03 +02:00
|
|
|
{
|
2019-06-03 23:47:27 +02:00
|
|
|
connection_.emitInterfacesAddedSignal(objectPath_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::emitInterfacesAddedSignal(const std::vector<std::string>& interfaces)
|
|
|
|
|
{
|
|
|
|
|
connection_.emitInterfacesAddedSignal(objectPath_, interfaces);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::emitInterfacesRemovedSignal()
|
|
|
|
|
{
|
|
|
|
|
connection_.emitInterfacesRemovedSignal(objectPath_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::emitInterfacesRemovedSignal(const std::vector<std::string>& interfaces)
|
|
|
|
|
{
|
|
|
|
|
connection_.emitInterfacesRemovedSignal(objectPath_, interfaces);
|
2019-04-04 20:39:03 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-29 22:28:15 +02:00
|
|
|
void Object::addObjectManager()
|
|
|
|
|
{
|
2023-12-30 19:22:45 +01:00
|
|
|
objectManagerSlot_ = connection_.addObjectManager(objectPath_, return_slot);
|
2019-05-29 22:28:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::removeObjectManager()
|
|
|
|
|
{
|
|
|
|
|
objectManagerSlot_.reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Object::hasObjectManager() const
|
|
|
|
|
{
|
|
|
|
|
return objectManagerSlot_ != nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-03 23:47:27 +02:00
|
|
|
sdbus::IConnection& Object::getConnection() const
|
|
|
|
|
{
|
2022-06-15 15:42:24 +02:00
|
|
|
return connection_;
|
2019-06-03 23:47:27 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-28 15:36:58 +02:00
|
|
|
const std::string& Object::getObjectPath() const
|
|
|
|
|
{
|
|
|
|
|
return objectPath_;
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-02 21:51:09 +01:00
|
|
|
Message Object::getCurrentlyProcessedMessage() const
|
2021-06-02 15:17:20 +00:00
|
|
|
{
|
2023-02-02 21:51:09 +01:00
|
|
|
return connection_.getCurrentlyProcessedMessage();
|
2021-06-02 15:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
Object::VTable Object::createInternalVTable(std::string interfaceName, std::vector<VTableItem> vtable)
|
2021-07-22 17:33:59 +02:00
|
|
|
{
|
2023-12-30 18:40:38 +01:00
|
|
|
VTable internalVTable;
|
2021-07-22 17:33:59 +02:00
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
internalVTable.interfaceName = std::move(interfaceName);
|
2018-05-25 20:48:20 +02:00
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
for (auto& vtableItem : vtable)
|
2018-05-25 20:48:20 +02:00
|
|
|
{
|
2023-12-30 18:40:38 +01:00
|
|
|
std::visit( overload{ [&](InterfaceFlagsVTableItem&& interfaceFlags){ writeInterfaceFlagsToVTable(std::move(interfaceFlags), internalVTable); }
|
|
|
|
|
, [&](MethodVTableItem&& method){ writeMethodRecordToVTable(std::move(method), internalVTable); }
|
|
|
|
|
, [&](SignalVTableItem&& signal){ writeSignalRecordToVTable(std::move(signal), internalVTable); }
|
|
|
|
|
, [&](PropertyVTableItem&& property){ writePropertyRecordToVTable(std::move(property), internalVTable); } }
|
|
|
|
|
, std::move(vtableItem) );
|
2018-05-25 20:48:20 +02:00
|
|
|
}
|
2023-12-30 18:40:38 +01:00
|
|
|
|
|
|
|
|
// Sort arrays so we can do fast searching for an item in sd-bus callback handlers
|
|
|
|
|
std::sort(internalVTable.methods.begin(), internalVTable.methods.end(), [](const auto& a, const auto& b){ return a.name < b.name; });
|
|
|
|
|
std::sort(internalVTable.signals.begin(), internalVTable.signals.end(), [](const auto& a, const auto& b){ return a.name < b.name; });
|
|
|
|
|
std::sort(internalVTable.properties.begin(), internalVTable.properties.end(), [](const auto& a, const auto& b){ return a.name < b.name; });
|
|
|
|
|
|
|
|
|
|
internalVTable.object = this;
|
|
|
|
|
|
|
|
|
|
return internalVTable;
|
2018-05-25 20:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
void Object::writeInterfaceFlagsToVTable(InterfaceFlagsVTableItem flags, VTable& vtable)
|
2018-05-25 20:48:20 +02:00
|
|
|
{
|
2023-12-30 18:40:38 +01:00
|
|
|
vtable.interfaceFlags = std::move(flags.flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::writeMethodRecordToVTable(MethodVTableItem method, VTable& vtable)
|
|
|
|
|
{
|
|
|
|
|
SDBUS_CHECK_MEMBER_NAME(method.name);
|
|
|
|
|
SDBUS_THROW_ERROR_IF(!method.callbackHandler, "Invalid method callback provided", EINVAL);
|
|
|
|
|
|
|
|
|
|
vtable.methods.push_back({ std::move(method.name)
|
|
|
|
|
, std::move(method.inputSignature)
|
|
|
|
|
, std::move(method.outputSignature)
|
|
|
|
|
, paramNamesToString(method.inputParamNames) + paramNamesToString(method.outputParamNames)
|
|
|
|
|
, std::move(method.callbackHandler)
|
|
|
|
|
, std::move(method.flags) });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::writeSignalRecordToVTable(SignalVTableItem signal, VTable& vtable)
|
|
|
|
|
{
|
|
|
|
|
SDBUS_CHECK_MEMBER_NAME(signal.name);
|
|
|
|
|
|
|
|
|
|
vtable.signals.push_back({ std::move(signal.name)
|
|
|
|
|
, std::move(signal.signature)
|
|
|
|
|
, paramNamesToString(signal.paramNames)
|
|
|
|
|
, std::move(signal.flags) });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::writePropertyRecordToVTable(PropertyVTableItem property, VTable& vtable)
|
|
|
|
|
{
|
|
|
|
|
SDBUS_CHECK_MEMBER_NAME(property.name);
|
|
|
|
|
SDBUS_THROW_ERROR_IF(!property.getter && !property.setter, "Invalid property callbacks provided", EINVAL);
|
|
|
|
|
|
|
|
|
|
vtable.properties.push_back({ std::move(property.name)
|
|
|
|
|
, std::move(property.signature)
|
|
|
|
|
, std::move(property.getter)
|
|
|
|
|
, std::move(property.setter)
|
|
|
|
|
, std::move(property.flags) });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<sd_bus_vtable> Object::createInternalSdBusVTable(const VTable& vtable)
|
|
|
|
|
{
|
|
|
|
|
std::vector<sd_bus_vtable> sdbusVTable;
|
|
|
|
|
|
|
|
|
|
startSdBusVTable(vtable.interfaceFlags, sdbusVTable);
|
|
|
|
|
for (const auto& methodItem : vtable.methods)
|
|
|
|
|
writeMethodRecordToSdBusVTable(methodItem, sdbusVTable);
|
|
|
|
|
for (const auto& signalItem : vtable.signals)
|
|
|
|
|
writeSignalRecordToSdBusVTable(signalItem, sdbusVTable);
|
|
|
|
|
for (const auto& propertyItem : vtable.properties)
|
|
|
|
|
writePropertyRecordToSdBusVTable(propertyItem, sdbusVTable);
|
|
|
|
|
finalizeSdBusVTable(sdbusVTable);
|
|
|
|
|
|
|
|
|
|
return sdbusVTable;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::startSdBusVTable(const Flags& interfaceFlags, std::vector<sd_bus_vtable>& vtable)
|
|
|
|
|
{
|
|
|
|
|
auto vtableItem = createSdBusVTableStartItem(interfaceFlags.toSdBusInterfaceFlags());
|
|
|
|
|
vtable.push_back(std::move(vtableItem));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::writeMethodRecordToSdBusVTable(const VTable::MethodItem& method, std::vector<sd_bus_vtable>& vtable)
|
|
|
|
|
{
|
|
|
|
|
auto vtableItem = createSdBusVTableMethodItem( method.name.c_str()
|
|
|
|
|
, method.inputArgs.c_str()
|
|
|
|
|
, method.outputArgs.c_str()
|
|
|
|
|
, method.paramNames.c_str()
|
|
|
|
|
, &Object::sdbus_method_callback
|
|
|
|
|
, method.flags.toSdBusMethodFlags() );
|
|
|
|
|
vtable.push_back(std::move(vtableItem));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::writeSignalRecordToSdBusVTable(const VTable::SignalItem& signal, std::vector<sd_bus_vtable>& vtable)
|
|
|
|
|
{
|
|
|
|
|
auto vtableItem = createSdBusVTableSignalItem( signal.name.c_str()
|
|
|
|
|
, signal.signature.c_str()
|
|
|
|
|
, signal.paramNames.c_str()
|
|
|
|
|
, signal.flags.toSdBusSignalFlags() );
|
|
|
|
|
vtable.push_back(std::move(vtableItem));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::writePropertyRecordToSdBusVTable(const VTable::PropertyItem& property, std::vector<sd_bus_vtable>& vtable)
|
|
|
|
|
{
|
|
|
|
|
auto vtableItem = !property.setCallback
|
|
|
|
|
? createSdBusVTableReadOnlyPropertyItem( property.name.c_str()
|
|
|
|
|
, property.signature.c_str()
|
|
|
|
|
, &Object::sdbus_property_get_callback
|
|
|
|
|
, property.flags.toSdBusPropertyFlags() )
|
|
|
|
|
: createSdBusVTableWritablePropertyItem( property.name.c_str()
|
|
|
|
|
, property.signature.c_str()
|
|
|
|
|
, &Object::sdbus_property_get_callback
|
|
|
|
|
, &Object::sdbus_property_set_callback
|
|
|
|
|
, property.flags.toSdBusWritablePropertyFlags() );
|
|
|
|
|
vtable.push_back(std::move(vtableItem));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Object::finalizeSdBusVTable(std::vector<sd_bus_vtable>& vtable)
|
|
|
|
|
{
|
|
|
|
|
vtable.push_back(createSdBusVTableEndItem());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Object::VTable::MethodItem* Object::findMethod(const VTable& vtable, const std::string& methodName)
|
|
|
|
|
{
|
|
|
|
|
auto it = std::lower_bound(vtable.methods.begin(), vtable.methods.end(), methodName, [](const auto& methodItem, const auto& methodName)
|
2018-05-25 20:48:20 +02:00
|
|
|
{
|
2023-12-30 18:40:38 +01:00
|
|
|
return methodItem.name < methodName;
|
|
|
|
|
});
|
2018-05-25 20:48:20 +02:00
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
return it != vtable.methods.end() && it->name == methodName ? &*it : nullptr;
|
2018-05-25 20:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
const Object::VTable::PropertyItem* Object::findProperty(const VTable& vtable, const std::string& propertyName)
|
2018-05-25 20:48:20 +02:00
|
|
|
{
|
2023-12-30 18:40:38 +01:00
|
|
|
auto it = std::lower_bound(vtable.properties.begin(), vtable.properties.end(), propertyName, [](const auto& propertyItem, const auto& propertyName)
|
2018-05-25 20:48:20 +02:00
|
|
|
{
|
2023-12-30 18:40:38 +01:00
|
|
|
return propertyItem.name < propertyName;
|
|
|
|
|
});
|
2018-05-25 20:48:20 +02:00
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
return it != vtable.properties.end() && it->name == propertyName ? &*it : nullptr;
|
2020-01-27 07:57:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string Object::paramNamesToString(const std::vector<std::string>& paramNames)
|
|
|
|
|
{
|
|
|
|
|
std::string names;
|
|
|
|
|
for (const auto& name : paramNames)
|
|
|
|
|
names += name + '\0';
|
|
|
|
|
return names;
|
2018-05-25 20:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
2017-11-27 14:13:55 +01:00
|
|
|
int Object::sdbus_method_callback(sd_bus_message *sdbusMessage, void *userData, sd_bus_error *retError)
|
|
|
|
|
{
|
2023-12-30 18:40:38 +01:00
|
|
|
auto* vtable = static_cast<VTable*>(userData);
|
|
|
|
|
assert(vtable != nullptr);
|
|
|
|
|
assert(vtable->object != nullptr);
|
2019-03-25 16:28:31 +01:00
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
auto message = Message::Factory::create<MethodCall>(sdbusMessage, &vtable->object->connection_.getSdBusInterface());
|
2019-03-25 16:28:31 +01:00
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
const auto* methodItem = findMethod(*vtable, message.getMemberName());
|
|
|
|
|
assert(methodItem != nullptr);
|
|
|
|
|
assert(methodItem->callback);
|
2017-11-27 14:13:55 +01:00
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
auto ok = invokeHandlerAndCatchErrors([&](){ methodItem->callback(std::move(message)); }, retError);
|
2017-11-27 14:13:55 +01:00
|
|
|
|
2023-11-03 18:03:01 +01:00
|
|
|
return ok ? 1 : -1;
|
2017-11-27 14:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Object::sdbus_property_get_callback( sd_bus */*bus*/
|
|
|
|
|
, const char */*objectPath*/
|
2021-07-22 17:33:59 +02:00
|
|
|
, const char */*interface*/
|
2017-11-27 14:13:55 +01:00
|
|
|
, const char *property
|
|
|
|
|
, sd_bus_message *sdbusReply
|
|
|
|
|
, void *userData
|
|
|
|
|
, sd_bus_error *retError )
|
|
|
|
|
{
|
2023-12-30 18:40:38 +01:00
|
|
|
auto* vtable = static_cast<VTable*>(userData);
|
|
|
|
|
assert(vtable != nullptr);
|
|
|
|
|
assert(vtable->object != nullptr);
|
2019-03-25 16:28:31 +01:00
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
const auto* propertyItem = findProperty(*vtable, property);
|
|
|
|
|
assert(propertyItem != nullptr);
|
|
|
|
|
|
|
|
|
|
// Getter may be empty - the case of "write-only" property
|
|
|
|
|
if (!propertyItem->getCallback)
|
2017-11-27 14:13:55 +01:00
|
|
|
{
|
|
|
|
|
sd_bus_error_set(retError, "org.freedesktop.DBus.Error.Failed", "Cannot read property as it is write-only");
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
auto reply = Message::Factory::create<PropertyGetReply>(sdbusReply, &vtable->object->connection_.getSdBusInterface());
|
2019-03-25 16:28:31 +01:00
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
auto ok = invokeHandlerAndCatchErrors([&](){ propertyItem->getCallback(reply); }, retError);
|
2017-11-27 14:13:55 +01:00
|
|
|
|
2023-11-03 18:03:01 +01:00
|
|
|
return ok ? 1 : -1;
|
2017-11-27 14:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Object::sdbus_property_set_callback( sd_bus */*bus*/
|
|
|
|
|
, const char */*objectPath*/
|
2021-07-22 17:33:59 +02:00
|
|
|
, const char */*interface*/
|
2017-11-27 14:13:55 +01:00
|
|
|
, const char *property
|
|
|
|
|
, sd_bus_message *sdbusValue
|
|
|
|
|
, void *userData
|
|
|
|
|
, sd_bus_error *retError )
|
|
|
|
|
{
|
2023-12-30 18:40:38 +01:00
|
|
|
auto* vtable = static_cast<VTable*>(userData);
|
|
|
|
|
assert(vtable != nullptr);
|
|
|
|
|
assert(vtable->object != nullptr);
|
2019-03-25 16:28:31 +01:00
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
const auto* propertyItem = findProperty(*vtable, property);
|
|
|
|
|
assert(propertyItem != nullptr);
|
|
|
|
|
assert(propertyItem->setCallback);
|
2017-11-27 14:13:55 +01:00
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
auto value = Message::Factory::create<PropertySetCall>(sdbusValue, &vtable->object->connection_.getSdBusInterface());
|
2019-03-25 16:28:31 +01:00
|
|
|
|
2023-12-30 18:40:38 +01:00
|
|
|
auto ok = invokeHandlerAndCatchErrors([&](){ propertyItem->setCallback(std::move(value)); }, retError);
|
2017-11-27 14:13:55 +01:00
|
|
|
|
2023-11-03 18:03:01 +01:00
|
|
|
return ok ? 1 : -1;
|
2017-11-27 14:13:55 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-01 22:47:04 +01:00
|
|
|
}
|
2017-11-27 14:13:55 +01:00
|
|
|
|
|
|
|
|
namespace sdbus {
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<sdbus::IObject> createObject(sdbus::IConnection& connection, std::string objectPath)
|
|
|
|
|
{
|
|
|
|
|
auto* sdbusConnection = dynamic_cast<sdbus::internal::IConnection*>(&connection);
|
|
|
|
|
SDBUS_THROW_ERROR_IF(!sdbusConnection, "Connection is not a real sdbus-c++ connection", EINVAL);
|
|
|
|
|
|
|
|
|
|
return std::make_unique<sdbus::internal::Object>(*sdbusConnection, std::move(objectPath));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|