LCOV - code coverage report
Current view: top level - media/server/ipc/source - ServerManagerModuleService.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.4 % 76 71
Test Date: 2025-03-21 11:02:39 Functions: 100.0 % 8 8

            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 "ServerManagerModuleService.h"
      21              : #include "AckSender.h"
      22              : #include "ISessionServerManager.h"
      23              : #include "RialtoServerLogging.h"
      24              : #include <IIpcController.h>
      25              : 
      26              : namespace
      27              : {
      28           10 : firebolt::rialto::common::SessionServerState convertSessionServerState(const rialto::SessionServerState &state)
      29              : {
      30           10 :     switch (state)
      31              :     {
      32            1 :     case rialto::SessionServerState::UNINITIALIZED:
      33            1 :         return firebolt::rialto::common::SessionServerState::UNINITIALIZED;
      34            1 :     case rialto::SessionServerState::INACTIVE:
      35            1 :         return firebolt::rialto::common::SessionServerState::INACTIVE;
      36            6 :     case rialto::SessionServerState::ACTIVE:
      37            6 :         return firebolt::rialto::common::SessionServerState::ACTIVE;
      38            1 :     case rialto::SessionServerState::NOT_RUNNING:
      39            1 :         return firebolt::rialto::common::SessionServerState::NOT_RUNNING;
      40            1 :     case rialto::SessionServerState::ERROR:
      41            1 :         return firebolt::rialto::common::SessionServerState::ERROR;
      42              :     }
      43            0 :     return firebolt::rialto::common::SessionServerState::ERROR;
      44              : }
      45              : } // namespace
      46              : 
      47              : namespace firebolt::rialto::server::ipc
      48              : {
      49           14 : std::shared_ptr<IServerManagerModuleServiceFactory> IServerManagerModuleServiceFactory::createFactory()
      50              : {
      51           14 :     std::shared_ptr<IServerManagerModuleServiceFactory> factory;
      52              : 
      53              :     try
      54              :     {
      55           14 :         factory = std::make_shared<ServerManagerModuleServiceFactory>();
      56              :     }
      57            0 :     catch (const std::exception &e)
      58              :     {
      59            0 :         RIALTO_SERVER_LOG_ERROR("Failed to create the server maanger module service factory, reason: %s", e.what());
      60              :     }
      61              : 
      62           14 :     return factory;
      63              : }
      64              : 
      65              : std::shared_ptr<::rialto::ServerManagerModule>
      66           14 : ServerManagerModuleServiceFactory::create(service::ISessionServerManager &sessionServerManager) const
      67              : {
      68           14 :     std::shared_ptr<::rialto::ServerManagerModule> serverManagerModule;
      69              :     try
      70              :     {
      71           14 :         serverManagerModule = std::make_shared<ServerManagerModuleService>(sessionServerManager);
      72              :     }
      73            0 :     catch (const std::exception &e)
      74              :     {
      75            0 :         RIALTO_SERVER_LOG_ERROR("Failed to create the server manager module service, reason: %s", e.what());
      76              :     }
      77              : 
      78           14 :     return serverManagerModule;
      79              : }
      80              : 
      81           14 : ServerManagerModuleService::ServerManagerModuleService(service::ISessionServerManager &sessionServerManager)
      82           14 :     : m_sessionServerManager{sessionServerManager}
      83              : {
      84              : }
      85              : 
      86              : ServerManagerModuleService::~ServerManagerModuleService() {}
      87              : 
      88            4 : void ServerManagerModuleService::setConfiguration(::google::protobuf::RpcController *controller,
      89              :                                                   const ::rialto::SetConfigurationRequest *request,
      90              :                                                   ::rialto::SetConfigurationResponse *response,
      91              :                                                   ::google::protobuf::Closure *done)
      92              : {
      93            4 :     RIALTO_SERVER_LOG_DEBUG("SetConfiguration received from ServerManager");
      94            4 :     common::MaxResourceCapabilitites maxResource{request->resources().maxplaybacks(),
      95            4 :                                                  request->resources().maxwebaudioplayers()};
      96            4 :     const auto kClientDisplayName = request->has_clientdisplayname() ? request->clientdisplayname() : "";
      97            4 :     bool success{true};
      98            4 :     if (request->has_sessionmanagementsocketfd())
      99              :     {
     100            2 :         m_sessionServerManager.configureIpc(request->sessionmanagementsocketfd());
     101              :     }
     102              :     else
     103              :     {
     104            2 :         m_sessionServerManager.configureIpc(request->sessionmanagementsocketname(), request->socketpermissions(),
     105              :                                             request->socketowner(), request->socketgroup());
     106              :     }
     107            4 :     success &= m_sessionServerManager.configureServices(convertSessionServerState(request->initialsessionserverstate()),
     108              :                                                         maxResource, kClientDisplayName, request->appname());
     109            4 :     m_sessionServerManager.setLogLevels(static_cast<RIALTO_DEBUG_LEVEL>(request->loglevels().defaultloglevels()),
     110            4 :                                         static_cast<RIALTO_DEBUG_LEVEL>(request->loglevels().clientloglevels()),
     111            4 :                                         static_cast<RIALTO_DEBUG_LEVEL>(request->loglevels().sessionserverloglevels()),
     112            4 :                                         static_cast<RIALTO_DEBUG_LEVEL>(request->loglevels().ipcloglevels()),
     113            4 :                                         static_cast<RIALTO_DEBUG_LEVEL>(request->loglevels().servermanagerloglevels()),
     114            4 :                                         static_cast<RIALTO_DEBUG_LEVEL>(request->loglevels().commonloglevels()));
     115            4 :     if (!success)
     116              :     {
     117            2 :         RIALTO_SERVER_LOG_ERROR("SetConfiguration operation failed");
     118            6 :         controller->SetFailed("SetConfiguration failed");
     119              :     }
     120            4 :     done->Run();
     121              : }
     122              : 
     123            6 : void ServerManagerModuleService::setState(::google::protobuf::RpcController *controller,
     124              :                                           const ::rialto::SetStateRequest *request,
     125              :                                           ::rialto::SetStateResponse *response, ::google::protobuf::Closure *done)
     126              : {
     127            6 :     RIALTO_SERVER_LOG_DEBUG("SetState received from ServerManager");
     128            6 :     bool success = m_sessionServerManager.setState(convertSessionServerState(request->sessionserverstate()));
     129            6 :     if (!success)
     130              :     {
     131            1 :         RIALTO_SERVER_LOG_ERROR("SetState operation failed");
     132            3 :         controller->SetFailed("SetState failed");
     133              :     }
     134            6 :     done->Run();
     135              : }
     136              : 
     137            1 : void ServerManagerModuleService::setLogLevels(::google::protobuf::RpcController *controller,
     138              :                                               const ::rialto::SetLogLevelsRequest *request,
     139              :                                               ::rialto::SetLogLevelsResponse *response, ::google::protobuf::Closure *done)
     140              : {
     141            1 :     RIALTO_SERVER_LOG_DEBUG("setLogLevels received from ServerManager");
     142            1 :     m_sessionServerManager.setLogLevels(static_cast<RIALTO_DEBUG_LEVEL>(request->loglevels().defaultloglevels()),
     143            1 :                                         static_cast<RIALTO_DEBUG_LEVEL>(request->loglevels().clientloglevels()),
     144            1 :                                         static_cast<RIALTO_DEBUG_LEVEL>(request->loglevels().sessionserverloglevels()),
     145            1 :                                         static_cast<RIALTO_DEBUG_LEVEL>(request->loglevels().ipcloglevels()),
     146            1 :                                         static_cast<RIALTO_DEBUG_LEVEL>(request->loglevels().servermanagerloglevels()),
     147            1 :                                         static_cast<RIALTO_DEBUG_LEVEL>(request->loglevels().commonloglevels()));
     148            1 :     done->Run();
     149              : }
     150              : 
     151            3 : void ServerManagerModuleService::ping(::google::protobuf::RpcController *controller, const ::rialto::PingRequest *request,
     152              :                                       ::rialto::PingResponse *response, ::google::protobuf::Closure *done)
     153              : {
     154            3 :     RIALTO_SERVER_LOG_DEBUG("Ping received from ServerManager");
     155            3 :     auto ipcController = dynamic_cast<firebolt::rialto::ipc::IController *>(controller);
     156            3 :     if (!ipcController)
     157              :     {
     158            1 :         RIALTO_SERVER_LOG_ERROR("ipc library provided incompatible controller object");
     159            2 :         controller->SetFailed("ipc library provided incompatible controller object");
     160            1 :         done->Run();
     161            1 :         return;
     162              :     }
     163            2 :     bool success = m_sessionServerManager.ping(request->id(), std::make_shared<AckSender>(ipcController->getClient()));
     164            2 :     if (!success)
     165              :     {
     166            1 :         RIALTO_SERVER_LOG_ERROR("Ping failed");
     167            3 :         controller->SetFailed("Ping failed");
     168              :     }
     169            2 :     done->Run();
     170              : }
     171              : } // namespace firebolt::rialto::server::ipc
        

Generated by: LCOV version 2.0-1