2 # Author: Eric von Bayer
4 # Date: August 18, 2009
6 # Module to handle deferred callbacks in stages.
8 # Copyright (c) 2009, Eric von Bayer
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions are met:
14 # * Redistributions of source code must retain the above copyright notice,
15 # this list of conditions and the following disclaimer.
16 # * Redistributions in binary form must reproduce the above copyright notice,
17 # this list of conditions and the following disclaimer in the documentation
18 # and/or other materials provided with the distribution.
19 # * The names of the contributors may not be used to endorse or promote
20 # products derived from this software without specific prior written
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
27 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 # Class to hold a stage
36 """An individual stage to be executed at a later time"""
38 # Initialize the stage
40 self
.__callbacks
= list()
43 # Execute all the callbacks in the stage
45 if self
.__done
== False:
47 for call
in self
.__callbacks
:
51 # Add a callback to the stage
52 def AddCallback(self
, call
):
53 if self
.__done
== True:
56 self
.__callbacks
.append( call
)
58 # Internal storage for the stages
59 stager_stages
= dict()
61 # Execute the named stage
63 if name
in stager_stages
:
64 stager_stages
[name
].Execute()
66 # Add a callback to the named stage
67 def AddCallback(name
, call
):
68 if not name
in stager_stages
:
69 stager_stages
[name
] = Stage()
71 stager_stages
[name
].AddCallback( call
)