summaryrefslogtreecommitdiffstats
path: root/xbmc/interfaces/AnnouncementManager.h
blob: 44b6d97071a3d527d9f6ebef352b5c6aaa141a44 (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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 *  Copyright (C) 2005-2018 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.
 */

#pragma once

#include "IAnnouncer.h"
#include "threads/CriticalSection.h"
#include "threads/Event.h"
#include "threads/Thread.h"
#include "utils/Variant.h"

#include <list>
#include <memory>
#include <vector>

class CFileItem;
class CVariant;

namespace ANNOUNCEMENT
{
  class CAnnouncementManager : public CThread
  {
  public:
    CAnnouncementManager();
    ~CAnnouncementManager() override;

    void Start();
    void Deinitialize();

    void AddAnnouncer(IAnnouncer *listener);
    void RemoveAnnouncer(IAnnouncer *listener);

    void Announce(AnnouncementFlag flag, const std::string& message);
    void Announce(AnnouncementFlag flag, const std::string& message, const CVariant& data);
    void Announce(AnnouncementFlag flag,
                  const std::string& message,
                  const std::shared_ptr<const CFileItem>& item);
    void Announce(AnnouncementFlag flag,
                  const std::string& message,
                  const std::shared_ptr<const CFileItem>& item,
                  const CVariant& data);

    void Announce(AnnouncementFlag flag, const std::string& sender, const std::string& message);
    void Announce(AnnouncementFlag flag,
                  const std::string& sender,
                  const std::string& message,
                  const CVariant& data);
    void Announce(AnnouncementFlag flag,
                  const std::string& sender,
                  const std::string& message,
                  const std::shared_ptr<const CFileItem>& item,
                  const CVariant& data);

    // The sender is not related to the application name.
    // Also it's part of Kodi's API - changing it will break
    // a big number of python addons and third party json consumers.
    static const std::string ANNOUNCEMENT_SENDER;

  protected:
    void Process() override;
    void DoAnnounce(AnnouncementFlag flag,
                    const std::string& sender,
                    const std::string& message,
                    const std::shared_ptr<CFileItem>& item,
                    const CVariant& data);
    void DoAnnounce(AnnouncementFlag flag,
                    const std::string& sender,
                    const std::string& message,
                    const CVariant& data);

    struct CAnnounceData
    {
      AnnouncementFlag flag;
      std::string sender;
      std::string message;
      std::shared_ptr<CFileItem> item;
      CVariant data;
    };
    std::list<CAnnounceData> m_announcementQueue;
    CEvent m_queueEvent;

  private:
    CAnnouncementManager(const CAnnouncementManager&) = delete;
    CAnnouncementManager const& operator=(CAnnouncementManager const&) = delete;

    CCriticalSection m_announcersCritSection;
    CCriticalSection m_queueCritSection;
    std::vector<IAnnouncer *> m_announcers;
  };
}