PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/xbmc/interfaces/python/XBPython.h

https://github.com/dahool84/xbmc
C Header | 143 lines | 85 code | 24 blank | 34 comment | 0 complexity | c0f7886bf09116a6323b90fd8d303810 MD5 | raw file
  1. #pragma once
  2. /*
  3. * Copyright (C) 2005-2008 Team XBMC
  4. * http://www.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, write to
  18. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19. * http://www.gnu.org/copyleft/gpl.html
  20. *
  21. */
  22. #include "XBPyThread.h"
  23. #include "cores/IPlayer.h"
  24. #include "threads/CriticalSection.h"
  25. #include "interfaces/IAnnouncer.h"
  26. #include "addons/IAddon.h"
  27. #include <vector>
  28. typedef struct {
  29. int id;
  30. bool bDone;
  31. std::string strFile;
  32. XBPyThread *pyThread;
  33. }PyElem;
  34. class LibraryLoader;
  35. class CPythonMonitor;
  36. typedef std::vector<PyElem> PyList;
  37. typedef std::vector<PVOID> PlayerCallbackList;
  38. typedef std::vector<PVOID> MonitorCallbackList;
  39. typedef std::vector<LibraryLoader*> PythonExtensionLibraries;
  40. class XBPython :
  41. public IPlayerCallback,
  42. public ANNOUNCEMENT::IAnnouncer
  43. {
  44. public:
  45. XBPython();
  46. virtual ~XBPython();
  47. virtual void OnPlayBackEnded();
  48. virtual void OnPlayBackStarted();
  49. virtual void OnPlayBackPaused();
  50. virtual void OnPlayBackResumed();
  51. virtual void OnPlayBackStopped();
  52. virtual void OnQueueNextItem() {};
  53. virtual void Announce(ANNOUNCEMENT::AnnouncementFlag flag, const char *sender, const char *message, const CVariant &data);
  54. void RegisterPythonPlayerCallBack(IPlayerCallback* pCallback);
  55. void UnregisterPythonPlayerCallBack(IPlayerCallback* pCallback);
  56. void RegisterPythonMonitorCallBack(CPythonMonitor* pCallback);
  57. void UnregisterPythonMonitorCallBack(CPythonMonitor* pCallback);
  58. void OnSettingsChanged(const CStdString &strings);
  59. void OnScreensaverActivated();
  60. void OnScreensaverDeactivated();
  61. void OnDatabaseUpdated(const std::string &database);
  62. void Initialize();
  63. void Finalize();
  64. void FinalizeScript();
  65. void FreeResources();
  66. void Process();
  67. void PulseGlobalEvent();
  68. void WaitForEvent(CEvent& hEvent, unsigned int timeout);
  69. int ScriptsSize();
  70. int GetPythonScriptId(int scriptPosition);
  71. int evalFile(const CStdString &src, ADDON::AddonPtr addon);
  72. int evalFile(const CStdString &src, const std::vector<CStdString> &argv, ADDON::AddonPtr addon);
  73. int evalString(const CStdString &src, const std::vector<CStdString> &argv);
  74. bool isRunning(int scriptId);
  75. bool isStopping(int scriptId);
  76. void setDone(int id);
  77. /*! \brief Stop a script if it's running
  78. \param path path to the script
  79. \return true if the script was running and is now stopped, false otherwise
  80. */
  81. bool StopScript(const CStdString &path);
  82. // inject xbmc stuff into the interpreter.
  83. // should be called for every new interpreter
  84. void InitializeInterpreter(ADDON::AddonPtr addon);
  85. // remove modules and references when interpreter done
  86. void DeInitializeInterpreter();
  87. void RegisterExtensionLib(LibraryLoader *pLib);
  88. void UnregisterExtensionLib(LibraryLoader *pLib);
  89. void UnloadExtensionLibs();
  90. //only should be called from thread which is running the script
  91. void stopScript(int scriptId);
  92. // returns NULL if script doesn't exist or if script doesn't have a filename
  93. const char* getFileName(int scriptId);
  94. // returns -1 if no scripts exist with specified filename
  95. int getScriptId(const CStdString &strFile);
  96. void* getMainThreadState();
  97. bool m_bLogin;
  98. CCriticalSection m_critSection;
  99. private:
  100. bool FileExist(const char* strFile);
  101. int m_nextid;
  102. void* m_mainThreadState;
  103. ThreadIdentifier m_ThreadId;
  104. bool m_bInitialized;
  105. int m_iDllScriptCounter; // to keep track of the total scripts running that need the dll
  106. HMODULE m_hModule;
  107. unsigned int m_endtime;
  108. //Vector with list of threads used for running scripts
  109. PyList m_vecPyList;
  110. PlayerCallbackList m_vecPlayerCallbackList;
  111. MonitorCallbackList m_vecMonitorCallbackList;
  112. LibraryLoader* m_pDll;
  113. // any global events that scripts should be using
  114. CEvent m_globalEvent;
  115. // in order to finalize and unload the python library, need to save all the extension libraries that are
  116. // loaded by it and unload them first (not done by finalize)
  117. PythonExtensionLibraries m_extensions;
  118. };
  119. extern XBPython g_pythonParser;