LCOV - code coverage report
Current view: top level - serverManager/service/source - ServerManagerService.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 66.7 % 48 32
Test Date: 2025-02-18 13:13:53 Functions: 100.0 % 9 9

            Line data    Source code
       1              : /*
       2              :  * If not stated otherwise in this file or this component's LICENSE file the
       3              :  * following copyright and licenses apply:
       4              :  *
       5              :  * Copyright 2022 Sky UK
       6              :  *
       7              :  * Licensed under the Apache License, Version 2.0 (the "License");
       8              :  * you may not use this file except in compliance with the License.
       9              :  * You may obtain a copy of the License at
      10              :  *
      11              :  * http://www.apache.org/licenses/LICENSE-2.0
      12              :  *
      13              :  * Unless required by applicable law or agreed to in writing, software
      14              :  * distributed under the License is distributed on an "AS IS" BASIS,
      15              :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      16              :  * See the License for the specific language governing permissions and
      17              :  * limitations under the License.
      18              :  */
      19              : 
      20              : #include "ServerManagerService.h"
      21              : #include "ISessionServerAppManager.h"
      22              : #include "RialtoServerManagerLogging.h"
      23              : 
      24              : namespace
      25              : {
      26            1 : rialto::servermanager::service::ILogHandler::Level convertLevel(const RIALTO_DEBUG_LEVEL &level)
      27              : {
      28            1 :     switch (level)
      29              :     {
      30            0 :     case RIALTO_DEBUG_LEVEL_FATAL:
      31            0 :         return rialto::servermanager::service::ILogHandler::Level::Fatal;
      32            0 :     case RIALTO_DEBUG_LEVEL_ERROR:
      33            0 :         return rialto::servermanager::service::ILogHandler::Level::Error;
      34            0 :     case RIALTO_DEBUG_LEVEL_WARNING:
      35            0 :         return rialto::servermanager::service::ILogHandler::Level::Warning;
      36            0 :     case RIALTO_DEBUG_LEVEL_MILESTONE:
      37            0 :         return rialto::servermanager::service::ILogHandler::Level::Milestone;
      38            1 :     case RIALTO_DEBUG_LEVEL_INFO:
      39            1 :         return rialto::servermanager::service::ILogHandler::Level::Info;
      40            0 :     case RIALTO_DEBUG_LEVEL_DEBUG:
      41            0 :         return rialto::servermanager::service::ILogHandler::Level::Debug;
      42            0 :     case RIALTO_DEBUG_LEVEL_EXTERNAL:
      43            0 :         return rialto::servermanager::service::ILogHandler::Level::External;
      44            0 :     case RIALTO_DEBUG_LEVEL_DEFAULT:
      45            0 :         return rialto::servermanager::service::ILogHandler::Level::Milestone;
      46              :     }
      47            0 :     return rialto::servermanager::service::ILogHandler::Level::Debug;
      48              : }
      49              : } // namespace
      50              : 
      51              : namespace rialto::servermanager::service
      52              : {
      53            9 : ServerManagerService::ServerManagerService(std::unique_ptr<IServiceContext> &&context, unsigned numOfPreloadedServers)
      54            9 :     : m_kContext{std::move(context)}
      55              : {
      56            9 :     RIALTO_SERVER_MANAGER_LOG_MIL("RialtoServerManager is starting...");
      57            9 :     m_kContext->getSessionServerAppManager().preloadSessionServers(numOfPreloadedServers);
      58              : }
      59              : 
      60           27 : ServerManagerService::~ServerManagerService()
      61              : {
      62            9 :     RIALTO_SERVER_MANAGER_LOG_INFO("RialtoServerManager is closing...");
      63            9 :     if (m_logHandler)
      64              :     {
      65            1 :         firebolt::rialto::logging::setLogHandler(RIALTO_COMPONENT_SERVER_MANAGER, 0, false);
      66              :     }
      67           18 : }
      68              : 
      69            2 : bool ServerManagerService::initiateApplication(const std::string &appId,
      70              :                                                const firebolt::rialto::common::SessionServerState &state,
      71              :                                                const firebolt::rialto::common::AppConfig &appConfig)
      72              : {
      73            2 :     return m_kContext->getSessionServerAppManager().initiateApplication(appId, state, appConfig);
      74              : }
      75              : 
      76            2 : bool ServerManagerService::changeSessionServerState(const std::string &appId,
      77              :                                                     const firebolt::rialto::common::SessionServerState &state)
      78              : {
      79            2 :     return m_kContext->getSessionServerAppManager().setSessionServerState(appId, state);
      80              : }
      81              : 
      82            1 : std::string ServerManagerService::getAppConnectionInfo(const std::string &appId) const
      83              : {
      84            1 :     return m_kContext->getSessionServerAppManager().getAppConnectionInfo(appId);
      85              : }
      86              : 
      87            2 : bool ServerManagerService::setLogLevels(const LoggingLevels &logLevels) const
      88              : {
      89            2 :     return m_kContext->getSessionServerAppManager().setLogLevels(logLevels);
      90              : }
      91              : 
      92            2 : bool ServerManagerService::registerLogHandler(const std::shared_ptr<ILogHandler> &handler)
      93              : {
      94            2 :     if (!handler)
      95              :     {
      96            1 :         RIALTO_SERVER_MANAGER_LOG_ERROR("Cannot set custom log handler - ptr is null!");
      97            1 :         return false;
      98              :     }
      99            1 :     m_logHandler = handler;
     100              :     return firebolt::rialto::logging::RIALTO_LOGGING_STATUS_OK ==
     101            1 :            firebolt::rialto::logging::setLogHandler(RIALTO_COMPONENT_SERVER_MANAGER,
     102            2 :                                                     std::bind(&ServerManagerService::forwardLog, this,
     103              :                                                               std::placeholders::_1, std::placeholders::_2,
     104              :                                                               std::placeholders::_3, std::placeholders::_4,
     105              :                                                               std::placeholders::_5, std::placeholders::_6),
     106            1 :                                                     false);
     107              : }
     108              : 
     109            1 : void ServerManagerService::forwardLog(RIALTO_DEBUG_LEVEL level, const char *file, int line, const char *function,
     110              :                                       const char *message, std::size_t messageLen) const
     111              : {
     112            1 :     if (!m_logHandler)
     113              :     {
     114            0 :         return;
     115              :     }
     116            1 :     m_logHandler->log(convertLevel(level), std::string(file), line, std::string(function), std::string(message));
     117              : }
     118              : } // namespace rialto::servermanager::service
        

Generated by: LCOV version 2.0-1