Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 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 | |