2019-10-24 17:45:24 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# module CGenericMultiPartTemp
|
|
|
|
#
|
|
|
|
# Copyright (C) 2019 AleaJactaEst
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import logging
|
|
|
|
from tools import BitStream
|
|
|
|
|
|
|
|
LOGGER='CGenericMultiPartTemp'
|
|
|
|
|
|
|
|
class CGenericMultiPartTemp():
|
|
|
|
def __init__(self):
|
|
|
|
self.NbBlock = 0xFFFFFFFF
|
|
|
|
self.MsgDecoded = None
|
|
|
|
self.FirstRead = False
|
2020-04-11 21:52:41 +00:00
|
|
|
self.Reference = []
|
2020-04-15 17:28:02 +00:00
|
|
|
self.block = {}
|
2020-04-11 21:52:41 +00:00
|
|
|
self.Name = None
|
2019-10-24 17:45:24 +00:00
|
|
|
|
2020-04-15 17:28:02 +00:00
|
|
|
def getNbCurrentBlock(self):
|
|
|
|
return len(self.block)
|
|
|
|
|
2020-04-11 21:52:41 +00:00
|
|
|
def set(self, Number, Part, NbBlock, PartCont, decodeImpulse, world, Reference = None, Name = None):
|
2019-10-24 17:45:24 +00:00
|
|
|
'''
|
|
|
|
khanat-opennel-code/code/ryzom/client/src/network_connection.cpp # void CNetworkConnection::CGenericMultiPartTemp::set (CActionGenericMultiPart *agmp, CNetworkConnection *parent)
|
|
|
|
'''
|
|
|
|
logging.getLogger(LOGGER).debug("set Number:%d Part:%d NbBlock:%d" % (Number, Part, NbBlock))
|
2020-04-11 21:52:41 +00:00
|
|
|
ret = None
|
|
|
|
if not self.Name:
|
|
|
|
self.Name = Name
|
|
|
|
if Reference:
|
|
|
|
self.Reference.append(Reference)
|
2019-10-24 17:45:24 +00:00
|
|
|
if self.NbBlock == 0xFFFFFFFF:
|
|
|
|
# Initialize
|
|
|
|
self.NbBlock = NbBlock
|
2020-04-15 17:28:02 +00:00
|
|
|
self.block.setdefault(Part, PartCont)
|
|
|
|
self.block.setdefault(Part, None)
|
|
|
|
self.block[Part] = PartCont
|
|
|
|
logging.getLogger(LOGGER).error("CGenericMultiPartTemp : Number:%d len:%d/%d" % (Number, len(self.block), self.NbBlock))
|
|
|
|
if len(self.block) == self.NbBlock:
|
2019-10-24 17:45:24 +00:00
|
|
|
# reform the total action
|
|
|
|
bms = BitStream.BitStream()
|
|
|
|
|
|
|
|
self.NbBlock == 0xFFFFFFFF
|
2020-04-15 17:28:02 +00:00
|
|
|
for data in self.block:
|
|
|
|
logging.getLogger(LOGGER).error("CGenericMultiPartTemp : Number:%d id:%d len:%d/%d" % (Number, data, len(self.block), self.NbBlock))
|
|
|
|
bms.pushBitStream(self.block[data])
|
|
|
|
try:
|
|
|
|
ret = decodeImpulse.execute(bms, world)
|
|
|
|
except:
|
|
|
|
logging.getLogger(LOGGER).error("CGenericMultiPartTemp : Error to decode - Number:%d len:%d/%d msg:%s" % (Number, len(self.block), self.NbBlock, bms.showAllData()))
|
|
|
|
return ret
|
|
|
|
logging.getLogger(LOGGER).error("CGenericMultiPartTemp : data : %s" % bms.showAllData())
|
2019-10-24 17:45:24 +00:00
|
|
|
self.MsgDecoded = bms
|
|
|
|
else:
|
2020-04-15 17:28:02 +00:00
|
|
|
logging.getLogger(LOGGER).error("CGenericMultiPartTemp : Wait other block Number:%d [%d/%d]" % (Number, len(self.block), self.NbBlock))
|
2020-04-11 21:52:41 +00:00
|
|
|
return ret
|
2019-10-24 17:45:24 +00:00
|
|
|
|
2020-04-15 17:28:02 +00:00
|
|
|
def isDecoded(self):
|
|
|
|
if self.MsgDecoded:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2019-10-24 17:45:24 +00:00
|
|
|
def isAvailable(self):
|
|
|
|
if self.MsgDecoded and not self.FirstRead:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def read(self):
|
|
|
|
self.FirstRead = True
|
|
|
|
return self.MsgDecoded
|
|
|
|
|
|
|
|
|
|
|
|
class GenericMultiPartTemp():
|
|
|
|
def __init__(self):
|
|
|
|
self.data = {}
|
|
|
|
|
|
|
|
def addGenericMultiPartTemp(self, Number):
|
|
|
|
self.data.setdefault(Number, CGenericMultiPartTemp())
|
|
|
|
|
2020-04-11 21:52:41 +00:00
|
|
|
def setGenericMultiPartTemp(self, Number, Part, NbBlock, PartCont, decodeImpulse, world, Reference = None, Name = None):
|
|
|
|
self.data[Number].set(Number, Part, NbBlock, PartCont, decodeImpulse, world, Reference, Name)
|