void CScreenSaver::Destroy() { #ifdef HAS_PYTHON if (URIUtils::HasExtension(LibPath(), ".py")) { /* FIXME: This is a hack but a proper fix is non-trivial. Basically this code * makes sure the addon gets terminated after we've moved out of the screensaver window. * If we don't do this, we may simply lockup. */ g_alarmClock.Start(SCRIPT_ALARM, SCRIPT_TIMEOUT, "StopScript(" + LibPath() + ")", true, false); return; } #endif // Release what was allocated in method CScreenSaver::CreateScreenSaver. if (m_info.name) { free((void *) m_info.name); m_info.name = nullptr; } if (m_info.presets) { free((void *) m_info.presets); m_info.presets = nullptr; } if (m_info.profile) { free((void *) m_info.profile); m_info.profile = nullptr; } CAddonDll::Destroy(); }
bool CScreenSaver::CreateScreenSaver() { if (CScriptInvocationManager::GetInstance().HasLanguageInvoker(LibPath())) { // Don't allow a previously-scheduled alarm to kill our new screensaver g_alarmClock.Stop(SCRIPT_ALARM, true); if (!CScriptInvocationManager::GetInstance().Stop(LibPath())) CScriptInvocationManager::GetInstance().ExecuteAsync(LibPath(), AddonPtr(new CScreenSaver(*this))); return true; } // pass it the screen width,height // and the name of the screensaver int iWidth = g_graphicsContext.GetWidth(); int iHeight = g_graphicsContext.GetHeight(); #ifdef HAS_DX m_info.device = g_Windowing.Get3D11Context(); #else m_info.device = NULL; #endif m_info.x = 0; m_info.y = 0; m_info.width = iWidth; m_info.height = iHeight; m_info.pixelRatio = g_graphicsContext.GetResInfo().fPixelRatio; m_info.name = strdup(Name().c_str()); m_info.presets = strdup(CSpecialProtocol::TranslatePath(Path()).c_str()); m_info.profile = strdup(CSpecialProtocol::TranslatePath(Profile()).c_str()); if (CAddonDll::Create(&m_struct, &m_info) == ADDON_STATUS_OK) return true; return false; }
bool CScreenSaver::CreateScreenSaver() { if (CScriptInvocationManager::GetInstance().HasLanguageInvoker(LibPath())) { // Don't allow a previously-scheduled alarm to kill our new screensaver g_alarmClock.Stop(SCRIPT_ALARM, true); if (!CScriptInvocationManager::GetInstance().Stop(LibPath())) CScriptInvocationManager::GetInstance().ExecuteAsync(LibPath(), Clone()); return true; } // pass it the screen width,height // and the name of the screensaver int iWidth = g_graphicsContext.GetWidth(); int iHeight = g_graphicsContext.GetHeight(); m_pInfo = new SCR_PROPS; m_pInfo->device = NULL; m_pInfo->x = 0; m_pInfo->y = 0; m_pInfo->width = iWidth; m_pInfo->height = iHeight; m_pInfo->pixelRatio = g_graphicsContext.GetResInfo().fPixelRatio; m_pInfo->name = strdup(Name().c_str()); m_pInfo->presets = strdup(CSpecialProtocol::TranslatePath(Path()).c_str()); m_pInfo->profile = strdup(CSpecialProtocol::TranslatePath(Profile()).c_str()); if (CAddonDll<DllScreenSaver, ScreenSaver, SCR_PROPS>::Create() == ADDON_STATUS_OK) return true; return false; }
CContextMenuAddon::CContextMenuAddon(const cp_extension_t *ext) : CAddon(ext) { cp_cfg_element_t* menu = CAddonMgr::GetInstance().GetExtElement(ext->configuration, "menu"); if (menu) { int tmp = 0; ParseMenu(menu, "", tmp); } else { //backwards compatibility. add first item definition ELEMENTS items; if (CAddonMgr::GetInstance().GetExtElements(ext->configuration, "item", items)) { cp_cfg_element_t *item = items[0]; std::string visCondition = CAddonMgr::GetInstance().GetExtValue(item, "visible"); if (visCondition.empty()) visCondition = "false"; std::string parent = CAddonMgr::GetInstance().GetExtValue(item, "parent") == "kodi.core.manage" ? CContextMenuManager::MANAGE.m_groupId : CContextMenuManager::MAIN.m_groupId; auto label = CAddonMgr::GetInstance().GetExtValue(item, "label"); if (StringUtils::IsNaturalNumber(label)) label = g_localizeStrings.GetAddonString(ID(), atoi(label.c_str())); CContextMenuItem menuItem = CContextMenuItem::CreateItem(label, parent,LibPath(), g_infoManager.Register(visCondition, 0)); m_items.push_back(menuItem); } } }
bool CAddonDll::LoadDll() { if (m_pDll) return true; std::string strFileName = LibPath(); if (strFileName.empty()) return false; /* Load the Dll */ m_pDll = new DllAddon; m_pDll->SetFile(strFileName); m_pDll->EnableDelayedUnload(false); if (!m_pDll->Load()) { delete m_pDll; m_pDll = NULL; std::string heading = StringUtils::Format("%s: %s", CAddonInfo::TranslateType(Type(), true).c_str(), Name().c_str()); HELPERS::ShowOKDialogLines(CVariant{heading}, CVariant{24070}, CVariant{24071}); return false; } return true; }
void CScreenSaver::Destroy() { #ifdef HAS_PYTHON if (URIUtils::HasExtension(LibPath(), ".py")) { g_alarmClock.Start(SCRIPT_ALARM, SCRIPT_TIMEOUT, "StopScript(" + LibPath() + ")", true, false); return; } #endif // Release what was allocated in method CScreenSaver::CreateScreenSaver. if (m_pInfo) { free((void *) m_pInfo->name); free((void *) m_pInfo->presets); free((void *) m_pInfo->profile); delete m_pInfo; m_pInfo = NULL; } CAddonDll<DllScreenSaver, ScreenSaver, SCR_PROPS>::Destroy(); }
bool CScreenSaver::CreateScreenSaver() { #ifdef HAS_PYTHON if (URIUtils::HasExtension(LibPath(), ".py")) { // Don't allow a previously-scheduled alarm to kill our new screensaver g_alarmClock.Stop(PYTHON_ALARM, true); if (!g_pythonParser.StopScript(LibPath())) g_pythonParser.evalFile(LibPath(), AddonPtr(new CScreenSaver(Props()))); return true; } #endif // pass it the screen width,height // and the name of the screensaver int iWidth = g_graphicsContext.GetWidth(); int iHeight = g_graphicsContext.GetHeight(); m_pInfo = new SCR_PROPS; #ifdef HAS_DX m_pInfo->device = g_Windowing.Get3DDevice(); #else m_pInfo->device = NULL; #endif m_pInfo->x = 0; m_pInfo->y = 0; m_pInfo->width = iWidth; m_pInfo->height = iHeight; m_pInfo->pixelRatio = CDisplaySettings::Get().GetResolutionInfo(g_graphicsContext.GetVideoResolution()).fPixelRatio; m_pInfo->name = strdup(Name().c_str()); m_pInfo->presets = strdup(CSpecialProtocol::TranslatePath(Path()).c_str()); m_pInfo->profile = strdup(CSpecialProtocol::TranslatePath(Profile()).c_str()); if (CAddonDll<DllScreenSaver, ScreenSaver, SCR_PROPS>::Create() == ADDON_STATUS_OK) return true; return false; }
bool CService::Start() { bool ret = true; switch (m_type) { #ifdef HAS_PYTHON case PYTHON: ret = (CScriptInvocationManager::Get().Execute(LibPath(), this->shared_from_this()) != -1); break; #endif case UNKNOWN: default: ret = false; break; } return ret; }
bool CService::Start() { bool ret = true; switch (m_type) { #ifdef HAS_PYTHON case PYTHON: ret = (g_pythonParser.evalFile(LibPath()) != -1); break; #endif case UNKNOWN: default: ret = false; break; } return ret; }
bool CService::Stop() { bool ret = true; switch (m_type) { #ifdef HAS_PYTHON case PYTHON: ret = CScriptInvocationManager::Get().Stop(LibPath()); break; #endif case UNKNOWN: default: ret = false; break; } return ret; }
bool CService::Stop() { bool ret = true; switch (m_type) { #ifdef HAS_PYTHON case PYTHON: ret = g_pythonParser.StopScript(LibPath()); break; #endif case UNKNOWN: default: ret = false; break; } return ret; }
void CService::BuildServiceType() { CStdString str = LibPath(); CStdString ext; size_t p = str.find_last_of('.'); if (p != string::npos) ext = str.substr(p + 1); #ifdef HAS_PYTHON CStdString pythonExt = ADDON_PYTHON_EXT; pythonExt.erase(0, 2); if ( ext.Equals(pythonExt) ) m_type = PYTHON; else #endif { m_type = UNKNOWN; CLog::Log(LOGERROR, "ADDON: extension '%s' is not currently supported for service addon", ext.c_str()); } }
bool CAddonDll::LoadDll() { if (m_pDll) return true; std::string strFileName; std::string strAltFileName; if (!m_bIsChild) { strFileName = LibPath(); } else { std::string libPath = LibPath(); if (!XFILE::CFile::Exists(libPath)) { std::string temp = CSpecialProtocol::TranslatePath("special://xbmc/"); std::string tempbin = CSpecialProtocol::TranslatePath("special://xbmcbin/"); libPath.erase(0, temp.size()); libPath = tempbin + libPath; if (!XFILE::CFile::Exists(libPath)) { CLog::Log(LOGERROR, "ADDON: Could not locate %s", m_props.libname.c_str()); return false; } } std::stringstream childcount; childcount << GetChildCount(); std::string extension = URIUtils::GetExtension(libPath); strFileName = "special://temp/" + ID() + "-" + childcount.str() + extension; XFILE::CFile::Copy(libPath, strFileName); m_parentLib = libPath; CLog::Log(LOGNOTICE, "ADDON: Loaded virtual child addon %s", strFileName.c_str()); } /* Check if lib being loaded exists, else check in XBMC binary location */ #if defined(TARGET_ANDROID) // Android libs MUST live in this path, else multi-arch will break. // The usual soname requirements apply. no subdirs, and filename is ^lib.*\.so$ if (!XFILE::CFile::Exists(strFileName)) { std::string tempbin = getenv("XBMC_ANDROID_LIBS"); strFileName = tempbin + "/" + m_props.libname; } #endif if (!XFILE::CFile::Exists(strFileName)) { std::string altbin = CSpecialProtocol::TranslatePath("special://xbmcaltbinaddons/"); if (!altbin.empty()) { strAltFileName = altbin + m_props.libname; if (!XFILE::CFile::Exists(strAltFileName)) { std::string temp = CSpecialProtocol::TranslatePath("special://xbmc/addons/"); strAltFileName = strFileName; strAltFileName.erase(0, temp.size()); strAltFileName = altbin + strAltFileName; } CLog::Log(LOGDEBUG, "ADDON: Trying to load %s", strAltFileName.c_str()); } if (XFILE::CFile::Exists(strAltFileName)) strFileName = strAltFileName; else { std::string temp = CSpecialProtocol::TranslatePath("special://xbmc/"); std::string tempbin = CSpecialProtocol::TranslatePath("special://xbmcbin/"); strFileName.erase(0, temp.size()); strFileName = tempbin + strFileName; if (!XFILE::CFile::Exists(strFileName)) { CLog::Log(LOGERROR, "ADDON: Could not locate %s", m_props.libname.c_str()); return false; } } } /* Load the Dll */ m_pDll = new DllAddon; m_pDll->SetFile(strFileName); m_pDll->EnableDelayedUnload(false); if (!m_pDll->Load()) { delete m_pDll; m_pDll = NULL; CGUIDialogOK* pDialog = g_windowManager.GetWindow<CGUIDialogOK>(WINDOW_DIALOG_OK); if (pDialog) { std::string heading = StringUtils::Format("%s: %s", TranslateType(Type(), true).c_str(), Name().c_str()); pDialog->SetHeading(CVariant{heading}); pDialog->SetLine(1, CVariant{24070}); pDialog->SetLine(2, CVariant{24071}); pDialog->SetLine(2, CVariant{"Can't load shared library"}); pDialog->Open(); } return false; } return true; }