DCOPRef and dynamic stubs ( 3.1? )
Simon Hausmann
hausmann at kde.org
Mon Sep 9 12:51:13 BST 2002
On Mon, Sep 09, 2002 at 01:13:24PM +0200, Matthias Ettrich wrote:
> On Monday 09 September 2002 10:25, Simon Hausmann wrote:
>
> [snip]
> >
> > > your send call would look like
> > >
> > > DCOPRef( "desktop" ).send( "setFoo", blah, blubb );
> > >
> > > Doesn't that look even better? "setFoo" is automatically extended to
> > > "setFoo(int, QString)" depending on the types of the arguments 'blah' and
> > > 'blubb'.
> >
> > How does the signature of send look like?
>
>
> template <class T1,class T2,class T3,class T4,class T5,... >
> bool send( const QCString& fun,
> const T1& t1,
> const T2& t2,
> const T3& t3,
> const T4& t4,
> const T5& t5,
> ...
> );
>
> Currently I do up to 8 arguments, which I think is more than enough.
True. Anyone using more than 8 should probably re-think his design
:)
Another approach coming to my mind looks like this:
DCOPMethod DCOPRef::method( const QString &methodName );
with
class DCOPMethod
{
public:
DCOPMethod( const DCOPRef &_ref, const QString &_methodName );
: data(), stream( &data, IO_WriteOnly), ref( _ref ), methodName( _methodName )
{
methodName.append( "(" );
}
template <class Argument>
DOCPMethod arg( const Argument &argument )
{
return arg( argument, dcopTypeName( argument ) );
}
template <class Argument>
DOCPMethod arg( const Argument &argument, const QString &typeName )
{
stream << argument;
methodName.append( typeName );
return *this;
}
void send()
{
methodName.append( ")" );
ref.send( methodName, data );
}
DCOPReply call()
{
methodName.append( ")" );
return ref.call( methodName, data );
}
private:
QByteArray data;
QDataStream stream;
DCOPRef ref;
QString methodName;
}
And you'd get
int foo = DCOPRef( "kdesktop" ).method( "int fooForBar" ).arg( blah ).arg( url, "KURL" ).call();
Not as beautiful as one call, but general and easy to extend for
custom types :-)
Simon
More information about the kde-core-devel
mailing list