3 * D-Bus++ - C++ bindings for D-Bus
5 * Copyright (C) 2005-2009 Paolo Durante <shackan@gmail.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifndef __DBUSXX_INTERFACE_H
26 #define __DBUSXX_INTERFACE_H
35 #include "pendingcall.h"
39 //todo: this should belong to to properties.h
40 struct DBUSXXAPI PropertyData
48 typedef std::map
<std::string
, PropertyData
> PropertyTable
;
50 class IntrospectedInterface
;
53 class InterfaceAdaptor
;
56 typedef std::map
<std::string
, InterfaceAdaptor
*> InterfaceAdaptorTable
;
58 class DBUSXXAPI AdaptorBase
62 virtual ObjectAdaptor
&object() = 0 ;
66 InterfaceAdaptor
*find_interface(const std::string
&name
);
68 virtual ~AdaptorBase()
71 virtual void _emit_signal(SignalMessage
&) = 0;
73 InterfaceAdaptorTable _interfaces
;
83 typedef std::map
<std::string
, InterfaceProxy
*> InterfaceProxyTable
;
85 class DBUSXXAPI ProxyBase
89 virtual ObjectProxy
&object() = 0 ;
93 InterfaceProxy
*find_interface(const std::string
&name
);
98 virtual Message
_invoke_method(CallMessage
&, int timeout
) = 0;
100 virtual PendingCall
_invoke_method_async(CallMessage
&, const PendingCallSlot
&, void* p
, int timeout
) = 0;
102 InterfaceProxyTable _interfaces
;
105 class DBUSXXAPI Interface
109 Interface(const std::string
&name
);
111 virtual ~Interface();
113 const std::string
&name() const { return _name
; }
123 typedef std::map
< std::string
, Slot
<Message
, const CallMessage
&> > MethodTable
;
124 typedef std::map
< std::string
, Slot
<void, const CallMessage
&> > AsyncTable
;
126 class DBUSXXAPI InterfaceAdaptor
: public Interface
, public virtual AdaptorBase
130 InterfaceAdaptor(const std::string
&name
);
132 void dispatch_method(const CallMessage
&, Message
**);
134 void emit_signal(const SignalMessage
&);
136 Variant
*get_property(const std::string
&name
);
138 void set_property(const std::string
&name
, Variant
&value
);
140 virtual IntrospectedInterface
*const introspect() const { return NULL
; }
144 MethodTable _methods
;
146 PropertyTable _properties
;
152 typedef std::map
< std::string
, Slot
<void, const SignalMessage
&> > SignalTable
;
154 class DBUSXXAPI InterfaceProxy
: public Interface
, public virtual ProxyBase
158 InterfaceProxy(const std::string
&name
);
160 Message
invoke_method(const CallMessage
&, int timeout
= -1);
162 PendingCall
invoke_method_async(const CallMessage
&, const PendingCallSlot
&, void*, int timeout
= -1);
164 bool dispatch_signal(const SignalMessage
&);
168 SignalTable _signals
;
171 # define register_method(interface, method, callback) \
172 InterfaceAdaptor::_methods[ #method ] = \
173 new ::DBus::Callback< interface, ::DBus::Message, const ::DBus::CallMessage &>(this, & interface :: callback, ::DBus::CallMessage());
175 # define register_async(interface, method, callback) \
176 InterfaceAdaptor::_asyncs[ #method ] = \
177 new ::DBus::CallbackNoReturn< interface, const ::DBus::CallMessage &>(this, & interface :: callback);
179 # define bind_property(variable, type, can_read, can_write) \
180 InterfaceAdaptor::_properties[ #variable ].read = can_read; \
181 InterfaceAdaptor::_properties[ #variable ].write = can_write; \
182 InterfaceAdaptor::_properties[ #variable ].sig = type; \
183 variable.bind(InterfaceAdaptor::_properties[ #variable ]);
185 # define connect_signal(interface, signal, callback) \
186 InterfaceProxy::_signals[ #signal ] = \
187 new ::DBus::CallbackNoReturn< interface, const ::DBus::SignalMessage &>(this, & interface :: callback);
189 } /* namespace DBus */
191 #endif//__DBUSXX_INTERFACE_H