Add support for callbacks
Callbacks are the response in the PDM 'trigger->response' model.
Add general support for implementing callbacks and implement
a log to systemd journal using that framework.
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Change-Id: I8bead5368ee5472a02b47e8bba9e9df3a1f346bc
diff --git a/src/pdmgen.py b/src/pdmgen.py
index 070c118..e4a97e7 100755
--- a/src/pdmgen.py
+++ b/src/pdmgen.py
@@ -413,6 +413,29 @@
super(PropertyWatch, self).__init__(**kw)
+class Callback(HasPropertyIndex):
+ '''Interface and common logic for callbacks.'''
+
+ def __init__(self, *a, **kw):
+ super(Callback, self).__init__(**kw)
+
+
+class Journal(Callback, Renderer):
+ '''Handle the journal callback config file directive.'''
+
+ def __init__(self, *a, **kw):
+ self.severity = kw.pop('severity')
+ self.message = kw.pop('message')
+ super(Journal, self).__init__(**kw)
+
+ def construct(self, loader, indent):
+ return self.render(
+ loader,
+ 'journal.mako.cpp',
+ c=self,
+ indent=indent)
+
+
class Everything(Renderer):
'''Parse/render entry point.'''
@@ -440,6 +463,9 @@
'instance': {
'element': Instance,
},
+ 'callback': {
+ 'journal': Journal,
+ },
}
if cls not in class_map:
@@ -529,6 +555,7 @@
self.instances = kw.pop('instance', [])
self.instancegroups = kw.pop('instancegroup', [])
self.watches = kw.pop('watch', [])
+ self.callbacks = kw.pop('callback', [])
super(Everything, self).__init__(**kw)
@@ -550,6 +577,7 @@
instances=self.instances,
watches=self.watches,
instancegroups=self.instancegroups,
+ callbacks=self.callbacks,
indent=Indent()))
if __name__ == '__main__':