interface.h
Go to the documentation of this file.
1 /*
2  *
3  * D-Bus++ - C++ bindings for D-Bus
4  *
5  * Copyright (C) 2005-2007 Paolo Durante <shackan@gmail.com>
6  *
7  *
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.
12  *
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.
17  *
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
21  *
22  */
23 
24 
25 #ifndef __DBUSXX_INTERFACE_H
26 #define __DBUSXX_INTERFACE_H
27 
28 #include <string>
29 #include <map>
30 #include "api.h"
31 #include "util.h"
32 #include "types.h"
33 
34 #include "message.h"
35 
36 namespace DBus
37 {
38 
39 //todo: this should belong to to properties.h
41 {
42  bool read;
43  bool write;
44  std::string sig;
46 };
47 
48 typedef std::map<std::string, PropertyData> PropertyTable;
49 
51 
52 class ObjectAdaptor;
53 class InterfaceAdaptor;
55 
56 typedef std::map<std::string, InterfaceAdaptor *> InterfaceAdaptorTable;
57 
59 {
60 public:
61 
62  virtual const ObjectAdaptor *object() const = 0 ;
63 
64 protected:
65 
66  InterfaceAdaptor *find_interface(const std::string &name);
67 
68  virtual ~AdaptorBase()
69  {}
70 
71  virtual void _emit_signal(SignalMessage &) = 0;
72 
74 };
75 
76 /*
77 */
78 
79 class ObjectProxy;
80 class InterfaceProxy;
82 
83 typedef std::map<std::string, InterfaceProxy *> InterfaceProxyTable;
84 
86 {
87 public:
88 
89  virtual const ObjectProxy *object() const = 0 ;
90 
91 protected:
92 
93  InterfaceProxy *find_interface(const std::string &name);
94 
95  virtual ~ProxyBase()
96  {}
97 
98  virtual Message _invoke_method(CallMessage &) = 0;
99 
100  virtual bool _invoke_method_noreply(CallMessage &call) = 0;
101 
103 };
104 
106 {
107 public:
108 
109  Interface(const std::string &name);
110 
111  virtual ~Interface();
112 
113  inline const std::string &name() const;
114 
115 private:
116 
117  std::string _name;
118 };
119 
120 /*
121 */
122 
123 const std::string &Interface::name() const
124 {
125  return _name;
126 }
127 
128 /*
129 */
130 
131 typedef std::map< std::string, Slot<Message, const CallMessage &> > MethodTable;
132 
133 class DXXAPI InterfaceAdaptor : public Interface, public virtual AdaptorBase
134 {
135 public:
136 
137  InterfaceAdaptor(const std::string &name);
138 
139  Message dispatch_method(const CallMessage &);
140 
141  void emit_signal(const SignalMessage &);
142 
143  Variant *get_property(const std::string &name);
144 
145  void set_property(const std::string &name, Variant &value);
146 
148  {
149  return NULL;
150  }
151 
152 protected:
153 
156 };
157 
158 /*
159 */
160 
161 typedef std::map< std::string, Slot<void, const SignalMessage &> > SignalTable;
162 
163 class DXXAPI InterfaceProxy : public Interface, public virtual ProxyBase
164 {
165 public:
166 
167  InterfaceProxy(const std::string &name);
168 
169  Message invoke_method(const CallMessage &);
170 
171  bool invoke_method_noreply(const CallMessage &call);
172 
173  bool dispatch_signal(const SignalMessage &);
174 
175 protected:
176 
178 };
179 
180 # define register_method(interface, method, callback) \
181  InterfaceAdaptor::_methods[ #method ] = \
182  new ::DBus::Callback< interface, ::DBus::Message, const ::DBus::CallMessage &>(this, & interface :: callback);
183 
184 # define bind_property(variable, type, can_read, can_write) \
185  InterfaceAdaptor::_properties[ #variable ].read = can_read; \
186  InterfaceAdaptor::_properties[ #variable ].write = can_write; \
187  InterfaceAdaptor::_properties[ #variable ].sig = type; \
188  variable.bind(InterfaceAdaptor::_properties[ #variable ]);
189 
190 # define connect_signal(interface, signal, callback) \
191  InterfaceProxy::_signals[ #signal ] = \
192  new ::DBus::Callback< interface, void, const ::DBus::SignalMessage &>(this, & interface :: callback);
193 
194 } /* namespace DBus */
195 
196 #endif//__DBUSXX_INTERFACE_H
std::string _name
Definition: interface.h:117
std::map< std::string, Slot< void, const SignalMessage & > > SignalTable
Definition: interface.h:161
const std::string & name() const
Definition: interface.h:123
std::map< std::string, Slot< Message, const CallMessage & > > MethodTable
Definition: interface.h:131
std::map< std::string, PropertyData > PropertyTable
Definition: interface.h:48
MethodTable _methods
Definition: interface.h:154
PropertyTable _properties
Definition: interface.h:155
#define DXXAPI
Definition: api.h:36
virtual ~AdaptorBase()
Definition: interface.h:68
std::map< std::string, InterfaceProxy * > InterfaceProxyTable
Definition: interface.h:81
std::string sig
Definition: interface.h:44
std::map< std::string, InterfaceAdaptor * > InterfaceAdaptorTable
Definition: interface.h:54
SignalTable _signals
Definition: interface.h:177
InterfaceAdaptorTable _interfaces
Definition: interface.h:73
InterfaceProxyTable _interfaces
Definition: interface.h:102
virtual IntrospectedInterface * introspect() const
Definition: interface.h:147
virtual ~ProxyBase()
Definition: interface.h:95