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
);
67 InterfaceAdaptor
*find_interface_with_method(const std::string
&method
);
69 virtual ~AdaptorBase()
72 virtual void _emit_signal(SignalMessage
&) = 0;
74 InterfaceAdaptorTable _interfaces
;
84 typedef std::map
<std::string
, InterfaceProxy
*> InterfaceProxyTable
;
86 class DBUSXXAPI ProxyBase
90 virtual ObjectProxy
&object() = 0 ;
94 InterfaceProxy
*find_interface(const std::string
&name
);
99 virtual Message
_invoke_method(CallMessage
&, int timeout
) = 0;
101 virtual PendingCall
_invoke_method_async(CallMessage
&, const PendingCallSlot
&, void* p
, int timeout
) = 0;
103 InterfaceProxyTable _interfaces
;
106 class DBUSXXAPI Interface
110 Interface(const std::string
&name
);
112 virtual ~Interface();
114 const std::string
&name() const { return _name
; }
124 typedef std::map
< std::string
, Slot
<Message
, const CallMessage
&> > MethodTable
;
125 typedef std::map
< std::string
, Slot
<void, const CallMessage
&> > AsyncTable
;
127 class DBUSXXAPI InterfaceAdaptor
: public Interface
, public virtual AdaptorBase
131 InterfaceAdaptor(const std::string
&name
);
133 void dispatch_method(const CallMessage
&, Message
**);
135 void emit_signal(const SignalMessage
&);
137 Variant
*get_property(const std::string
&name
);
139 void set_property(const std::string
&name
, Variant
&value
);
141 bool has_method(const std::string
&name
) const;
143 virtual IntrospectedInterface
*const introspect() const { return NULL
; }
147 MethodTable _methods
;
149 PropertyTable _properties
;
155 typedef std::map
< std::string
, Slot
<void, const SignalMessage
&> > SignalTable
;
157 class DBUSXXAPI InterfaceProxy
: public Interface
, public virtual ProxyBase
161 InterfaceProxy(const std::string
&name
);
163 Message
invoke_method(const CallMessage
&, int timeout
= -1);
165 PendingCall
invoke_method_async(const CallMessage
&, const PendingCallSlot
&, void*, int timeout
= -1);
167 bool dispatch_signal(const SignalMessage
&);
171 SignalTable _signals
;
174 # define register_method(interface, method, callback) \
175 InterfaceAdaptor::_methods[ #method ] = \
176 new ::DBus::Callback< interface, ::DBus::Message, const ::DBus::CallMessage &>(this, & interface :: callback, ::DBus::CallMessage());
178 # define register_async(interface, method, callback) \
179 InterfaceAdaptor::_asyncs[ #method ] = \
180 new ::DBus::CallbackNoReturn< interface, const ::DBus::CallMessage &>(this, & interface :: callback);
182 # define bind_property(variable, type, can_read, can_write) \
183 InterfaceAdaptor::_properties[ #variable ].read = can_read; \
184 InterfaceAdaptor::_properties[ #variable ].write = can_write; \
185 InterfaceAdaptor::_properties[ #variable ].sig = type; \
186 variable.bind(InterfaceAdaptor::_properties[ #variable ]);
188 # define connect_signal(interface, signal, callback) \
189 InterfaceProxy::_signals[ #signal ] = \
190 new ::DBus::CallbackNoReturn< interface, const ::DBus::SignalMessage &>(this, & interface :: callback);
192 } /* namespace DBus */
194 #endif//__DBUSXX_INTERFACE_H