summaryrefslogtreecommitdiffstats
path: root/fevendoor.py
blob: 2e4d8a5433d5692c2947dc4bbcad239100d9da9a (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
#/***************************************************************************
#                             fevendata.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>
#


"""/** Door of the room.

  function : evenDoor of the room. Connect the room to external world.
             To a specific prototcol and data format.

  description : evenDoor would convert a specific data format to the internal
                evenData format and the evenData format to the external data format.

  *@author Fabian Padilla
  */"""

__all__ = ["FevenDoor"]

from flist import Flist
from fstringhash import FstringHash
from globalvars import gvActionSysAddDest
from fportbkpevendata import FportBkpEvenData

from returncodes import RET_OK
from returncodes import RET_NOTEXIST

from evenjastrings import XML_LNKTYPE
from evenjastrings import XML_LNKVALUE
from evenjastrings import XML_LNKFIELDS
from evenjastrings import XML_LNKDEST
from evenjastrings import TXT_NULL

class FspecialDestination:
    """ """

    def __init__(self, linkTypesNames, valueA, linkFieldsNames, linkDest):
        self.type = FstringHash()
        self.value = FstringHash()
        self.fields = FstringHash()
        self.dest = FstringHash()

        self.type.setString(linkTypesNames)
        self.value.setString(valueA)
        self.fields.setString(linkFieldsNames)
        self.dest.setString(linkDest)


class FevenDoor(FportBkpEvenData):
    """ """
    def __init__(self):
        FportBkpEvenData.__init__(self)        # force constructor
        self.list = Flist()            #/** List of special destination */a

    def __del__(self):
        """I believe this is for no use."""
        while self.list.getCount():
                self.list.remove(0)

    def __str__(self):
        return "\t"+FportBkpEvenData.__str__(self)+\
                "FevenDoor - list : "+str(self.list)+"\n"

    def justDoItSys(self,evenData):
        """/** Methods called by Fstarter. */"""
        ret = RET_OK
        if evenData.getCurrentDestination().getAction().equals(gvActionSysAddDest):
            ret = self.list.add( FspecialDestination(evenData.getData(XML_LNKTYPE),\
                                 evenData.getData(XML_LNKVALUE),\
                                 evenData.getData(XML_LNKFIELDS),\
                                 evenData.getData(XML_LNKDEST)))
        self.setFreeEvenData(evenData)
        return ret

    def sendEvenData(self,evenData):
        """/** Methods to enable all ports to sends evenDatas to a port. */"""
        spDestToDo = None
        if evenData.getCurrentDestination() != RET_NOTEXIST:
            return FportBkpEvenData.sendEvenData(self,evenData)
        for I in range(self.list.getCount()):
            spDest = self.list.get(I)
            spDestString = spDest.type.getString()
            if spDestString != TXT_NULL:                # if we got a destination
                evenData.setLinkFieldsNames(spDestString)
            if spDestString == TXT_NULL or evenData.equals(spDest.value):
                if spDestToDo <> None:
                    evenDataToDo = getFreeEvenData()
                    evenDataToDo = copyFrom(evenData)
                    evenDataToDo.setSource(self.getString())
                    evenDataToDo.setLinkFieldsNames(spDestToDo.fields.getString())
                    evenDataToDo.resetDestination()
                    evenDataToDo.addDestinatio(spDestToDo.dest.getString())
                    FportBkpEvenData.sendEvenData(self,evenDataToDo)
                spDestToDo = spDest
        if spDestToDo:    # something to send
            evenData.setSource(self.getString())
            evenData.setLinkFieldsNames(spDestToDo.fields.getString())
            evenData.resetDestination()
            evenData.addDestination(spDestToDo.dest.getString())
            FportBkpEvenData.sendEvenData(self,evenData)
        else:
            self.parent.setFreeEvenData(evenData)

    def getFreeEvenData(self):
        """/** Get a new evenData. */"""
        return self.parent.getFreeEvenData()