Changeset 355:872f6018c59e for src/mlx
- Timestamp:
- 12/12/12 19:49:47 (12 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mlx/checks.py
r354 r355 337 337 self._firstChange = None 338 338 self._lastChangeState = None 339 self._lastLoggedValue = None 340 341 self._logState = lambda flight, logger, state, forced = False: \ 342 StateChangeLogger.logState(self, flight, logger, state, 343 forced = forced) 344 self.logState = lambda flight, logger, state, forced = False: \ 345 DelayedChangeMixin.logState(self, flight, logger, state, 346 forced = forced) 339 347 340 348 def _changed(self, oldState, state): … … 345 353 newValue = self._getValue(state) 346 354 if self._isDifferent(self._oldValue, newValue): 347 if self._firstChange is None: 348 self._firstChange = state.timestamp 349 self._lastChangeState = state 355 if self._lastLoggedValue is not None and \ 356 not self._isDifferent(self._lastLoggedValue, newValue): 357 self._firstChange = None 358 else: 359 if self._firstChange is None: 360 self._firstChange = state.timestamp 361 self._lastChangeState = state 350 362 self._oldValue = newValue 351 363 … … 370 382 This default implementation checks for simple equality.""" 371 383 return oldValue!=newValue 384 385 def logState(self, flight, logger, state, forced): 386 """Log the given state. 387 388 The value belonging to that state is recorded in _lastLoggedValue. 389 390 It calls _logState to perform the real logging.""" 391 self._lastLoggedValue = self._getValue(state) 392 self._logState(flight, logger, state, forced = forced) 372 393 373 394 #--------------------------------------------------------------------------------------- … … 408 429 409 430 class ForceableLoggerMixin(object): 410 """A mixin for loggers that can be forced to log a certain state. 411 412 The last logged state is always maintained, and when checking for a change, 413 that state is compared to the current one (which may actually be the same, 414 if a forced logging was performed for that state). 415 416 Children should implement the following functions: 417 - _hasChanged(oldState, state): the real check for a change 418 - _logState(flight, logger, state, forced): the real logging function 419 """ 420 def __init__(self): 421 """Construct the mixin.""" 422 self._lastLoggedState = None 423 431 """A mixin for loggers that can be forced to log a certain state.""" 424 432 def forceLog(self, flight, logger, state): 425 433 """Force logging the given state.""" 426 434 self.logState(flight, logger, state, forced = True) 427 428 def logState(self, flight, logger, state, forced = False):429 """Log the state.430 431 It calls _logState to perform the real logging, and saves the given432 state as the last logged one."""433 self._logState(flight, logger, state, forced)434 self._lastLoggedState = state435 436 def _changed(self, oldState, state):437 """Check if the state has changed.438 439 This function calls _hasChanged for the real check, and replaces440 oldState with the stored last logged state, if any."""441 if self._lastLoggedState is not None:442 oldState = self._lastLoggedState443 return self._hasChanged(oldState, state)444 435 445 436 #--------------------------------------------------------------------------------------- … … 469 460 """Logger for NAV radios. 470 461 471 It also logs the OBS frequencyset."""462 It also logs the OBS radial set.""" 472 463 @staticmethod 473 464 def getMessage(logName, frequency, obs): … … 481 472 StateChangeLogger.__init__(self, logInitial = True) 482 473 DelayedChangeMixin.__init__(self) 483 ForceableLoggerMixin.__init__(self) 484 485 self.logState = lambda flight, logger, state, forced = False: \ 486 ForceableLoggerMixin.logState(self, flight, logger, state, 487 forced = forced) 474 488 475 self._getLogTimestamp = \ 489 476 lambda state, forced: \ 490 477 DelayedChangeMixin._getLogTimestamp(self, state, forced) 491 self._changed = lambda oldState, state: \492 ForceableLoggerMixin._changed(self, oldState, state)493 self._hasChanged = lambda oldState, state: \494 DelayedChangeMixin._changed(self, oldState, state)495 self._logState = lambda flight, logger, state, forced: \496 StateChangeLogger.logState(self, flight, logger, state,497 forced = forced)498 478 499 479 self._attrName = attrName … … 548 528 "%s: %%s" % (logName,), 549 529 minDelay = 3.0, maxDelay = 10.0) 550 ForceableLoggerMixin.__init__(self)551 552 self.logState = lambda flight, logger, state, forced = False: \553 ForceableLoggerMixin.logState(self, flight, logger, state,554 forced = forced)555 self._changed = lambda oldState, state: \556 ForceableLoggerMixin._changed(self, oldState, state)557 self._hasChanged = lambda oldState, state: \558 DelayedChangeMixin._changed(self, oldState, state)559 self._logState = lambda flight, logger, state, forced: \560 StateChangeLogger.logState(self, flight, logger, state, forced)561 530 562 531 #--------------------------------------------------------------------------------------- … … 725 694 DelayedChangeMixin.__init__(self) 726 695 self._lastLoggedState = None 696 self.logState = lambda flight, logger, state:\ 697 APLogger.logState(self, flight, logger, state) 727 698 728 699 def _getValue(self, state):
Note:
See TracChangeset
for help on using the changeset viewer.