LCOV - code coverage report
Current view: top level - media/client/main/source - KeyIdMap.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 24 24
Test Date: 2025-02-18 13:13:53 Functions: 100.0 % 5 5

            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 "KeyIdMap.h"
      21              : 
      22              : namespace firebolt::rialto::client
      23              : {
      24           20 : KeyIdMap &KeyIdMap::instance()
      25              : {
      26           20 :     static KeyIdMap keyIdMap;
      27           20 :     return keyIdMap;
      28              : }
      29              : 
      30            4 : void KeyIdMap::addSession(std::int32_t keySessionId)
      31              : {
      32            4 :     std::unique_lock<std::mutex> lock{m_mutex};
      33            4 :     m_keyIdMap.insert(std::make_pair(keySessionId, std::vector<uint8_t>()));
      34              : }
      35              : 
      36            5 : bool KeyIdMap::updateKey(std::int32_t keySessionId, const std::vector<std::uint8_t> &keyId)
      37              : {
      38            5 :     std::unique_lock<std::mutex> lock{m_mutex};
      39            5 :     auto keyIdIter{m_keyIdMap.find(keySessionId)};
      40            5 :     if (m_keyIdMap.end() == keyIdIter)
      41              :     {
      42            2 :         return false;
      43              :     }
      44            3 :     keyIdIter->second = keyId;
      45            3 :     return true;
      46            5 : }
      47              : 
      48            7 : std::vector<std::uint8_t> KeyIdMap::get(std::int32_t keySessionId) const
      49              : {
      50            7 :     std::unique_lock<std::mutex> lock{m_mutex};
      51            7 :     auto keyIdIter{m_keyIdMap.find(keySessionId)};
      52            7 :     if (m_keyIdMap.end() == keyIdIter)
      53              :     {
      54            3 :         return std::vector<std::uint8_t>();
      55              :     }
      56            4 :     return keyIdIter->second;
      57            7 : }
      58              : 
      59            4 : void KeyIdMap::erase(std::int32_t keySessionId)
      60              : {
      61            4 :     std::unique_lock<std::mutex> lock{m_mutex};
      62            4 :     m_keyIdMap.erase(keySessionId);
      63              : }
      64              : } // namespace firebolt::rialto::client
        

Generated by: LCOV version 2.0-1