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
|
|
|
*
|
2023-01-21 01:47:24 +01:00
|
|
|
* @file TestProxy.h
|
2017-11-27 14:13:55 +01:00
|
|
|
*
|
|
|
|
|
* Created on: Jan 2, 2017
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-07-18 20:16:57 +02:00
|
|
|
#ifndef SDBUS_CPP_INTEGRATIONTESTS_TESTPROXY_H_
|
|
|
|
|
#define SDBUS_CPP_INTEGRATIONTESTS_TESTPROXY_H_
|
2017-11-27 14:13:55 +01:00
|
|
|
|
2020-07-18 20:16:57 +02:00
|
|
|
#include "integrationtests-proxy.h"
|
|
|
|
|
#include "Defs.h"
|
|
|
|
|
#include <thread>
|
|
|
|
|
#include <chrono>
|
2019-06-04 22:48:54 +02:00
|
|
|
#include <atomic>
|
2023-01-29 22:12:10 +01:00
|
|
|
#include <future>
|
2023-02-02 21:51:09 +01:00
|
|
|
#include <memory>
|
2017-11-27 14:13:55 +01:00
|
|
|
|
2020-07-18 20:16:57 +02:00
|
|
|
namespace sdbus { namespace test {
|
|
|
|
|
|
2021-10-15 13:44:00 +02:00
|
|
|
class ObjectManagerTestProxy final : public sdbus::ProxyInterfaces< sdbus::ObjectManager_proxy >
|
2021-10-14 15:53:51 +02:00
|
|
|
{
|
|
|
|
|
public:
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
ObjectManagerTestProxy(sdbus::IConnection& connection, ServiceName destination, ObjectPath objectPath)
|
2021-10-14 15:53:51 +02:00
|
|
|
: ProxyInterfaces(connection, std::move(destination), std::move(objectPath))
|
|
|
|
|
{
|
|
|
|
|
registerProxy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~ObjectManagerTestProxy()
|
|
|
|
|
{
|
|
|
|
|
unregisterProxy();
|
|
|
|
|
}
|
|
|
|
|
protected:
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
void onInterfacesAdded(const sdbus::ObjectPath& objectPath, const std::map<sdbus::InterfaceName, std::map<PropertyName, sdbus::Variant>>& interfacesAndProperties) override
|
2021-10-14 15:53:51 +02:00
|
|
|
{
|
|
|
|
|
if (m_onInterfacesAddedHandler)
|
|
|
|
|
m_onInterfacesAddedHandler(objectPath, interfacesAndProperties);
|
|
|
|
|
}
|
|
|
|
|
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
void onInterfacesRemoved(const sdbus::ObjectPath& objectPath, const std::vector<sdbus::InterfaceName>& interfaces) override
|
2021-10-14 15:53:51 +02:00
|
|
|
{
|
|
|
|
|
if (m_onInterfacesRemovedHandler)
|
|
|
|
|
m_onInterfacesRemovedHandler(objectPath, interfaces);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public: // for tests
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
std::function<void(const sdbus::ObjectPath&, const std::map<sdbus::InterfaceName, std::map<PropertyName, sdbus::Variant>>&)> m_onInterfacesAddedHandler;
|
|
|
|
|
std::function<void(const sdbus::ObjectPath&, const std::vector<sdbus::InterfaceName>&)> m_onInterfacesRemovedHandler;
|
2021-10-14 15:53:51 +02:00
|
|
|
};
|
|
|
|
|
|
2020-07-18 20:16:57 +02:00
|
|
|
class TestProxy final : public sdbus::ProxyInterfaces< org::sdbuscpp::integrationtests_proxy
|
|
|
|
|
, sdbus::Peer_proxy
|
|
|
|
|
, sdbus::Introspectable_proxy
|
2021-10-14 15:53:51 +02:00
|
|
|
, sdbus::Properties_proxy >
|
2017-11-27 14:13:55 +01:00
|
|
|
{
|
|
|
|
|
public:
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
TestProxy(ServiceName destination, ObjectPath objectPath);
|
|
|
|
|
TestProxy(ServiceName destination, ObjectPath objectPath, dont_run_event_loop_thread_t);
|
|
|
|
|
TestProxy(sdbus::IConnection& connection, ServiceName destination, ObjectPath objectPath);
|
2020-07-18 20:16:57 +02:00
|
|
|
~TestProxy();
|
2019-03-25 14:45:48 +01:00
|
|
|
|
2017-11-27 14:13:55 +01:00
|
|
|
protected:
|
2020-07-18 20:16:57 +02:00
|
|
|
void onSimpleSignal() override;
|
|
|
|
|
void onSignalWithMap(const std::map<int32_t, std::string>& aMap) override;
|
|
|
|
|
void onSignalWithVariant(const sdbus::Variant& aVariant) override;
|
2017-11-27 14:13:55 +01:00
|
|
|
|
2020-07-18 20:16:57 +02:00
|
|
|
void onSignalWithoutRegistration(const sdbus::Struct<std::string, sdbus::Struct<sdbus::Signature>>& s);
|
2024-01-10 15:43:37 +01:00
|
|
|
void onDoOperationReply(uint32_t returnValue, std::optional<sdbus::Error> error);
|
2019-03-25 14:45:48 +01:00
|
|
|
|
2019-05-29 22:28:15 +02:00
|
|
|
// Signals of standard D-Bus interfaces
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
void onPropertiesChanged( const sdbus::InterfaceName& interfaceName
|
|
|
|
|
, const std::map<PropertyName, sdbus::Variant>& changedProperties
|
|
|
|
|
, const std::vector<PropertyName>& invalidatedProperties ) override;
|
2020-07-18 20:16:57 +02:00
|
|
|
|
|
|
|
|
public:
|
2024-01-10 15:43:37 +01:00
|
|
|
void installDoOperationClientSideAsyncReplyHandler(std::function<void(uint32_t res, std::optional<sdbus::Error> err)> handler);
|
2021-12-20 10:00:29 +01:00
|
|
|
uint32_t doOperationWithTimeout(const std::chrono::microseconds &timeout, uint32_t param);
|
2025-05-05 01:04:20 -05:00
|
|
|
MethodReply doOperationOnBasicAPILevel(uint32_t param);
|
2020-07-18 20:16:57 +02:00
|
|
|
sdbus::PendingAsyncCall doOperationClientSideAsync(uint32_t param);
|
2024-04-18 19:53:35 +02:00
|
|
|
[[nodiscard]] sdbus::Slot doOperationClientSideAsync(uint32_t param, sdbus::return_slot_t);
|
2023-01-29 22:12:10 +01:00
|
|
|
std::future<uint32_t> doOperationClientSideAsync(uint32_t param, with_future_t);
|
2024-10-10 16:10:20 +02:00
|
|
|
std::future<std::map<int32_t, std::string>> doOperationWithLargeDataClientSideAsync(const std::map<int32_t, std::string>& largeParam, with_future_t);
|
2023-01-29 22:12:10 +01:00
|
|
|
std::future<MethodReply> doOperationClientSideAsyncOnBasicAPILevel(uint32_t param);
|
|
|
|
|
std::future<void> doErroneousOperationClientSideAsync(with_future_t);
|
2020-07-18 20:16:57 +02:00
|
|
|
void doErroneousOperationClientSideAsync();
|
2021-12-20 10:00:29 +01:00
|
|
|
void doOperationClientSideAsyncWithTimeout(const std::chrono::microseconds &timeout, uint32_t param);
|
2020-07-18 20:16:57 +02:00
|
|
|
int32_t callNonexistentMethod();
|
|
|
|
|
int32_t callMethodOnNonexistentInterface();
|
|
|
|
|
void setStateProperty(const std::string& value);
|
2019-05-29 22:28:15 +02:00
|
|
|
|
|
|
|
|
//private:
|
2019-06-04 22:48:54 +02:00
|
|
|
public: // for tests
|
2020-01-12 13:10:34 +01:00
|
|
|
int m_SimpleSignals = 0;
|
2019-06-04 23:45:45 +02:00
|
|
|
std::atomic<bool> m_gotSimpleSignal{false};
|
|
|
|
|
std::atomic<bool> m_gotSignalWithMap{false};
|
2019-06-04 22:48:54 +02:00
|
|
|
std::map<int32_t, std::string> m_mapFromSignal;
|
2019-06-04 23:45:45 +02:00
|
|
|
std::atomic<bool> m_gotSignalWithVariant{false};
|
2019-06-04 22:48:54 +02:00
|
|
|
double m_variantFromSignal;
|
2019-06-04 23:45:45 +02:00
|
|
|
std::atomic<bool> m_gotSignalWithSignature{false};
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
std::map<std::string, Signature> m_signatureFromSignal;
|
2017-11-27 14:13:55 +01:00
|
|
|
|
2024-01-10 15:43:37 +01:00
|
|
|
std::function<void(uint32_t res, std::optional<sdbus::Error> err)> m_DoOperationClientSideAsyncReplyHandler;
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
std::function<void(const sdbus::InterfaceName&, const std::map<PropertyName, sdbus::Variant>&, const std::vector<PropertyName>&)> m_onPropertiesChangedHandler;
|
2021-06-02 15:17:20 +00:00
|
|
|
|
2025-05-05 01:04:20 -05:00
|
|
|
std::unique_ptr<const MethodCall> m_methodCallMsg;
|
2023-02-02 21:51:09 +01:00
|
|
|
std::unique_ptr<const Message> m_signalMsg;
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
SignalName m_signalName;
|
2017-11-27 14:13:55 +01:00
|
|
|
};
|
|
|
|
|
|
2022-09-01 11:04:45 +02:00
|
|
|
class DummyTestProxy final : public sdbus::ProxyInterfaces< org::sdbuscpp::integrationtests_proxy
|
|
|
|
|
, sdbus::Peer_proxy
|
|
|
|
|
, sdbus::Introspectable_proxy
|
|
|
|
|
, sdbus::Properties_proxy >
|
|
|
|
|
{
|
|
|
|
|
public:
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
DummyTestProxy(ServiceName destination, ObjectPath objectPath)
|
2022-09-01 11:04:45 +02:00
|
|
|
: ProxyInterfaces(destination, objectPath)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void onSimpleSignal() override {}
|
|
|
|
|
void onSignalWithMap(const std::map<int32_t, std::string>&) override {}
|
|
|
|
|
void onSignalWithVariant(const sdbus::Variant&) override {}
|
|
|
|
|
|
|
|
|
|
void onSignalWithoutRegistration(const sdbus::Struct<std::string, sdbus::Struct<sdbus::Signature>>&) {}
|
2024-01-10 15:43:37 +01:00
|
|
|
void onDoOperationReply(uint32_t, std::optional<sdbus::Error>) {}
|
2022-09-01 11:04:45 +02:00
|
|
|
|
|
|
|
|
// Signals of standard D-Bus interfaces
|
refactor: add strong types to public API (#414)
This introduces strong types for `std::string`-based D-Bus types. This facilitates safer, less error-prone and more expressive API.
What previously was `auto proxy = createProxy("org.sdbuscpp.concatenator", "/org/sdbuscpp/concatenator");` is now written like `auto proxy = createProxy(ServiceName{"org.sdbuscpp.concatenator"}, ObjectPath{"/org/sdbuscpp/concatenator"});`.
These types are:
* `ObjectPath` type for the object path (the type has been around already but now is also used consistently in sdbus-c++ API for object path strings),
* `InterfaceName` type for D-Bus interface names,
* `BusName` (and its aliases `ServiceName` and `ConnectionName`) type for bus/service/connection names,
* `MemberName` (and its aliases `MethodName`, `SignalName` and `PropertyName`) type for D-Bus method, signal and property names,
* `Signature` type for the D-Bus signature (the type has been around already but now is also used consistently in sdbus-c++ API for signature strings),
* `Error::Name` type for D-Bus error names.
2024-03-29 13:23:44 +01:00
|
|
|
void onPropertiesChanged(const InterfaceName&, const std::map<PropertyName, sdbus::Variant>&, const std::vector<PropertyName>&) override {}
|
2022-09-01 11:04:45 +02:00
|
|
|
};
|
|
|
|
|
|
2020-07-18 20:16:57 +02:00
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
#endif /* SDBUS_CPP_INTEGRATIONTESTS_TESTPROXY_H_ */
|