# DBus-C++

## Desktop Communication Bus System

libdbus-c-- Documentation 0.9.0

- Files
- Data Structures
- Globals
- Main Page

property.cpp
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#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <dbus-c++/debug.h>
29#include <dbus-c++/property.h>
30
31#include <dbus-c++/introspection.h>
32
33 using namespace DBus;
34
35 static const char *properties_name = "org.freedesktop.DBus.Properties";
36
37 PropertiesAdaptor::PropertiesAdaptor()
38 : InterfaceAdaptor(properties_name)
39{
40 register_method(PropertiesAdaptor, Get, Get);
41 register_method(PropertiesAdaptor, Set, Set);
42}
43
44 Message PropertiesAdaptor::Get(const CallMessage &call)
45{
46 MessageIter ri = call.reader();
47
48 std::string iface_name;
49 std::string property_name;
50
51 ri >> iface_name >> property_name;
52
53 debug_log("requesting property %s on interface %s", property_name.c_str(), iface_name.c_str());
54
55 InterfaceAdaptor *interface = (InterfaceAdaptor *) find_interface(iface_name);
56
57 if (!interface)
58 throw ErrorFailed("requested interface not found");
59
60 Variant *value = interface->get_property(property_name);
61
62 if (!value)
63 throw ErrorFailed("requested property not found");
64
65 on_get_property(*interface, property_name, *value);
66
67 ReturnMessage reply(call);
68
69 MessageIter wi = reply.writer();
70
71 wi << *value;
72 return reply;
73}
74
75 Message PropertiesAdaptor::Set(const CallMessage &call)
76{
77 MessageIter ri = call.reader();
78
79 std::string iface_name;
80 std::string property_name;
81 Variant value;
82
83 ri >> iface_name >> property_name >> value;
84
85 InterfaceAdaptor *interface = (InterfaceAdaptor *) find_interface(iface_name);
86
87 if (!interface)
88 throw ErrorFailed("requested interface not found");
89
90 on_set_property(*interface, property_name, value);
91
92 interface->set_property(property_name, value);
93
94 ReturnMessage reply(call);
95
96 return reply;
97}
98
99 IntrospectedInterface *PropertiesAdaptor::introspect() const
100{
101 static IntrospectedArgument Get_args[] =
102 {
103 { "interface_name", "s", true },
104 { "property_name", "s", true },
105 { "value", "v", false },
106 { 0, 0, 0 }
107 };
108 static IntrospectedArgument Set_args[] =
109 {
110 { "interface_name", "s", true },
111 { "property_name", "s", true },
112 { "value", "v", true },
113 { 0, 0, 0 }
114 };
115 static IntrospectedMethod Properties_methods[] =
116 {
117 { "Get", Get_args },
118 { "Set", Set_args },
119 { 0, 0 }
120 };
121 static IntrospectedMethod Properties_signals[] =
122 {
123 { 0, 0 }
124 };
125 static IntrospectedProperty Properties_properties[] =
126 {
127 { 0, 0, 0, 0 }
128 };
129 static IntrospectedInterface Properties_interface =
130 {
131 properties_name,
132 Properties_methods,
133 Properties_signals,
134 Properties_properties
135 };
136 return &Properties_interface;
137}
138
139 PropertiesProxy::PropertiesProxy()
140 : InterfaceProxy(properties_name)
141{
142}
143
144 Variant PropertiesProxy::Get(const std::string &iface, const std::string &property)
145{
146//todo
147 Variant v;
148 return v;
149}
150
151 void PropertiesProxy::Set(const std::string &iface, const std::string &property, const Variant &value)
152{
153//todo
154}
155
DBus::AdaptorBase::find_interface
InterfaceAdaptor * find_interface(const std::string &name)
Definition interface.cpp:42
DBus::CallMessage
Definition message.h:269
DBus::InterfaceAdaptor::InterfaceAdaptor
InterfaceAdaptor(const std::string &name)
Definition interface.cpp:49
DBus::InterfaceProxy::InterfaceProxy
InterfaceProxy(const std::string &name)
Definition interface.cpp:123
DBus::MessageIter
Definition message.h:45
DBus::Message
Definition message.h:159
DBus::Message::writer
MessageIter writer()
Definition message.cpp:473
DBus::Message::reader
MessageIter reader() const
Definition message.cpp:480
DBus::PropertiesAdaptor::PropertiesAdaptor
PropertiesAdaptor()
Definition property.cpp:37
DBus::PropertiesAdaptor::Set
Message Set(const CallMessage &)
Definition property.cpp:75
DBus::PropertiesAdaptor::on_get_property
virtual void on_get_property(InterfaceAdaptor &, const std::string &, Variant &)
Definition property.h:80
DBus::PropertiesAdaptor::on_set_property
virtual void on_set_property(InterfaceAdaptor &, const std::string &, const Variant &)
Definition property.h:83
DBus::PropertiesAdaptor::introspect
IntrospectedInterface * introspect() const
Definition property.cpp:99
DBus::PropertiesAdaptor::Get
Message Get(const CallMessage &)
Definition property.cpp:44
DBus::PropertiesProxy::PropertiesProxy
PropertiesProxy()
Definition property.cpp:139
DBus::PropertiesProxy::Set
void Set(const std::string &interface, const std::string &property, const Variant &value)
Definition property.cpp:151
DBus::PropertiesProxy::Get
Variant Get(const std::string &interface, const std::string &property)
Definition property.cpp:144
DBus::ReturnMessage
Definition message.h:299
DBus::Variant
Definition types.h:68
debug.h
register_method
#define register_method(interface, method, callback)
Definition interface.h:180
introspection.h
DBus
Definition connection_p.h:42
DBus::debug_log
DXXAPI LogFunction debug_log
Definition debug.cpp:55
properties_name
static const char * properties_name
Definition property.cpp:35
property.h
DBus::ErrorFailed
Definition error.h:75
DBus::IntrospectedArgument
Definition introspection.h:35
DBus::IntrospectedInterface
Definition introspection.h:56
DBus::IntrospectedMethod
Definition introspection.h:42
DBus::IntrospectedProperty
Definition introspection.h:48