#include "activation.hpp" namespace activation { int Engine::reserve(Handle& handle, int count) { if (handle.view.prepared + count > share_limit) { return ownership; } const int before = handle.view.prepared; for (int index = 0; index < count; ++index) { const int result = prepare_one(handle); if (result != ok) { undo_prepared(handle, before); return result; } } return ok; } int Engine::gate(Handle& handle, int count) { if (available(handle) < count) { return ownership; } const int before = handle.view.enabled; for (int index = 0; index < count; ++index) { const int result = enable_one(handle); if (result != ok) { undo_enabled(handle, before); return result; } } return ok; } int Engine::activate(Handle& handle, int count) { if (handle.view.prepared + count > share_limit) { return ownership; } const int prepared_before = handle.view.prepared; const int enabled_before = handle.view.enabled; for (int index = 0; index < count; ++index) { const int result = prepare_one(handle); if (result != ok) { undo_prepared(handle, prepared_before); return result; } } for (int index = 0; index < count; ++index) { const int result = enable_one(handle); if (result != ok) { undo_enabled(handle, enabled_before); undo_prepared(handle, prepared_before); return result; } } return ok; } int Engine::ungate(Handle& handle, int count) { if (handle.view.enabled < count) { return ownership; } for (int index = 0; index < count; ++index) { disable_one(handle); } return ok; } int Engine::release(Handle& handle, int count) { if (handle.view.prepared - handle.view.enabled < count) { return ownership; } for (int index = 0; index < count; ++index) { unprepare_one(handle); } return ok; } int Engine::deactivate(Handle& handle, int count) { if (handle.view.enabled < count) { return ownership; } for (int index = 0; index < count; ++index) { disable_one(handle); } for (int index = 0; index < count; ++index) { unprepare_one(handle); } return ok; } }