2017-11-27 14:13:55 +01:00
/**
2019-06-11 20:18:37 +02:00
* (C) 2016 - 2017 KISTLER INSTRUMENTE AG, Winterthur, Switzerland
* (C) 2016 - 2019 Stanislav Angelovic <angelovic.s@gmail.com>
2017-11-27 14:13:55 +01:00
*
* @file adaptor-glue.h
*
* 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/>.
*/
#ifndef SDBUS_CPP_INTEGRATIONTESTS_ADAPTOR_GLUE_H_
#define SDBUS_CPP_INTEGRATIONTESTS_ADAPTOR_GLUE_H_
#include "defs.h"
// sdbus
#include "sdbus-c++/sdbus-c++.h"
using ComplexType = std :: map <
uint64_t ,
sdbus :: Struct <
std :: map <
uint8_t ,
std :: vector <
sdbus :: Struct <
sdbus :: ObjectPath ,
bool ,
sdbus :: Variant ,
std :: map < int , std :: string >
>
>
> ,
sdbus :: Signature ,
std :: string // char* leads to type and memory issues, std::string is best choice
>
> ;
class testing_adaptor
{
protected :
testing_adaptor ( sdbus :: IObject & object ) :
object_ ( object )
{
2019-01-10 08:47:59 +01:00
object_ . setInterfaceFlags ( INTERFACE_NAME ). markAsDeprecated (). withPropertyUpdateBehavior ( sdbus :: Flags :: EMITS_NO_SIGNAL );
2017-11-27 14:13:55 +01:00
object_ . registerMethod ( "noArgNoReturn" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ](){ return this -> noArgNoReturn (); });
2020-01-27 07:57:38 +01:00
object_ . registerMethod ( "getInt" ). onInterface ( INTERFACE_NAME ). withOutputParamNames ( "anInt" ). implementedAs ([ this ](){ return this -> getInt (); });
2017-11-27 14:13:55 +01:00
object_ . registerMethod ( "getTuple" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ](){ return this -> getTuple (); });
2020-01-27 07:57:38 +01:00
object_ . registerMethod ( "multiply" ). onInterface ( INTERFACE_NAME ). withInputParamNames ( "a" , "b" ). withOutputParamNames ( "result" ). implementedAs ([ this ]( const int64_t & a , const double & b ){ return this -> multiply ( a , b ); });
2019-01-10 08:47:59 +01:00
object_ . registerMethod ( "multiplyWithNoReply" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ]( const int64_t & a , const double & b ){ this -> multiplyWithNoReply ( a , b ); }). markAsDeprecated (). withNoReply ();
2017-11-27 14:13:55 +01:00
object_ . registerMethod ( "getInts16FromStruct" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ](
const sdbus :: Struct < uint8_t , int16_t , double , std :: string , std :: vector < int16_t >>& x ){ return this -> getInts16FromStruct ( x ); });
object_ . registerMethod ( "processVariant" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ]( sdbus :: Variant & v ){ return this -> processVariant ( v ); });
2020-01-27 07:57:38 +01:00
object_ . registerMethod ( "getMapOfVariants" ). onInterface ( INTERFACE_NAME )
. withInputParamNames ( "x" , "y" ). withOutputParamNames ( "aMapOfVariants" ). implementedAs ([ this ](
2017-11-27 14:13:55 +01:00
const std :: vector < int32_t >& x , const sdbus :: Struct < sdbus :: Variant , sdbus :: Variant >& y ){ return this -> getMapOfVariants ( x , y ); });
object_ . registerMethod ( "getStructInStruct" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ](){ return this -> getStructInStruct (); });
object_ . registerMethod ( "sumStructItems" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ](
const sdbus :: Struct < uint8_t , uint16_t >& a , const sdbus :: Struct < int32_t , int64_t >& b ){
return this -> sumStructItems ( a , b );
});
object_ . registerMethod ( "sumVectorItems" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ](
const std :: vector < uint16_t >& a , const std :: vector < uint64_t >& b ){
return this -> sumVectorItems ( a , b );
});
2019-03-25 14:45:48 +01:00
object_ . registerMethod ( "doOperation" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ]( uint32_t param )
2018-07-02 11:22:00 +02:00
{
2019-03-25 14:45:48 +01:00
return this -> doOperation ( param );
2018-07-02 11:22:00 +02:00
});
object_ . registerMethod ( "doOperationAsync" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ]( sdbus :: Result < uint32_t > result , uint32_t param )
{
this -> doOperationAsync ( param , std :: move ( result ));
});
2017-11-27 14:13:55 +01:00
object_ . registerMethod ( "getSignature" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ](){ return this -> getSignature (); });
object_ . registerMethod ( "getObjectPath" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ](){ return this -> getObjectPath (); });
2019-06-08 21:35:22 +02:00
object_ . registerMethod ( "getUnixFd" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ](){ return this -> getUnixFd (); });
2017-11-27 14:13:55 +01:00
2019-01-10 08:47:59 +01:00
object_ . registerMethod ( "getComplex" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ](){ return this -> getComplex (); }). markAsDeprecated ();
object_ . registerMethod ( "throwError" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ](){ return this -> throwError (); });
object_ . registerMethod ( "throwErrorWithNoReply" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ](){ this -> throwError (); }). withNoReply ();
object_ . registerMethod ( "doPrivilegedStuff" ). onInterface ( INTERFACE_NAME ). implementedAs ([](){}). markAsPrivileged ();
2017-11-27 14:13:55 +01:00
2020-01-12 13:10:34 +01:00
object_ . registerMethod ( "emitTwoSimpleSignals" ). onInterface ( INTERFACE_NAME ). implementedAs ([ this ](){ this -> emitTwoSimpleSignals (); });
2017-11-27 14:13:55 +01:00
// registration of signals is optional, it is useful because of introspection
2019-01-10 08:47:59 +01:00
object_ . registerSignal ( "simpleSignal" ). onInterface ( INTERFACE_NAME ). markAsDeprecated ();
2020-01-27 07:57:38 +01:00
// Note: sd-bus of libsystemd up to v244 has a bug where it doesn't generate signal parameter names in introspection XML. Signal param names commented temporarily.
object_ . registerSignal ( "signalWithMap" ). onInterface ( INTERFACE_NAME ). withParameters < std :: map < int32_t , std :: string >> ( /*"aMap"*/ );
object_ . registerSignal ( "signalWithVariant" ). onInterface ( INTERFACE_NAME ). withParameters < sdbus :: Variant > ( /*"aVariant"*/ );
2017-11-27 14:13:55 +01:00
2019-01-10 08:47:59 +01:00
object_ . registerProperty ( "state" ). onInterface ( INTERFACE_NAME ). withGetter ([ this ](){ return this -> state (); }). markAsDeprecated (). withUpdateBehavior ( sdbus :: Flags :: CONST_PROPERTY_VALUE );
2019-05-29 22:28:15 +02:00
object_ . registerProperty ( "action" ). onInterface ( INTERFACE_NAME ). withGetter ([ this ](){ return this -> action (); }). withSetter ([ this ]( const uint32_t & value ){ this -> action ( value ); }). withUpdateBehavior ( sdbus :: Flags :: EMITS_INVALIDATION_SIGNAL );
//object_.registerProperty("blocking").onInterface(INTERFACE_NAME)./*withGetter([this](){ return this->blocking(); }).*/withSetter([this](const bool& value){ this->blocking(value); });
object_ . registerProperty ( "blocking" ). onInterface ( INTERFACE_NAME ). withGetter ([ this ](){ return this -> blocking (); }). withSetter ([ this ]( const bool & value ){ this -> blocking ( value ); });
2017-11-27 14:13:55 +01:00
}
2019-06-10 22:54:16 +02:00
~ testing_adaptor () = default ;
2017-11-27 14:13:55 +01:00
public :
2019-06-04 22:48:54 +02:00
void emitSimpleSignal ()
2017-11-27 14:13:55 +01:00
{
object_ . emitSignal ( "simpleSignal" ). onInterface ( INTERFACE_NAME );
}
2019-06-04 22:48:54 +02:00
void emitSignalWithMap ( const std :: map < int32_t , std :: string >& map )
2017-11-27 14:13:55 +01:00
{
object_ . emitSignal ( "signalWithMap" ). onInterface ( INTERFACE_NAME ). withArguments ( map );
}
2019-06-04 22:48:54 +02:00
void emitSignalWithVariant ( const sdbus :: Variant & v )
2017-11-27 14:13:55 +01:00
{
object_ . emitSignal ( "signalWithVariant" ). onInterface ( INTERFACE_NAME ). withArguments ( v );
}
2019-06-04 22:48:54 +02:00
void emitSignalWithoutRegistration ( const sdbus :: Struct < std :: string , sdbus :: Struct < sdbus :: Signature >>& s )
2017-11-27 14:13:55 +01:00
{
object_ . emitSignal ( "signalWithoutRegistration" ). onInterface ( INTERFACE_NAME ). withArguments ( s );
}
void emitSignalOnNonexistentInterface ()
{
2019-03-24 20:18:29 +01:00
object_ . emitSignal ( "simpleSignal" ). onInterface ( "sdbuscpp.interface.that.does.not.exist" );
2017-11-27 14:13:55 +01:00
}
private :
sdbus :: IObject & object_ ;
protected :
virtual void noArgNoReturn () const = 0 ;
virtual int32_t getInt () const = 0 ;
virtual std :: tuple < uint32_t , std :: string > getTuple () const = 0 ;
virtual double multiply ( const int64_t & a , const double & b ) const = 0 ;
2019-01-10 08:47:59 +01:00
virtual void multiplyWithNoReply ( const int64_t & a , const double & b ) const = 0 ;
2017-11-27 14:13:55 +01:00
virtual std :: vector < int16_t > getInts16FromStruct ( const sdbus :: Struct < uint8_t , int16_t , double , std :: string , std :: vector < int16_t >>& x ) const = 0 ;
virtual sdbus :: Variant processVariant ( sdbus :: Variant & v ) = 0 ;
virtual std :: map < int32_t , sdbus :: Variant > getMapOfVariants ( const std :: vector < int32_t >& x , const sdbus :: Struct < sdbus :: Variant , sdbus :: Variant >& y ) const = 0 ;
virtual sdbus :: Struct < std :: string , sdbus :: Struct < std :: map < int32_t , int32_t >>> getStructInStruct () const = 0 ;
virtual int32_t sumStructItems ( const sdbus :: Struct < uint8_t , uint16_t >& a , const sdbus :: Struct < int32_t , int64_t >& b ) = 0 ;
virtual uint32_t sumVectorItems ( const std :: vector < uint16_t >& a , const std :: vector < uint64_t >& b ) = 0 ;
2019-03-25 14:45:48 +01:00
virtual uint32_t doOperation ( uint32_t param ) = 0 ;
2018-07-02 11:22:00 +02:00
virtual void doOperationAsync ( uint32_t param , sdbus :: Result < uint32_t > result ) = 0 ;
2017-11-27 14:13:55 +01:00
virtual sdbus :: Signature getSignature () const = 0 ;
virtual sdbus :: ObjectPath getObjectPath () const = 0 ;
2019-06-08 21:35:22 +02:00
virtual sdbus :: UnixFd getUnixFd () const = 0 ;
2017-11-27 14:13:55 +01:00
virtual ComplexType getComplex () const = 0 ;
2019-01-10 08:47:59 +01:00
virtual void throwError () const = 0 ;
2020-01-12 13:10:34 +01:00
virtual void emitTwoSimpleSignals () = 0 ;
2017-11-27 14:13:55 +01:00
virtual std :: string state () = 0 ;
virtual uint32_t action () = 0 ;
virtual void action ( const uint32_t & value ) = 0 ;
virtual bool blocking () = 0 ;
virtual void blocking ( const bool & value ) = 0 ;
2019-01-10 08:47:59 +01:00
public : // For testing purposes
2019-01-16 19:58:26 +01:00
std :: string getExpectedXmlApiDescription ()
{
return
2019-01-10 08:47:59 +01:00
R "delimiter(<!DOCTYPE node PUBLIC " - //freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd" >
< node >
< interface name = "org.freedesktop.DBus.Peer" >
< method name = "Ping" />
< method name = "GetMachineId" >
< arg type = "s" name = "machine_uuid" direction = "out" />
</ method >
</ interface >
< interface name = "org.freedesktop.DBus.Introspectable" >
< method name = "Introspect" >
< arg name = "data" type = "s" direction = "out" />
</ method >
</ interface >
< interface name = "org.freedesktop.DBus.Properties" >
< method name = "Get" >
< arg name = "interface" direction = "in" type = "s" />
< arg name = "property" direction = "in" type = "s" />
< arg name = "value" direction = "out" type = "v" />
</ method >
< method name = "GetAll" >
< arg name = "interface" direction = "in" type = "s" />
< arg name = "properties" direction = "out" type = "a{sv}" />
</ method >
< method name = "Set" >
< arg name = "interface" direction = "in" type = "s" />
< arg name = "property" direction = "in" type = "s" />
< arg name = "value" direction = "in" type = "v" />
</ method >
< signal name = "PropertiesChanged" >
< arg type = "s" name = "interface" />
< arg type = "a{sv}" name = "changed_properties" />
< arg type = "as" name = "invalidated_properties" />
</ signal >
</ interface >
2019-06-05 12:17:43 +02:00
< interface name = "org.freedesktop.DBus.ObjectManager" >
< method name = "GetManagedObjects" >
< arg type = "a{oa{sa{sv}}}" name = "object_paths_interfaces_and_properties" direction = "out" />
</ method >
< signal name = "InterfacesAdded" >
< arg type = "o" name = "object_path" />
< arg type = "a{sa{sv}}" name = "interfaces_and_properties" />
</ signal >
< signal name = "InterfacesRemoved" >
< arg type = "o" name = "object_path" />
< arg type = "as" name = "interfaces" />
</ signal >
</ interface >
2019-03-28 18:25:31 +01:00
< interface name = "org.sdbuscpp.integrationtests" >
2019-01-10 08:47:59 +01:00
< annotation name = "org.freedesktop.DBus.Deprecated" value = "true" />
2019-03-25 14:45:48 +01:00
< method name = "doOperation" >
2019-01-10 08:47:59 +01:00
< arg type = "u" direction = "in" />
< arg type = "u" direction = "out" />
</ method >
2019-03-25 14:45:48 +01:00
< method name = "doOperationAsync" >
2019-01-10 08:47:59 +01:00
< arg type = "u" direction = "in" />
< arg type = "u" direction = "out" />
</ method >
< method name = "doPrivilegedStuff" >
< annotation name = "org.freedesktop.systemd1.Privileged" value = "true" />
</ method >
2020-01-12 13:10:34 +01:00
< method name = "emitTwoSimpleSignals" >
</ method >
2019-01-10 08:47:59 +01:00
< method name = "getComplex" >
< arg type = "a{t(a{ya(obva{is})}gs)}" direction = "out" />
< annotation name = "org.freedesktop.DBus.Deprecated" value = "true" />
</ method >
< method name = "getInt" >
2020-01-27 07:57:38 +01:00
< arg type = "i" name = "anInt" direction = "out" />
2019-01-10 08:47:59 +01:00
</ method >
< method name = "getInts16FromStruct" >
< arg type = "(yndsan)" direction = "in" />
< arg type = "an" direction = "out" />
</ method >
< method name = "getMapOfVariants" >
2020-01-27 07:57:38 +01:00
< arg type = "ai" name = "x" direction = "in" />
< arg type = "(vv)" name = "y" direction = "in" />
< arg type = "a{iv}" name = "aMapOfVariants" direction = "out" />
2019-01-10 08:47:59 +01:00
</ method >
< method name = "getObjectPath" >
< arg type = "o" direction = "out" />
</ method >
< method name = "getSignature" >
< arg type = "g" direction = "out" />
</ method >
< method name = "getStructInStruct" >
< arg type = "(s(a{ii}))" direction = "out" />
</ method >
< method name = "getTuple" >
< arg type = "u" direction = "out" />
< arg type = "s" direction = "out" />
</ method >
2019-06-08 21:35:22 +02:00
< method name = "getUnixFd" >
< arg type = "h" direction = "out" />
</ method >
2019-01-10 08:47:59 +01:00
< method name = "multiply" >
2020-01-27 07:57:38 +01:00
< arg type = "x" name = "a" direction = "in" />
< arg type = "d" name = "b" direction = "in" />
< arg type = "d" name = "result" direction = "out" />
2019-01-10 08:47:59 +01:00
</ method >
< method name = "multiplyWithNoReply" >
< arg type = "x" direction = "in" />
< arg type = "d" direction = "in" />
< annotation name = "org.freedesktop.DBus.Deprecated" value = "true" />
< annotation name = "org.freedesktop.DBus.Method.NoReply" value = "true" />
</ method >
< method name = "noArgNoReturn" >
</ method >
< method name = "processVariant" >
< arg type = "v" direction = "in" />
< arg type = "v" direction = "out" />
</ method >
< method name = "sumStructItems" >
< arg type = "(yq)" direction = "in" />
< arg type = "(ix)" direction = "in" />
< arg type = "i" direction = "out" />
</ method >
< method name = "sumVectorItems" >
< arg type = "aq" direction = "in" />
< arg type = "at" direction = "in" />
< arg type = "u" direction = "out" />
</ method >
< method name = "throwError" >
</ method >
< method name = "throwErrorWithNoReply" >
< annotation name = "org.freedesktop.DBus.Method.NoReply" value = "true" />
</ method >
< signal name = "signalWithMap" >
< arg type = "a{is}" />
</ signal >
< signal name = "signalWithVariant" >
< arg type = "v" />
</ signal >
< signal name = "simpleSignal" >
< annotation name = "org.freedesktop.DBus.Deprecated" value = "true" />
</ signal >
< property name = "action" type = "u" access = "readwrite" >
2019-05-29 22:28:15 +02:00
< annotation name = "org.freedesktop.DBus.Property.EmitsChangedSignal" value = "invalidates" />
2019-01-10 08:47:59 +01:00
</ property >
< property name = "blocking" type = "b" access = "readwrite" >
</ property >
< property name = "state" type = "s" access = "read" >
< annotation name = "org.freedesktop.DBus.Deprecated" value = "true" />
< annotation name = "org.freedesktop.DBus.Property.EmitsChangedSignal" value = "const" />
</ property >
</ interface >
</ node >
) delimiter ";
2019-01-16 19:58:26 +01:00
}
2019-01-10 08:47:59 +01:00
2017-11-27 14:13:55 +01:00
};
#endif /* SDBUS_CPP_INTEGRATIONTESTS_ADAPTOR_GLUE_H_ */