| 442 | } |
| 443 | |
| 444 | void DbConnection::UpdateObject(const ConfigObject::Ptr& object) |
| 445 | { |
| 446 | bool isShuttingDown = Application::IsShuttingDown(); |
| 447 | bool isRestarting = Application::IsRestarting(); |
| 448 | |
| 449 | #ifdef I2_DEBUG |
| 450 | if (isShuttingDown || isRestarting) { |
| 451 | //Log(LogDebug, "DbConnection") |
| 452 | // << "Updating object '" << object->GetName() << "' \t\t active '" << Convert::ToLong(object->IsActive()) |
| 453 | // << "' shutting down '" << Convert::ToLong(isShuttingDown) << "' restarting '" << Convert::ToLong(isRestarting) << "'."; |
| 454 | } |
| 455 | #endif /* I2_DEBUG */ |
| 456 | |
| 457 | /* Wait until a database connection is established on reconnect. */ |
| 458 | if (!GetConnected()) |
| 459 | return; |
| 460 | |
| 461 | /* Don't update inactive objects during shutdown/reload/restart. |
| 462 | * They would be marked as deleted. This gets triggered with ConfigObject::StopObjects(). |
| 463 | * During startup/reconnect this is fine, the handler is not active there. |
| 464 | */ |
| 465 | if (isShuttingDown || isRestarting) |
| 466 | return; |
| 467 | |
| 468 | DbObject::Ptr dbobj = DbObject::GetOrCreateByObject(object); |
| 469 | |
| 470 | if (dbobj) { |
| 471 | bool dbActive = GetObjectActive(dbobj); |
| 472 | bool active = object->IsActive(); |
| 473 | |
| 474 | if (active) { |
| 475 | if (!dbActive) |
| 476 | ActivateObject(dbobj); |
| 477 | |
| 478 | Dictionary::Ptr configFields = dbobj->GetConfigFields(); |
| 479 | String configHash = dbobj->CalculateConfigHash(configFields); |
| 480 | ASSERT(configHash.GetLength() <= 64); |
| 481 | configFields->Set("config_hash", configHash); |
| 482 | |
| 483 | String cachedHash = GetConfigHash(dbobj); |
| 484 | |
| 485 | if (cachedHash != configHash) { |
| 486 | dbobj->SendConfigUpdateHeavy(configFields); |
| 487 | dbobj->SendStatusUpdate(); |
| 488 | } else { |
| 489 | dbobj->SendConfigUpdateLight(); |
| 490 | } |
| 491 | } else if (!active) { |
| 492 | /* This may happen on reload/restart actions too |
| 493 | * and is blocked above already. |
| 494 | * |
| 495 | * Deactivate the deleted object no matter |
| 496 | * which state it had in the database. |
| 497 | */ |
| 498 | DeactivateObject(dbobj); |
| 499 | } |
| 500 | } |
| 501 | } |
nothing calls this directly
no test coverage detected