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>
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 @@
 ## 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 @@
     - 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 @@
     - 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 @@
         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 @@
                      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()
 };