Initial commit based on .zip from Glenn Schmottlach.
[dbus-cxx-async.git] / include / dbus-c++ / interface.h
blobe05328d7a0e6a6affb3f891bceed86d73b1c7be2
1 /*
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
28 #include <string>
29 #include <map>
30 #include "api.h"
31 #include "util.h"
32 #include "types.h"
34 #include "message.h"
35 #include "pendingcall.h"
37 namespace DBus {
39 //todo: this should belong to to properties.h
40 struct DBUSXXAPI PropertyData
42 bool read;
43 bool write;
44 std::string sig;
45 Variant value;
48 typedef std::map<std::string, PropertyData> PropertyTable;
50 class IntrospectedInterface;
52 class ObjectAdaptor;
53 class InterfaceAdaptor;
54 class SignalMessage;
56 typedef std::map<std::string, InterfaceAdaptor *> InterfaceAdaptorTable;
58 class DBUSXXAPI AdaptorBase
60 public:
62 virtual ObjectAdaptor &object() = 0 ;
64 protected:
66 InterfaceAdaptor *find_interface(const std::string &name);
68 virtual ~AdaptorBase()
71 virtual void _emit_signal(SignalMessage &) = 0;
73 InterfaceAdaptorTable _interfaces;
79 class ObjectProxy;
80 class InterfaceProxy;
81 class CallMessage;
83 typedef std::map<std::string, InterfaceProxy *> InterfaceProxyTable;
85 class DBUSXXAPI ProxyBase
87 public:
89 virtual ObjectProxy &object() = 0 ;
91 protected:
93 InterfaceProxy *find_interface(const std::string &name);
95 virtual ~ProxyBase()
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
107 public:
109 Interface(const std::string &name);
111 virtual ~Interface();
113 const std::string &name() const { return _name; }
115 private:
117 std::string _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
128 public:
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; }
142 protected:
144 MethodTable _methods;
145 AsyncTable _asyncs;
146 PropertyTable _properties;
152 typedef std::map< std::string, Slot<void, const SignalMessage &> > SignalTable;
154 class DBUSXXAPI InterfaceProxy : public Interface, public virtual ProxyBase
156 public:
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 &);
166 protected:
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