PageRenderTime 49ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/interfaces/python/XBPython.h

https://gitlab.com/fflayol/xbmc
C Header | 136 lines | 92 code | 21 blank | 23 comment | 0 complexity | 997d4ef298150c590be5f47deb10e9f6 MD5 | raw file
  1. #pragma once
  2. /*
  3. * Copyright (C) 2005-2013 Team XBMC
  4. * http://xbmc.org
  5. *
  6. * This Program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This Program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with XBMC; see the file COPYING. If not, see
  18. * <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #include "cores/IPlayerCallback.h"
  22. #include "threads/CriticalSection.h"
  23. #include "threads/Event.h"
  24. #include "threads/Thread.h"
  25. #include "interfaces/IAnnouncer.h"
  26. #include "interfaces/generic/ILanguageInvocationHandler.h"
  27. #include <memory>
  28. #include <vector>
  29. class CPythonInvoker;
  30. class CVariant;
  31. typedef struct {
  32. int id;
  33. bool bDone;
  34. CPythonInvoker* pyThread;
  35. }PyElem;
  36. class LibraryLoader;
  37. namespace XBMCAddon
  38. {
  39. namespace xbmc
  40. {
  41. class Monitor;
  42. }
  43. }
  44. template <class T> struct LockableType : public T, public CCriticalSection
  45. { bool hadSomethingRemoved; };
  46. typedef LockableType<std::vector<void*> > PlayerCallbackList;
  47. typedef LockableType<std::vector<XBMCAddon::xbmc::Monitor*> > MonitorCallbackList;
  48. typedef LockableType<std::vector<PyElem> > PyList;
  49. typedef std::vector<LibraryLoader*> PythonExtensionLibraries;
  50. class XBPython :
  51. public IPlayerCallback,
  52. public ANNOUNCEMENT::IAnnouncer,
  53. public ILanguageInvocationHandler
  54. {
  55. public:
  56. XBPython();
  57. virtual ~XBPython();
  58. virtual void OnPlayBackEnded();
  59. virtual void OnPlayBackStarted();
  60. virtual void OnPlayBackPaused();
  61. virtual void OnPlayBackResumed();
  62. virtual void OnPlayBackStopped();
  63. virtual void OnPlayBackSpeedChanged(int iSpeed);
  64. virtual void OnPlayBackSeek(int iTime, int seekOffset);
  65. virtual void OnPlayBackSeekChapter(int iChapter);
  66. virtual void OnQueueNextItem();
  67. virtual void Announce(ANNOUNCEMENT::AnnouncementFlag flag, const char *sender, const char *message, const CVariant &data);
  68. void RegisterPythonPlayerCallBack(IPlayerCallback* pCallback);
  69. void UnregisterPythonPlayerCallBack(IPlayerCallback* pCallback);
  70. void RegisterPythonMonitorCallBack(XBMCAddon::xbmc::Monitor* pCallback);
  71. void UnregisterPythonMonitorCallBack(XBMCAddon::xbmc::Monitor* pCallback);
  72. void OnSettingsChanged(const std::string &strings);
  73. void OnScreensaverActivated();
  74. void OnScreensaverDeactivated();
  75. void OnDPMSActivated();
  76. void OnDPMSDeactivated();
  77. void OnScanStarted(const std::string &library);
  78. void OnScanFinished(const std::string &library);
  79. void OnCleanStarted(const std::string &library);
  80. void OnCleanFinished(const std::string &library);
  81. void OnNotification(const std::string &sender, const std::string &method, const std::string &data);
  82. virtual void Process();
  83. virtual void PulseGlobalEvent();
  84. virtual void Uninitialize();
  85. virtual bool OnScriptInitialized(ILanguageInvoker *invoker);
  86. virtual void OnScriptStarted(ILanguageInvoker *invoker);
  87. virtual void OnScriptAbortRequested(ILanguageInvoker *invoker);
  88. virtual void OnScriptEnded(ILanguageInvoker *invoker);
  89. virtual void OnScriptFinalized(ILanguageInvoker *invoker);
  90. virtual ILanguageInvoker* CreateInvoker();
  91. bool WaitForEvent(CEvent& hEvent, unsigned int milliseconds);
  92. void RegisterExtensionLib(LibraryLoader *pLib);
  93. void UnregisterExtensionLib(LibraryLoader *pLib);
  94. void UnloadExtensionLibs();
  95. private:
  96. void Finalize();
  97. CCriticalSection m_critSection;
  98. bool FileExist(const char* strFile);
  99. void* m_mainThreadState;
  100. ThreadIdentifier m_ThreadId;
  101. bool m_bInitialized;
  102. int m_iDllScriptCounter; // to keep track of the total scripts running that need the dll
  103. unsigned int m_endtime;
  104. //Vector with list of threads used for running scripts
  105. PyList m_vecPyList;
  106. PlayerCallbackList m_vecPlayerCallbackList;
  107. MonitorCallbackList m_vecMonitorCallbackList;
  108. LibraryLoader* m_pDll;
  109. // any global events that scripts should be using
  110. CEvent m_globalEvent;
  111. // in order to finalize and unload the python library, need to save all the extension libraries that are
  112. // loaded by it and unload them first (not done by finalize)
  113. PythonExtensionLibraries m_extensions;
  114. };
  115. extern XBPython g_pythonParser;