ClientDistClass.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.broadcastRequiredCDU = self.listBroadcastRequiredCDU(self.allCDU)
  14. self.allRequiredCDU = self.listRequiredCDU(self.allCDU)
  15. # Import the class, and store the constructor
  16. exec("import " + self.name)
  17. self.constructor = eval(self.name + "." + self.name)
  18. return None
  19. def parseFields(self, dcClass):
  20. fields=[]
  21. for i in range(0,dcClass.getNumInheritedFields()):
  22. fields.append(dcClass.getInheritedField(i))
  23. return fields
  24. def createAllCDU(self, allFields):
  25. allCDU = []
  26. for i in allFields:
  27. allCDU.append(ClientDistUpdate.ClientDistUpdate(self, i))
  28. return allCDU
  29. def createNumber2CDUDict(self, allCDU):
  30. dict={}
  31. for i in allCDU:
  32. dict[i.number] = i
  33. return dict
  34. def createName2CDUDict(self, allCDU):
  35. dict={}
  36. for i in allCDU:
  37. dict[i.name] = i
  38. return dict
  39. def listBroadcastRequiredCDU(self, allCDU):
  40. requiredCDU = []
  41. for i in allCDU:
  42. atom = i.field.asAtomicField()
  43. if atom:
  44. if (atom.isRequired() and atom.isBroadcast()):
  45. requiredCDU.append(i)
  46. return requiredCDU
  47. def listRequiredCDU(self, allCDU):
  48. requiredCDU = []
  49. for i in allCDU:
  50. atom = i.field.asAtomicField()
  51. if atom:
  52. if (atom.isRequired()):
  53. requiredCDU.append(i)
  54. return requiredCDU
  55. def updateField(self, do, di):
  56. # Get the update field id
  57. fieldId = di.getArg(STUint16)
  58. # look up the CDU
  59. assert(self.number2CDU.has_key(fieldId))
  60. cdu = self.number2CDU[fieldId]
  61. # Let the cdu finish the job
  62. cdu.updateField(self, do, di)
  63. return None
  64. def sendUpdate(self, cr, do, fieldName, args, sendToId = None):
  65. # Look up the cdu
  66. assert(self.name2CDU.has_key(fieldName))
  67. cdu = self.name2CDU[fieldName]
  68. # Let the cdu finish the job
  69. cdu.sendUpdate(cr, do, args, sendToId)