Esempio n. 1
0
bool CScriptInvocationManager::Stop(int scriptId, bool wait /* = false */)
{
  if (scriptId < 0)
    return false;

  CSingleLock lock(m_critSection);
  CLanguageInvokerThreadPtr invokerThread = getInvokerThread(scriptId).thread;
  if (invokerThread == NULL)
    return false;

  return invokerThread->Stop(wait);
}
Esempio n. 2
0
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();
}
Esempio n. 4
0
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();
}