LCOV - code coverage report
Current view: top level - serverManager/ipc/source - Controller.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.4 % 61 57
Test Date: 2026-10-23 12:56:16 Functions: 100.0 % 10 10

            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 "Controller.h"
      21              : #include "RialtoServerManagerLogging.h"
      22              : #include <algorithm>
      23              : #include <string>
      24              : #include <utility>
      25              : 
      26              : namespace rialto::servermanager::ipc
      27              : {
      28           20 : Controller::Controller(std::unique_ptr<common::ISessionServerAppManager> &sessionServerAppManager)
      29           20 :     : m_sessionServerAppManager{sessionServerAppManager}
      30              : {
      31              : }
      32              : 
      33           40 : Controller::~Controller()
      34              : {
      35           20 :     std::map<int, std::unique_ptr<Client>> clients;
      36              :     {
      37           20 :         std::unique_lock<std::mutex> lock{m_clientMutex};
      38           20 :         m_isShuttingDown = true;
      39           20 :         clients.swap(m_clients);
      40              :     }
      41           20 :     clients.clear();
      42           40 : }
      43              : 
      44           19 : bool Controller::createClient(int serverId, int appMgmtSocket)
      45              : {
      46           19 :     std::unique_lock<std::mutex> lock{m_clientMutex};
      47           19 :     if (m_isShuttingDown)
      48              :     {
      49            0 :         RIALTO_SERVER_MANAGER_LOG_WARN("Not creating client for serverId: %d, controller is shutting down", serverId);
      50            0 :         return false;
      51              :     }
      52           19 :     if (m_clients.find(serverId) == m_clients.end())
      53              :     {
      54           18 :         auto newClient = std::make_unique<Client>(m_sessionServerAppManager, serverId, appMgmtSocket);
      55           18 :         if (newClient->connect())
      56              :         {
      57           17 :             m_clients.emplace(std::make_pair(serverId, std::move(newClient)));
      58           17 :             return true;
      59              :         }
      60            1 :         return false;
      61           18 :     }
      62            1 :     return false;
      63           19 : }
      64              : 
      65            1 : void Controller::removeClient(int serverId)
      66              : {
      67            1 :     std::unique_lock<std::mutex> lock{m_clientMutex};
      68            1 :     m_clients.erase(serverId);
      69              : }
      70              : 
      71            6 : bool Controller::performSetState(int serverId, const firebolt::rialto::common::SessionServerState &state)
      72              : {
      73            6 :     std::unique_lock<std::mutex> lock{m_clientMutex};
      74            6 :     auto client = m_clients.find(serverId);
      75            6 :     if (client != m_clients.end())
      76              :     {
      77            4 :         return client->second->performSetState(state);
      78              :     }
      79            2 :     return false;
      80            6 : }
      81              : 
      82            2 : bool Controller::performSetConfiguration(
      83              :     int serverId, const firebolt::rialto::common::SessionServerState &initialState, const std::string &socketName,
      84              :     const std::string &clientDisplayName, const firebolt::rialto::common::MaxResourceCapabilitites &maxResource,
      85              :     const unsigned int socketPermissions, const std::string &socketOwner, const std::string &socketGroup,
      86              :     const std::string &appName, const std::optional<firebolt::rialto::common::AudioDecoderCapabilities> &audioCaps,
      87              :     const std::optional<firebolt::rialto::common::VideoDecoderCapabilities> &videoCaps)
      88              : {
      89            2 :     std::unique_lock<std::mutex> lock{m_clientMutex};
      90            2 :     auto client = m_clients.find(serverId);
      91            2 :     if (client != m_clients.end())
      92              :     {
      93            2 :         return client->second->performSetConfiguration(initialState, socketName, clientDisplayName, maxResource,
      94              :                                                        socketPermissions, socketOwner, socketGroup, appName, audioCaps,
      95            2 :                                                        videoCaps);
      96              :     }
      97            0 :     return false;
      98            2 : }
      99              : 
     100            2 : bool Controller::performSetConfiguration(
     101              :     int serverId, const firebolt::rialto::common::SessionServerState &initialState, int socketFd,
     102              :     const std::string &clientDisplayName, const firebolt::rialto::common::MaxResourceCapabilitites &maxResource,
     103              :     const std::string &appName, const std::optional<firebolt::rialto::common::AudioDecoderCapabilities> &audioCaps,
     104              :     const std::optional<firebolt::rialto::common::VideoDecoderCapabilities> &videoCaps)
     105              : {
     106            2 :     std::unique_lock<std::mutex> lock{m_clientMutex};
     107            2 :     auto client = m_clients.find(serverId);
     108            2 :     if (client != m_clients.end())
     109              :     {
     110            2 :         return client->second->performSetConfiguration(initialState, socketFd, clientDisplayName, maxResource, appName,
     111            2 :                                                        audioCaps, videoCaps);
     112              :     }
     113            0 :     return false;
     114            2 : }
     115              : 
     116            3 : bool Controller::performPing(int serverId, int pingId)
     117              : {
     118            3 :     std::unique_lock<std::mutex> lock{m_clientMutex};
     119            3 :     auto client = m_clients.find(serverId);
     120            3 :     if (client != m_clients.end())
     121              :     {
     122            2 :         return client->second->performPing(pingId);
     123              :     }
     124            1 :     return false;
     125            3 : }
     126              : 
     127            2 : bool Controller::setLogLevels(const service::LoggingLevels &logLevels) const
     128              : {
     129            2 :     std::unique_lock<std::mutex> lock{m_clientMutex};
     130            2 :     return std::all_of(m_clients.begin(), m_clients.end(),
     131            6 :                        [&](const auto &client) { return client.second->setLogLevels(logLevels); });
     132            2 : }
     133              : } // namespace rialto::servermanager::ipc
        

Generated by: LCOV version 2.0-1