Changeset 56:1d491f271eaf in xplra
- Timestamp:
- 03/07/13 16:48:41 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/client/python/xplra.py
r53 r56 133 133 """Construct the object.""" 134 134 self._stream = None 135 self._multiBuffers = [] 135 136 136 137 def connect(self): … … 147 148 self._stream = s.makefile() 148 149 150 for multiBuffer in self._multiBuffers: 151 multiBuffer._reregister() 152 149 153 @property 150 154 def isConnected(self): … … 154 158 def createMultiGetter(self): 155 159 """Create a new multi-dataref getter for this X-Plane object.""" 156 return MultiGetter(self) 160 multiGetter = MultiGetter(self) 161 self._multiBuffers.append(multiGetter) 162 return multiGetter 157 163 158 164 def createMultiSetter(self): 159 165 """Create a new multi-dataref setter for this X-Plane object.""" 160 return MultiSetter(self) 166 multiSetter = MultiSetter(self) 167 self._multiBuffers.append(multiSetter) 168 return multiSetter 169 170 def destroyMultiBuffer(self, multiBuffer): 171 """Destroy the given multi-dataref buffer. 172 173 It actually removes it from the list of multiple buffers and 174 unregisters it safely. 175 176 Returns the result of the safe unregistration if the buffer was found, 177 None otherwise. 178 """ 179 if multiBuffer in self._multiBuffers: 180 self._multiBuffers.remove(multiBuffer) 181 return multiBuffer.unregisterSafely() 182 else: 183 return None 161 184 162 185 def getVersions(self): … … 283 306 """Disconnect from X-Plane.""" 284 307 if self._stream is not None: 285 self._stream.close() 286 self._stream = None 308 try: 309 self._stream.close() 310 finally: 311 self._stream = None 287 312 288 313 def _checkResult(self, resultCode = None, parameter = None, multi = False): … … 484 509 return self._values 485 510 511 @property 512 def wasRegistered(self): 513 """Determine if this buffer was registered.""" 514 return self._wasRegistered 515 486 516 def addInt(self, name): 487 517 """Add an integer to the buffer with the given name … … 544 574 self._xplane._flush() 545 575 self._xplane._checkResult() 576 self._registeredID = None 577 578 def unregisterSafely(self): 579 """Unregister the buffer from X-Plane, ignoring exceptions. 580 581 Returns True if the unregistration succeeded, False otherwise. 582 """ 583 try: 584 self.unregister() 585 return True 586 except: 587 return False 588 finally: 546 589 self._registeredID = None 547 590 … … 576 619 s += chr(c) 577 620 return s 621 622 def _reregister(self): 623 """Re-register the buffer in X-Plane, if it has been registered earlier 624 625 If it has not been registered, nothing is done. Otherwise the buffer 626 gets registered, and the old ID is forgotten. This function is meant to 627 be used by the XPlane object when it creates a new connection. If the 628 registration fails, the original ID is restored, so the _reregister() 629 could be called again 630 """ 631 if self._registeredID is not None: 632 origRegisteredID = self._registeredID 633 try: 634 self._registeredID = None 635 self.register() 636 except: 637 self._registeredID = origRegisteredID 638 raise 578 639 579 640 def _add(self, name, type, length = None, offset = None):
Note:
See TracChangeset
for help on using the changeset viewer.