diff options
author | Vincenzo Maffione <[email protected]> | 2017-03-19 12:41:28 +0100 |
---|---|---|
committer | Vincenzo Maffione <[email protected]> | 2017-03-19 12:41:28 +0100 |
commit | 450523ca3741a55c0663cca6f6a84afa6e084f00 (patch) | |
tree | c69e200e3b9cdffc7a554b4e15e8c8419a209d3e | |
parent | 59d62c1acb7e9d7d362486636acc3843a7cc80ed (diff) | |
download | rumba-450523ca3741a55c0663cca6f6a84afa6e084f00.tar.gz rumba-450523ca3741a55c0663cca6f6a84afa6e084f00.zip |
model: add Node._validate() to check for consistency
-rw-r--r-- | rumba/model.py | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/rumba/model.py b/rumba/model.py index 1ed67dc..f34df52 100644 --- a/rumba/model.py +++ b/rumba/model.py @@ -174,6 +174,26 @@ class Node: bindings = dict() self.bindings = bindings self.full_name = name + self.ipcps = [] + + self._validate() + + def _undeclared_dif(self, dif): + if dif not in self.difs: + raise Exception("Invalid registration: node %s is not declared "\ + "to be part of DIF %s" % (self.name, dif.name)) + + def _validate(self): + # Check that DIFs referenced in self.dif_registrations and + # in self.registrations are part of self.difs + for upper in self.dif_registrations: + self._undeclared_dif(upper) + for lower in self.dif_registrations[upper]: + self._undeclared_dif(lower) + + for appl in self.registrations: + for dif in self.registrations[appl]: + self._undeclared_dif(dif) def __repr__(self): s = "Node " + self.name + ":\n" @@ -184,10 +204,10 @@ class Node: s += " DIF registrations: [ " rl = [] - for dif_a in self.dif_registrations: - difs = self.dif_registrations[dif_a] - x = "%s => [" % dif_a.name - x += " ".join([dif_b.name for dif_b in difs]) + for upper in self.dif_registrations: + difs = self.dif_registrations[upper] + x = "%s => [" % upper.name + x += " ".join([lower.name for lower in difs]) x += "]" rl.append(x) s += ", ".join(rl) @@ -220,28 +240,36 @@ class Node: def add_dif(self, dif): self.difs.append(dif) dif.add_member(self) + self._validate() def del_dif(self, dif): self.difs.remove(dif) dif.del_member(self) + self._validate() - def add_dif_registration(self, dif_a, dif_b): - self.dif_registrations[dif_a].append(dif_b) + def add_dif_registration(self, upper, lower): + self.dif_registrations[upper].append(lower) + self._validate() - def del_dif_registration(self, dif_a, dif_b): - self.dif_registrations[dif_a].remove(dif_b) + def del_dif_registration(self, upper, lower): + self.dif_registrations[upper].remove(lower) + self._validate() def add_registration(self, name, dif): self.dif_registrations[name].append(dif) + self._validate() def del_registration(self, name, dif): self.dif_registrations[name].remove(dif) + self._validate() def add_binding(self, name, ap): self.dif_bindings[name] = ap + self._validate() def del_binding(self, name): del self.dif_bindings[name] + self._validate() # Class representing an IPC Process to be created in the experiment # |