summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Williams <patrick@stwcx.xyz>2016-11-15 11:07:39 -0600
committerPatrick Williams <patrick@stwcx.xyz>2016-11-18 14:26:34 +0000
commit8c00fed2750e43486e1b10c3e751315aef03afbf (patch)
treea20ffe9451dcba67b9f3f47639608817044d39d9
parentfa5c311bc2d0da21599a1cf7bbaba01c923b7507 (diff)
downloadsdbusplus-8c00fed2750e43486e1b10c3e751315aef03afbf.tar.gz
sdbusplus-8c00fed2750e43486e1b10c3e751315aef03afbf.zip
sdbus++: add enumeration parsing
Change-Id: I6d02574942b38adbe2dc537f5279721cde2c8bc7 Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
-rw-r--r--tools/example/net/poettering/Calculator.interface.yaml17
-rw-r--r--tools/sdbusplus/enum.py11
-rw-r--r--tools/sdbusplus/interface.py3
3 files changed, 30 insertions, 1 deletions
diff --git a/tools/example/net/poettering/Calculator.interface.yaml b/tools/example/net/poettering/Calculator.interface.yaml
index 3c70cbc..7932aed 100644
--- a/tools/example/net/poettering/Calculator.interface.yaml
+++ b/tools/example/net/poettering/Calculator.interface.yaml
@@ -50,6 +50,11 @@ properties:
default: 0
description: >
The result of the most recent calculation.
+ - name: Status
+ type: enum[self.State]
+ default: Success
+ description: >
+ The current state of the Calculator.
signals:
- name: Cleared
description: >
@@ -59,4 +64,14 @@ signals:
- type: int64
description: >
Value of LastReset prior to Clear.
-
+enumerations:
+ - name: State
+ description: >
+ Identifies if the service has encountered an error or not.
+ values:
+ - name: Success
+ description: >
+ No error has been encountered.
+ - name: Error
+ description: >
+ The service has encountered an error.
diff --git a/tools/sdbusplus/enum.py b/tools/sdbusplus/enum.py
new file mode 100644
index 0000000..a5feda7
--- /dev/null
+++ b/tools/sdbusplus/enum.py
@@ -0,0 +1,11 @@
+from .namedelement import NamedElement
+from .property import Property
+
+""" Class for parsing 'enum' definition elements from an interface.
+"""
+class Enum(NamedElement):
+ def __init__(self, **kwargs):
+ self.values = \
+ [Property(**v) for v in kwargs.pop('values', [])]
+
+ super(Enum, self).__init__(**kwargs)
diff --git a/tools/sdbusplus/interface.py b/tools/sdbusplus/interface.py
index bf1b8ba..b9def8d 100644
--- a/tools/sdbusplus/interface.py
+++ b/tools/sdbusplus/interface.py
@@ -4,6 +4,7 @@ from .namedelement import NamedElement
from .property import Property
from .method import Method
from .signal import Signal
+from .enum import Enum
from .renderer import Renderer
@@ -26,6 +27,8 @@ class Interface(NamedElement, Renderer):
[Method(**m) for m in kwargs.pop('methods', [])]
self.signals = \
[Signal(**s) for s in kwargs.pop('signals', [])]
+ self.enums = \
+ [Enum(**e) for e in kwargs.pop('enumerations', [])]
super(Interface, self).__init__(**kwargs)
OpenPOWER on IntegriCloud