changeset 1:d8a11a5981e2

start cvs
author drewp
date Wed, 03 Jul 2002 09:43:24 +0000
parents 45b12307c695
children 022e35e17182
files nodetype.py
diffstat 1 files changed, 61 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nodetype.py	Wed Jul 03 09:43:24 2002 +0000
@@ -0,0 +1,61 @@
+"""each node descends from this base class"""
+
+class Node:
+    def __init__(self):
+        """TBD"""
+        self.ops = Ops()
+        ''' there should be default ports, just to give people a template:
+        self.iports = [InputPort("default")]
+        self.oports = [OutputPort("default")]
+
+        # no params
+        self.params = []
+
+        # initialize state with created op?  no way
+        # here's why: 1. we would need to pass stateaccess into this function
+        # and they would be allowed to initialize their state here
+        # 2. scheduler/statemanager will call created when it's good and ready,
+        # ok?  no need to push it!
+        # unless... we should put real init code in NodeType or Node(Instance)
+        # inits.  that might be better than having a whole op for it.
+        
+        '''
+    def get_state(self, stateaccess):
+        """This is similar to the pickle.__getstate__ method, except
+        we need this alternate version in order to give the node
+        (which holds no state) access to its instance's state.
+
+        If your node keeps some transient items in its state dict
+        (such as a buffer of recently received inputs), it may want to
+        return a copy of the state dict without those items. set_state
+        should restore them properly (if they're missing from the
+        current state, which they might not be).
+
+        get_state might be called at any time, and it's certainly not
+        guaranteed that the node instance is going out of service.
+        get_state might get called to checkpoint the nodes for a
+        backup, for example. set_state might also get called anytime.
+        """
+        return stateaccess
+    def set_state(self, stateaccess, dict):
+        """dict (named after the pickle.__setstate__ argument) is
+        always a value that was previously returned from
+        get_state. Don't adjust the current node's state, of course;
+        use dict to update stateaccess.  If there were elements
+        missing from dict (see the note in get_state for why this
+        might be the case), you should restore them here as
+        appropriate.
+        """        
+        stateaccess.update(dict)
+
+# warning: pseduocode
+class NodeInstance:
+    ip_addr?
+    get_this_nodes_url()
+
+    type = the node type (a subclass of Node)
+        ops (get from type)
+    input,output = the ports that are created for the node instance
+    state = associated state
+
+