3
* D-Bus++ - C++ bindings for D-Bus
5
* Copyright (C) 2005-2007 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
28
#include <dbus-c++/debug.h>
29
#include <dbus-c++/interface.h>
31
#include "internalerror.h"
35
Interface::Interface(const std::string &name)
39
Interface::~Interface()
42
InterfaceAdaptor *AdaptorBase::find_interface(const std::string &name)
44
InterfaceAdaptorTable::const_iterator ii = _interfaces.find(name);
46
return ii != _interfaces.end() ? ii->second : NULL;
49
InterfaceAdaptor::InterfaceAdaptor(const std::string &name)
52
debug_log("adding interface %s", name.c_str());
54
_interfaces[name] = this;
57
Message InterfaceAdaptor::dispatch_method(const CallMessage &msg)
59
const char *name = msg.member();
61
MethodTable::iterator mi = _methods.find(name);
62
if (mi != _methods.end())
64
return mi->second.call(msg);
68
return ErrorMessage(msg, DBUS_ERROR_UNKNOWN_METHOD, name);
72
void InterfaceAdaptor::emit_signal(const SignalMessage &sig)
74
SignalMessage &sig2 = const_cast<SignalMessage &>(sig);
76
if (sig2.interface() == NULL)
77
sig2.interface(name().c_str());
82
Variant *InterfaceAdaptor::get_property(const std::string &name)
84
PropertyTable::iterator pti = _properties.find(name);
86
if (pti != _properties.end())
88
if (!pti->second.read)
89
throw ErrorAccessDenied("property is not readable");
91
return &(pti->second.value);
96
void InterfaceAdaptor::set_property(const std::string &name, Variant &value)
98
PropertyTable::iterator pti = _properties.find(name);
100
if (pti != _properties.end())
102
if (!pti->second.write)
103
throw ErrorAccessDenied("property is not writeable");
105
Signature sig = value.signature();
107
if (pti->second.sig != sig)
108
throw ErrorInvalidSignature("property expects a different type");
110
pti->second.value = value;
113
throw ErrorFailed("requested property not found");
116
InterfaceProxy *ProxyBase::find_interface(const std::string &name)
118
InterfaceProxyTable::const_iterator ii = _interfaces.find(name);
120
return ii != _interfaces.end() ? ii->second : NULL;
123
InterfaceProxy::InterfaceProxy(const std::string &name)
126
debug_log("adding interface %s", name.c_str());
128
_interfaces[name] = this;
131
bool InterfaceProxy::dispatch_signal(const SignalMessage &msg)
133
const char *name = msg.member();
135
SignalTable::iterator si = _signals.find(name);
136
if (si != _signals.end())
138
si->second.call(msg);
139
// Here we always return false because there might be
140
// another InterfaceProxy listening for the same signal.
141
// This way we instruct libdbus-1 to go on dispatching
151
Message InterfaceProxy::invoke_method(const CallMessage &call)
153
CallMessage &call2 = const_cast<CallMessage &>(call);
155
if (call.interface() == NULL)
156
call2.interface(name().c_str());
158
return _invoke_method(call2);
161
bool InterfaceProxy::invoke_method_noreply(const CallMessage &call)
163
CallMessage &call2 = const_cast<CallMessage &>(call);
165
if (call.interface() == NULL)
166
call2.interface(name().c_str());
168
return _invoke_method_noreply(call2);