int CScriptInvocationManager::ExecuteAsync(const std::string &script, LanguageInvokerPtr languageInvoker, const ADDON::AddonPtr &addon /* = ADDON::AddonPtr() */, const std::vector<std::string> &arguments /* = std::vector<std::string>() */, bool reuseable /* = false */, int pluginHandle /* = -1 */) { if (script.empty() || languageInvoker == NULL) return -1; if (!CFile::Exists(script, false)) { CLog::Log(LOGERROR, "%s - Not executing non-existing script %s", __FUNCTION__, script.c_str()); return -1; } CSingleLock lock(m_critSection); if (m_lastInvokerThread && m_lastInvokerThread->GetInvoker() == languageInvoker) { if (addon != NULL) m_lastInvokerThread->SetAddon(addon); // After we leave the lock, m_lastInvokerThread can be released -> copy! CLanguageInvokerThreadPtr invokerThread = m_lastInvokerThread; lock.Leave(); invokerThread->Execute(script, arguments); return invokerThread->GetId(); } m_lastInvokerThread = CLanguageInvokerThreadPtr(new CLanguageInvokerThread(languageInvoker, this, reuseable)); if (m_lastInvokerThread == NULL) return -1; if (addon != NULL) m_lastInvokerThread->SetAddon(addon); m_lastInvokerThread->SetId(m_nextId++); m_lastPluginHandle = pluginHandle; LanguageInvokerThread thread = { m_lastInvokerThread, script, false }; m_scripts.insert(std::make_pair(m_lastInvokerThread->GetId(), thread)); m_scriptPaths.insert(std::make_pair(script, m_lastInvokerThread->GetId())); // After we leave the lock, m_lastInvokerThread can be released -> copy! CLanguageInvokerThreadPtr invokerThread = m_lastInvokerThread; lock.Leave(); invokerThread->Execute(script, arguments); return invokerThread->GetId(); }
int CScriptInvocationManager::Execute(const std::string &script, const ADDON::AddonPtr &addon /* = ADDON::AddonPtr() */, const std::vector<std::string> &arguments /* = std::vector<std::string>() */) { if (script.empty() || !CFile::Exists(script, false)) return -1; ILanguageInvoker *invoker = GetLanguageInvoker(script); if (invoker == NULL) return -1; CLanguageInvokerThreadPtr invokerThread = CLanguageInvokerThreadPtr(new CLanguageInvokerThread(invoker, this)); if (invokerThread == NULL) return -1; if (addon != NULL) invokerThread->SetAddon(addon); CSingleLock lock(m_critSection); invokerThread->SetId(m_nextId++); lock.Leave(); LanguageInvokerThread thread = { invokerThread, script, false }; m_scripts.insert(make_pair(invokerThread->GetId(), thread)); m_scriptPaths.insert(make_pair(script, invokerThread->GetId())); invokerThread->Execute(script, arguments); return invokerThread->GetId(); }
int CScriptInvocationManager::ExecuteAsync(const std::string &script, LanguageInvokerPtr languageInvoker, const ADDON::AddonPtr &addon /* = ADDON::AddonPtr() */, const std::vector<std::string> &arguments /* = std::vector<std::string>() */) { if (script.empty() || languageInvoker == NULL) return -1; if (!CFile::Exists(script, false)) { CLog::Log(LOGERROR, "%s - Not executing non-existing script %s", __FUNCTION__, script.c_str()); return -1; } CLanguageInvokerThreadPtr invokerThread = CLanguageInvokerThreadPtr(new CLanguageInvokerThread(languageInvoker, this)); if (invokerThread == NULL) return -1; if (addon != NULL) invokerThread->SetAddon(addon); CSingleLock lock(m_critSection); invokerThread->SetId(m_nextId++); lock.Leave(); LanguageInvokerThread thread = { invokerThread, script, false }; m_scripts.insert(std::make_pair(invokerThread->GetId(), thread)); m_scriptPaths.insert(std::make_pair(script, invokerThread->GetId())); invokerThread->Execute(script, arguments); return invokerThread->GetId(); }