bool CPeripheralBusAddon::RequestRestart(ADDON::AddonPtr addon, bool datachanged) { // make sure this is a peripheral addon PeripheralAddonPtr peripheralAddon = std::dynamic_pointer_cast<CPeripheralAddon>(addon); if (peripheralAddon == nullptr) return false; if (peripheralAddon->CreateAddon() != ADDON_STATUS_OK) { CSingleLock lock(m_critSection); m_addons.erase(std::remove(m_addons.begin(), m_addons.end(), peripheralAddon), m_addons.end()); m_failedAddons.push_back(peripheralAddon); } return true; }
void CPeripheralBusAddon::UpdateAddons(void) { using namespace ADDON; auto GetPeripheralAddonID = [](const PeripheralAddonPtr& addon) { return addon->ID(); }; auto GetAddonID = [](const BinaryAddonBasePtr& addon) { return addon->ID(); }; std::set<std::string> currentIds; std::set<std::string> newIds; std::set<std::string> added; std::set<std::string> removed; // Get new add-ons BinaryAddonBaseList newAddons; CServiceBroker::GetBinaryAddonManager().GetAddonInfos(newAddons, true, ADDON_PERIPHERALDLL); std::transform(newAddons.begin(), newAddons.end(), std::inserter(newIds, newIds.end()), GetAddonID); CSingleLock lock(m_critSection); // Get current add-ons std::transform(m_addons.begin(), m_addons.end(), std::inserter(currentIds, currentIds.end()), GetPeripheralAddonID); std::transform(m_failedAddons.begin(), m_failedAddons.end(), std::inserter(currentIds, currentIds.end()), GetPeripheralAddonID); // Differences std::set_difference(newIds.begin(), newIds.end(), currentIds.begin(), currentIds.end(), std::inserter(added, added.end())); std::set_difference(currentIds.begin(), currentIds.end(), newIds.begin(), newIds.end(), std::inserter(removed, removed.end())); // Register new add-ons for (const std::string& addonId : added) { CLog::Log(LOGDEBUG, "Add-on bus: Registering add-on %s", addonId.c_str()); auto GetAddon = [&addonId](const BinaryAddonBasePtr& addon) { return addon->ID() == addonId; }; BinaryAddonBaseList::iterator it = std::find_if(newAddons.begin(), newAddons.end(), GetAddon); if (it != newAddons.end()) { PeripheralAddonPtr newAddon = std::make_shared<CPeripheralAddon>(*it, m_manager); if (newAddon) { bool bCreated; { CSingleExit exit(m_critSection); bCreated = newAddon->CreateAddon(); } if (bCreated) m_addons.emplace_back(std::move(newAddon)); else m_failedAddons.emplace_back(std::move(newAddon)); } } } // Destroy removed add-ons for (const std::string& addonId : removed) { UnRegisterAddon(addonId); } }