Go to the documentation of this file.00001
00002
00003
00004
00005
00006 from smclib import statemap
00007
00008
00009 class BondSMState(statemap.State):
00010
00011 def Entry(self, fsm):
00012 pass
00013
00014 def Exit(self, fsm):
00015 pass
00016
00017 def ConnectTimeout(self, fsm):
00018 self.Default(fsm)
00019
00020 def Die(self, fsm):
00021 self.Default(fsm)
00022
00023 def DisconnectTimeout(self, fsm):
00024 self.Default(fsm)
00025
00026 def HeartbeatTimeout(self, fsm):
00027 self.Default(fsm)
00028
00029 def SisterAlive(self, fsm):
00030 self.Default(fsm)
00031
00032 def SisterDead(self, fsm):
00033 self.Default(fsm)
00034
00035 def Default(self, fsm):
00036 msg = "\n\tState: %s\n\tTransition: %s" % (
00037 fsm.getState().getName(), fsm.getTransition())
00038 raise statemap.TransitionUndefinedException(msg)
00039
00040
00041 class SM_Default(BondSMState):
00042 pass
00043
00044
00045 class SM_WaitingForSister(SM_Default):
00046
00047 def ConnectTimeout(self, fsm):
00048 ctxt = fsm.getOwner()
00049 fsm.getState().Exit(fsm)
00050 fsm.clearState()
00051 try:
00052 ctxt.Death()
00053 finally:
00054 fsm.setState(SM.Dead)
00055 fsm.getState().Entry(fsm)
00056
00057 def Die(self, fsm):
00058 ctxt = fsm.getOwner()
00059 fsm.getState().Exit(fsm)
00060 fsm.clearState()
00061 try:
00062 ctxt.Death()
00063 finally:
00064 fsm.setState(SM.Dead)
00065 fsm.getState().Entry(fsm)
00066
00067 def SisterAlive(self, fsm):
00068 ctxt = fsm.getOwner()
00069 fsm.getState().Exit(fsm)
00070 fsm.clearState()
00071 try:
00072 ctxt.Connected()
00073 finally:
00074 fsm.setState(SM.Alive)
00075 fsm.getState().Entry(fsm)
00076
00077 def SisterDead(self, fsm):
00078 ctxt = fsm.getOwner()
00079 fsm.getState().Exit(fsm)
00080 fsm.clearState()
00081 try:
00082 ctxt.Connected()
00083 ctxt.SisterDied()
00084 ctxt.Death()
00085 finally:
00086 fsm.setState(SM.Dead)
00087 fsm.getState().Entry(fsm)
00088
00089
00090 class SM_Alive(SM_Default):
00091
00092 def Die(self, fsm):
00093 ctxt = fsm.getOwner()
00094 fsm.getState().Exit(fsm)
00095 fsm.clearState()
00096 try:
00097 ctxt.StartDying()
00098 finally:
00099 fsm.setState(SM.AwaitSisterDeath)
00100 fsm.getState().Entry(fsm)
00101
00102 def HeartbeatTimeout(self, fsm):
00103 ctxt = fsm.getOwner()
00104 fsm.getState().Exit(fsm)
00105 fsm.clearState()
00106 try:
00107 ctxt.Death()
00108 finally:
00109 fsm.setState(SM.Dead)
00110 fsm.getState().Entry(fsm)
00111
00112 def SisterAlive(self, fsm):
00113 ctxt = fsm.getOwner()
00114 fsm.getState().Exit(fsm)
00115 fsm.clearState()
00116 try:
00117 ctxt.Heartbeat()
00118 finally:
00119 fsm.setState(SM.Alive)
00120 fsm.getState().Entry(fsm)
00121
00122 def SisterDead(self, fsm):
00123 ctxt = fsm.getOwner()
00124 fsm.getState().Exit(fsm)
00125 fsm.clearState()
00126 try:
00127 ctxt.SisterDied()
00128 ctxt.Death()
00129 finally:
00130 fsm.setState(SM.Dead)
00131 fsm.getState().Entry(fsm)
00132
00133
00134 class SM_AwaitSisterDeath(SM_Default):
00135
00136 def Die(self, fsm):
00137 fsm.getState().Exit(fsm)
00138 fsm.setState(SM.AwaitSisterDeath)
00139 fsm.getState().Entry(fsm)
00140
00141 def DisconnectTimeout(self, fsm):
00142 ctxt = fsm.getOwner()
00143 fsm.getState().Exit(fsm)
00144 fsm.clearState()
00145 try:
00146 ctxt.Death()
00147 finally:
00148 fsm.setState(SM.Dead)
00149 fsm.getState().Entry(fsm)
00150
00151 def HeartbeatTimeout(self, fsm):
00152 fsm.getState().Exit(fsm)
00153 fsm.setState(SM.AwaitSisterDeath)
00154 fsm.getState().Entry(fsm)
00155
00156 def SisterAlive(self, fsm):
00157 fsm.getState().Exit(fsm)
00158 fsm.setState(SM.AwaitSisterDeath)
00159 fsm.getState().Entry(fsm)
00160
00161 def SisterDead(self, fsm):
00162 ctxt = fsm.getOwner()
00163 fsm.getState().Exit(fsm)
00164 fsm.clearState()
00165 try:
00166 ctxt.Death()
00167 finally:
00168 fsm.setState(SM.Dead)
00169 fsm.getState().Entry(fsm)
00170
00171
00172 class SM_Dead(SM_Default):
00173
00174 def ConnectTimeout(self, fsm):
00175 fsm.getState().Exit(fsm)
00176 fsm.setState(SM.Dead)
00177 fsm.getState().Entry(fsm)
00178
00179 def Die(self, fsm):
00180 fsm.getState().Exit(fsm)
00181 fsm.setState(SM.Dead)
00182 fsm.getState().Entry(fsm)
00183
00184 def DisconnectTimeout(self, fsm):
00185 fsm.getState().Exit(fsm)
00186 fsm.setState(SM.Dead)
00187 fsm.getState().Entry(fsm)
00188
00189 def HeartbeatTimeout(self, fsm):
00190 fsm.getState().Exit(fsm)
00191 fsm.setState(SM.Dead)
00192 fsm.getState().Entry(fsm)
00193
00194 def SisterAlive(self, fsm):
00195 fsm.getState().Exit(fsm)
00196 fsm.setState(SM.Dead)
00197 fsm.getState().Entry(fsm)
00198
00199 def SisterDead(self, fsm):
00200 fsm.getState().Exit(fsm)
00201 fsm.setState(SM.Dead)
00202 fsm.getState().Entry(fsm)
00203
00204
00205 class SM(object):
00206
00207 WaitingForSister = SM_WaitingForSister('SM.WaitingForSister', 0)
00208 Alive = SM_Alive('SM.Alive', 1)
00209 AwaitSisterDeath = SM_AwaitSisterDeath('SM.AwaitSisterDeath', 2)
00210 Dead = SM_Dead('SM.Dead', 3)
00211 Default = SM_Default('SM.Default', -1)
00212
00213
00214 class BondSM_sm(statemap.FSMContext):
00215
00216 def __init__(self, owner):
00217 statemap.FSMContext.__init__(self, SM.WaitingForSister)
00218 self._owner = owner
00219
00220 def __getattr__(self, attrib):
00221 def trans_sm(*arglist):
00222 self._transition = attrib
00223 getattr(self.getState(), attrib)(self, *arglist)
00224 self._transition = None
00225 return trans_sm
00226
00227 def enterStartState(self):
00228 self._state.Entry(self)
00229
00230 def getOwner(self):
00231 return self._owner
00232
00233
00234
00235