LCOV - code coverage report
Current view: top level - serverManager/ipc/source - Controller.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 97.7 % 43 42
Test Date: 2025-02-18 13:13:53 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 "Controller.h"
      21              : #include "RialtoServerManagerLogging.h"
      22              : #include <algorithm>
      23              : #include <string>
      24              : #include <utility>
      25              : 
      26              : namespace rialto::servermanager::ipc
      27              : {
      28           17 : Controller::Controller(std::unique_ptr<common::ISessionServerAppManager> &sessionServerAppManager)
      29           17 :     : m_sessionServerAppManager{sessionServerAppManager}
      30              : {
      31              : }
      32              : 
      33           16 : bool Controller::createClient(int serverId, int appMgmtSocket)
      34              : {
      35           16 :     std::unique_lock<std::mutex> lock{m_clientMutex};
      36           16 :     if (m_clients.find(serverId) == m_clients.end())
      37              :     {
      38           15 :         auto newClient = std::make_unique<Client>(m_sessionServerAppManager, serverId, appMgmtSocket);
      39           15 :         if (newClient->connect())
      40              :         {
      41           14 :             m_clients.emplace(std::make_pair(serverId, std::move(newClient)));
      42           14 :             return true;
      43              :         }
      44            1 :         return false;
      45           15 :     }
      46            1 :     return false;
      47           16 : }
      48              : 
      49            1 : void Controller::removeClient(int serverId)
      50              : {
      51            1 :     std::unique_lock<std::mutex> lock{m_clientMutex};
      52            1 :     m_clients.erase(serverId);
      53              : }
      54              : 
      55            4 : bool Controller::performSetState(int serverId, const firebolt::rialto::common::SessionServerState &state)
      56              : {
      57            4 :     std::unique_lock<std::mutex> lock{m_clientMutex};
      58            4 :     auto client = m_clients.find(serverId);
      59            4 :     if (client != m_clients.end())
      60              :     {
      61            2 :         return client->second->performSetState(state);
      62              :     }
      63            2 :     return false;
      64            4 : }
      65              : 
      66            2 : bool Controller::performSetConfiguration(int serverId, const firebolt::rialto::common::SessionServerState &initialState,
      67              :                                          const std::string &socketName, const std::string &clientDisplayName,
      68              :                                          const firebolt::rialto::common::MaxResourceCapabilitites &maxResource,
      69              :                                          const unsigned int socketPermissions, const std::string &socketOwner,
      70              :                                          const std::string &socketGroup, const std::string &appName)
      71              : {
      72            2 :     std::unique_lock<std::mutex> lock{m_clientMutex};
      73            2 :     auto client = m_clients.find(serverId);
      74            2 :     if (client != m_clients.end())
      75              :     {
      76            2 :         return client->second->performSetConfiguration(initialState, socketName, clientDisplayName, maxResource,
      77            2 :                                                        socketPermissions, socketOwner, socketGroup, appName);
      78              :     }
      79            0 :     return false;
      80            2 : }
      81              : 
      82            3 : bool Controller::performPing(int serverId, int pingId)
      83              : {
      84            3 :     std::unique_lock<std::mutex> lock{m_clientMutex};
      85            3 :     auto client = m_clients.find(serverId);
      86            3 :     if (client != m_clients.end())
      87              :     {
      88            2 :         return client->second->performPing(pingId);
      89              :     }
      90            1 :     return false;
      91            3 : }
      92              : 
      93            2 : bool Controller::setLogLevels(const service::LoggingLevels &logLevels) const
      94              : {
      95            2 :     std::unique_lock<std::mutex> lock{m_clientMutex};
      96            2 :     return std::all_of(m_clients.begin(), m_clients.end(),
      97            6 :                        [&](const auto &client) { return client.second->setLogLevels(logLevels); });
      98            2 : }
      99              : } // namespace rialto::servermanager::ipc
        

Generated by: LCOV version 2.0-1