kodi
LanguageHook.h
1 /*
2  * Copyright (C) 2005-2018 Team Kodi
3  * This file is part of Kodi - https://kodi.tv
4  *
5  * SPDX-License-Identifier: GPL-2.0-or-later
6  * See LICENSES/README.md for more information.
7  */
8 
9 #pragma once
10 
11 #include "interfaces/legacy/LanguageHook.h"
12 #include "threads/Event.h"
13 
14 #include <map>
15 #include <mutex>
16 #include <set>
17 
18 #include <Python.h>
19 
20 namespace XBMCAddon
21 {
22  namespace Python
23  {
24  struct MutableInteger;
25 
32  {
33  PyInterpreterState* m_interp;
34  CCriticalSection crit;
35  std::set<AddonClass*> currentObjects;
36 
37  // This constructor is only used to instantiate the global LanguageHook
38  inline PythonLanguageHook() : m_interp(NULL) { }
39 
40  public:
41 
42  inline explicit PythonLanguageHook(PyInterpreterState* interp) : m_interp(interp) { }
43  ~PythonLanguageHook() override;
44 
45  void DelayedCallOpen() override;
46  void DelayedCallClose() override;
47  void MakePendingCalls() override;
48 
62 
63  String GetAddonId() override;
64  String GetAddonVersion() override;
65  long GetInvokerId() override;
66 
67  void RegisterPlayerCallback(IPlayerCallback* player) override;
68  void UnregisterPlayerCallback(IPlayerCallback* player) override;
69  void RegisterMonitorCallback(XBMCAddon::xbmc::Monitor* monitor) override;
70  void UnregisterMonitorCallback(XBMCAddon::xbmc::Monitor* monitor) override;
71  bool WaitForEvent(CEvent& hEvent, unsigned int milliseconds) override;
72 
73  static AddonClass::Ref<PythonLanguageHook> GetIfExists(PyInterpreterState* interp);
74  static bool IsAddonClassInstanceRegistered(AddonClass* obj);
75 
76  void RegisterAddonClassInstance(AddonClass* obj);
77  void UnregisterAddonClassInstance(AddonClass* obj);
78  bool HasRegisteredAddonClassInstance(AddonClass* obj);
79  inline bool HasRegisteredAddonClasses()
80  {
81  std::unique_lock<CCriticalSection> l(*this);
82  return !currentObjects.empty();
83  }
84 
85  // You should hold the lock on the LanguageHook itself if you're
86  // going to do anything with the set that gets returned.
87  inline std::set<AddonClass*>& GetRegisteredAddonClasses() { return currentObjects; }
88 
89  void UnregisterMe();
90  void RegisterMe();
91  };
92  }
93 }
94 
This is an Event class built from a ConditionVariable.
Definition: Event.h:35
This class supplies the python specific functionality for plugging into the API.
Definition: LanguageHook.h:31
This class is a smart pointer for a Referenced class.
Definition: AddonClass.h:154
String GetAddonId() override
This method should be done a different way but since the only other way I can think to do it requires...
Definition: LanguageHook.cpp:119
This is the abstraction representing different ways to handle the execution of callbacks.
Definition: CallbackHandler.h:21
XBMCAddon::CallbackHandler * GetCallbackHandler() override
PythonCallbackHandler expects to be instantiated PER AddonClass instance that is to be used as a call...
Definition: LanguageHook.cpp:113
Definition: Monitor.h:29
Defining LOG_LIFECYCLE_EVENTS will log all instantiations, deletions and also reference countings (in...
Definition: Addon.cpp:25
Definition: IPlayerCallback.h:18
Definition: LanguageHook.h:29
void DelayedCallClose() override
If the scripting language needs special handling for calls that block or are delayed in any other mea...
Definition: LanguageHook.cpp:49
This class is the superclass for all reference counted classes in the api.
Definition: AddonClass.h:57
void DelayedCallOpen() override
If the scripting language needs special handling for calls that block or are delayed in any other mea...
Definition: LanguageHook.cpp:43