LCOV - code coverage report
Current view: top level - xenolith/resources/storage - XLStorageComponent.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 34 34 100.0 %
Date: 2024-05-12 00:16:13 Functions: 11 11 100.0 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #include "XLStorageComponent.h"
      24             : #include "XLStorageServer.h"
      25             : 
      26             : namespace STAPPLER_VERSIONIZED stappler::xenolith::storage {
      27             : 
      28             : SP_COVERAGE_TRIVIAL
      29             : Component::~Component() {
      30             : 
      31             : }
      32             : 
      33          42 : Component::Component(ComponentLoader &loader, StringView name)
      34          42 : : _name(name.str<db::Interface>()) {
      35          42 :         loader.exportComponent(this);
      36          41 : }
      37             : 
      38          42 : void Component::handleChildInit(const Server &, const db::Transaction &) {
      39             : 
      40          42 : }
      41             : 
      42          42 : void Component::handleChildRelease(const Server &, const db::Transaction &) {
      43             : 
      44          42 : }
      45             : 
      46        1491 : void Component::handleStorageTransaction(db::Transaction &) { }
      47             : 
      48         303 : void Component::handleHeartbeat(const Server &) { }
      49             : 
      50             : 
      51             : SP_COVERAGE_TRIVIAL
      52             : ComponentLoader::~ComponentLoader() {
      53             : 
      54             : }
      55             : 
      56             : SP_COVERAGE_TRIVIAL
      57             : ComponentContainer::~ComponentContainer() {
      58             : 
      59             : }
      60             : 
      61          42 : bool ComponentContainer::init(StringView str) {
      62          42 :         _name = str.str<Interface>();
      63          42 :         return true;
      64             : }
      65             : 
      66          42 : void ComponentContainer::handleStorageInit(ComponentLoader &loader) {
      67             : 
      68          42 : }
      69             : 
      70          42 : void ComponentContainer::handleStorageDisposed(const db::Transaction &t) {
      71             : 
      72          42 : }
      73             : 
      74          42 : void ComponentContainer::handleComponentsLoaded(const Server &serv) {
      75          42 :         _loaded = true;
      76          42 :         _server = &serv;
      77             : 
      78          42 :         if (!_pendingTasks.empty()) {
      79          42 :                 for (auto &it : _pendingTasks) {
      80          21 :                         perform(move(it.first), it.second);
      81             :                 }
      82          21 :                 _pendingTasks.clear();
      83             :         }
      84          42 : }
      85             : 
      86          42 : void ComponentContainer::handleComponentsUnloaded(const Server &serv) {
      87          42 :         _server = nullptr;
      88          42 :         _loaded = false;
      89          42 : }
      90             : 
      91          63 : bool ComponentContainer::perform(Function<bool(const Server &, const db::Transaction &)> &&cb, Ref *ref) const {
      92          63 :         if (!_server || !_loaded) {
      93          21 :                 _pendingTasks.emplace_back(pair(move(cb), Rc<Ref>(ref)));
      94          21 :                 return false;
      95             :         }
      96             : 
      97          42 :         return _server->perform(move(cb), ref);
      98             : }
      99             : 
     100             : }

Generated by: LCOV version 1.14