blob: 88dd7c0e0f5e12ec0f7bb3f29d358f1138dbd42a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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()
|