diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2012-04-13 21:07:42 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2012-04-13 21:07:42 +0200 |
commit | a62cb4e37d008d47480cdd6c25d928044b8afe31 (patch) | |
tree | f16e0109caf00d8989d56e2e5392851117db8814 /fstarter.py | |
download | pyevenja-a62cb4e37d008d47480cdd6c25d928044b8afe31.zip pyevenja-a62cb4e37d008d47480cdd6c25d928044b8afe31.tar.gz |
initial commit, old code from ~2007
Diffstat (limited to 'fstarter.py')
-rw-r--r-- | fstarter.py | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/fstarter.py b/fstarter.py new file mode 100644 index 0000000..28567e7 --- /dev/null +++ b/fstarter.py @@ -0,0 +1,138 @@ +#/*************************************************************************** +# fstarter.h +# ----------- +# begin : sam nov 2 2002 +# copyright : (C) 1992-2004 by Fabian Padilla +# email : fp@bridgethink.com +# ***************************************************************************/ + +# /*************************************************************************** +# * * +# * This program is free software; you can redistribute it and/or modify * +# * it under the terms of the Foundation Public License as published by * +# * bridgethink sarl; either version 2 of the License, or * +# * (at your option) any later version. * +# * * +# ***************************************************************************/ + +# +# from C++ to python by Jeremy Zurcher <jeremy@asynk.ch> +# + +"""/** First class of evenja and evendoor to be created. + This class will ask the firstRouter to create the first level of classes. + + *@author Fabian Padilla + */""" + + +__all__ = ["Fstarter"] + + +from frouter import Frouter +from fevendata import FevenData +from fstringhash import FstringHash + +from returncodes import RET_OK +from evenjastrings import XML_SERVER + +class Fstarter(Frouter): + """This is the main dispather, it receives all messages""" + + def __init__(self): + Frouter.__init__(self) # force constructor + #/** Is the software a server (deamon) or a normal software. + # A Server or deamon software wait until a signal ask for the end + # A normal software wil end when nothing is to do (at the end) */ + self.server = False + self.exit = False + + def __str__(self): + return "\t"+Frouter.__str__(self)+\ + "Fstarter - (null)\n" + + def setExit(self): + """/** Kill the application */""" + self.exit = True + + def start(self,FileName): + """/** Open the config file and transmit the first level of the rooms to the firstRouter. */""" + ret = Frouter.start(self,None,FileName) # set None as parent router + if ret == RET_OK: + self.pushCurrent() + self.server = not self.Find(XML_SERVER) + self.popCurrent() + return ret + + def execute(self,trace): + """/** Method called by the "main" of the application. + It send an evenData to all evenBoard and then to all evenDoor to really start the work of the rooms. + And wait until a TERM signal arrives from theself.__class__. OS. */""" + + if trace: + while True: + while self.listMsgSys.getCount() or self.listMsg.getCount(): + if self.listMsgSys.getCount(): + data = self.listMsgSys.removeFifo() + print '<?xml version="1.0"?>' + print '< *** SYS MSG *** />' + print data + data.getActivePort().justDoItSys(data) + else: + data = self.listMsg.removeFifo() + print '<?xml version="1.0"?>' + print '< *** MSG *** />' + print data + data.getActivePort().justDoIt(data) + if self.exit: + break + if not self.server or self.exit: + break + # TODO a small time out maybe ??? + + else: + while True: + while self.listMsgSys.getCount() or self.listMsg.getCount(): + if self.listMsgSys.getCount(): + data = self.listMsgSys.removeFifo() + data.getActivePort().justDoItSys(data) + else: + data = self.listMsg.removeFifo() + data.getActivePort().justDoIt(data) + if self.exit: + break + if not self.server or self.exit: + break + # TODO a small time out maybe ??? + + return RET_OK + + def end(self): + """/** Manage if Fstarter saves the config file ( in a dinamyc configuration of rooms). + Or if it is not needed because it is a static configuration. */""" + return Frouter.end(self) + + + + +if __name__ == '__main__': + + import unittest + + starter1 = Fstarter(); + starter2 = Fstarter(); + + class FstarterTestCase(unittest.TestCase): + + def test1Name(self): + self.assertEquals(starter1.start( "testezlog.xml"),RET_OK) + + strH = FstringHash() + strH.setString( "TEST00") + + #// TEST Name from file + self.assertEquals(starter1.equals( strH),True) + + starter1.end() + + unittest.main() |