summaryrefslogtreecommitdiffstats
path: root/xbmc/interfaces/python/LanguageHook.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 18:07:22 +0000
commitc04dcc2e7d834218ef2d4194331e383402495ae1 (patch)
tree7333e38d10d75386e60f336b80c2443c1166031d /xbmc/interfaces/python/LanguageHook.h
parentInitial commit. (diff)
downloadkodi-c04dcc2e7d834218ef2d4194331e383402495ae1.tar.xz
kodi-c04dcc2e7d834218ef2d4194331e383402495ae1.zip
Adding upstream version 2:20.4+dfsg.upstream/2%20.4+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'xbmc/interfaces/python/LanguageHook.h')
-rw-r--r--xbmc/interfaces/python/LanguageHook.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/xbmc/interfaces/python/LanguageHook.h b/xbmc/interfaces/python/LanguageHook.h
new file mode 100644
index 0000000..6a4e0d0
--- /dev/null
+++ b/xbmc/interfaces/python/LanguageHook.h
@@ -0,0 +1,94 @@
+/*
+ * 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 "interfaces/legacy/LanguageHook.h"
+#include "threads/Event.h"
+
+#include <map>
+#include <mutex>
+#include <set>
+
+#include <Python.h>
+
+namespace XBMCAddon
+{
+ namespace Python
+ {
+ struct MutableInteger;
+
+ /**
+ * This class supplies the python specific functionality for
+ * plugging into the API. It's got a static only implementation
+ * and uses the singleton pattern for access.
+ */
+ class PythonLanguageHook : public XBMCAddon::LanguageHook
+ {
+ PyInterpreterState* m_interp;
+ CCriticalSection crit;
+ std::set<AddonClass*> currentObjects;
+
+ // This constructor is only used to instantiate the global LanguageHook
+ inline PythonLanguageHook() : m_interp(NULL) { }
+
+ public:
+
+ inline explicit PythonLanguageHook(PyInterpreterState* interp) : m_interp(interp) { }
+ ~PythonLanguageHook() override;
+
+ void DelayedCallOpen() override;
+ void DelayedCallClose() override;
+ void MakePendingCalls() override;
+
+ /**
+ * PythonCallbackHandler expects to be instantiated PER AddonClass instance
+ * that is to be used as a callback. This is why this cannot be instantiated
+ * once.
+ *
+ * There is an expectation that this method is called from the Python thread
+ * that instantiated an AddonClass that has the potential for a callback.
+ *
+ * See RetardedAsyncCallbackHandler for more details.
+ * See PythonCallbackHandler for more details
+ * See PythonCallbackHandler::PythonCallbackHandler for more details
+ */
+ XBMCAddon::CallbackHandler* GetCallbackHandler() override;
+
+ String GetAddonId() override;
+ String GetAddonVersion() override;
+ long GetInvokerId() override;
+
+ void RegisterPlayerCallback(IPlayerCallback* player) override;
+ void UnregisterPlayerCallback(IPlayerCallback* player) override;
+ void RegisterMonitorCallback(XBMCAddon::xbmc::Monitor* monitor) override;
+ void UnregisterMonitorCallback(XBMCAddon::xbmc::Monitor* monitor) override;
+ bool WaitForEvent(CEvent& hEvent, unsigned int milliseconds) override;
+
+ static AddonClass::Ref<PythonLanguageHook> GetIfExists(PyInterpreterState* interp);
+ static bool IsAddonClassInstanceRegistered(AddonClass* obj);
+
+ void RegisterAddonClassInstance(AddonClass* obj);
+ void UnregisterAddonClassInstance(AddonClass* obj);
+ bool HasRegisteredAddonClassInstance(AddonClass* obj);
+ inline bool HasRegisteredAddonClasses()
+ {
+ std::unique_lock<CCriticalSection> l(*this);
+ return !currentObjects.empty();
+ }
+
+ // You should hold the lock on the LanguageHook itself if you're
+ // going to do anything with the set that gets returned.
+ inline std::set<AddonClass*>& GetRegisteredAddonClasses() { return currentObjects; }
+
+ void UnregisterMe();
+ void RegisterMe();
+ };
+ }
+}
+