summaryrefslogtreecommitdiffstats
path: root/src/pdmgen.py
diff options
context:
space:
mode:
authorBrad Bishop <bradleyb@fuzziesquirrel.com>2017-05-21 10:06:07 -0400
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-06-19 16:26:47 -0400
commit4041d720cf6387aa198c620cc9c6eaa86ac18cba (patch)
treeda24ecea922de6ea3cd83276ded0c148cbeddeba /src/pdmgen.py
parent731171a12c6d52ead2d93303867b6d731d4d6728 (diff)
downloadphosphor-dbus-monitor-4041d720cf6387aa198c620cc9c6eaa86ac18cba.tar.gz
phosphor-dbus-monitor-4041d720cf6387aa198c620cc9c6eaa86ac18cba.zip
Add conditional callbacks
Enable conditional application of callbacks. Change-Id: I9d765e5f585aac40994b65da3b51ea891beae9bf Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Diffstat (limited to 'src/pdmgen.py')
-rwxr-xr-xsrc/pdmgen.py98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/pdmgen.py b/src/pdmgen.py
index b20436e..4a958e1 100755
--- a/src/pdmgen.py
+++ b/src/pdmgen.py
@@ -420,6 +420,99 @@ class Callback(HasPropertyIndex):
super(Callback, self).__init__(**kw)
+class ConditionCallback(ConfigEntry, Renderer):
+ '''Handle the journal callback config file directive.'''
+
+ def __init__(self, *a, **kw):
+ self.condition = kw.pop('condition')
+ self.instance = kw.pop('instance')
+ super(ConditionCallback, self).__init__(**kw)
+
+ def factory(self, objs):
+ '''Create a graph instance for this callback.'''
+
+ args = {
+ 'configfile': self.configfile,
+ 'members': [self.instance],
+ 'class': 'callbackgroup',
+ 'callbackgroup': 'callback',
+ 'name': [self.instance]
+ }
+
+ entry = CallbackGraphEntry(**args)
+ add_unique(entry, objs, config=self.configfile)
+
+ super(ConditionCallback, self).factory(objs)
+
+ def setup(self, objs):
+ '''Resolve condition and graph entry.'''
+
+ self.graph = get_index(
+ objs,
+ 'callbackgroup',
+ [self.instance],
+ config=self.configfile)
+
+ self.condition = get_index(
+ objs,
+ 'condition',
+ self.name,
+ config=self.configfile)
+
+ super(ConditionCallback, self).setup(objs)
+
+ def construct(self, loader, indent):
+ return self.render(
+ loader,
+ 'conditional.mako.cpp',
+ c=self,
+ indent=indent)
+
+
+class Condition(HasPropertyIndex):
+ '''Interface and common logic for conditions.'''
+
+ def __init__(self, *a, **kw):
+ self.callback = kw.pop('callback')
+ super(Condition, self).__init__(**kw)
+
+ def factory(self, objs):
+ '''Create a callback instance for this conditional.'''
+
+ args = {
+ 'configfile': self.configfile,
+ 'condition': self.name,
+ 'class': 'callback',
+ 'callback': 'conditional',
+ 'instance': self.callback,
+ 'name': self.name,
+ }
+
+ callback = ConditionCallback(**args)
+ add_unique(callback, objs, config=self.configfile)
+ callback.factory(objs)
+
+ super(Condition, self).factory(objs)
+
+
+class CountCondition(Condition, Renderer):
+ '''Handle the count condition config file directive.'''
+
+ def __init__(self, *a, **kw):
+ self.countop = kw.pop('countop')
+ self.countbound = kw.pop('countbound')
+ self.op = kw.pop('op')
+ self.bound = kw.pop('bound')
+ super(CountCondition, self).__init__(**kw)
+
+ def construct(self, loader, indent):
+ return self.render(
+ loader,
+ 'count.mako.cpp',
+ c=self,
+ indent=indent)
+
+
class Journal(Callback, Renderer):
'''Handle the journal callback config file directive.'''
@@ -526,6 +619,9 @@ class Everything(Renderer):
'journal': Journal,
'group': GroupOfCallbacks,
},
+ 'condition': {
+ 'count': CountCondition,
+ },
}
if cls not in class_map:
@@ -617,6 +713,7 @@ class Everything(Renderer):
self.watches = kw.pop('watch', [])
self.callbacks = kw.pop('callback', [])
self.callbackgroups = kw.pop('callbackgroup', [])
+ self.conditions = kw.pop('condition', [])
super(Everything, self).__init__(**kw)
@@ -640,6 +737,7 @@ class Everything(Renderer):
instancegroups=self.instancegroups,
callbacks=self.callbacks,
callbackgroups=self.callbackgroups,
+ conditions=self.conditions,
indent=Indent()))
if __name__ == '__main__':
OpenPOWER on IntegriCloud