2017-11-27 14:13:55 +01:00
|
|
|
/**
|
|
|
|
|
* (C) 2017 KISTLER INSTRUMENTE AG, Winterthur, Switzerland
|
|
|
|
|
*
|
|
|
|
|
* @file ObjectProxy.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_INTERNAL_OBJECTPROXY_H_
|
|
|
|
|
#define SDBUS_CXX_INTERNAL_OBJECTPROXY_H_
|
|
|
|
|
|
|
|
|
|
#include <sdbus-c++/IObjectProxy.h>
|
|
|
|
|
#include <systemd/sd-bus.h>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
|
|
// Forward declarations
|
|
|
|
|
namespace sdbus { namespace internal {
|
|
|
|
|
class IConnection;
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
namespace sdbus {
|
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
|
|
class ObjectProxy
|
|
|
|
|
: public IObjectProxy
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ObjectProxy( sdbus::internal::IConnection& connection
|
|
|
|
|
, std::string destination
|
|
|
|
|
, std::string objectPath );
|
|
|
|
|
ObjectProxy( std::unique_ptr<sdbus::internal::IConnection>&& connection
|
|
|
|
|
, std::string destination
|
|
|
|
|
, std::string objectPath );
|
|
|
|
|
|
2018-07-02 11:22:00 +02:00
|
|
|
MethodCall createMethodCall(const std::string& interfaceName, const std::string& methodName) override;
|
2019-03-25 14:45:48 +01:00
|
|
|
AsyncMethodCall createAsyncMethodCall(const std::string& interfaceName, const std::string& methodName) override;
|
2018-07-02 11:22:00 +02:00
|
|
|
MethodReply callMethod(const MethodCall& message) override;
|
2019-03-25 14:45:48 +01:00
|
|
|
void callMethod(const AsyncMethodCall& message, async_reply_handler asyncReplyCallback) override;
|
2017-11-27 14:13:55 +01:00
|
|
|
|
|
|
|
|
void registerSignalHandler( const std::string& interfaceName
|
|
|
|
|
, const std::string& signalName
|
|
|
|
|
, signal_handler signalHandler ) override;
|
|
|
|
|
void finishRegistration() override;
|
|
|
|
|
|
|
|
|
|
private:
|
2019-03-25 16:28:31 +01:00
|
|
|
struct AsyncReplyUserData
|
|
|
|
|
{
|
|
|
|
|
ObjectProxy& proxy;
|
|
|
|
|
async_reply_handler callback;
|
|
|
|
|
};
|
|
|
|
|
|
2017-11-27 14:13:55 +01:00
|
|
|
void registerSignalHandlers(sdbus::internal::IConnection& connection);
|
2019-03-25 14:45:48 +01:00
|
|
|
static int sdbus_async_reply_handler(sd_bus_message *sdbusMessage, void *userData, sd_bus_error *retError);
|
2017-11-27 14:13:55 +01:00
|
|
|
static int sdbus_signal_callback(sd_bus_message *sdbusMessage, void *userData, sd_bus_error *retError);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::unique_ptr< sdbus::internal::IConnection
|
|
|
|
|
, std::function<void(sdbus::internal::IConnection*)>
|
|
|
|
|
> connection_;
|
|
|
|
|
std::string destination_;
|
|
|
|
|
std::string objectPath_;
|
|
|
|
|
|
|
|
|
|
using InterfaceName = std::string;
|
|
|
|
|
struct InterfaceData
|
|
|
|
|
{
|
|
|
|
|
using SignalName = std::string;
|
|
|
|
|
struct SignalData
|
|
|
|
|
{
|
|
|
|
|
signal_handler callback_;
|
2019-03-19 20:11:18 +01:00
|
|
|
std::unique_ptr<sd_bus_slot, std::function<void(sd_bus_slot*)>> slot_;
|
2017-11-27 14:13:55 +01:00
|
|
|
};
|
|
|
|
|
std::map<SignalName, SignalData> signals_;
|
|
|
|
|
};
|
|
|
|
|
std::map<InterfaceName, InterfaceData> interfaces_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
|
|
#endif /* SDBUS_CXX_INTERNAL_OBJECTPROXY_H_ */
|