def handleQueryObjectResp(self, msgType, di): ctx = di.getUint32() success = di.getUint8() if ctx not in self._callbacks: self.notify.warning('Received unexpected %s' ' (ctx %d)' % (MsgId2Names[msgType], ctx)) return try: if not success: if self._callbacks[ctx]: self._callbacks[ctx](None, None) return if msgType == DBSERVER_OBJECT_GET_ALL_RESP: dclassId = di.getUint16() dclass = self.air.dclassesByNumber.get(dclassId) else: dclass = self._dclasses[ctx] if not dclass: self.notify.error('Received bad dclass %d in' ' DBSERVER_OBJECT_GET_ALL_RESP' % (dclassId)) if msgType == DBSERVER_OBJECT_GET_FIELD_RESP: fieldCount = 1 else: fieldCount = di.getUint16() unpacker = DCPacker() unpacker.setUnpackData(di.getRemainingBytes()) fields = {} for x in range(fieldCount): fieldId = unpacker.rawUnpackInt16() field = dclass.getFieldByIndex(fieldId) if not field: self.notify.error('Received bad field %d in query for' ' %s object' % (fieldId, dclass.getName())) unpacker.beginUnpack(field) fields[field.getName()] = field.unpackArgs(unpacker) unpacker.endUnpack() if self._callbacks[ctx]: self._callbacks[ctx](dclass, fields) finally: del self._callbacks[ctx] del self._dclasses[ctx]
def handleUpdateObjectResp(self, di, multi): ctx = di.getUint32() success = di.getUint8() if ctx not in self._callbacks: self.notify.warning('Received unexpected' ' DBSERVER_OBJECT_SET_FIELD(S)_IF_EQUALS_RESP' ' (ctx %d)' % (ctx)) return try: if success: if self._callbacks[ctx]: self._callbacks[ctx](None) return if not di.getRemainingSize(): # We failed due to other reasons. if self._callbacks[ctx]: return self._callbacks[ctx]({}) if multi: fieldCount = di.getUint16() else: fieldCount = 1 unpacker = DCPacker() unpacker.setUnpackData(di.getRemainingBytes()) fields = {} for x in range(fieldCount): fieldId = unpacker.rawUnpackInt16() field = self.air.getDcFile().getFieldByIndex(fieldId) if not field: self.notify.error('Received bad field %d in update' ' failure response message' % (fieldId)) unpacker.beginUnpack(field) fields[field.getName()] = field.unpackArgs(unpacker) unpacker.endUnpack() if self._callbacks[ctx]: self._callbacks[ctx](fields) finally: del self._callbacks[ctx]