ClientDistClass.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. """ClientDistClass module: contains the ClientDistClass class"""
  2. from PandaModules import *
  3. import DirectNotifyGlobal
  4. import ClientDistUpdate
  5. class ClientDistClass:
  6. def __init__(self, dcClass):
  7. self.number = dcClass.getNumber()
  8. self.name = dcClass.getName()
  9. self.allFields = self.parseFields(dcClass)
  10. self.allCDU = self.createAllCDU(self.allFields)
  11. self.number2CDU = self.createNumber2CDUDict(self.allCDU)
  12. self.name2CDU = self.createName2CDUDict(self.allCDU)
  13. self.allRequiredCDU = self.listRequiredCDU(self.allCDU)
  14. return None
  15. def parseFields(self, dcClass):
  16. fields=[]
  17. for i in range(0,dcClass.getNumInheritedFields()):
  18. fields.append(dcClass.getInheritedField(i))
  19. return fields
  20. def createAllCDU(self, allFields):
  21. allCDU = []
  22. for i in allFields:
  23. allCDU.append(ClientDistUpdate.ClientDistUpdate(i))
  24. return allCDU
  25. def createNumber2CDUDict(self, allCDU):
  26. dict={}
  27. for i in allCDU:
  28. dict[i.number] = i
  29. return dict
  30. def createName2CDUDict(self, allCDU):
  31. dict={}
  32. for i in allCDU:
  33. dict[i.name] = i
  34. return dict
  35. def listRequiredCDU(self, allCDU):
  36. requiredCDU = []
  37. for i in allCDU:
  38. atom = i.field.asAtomicField()
  39. if atom:
  40. if (atom.isRequired() and atom.isBroadcast()):
  41. requiredCDU.append(i)
  42. return requiredCDU
  43. def updateField(self, do, di):
  44. # Get the update field id
  45. fieldId = di.getArg(STUint16)
  46. # look up the CDU
  47. assert(self.number2CDU.has_key(fieldId))
  48. cdu = self.number2CDU[fieldId]
  49. # Let the cdu finish the job
  50. cdu.updateField(self, do, di)
  51. return None
  52. def sendUpdate(self, cr, do, fieldName, args):
  53. # Look up the cdu
  54. assert(self.name2CDU.has_key(fieldName))
  55. cdu = self.name2CDU[fieldName]
  56. # Let the cdu finish the job
  57. cdu.sendUpdate(cr, do, args)