summaryrefslogtreecommitdiffstats
path: root/xbmc/pvr/addons/PVRClientUID.cpp
blob: 87883851eaa4588c6536d52ecb1bae8320e568da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*
 *  Copyright (C) 2012-2022 Team Kodi
 *  This file is part of Kodi - https://kodi.tv
 *
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "PVRClientUID.h"

#include <functional>

using namespace PVR;

int CPVRClientUID::GetUID() const
{
  if (!m_uidCreated)
  {
    std::hash<std::string> hasher;

    // Note: For database backwards compatibility reasons the hash of the first instance
    // must be calculated just from the addonId, not from addonId and instanceId.
    m_uid = static_cast<int>(hasher(
        (m_instanceID > ADDON::ADDON_FIRST_INSTANCE_ID ? std::to_string(m_instanceID) + "@" : "") +
        m_addonID));
    if (m_uid < 0)
      m_uid = -m_uid;

    m_uidCreated = true;
  }

  return m_uid;
}