#pragma once #include #include #include #include #include #include #include "warp.h" #include "binaryninjaapi.h" #include "uitypes.h" enum WarpFetchCompletionStatus { KeepCallback, RemoveCallback, }; // Responsible for fetching data from the containers, to later be queried from the container interface. class WarpFetcher { LoggerRef m_logger; std::mutex m_requestMutex; std::vector m_pendingRequests; // TODO: Easy way to clear this if user wants to refetch. std::unordered_set m_processedGuids; // List of callbacks to call when done fetching data, assume that others are using this as well. std::vector > m_completionCallbacks; public: explicit WarpFetcher(); // The global fetcher instance, this is used for the fetch dialog and the sidebar. static std::shared_ptr Global(); std::atomic m_requestInProgress = false; // Set the allowed source tags, sources with none of these tags will not be fetched from. void SetTags(const std::vector &tags) { std::lock_guard lock(m_requestMutex); // TODO: This is kinda a hack, the fetcher instance should not sync through qt settings! QStringList qtTags = {}; for (const auto& t : tags) qtTags.append(QString::fromStdString(t)); QSettings().setValue("warp/allowedTags", qtTags); } std::vector GetTags() const { std::lock_guard lock(const_cast(m_requestMutex)); // TODO: This is kinda a hack, the fetcher instance should not sync through qt settings! QSettings qtSettings; QStringList tags = qtSettings.value("warp/allowedTags").toStringList(); if (tags.isEmpty()) { // The default tags to allow. tags = QStringList{ "official", "trusted" }; qtSettings.setValue("warp/allowedTags", tags); qtSettings.sync(); } std::vector initialTags = {}; for (const auto& t : tags) initialTags.emplace_back(t.trimmed().toStdString()); return initialTags; } void AddCompletionCallback(std::function cb) { std::lock_guard lock(m_requestMutex); m_completionCallbacks.push_back(std::move(cb)); } void AddPendingFunction(const FunctionRef &func); void FetchPendingFunctions(); void ClearProcessed(); private: std::vector FlushPendingFunctions(); void ExecuteCompletionCallback(); };