comparison nodetype.py @ 1:d8a11a5981e2

start cvs
author drewp
date Wed, 03 Jul 2002 09:43:24 +0000
parents
children
comparison
equal deleted inserted replaced
0:45b12307c695 1:d8a11a5981e2
1 """each node descends from this base class"""
2
3 class Node:
4 def __init__(self):
5 """TBD"""
6 self.ops = Ops()
7 ''' there should be default ports, just to give people a template:
8 self.iports = [InputPort("default")]
9 self.oports = [OutputPort("default")]
10
11 # no params
12 self.params = []
13
14 # initialize state with created op? no way
15 # here's why: 1. we would need to pass stateaccess into this function
16 # and they would be allowed to initialize their state here
17 # 2. scheduler/statemanager will call created when it's good and ready,
18 # ok? no need to push it!
19 # unless... we should put real init code in NodeType or Node(Instance)
20 # inits. that might be better than having a whole op for it.
21
22 '''
23 def get_state(self, stateaccess):
24 """This is similar to the pickle.__getstate__ method, except
25 we need this alternate version in order to give the node
26 (which holds no state) access to its instance's state.
27
28 If your node keeps some transient items in its state dict
29 (such as a buffer of recently received inputs), it may want to
30 return a copy of the state dict without those items. set_state
31 should restore them properly (if they're missing from the
32 current state, which they might not be).
33
34 get_state might be called at any time, and it's certainly not
35 guaranteed that the node instance is going out of service.
36 get_state might get called to checkpoint the nodes for a
37 backup, for example. set_state might also get called anytime.
38 """
39 return stateaccess
40 def set_state(self, stateaccess, dict):
41 """dict (named after the pickle.__setstate__ argument) is
42 always a value that was previously returned from
43 get_state. Don't adjust the current node's state, of course;
44 use dict to update stateaccess. If there were elements
45 missing from dict (see the note in get_state for why this
46 might be the case), you should restore them here as
47 appropriate.
48 """
49 stateaccess.update(dict)
50
51 # warning: pseduocode
52 class NodeInstance:
53 ip_addr?
54 get_this_nodes_url()
55
56 type = the node type (a subclass of Node)
57 ops (get from type)
58 input,output = the ports that are created for the node instance
59 state = associated state
60
61