summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdriana Kobylak <anoo@us.ibm.com>2018-08-17 13:55:19 -0500
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2018-08-21 21:27:26 +0000
commit69425eb7d30816c03f88962c44b12b6de5b3cc71 (patch)
tree43b81342259cc37737ed630e203ab3cc306bb452
parent31a4b13701c2084bcf3ec19fde7be29808205ab4 (diff)
downloadsdbusplus-69425eb7d30816c03f88962c44b12b6de5b3cc71.tar.gz
sdbusplus-69425eb7d30816c03f88962c44b12b6de5b3cc71.zip
property: Add support for const (read-only) values
There is already support for setting a property as const (see vtable.hpp and corresponding test cases). Implement this in the generated code by adding support for a new yaml flag. Closes openbmc/openbmc#2028 Tested: Added the const flag to the Software Priority property, and changing the value via REST and busctl would fail with "org.freedesktop.DBus.Error.PropertyReadOnly", but the code update app was able to set its value. Change-Id: I8534753233080366503fd4f1a0c224c2946e8764 Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
-rw-r--r--docs/interface.md11
-rw-r--r--example/net/poettering/Calculator.interface.yaml2
-rw-r--r--tools/sdbusplus/property.py1
-rw-r--r--tools/sdbusplus/templates/interface.mako.server.cpp.in4
4 files changed, 15 insertions, 3 deletions
diff --git a/docs/interface.md b/docs/interface.md
index 1613021..f32bd3b 100644
--- a/docs/interface.md
+++ b/docs/interface.md
@@ -141,9 +141,12 @@ methods:
## Properties
A property must have the YAML property `name` and `type` and may optionally
-have `description`, `default`, and `errors`. The `default` defines the default
-value of the property. See the `Methods` section above for more information on
-errors.
+have `description`, `flags`, `default`, and `errors`. The `default` defines the
+default value of the property. See the `Methods` section above for more
+information on errors.
+The only current supported value for `flags` is `const`, which corresponds to
+SD_BUS_VTABLE_PROPERTY_CONST, making the property read-only via D-Bus but
+still writable by the app implementing it.
Example:
```
@@ -151,6 +154,8 @@ properties:
- name: CardsRemaining
type: uint32
default: 52
+ flags:
+ - const
description: >
The number of cards remaining in the deck.
errors:
diff --git a/example/net/poettering/Calculator.interface.yaml b/example/net/poettering/Calculator.interface.yaml
index af4dd1b..6e44093 100644
--- a/example/net/poettering/Calculator.interface.yaml
+++ b/example/net/poettering/Calculator.interface.yaml
@@ -53,6 +53,8 @@ properties:
- name: Status
type: enum[self.State]
default: Success
+ flags:
+ - const
description: >
The current state of the Calculator.
- name: Owner
diff --git a/tools/sdbusplus/property.py b/tools/sdbusplus/property.py
index 8465315..33c7e25 100644
--- a/tools/sdbusplus/property.py
+++ b/tools/sdbusplus/property.py
@@ -8,6 +8,7 @@ class Property(NamedElement, Renderer):
self.typeName = kwargs.pop('type', None)
self.cppTypeName = self.parse_cpp_type(self.typeName)
self.defaultValue = kwargs.pop('default', None)
+ self.flags = kwargs.pop('flags', [])
self.errors = kwargs.pop('errors', [])
super(Property, self).__init__(**kwargs)
diff --git a/tools/sdbusplus/templates/interface.mako.server.cpp.in b/tools/sdbusplus/templates/interface.mako.server.cpp.in
index aee5424..c8d5f65 100644
--- a/tools/sdbusplus/templates/interface.mako.server.cpp.in
+++ b/tools/sdbusplus/templates/interface.mako.server.cpp.in
@@ -142,8 +142,12 @@ ${ s.cpp_prototype(loader, interface=interface, ptype='vtable') }
details::${classname}::_property_${p.name}
.data(),
_callback_get_${p.name},
+ % if 'const' in p.flags:
+ vtable::property_::const_),
+ % else:
_callback_set_${p.name},
vtable::property_::emits_change),
+ %endif
% endfor
vtable::end()
};
OpenPOWER on IntegriCloud