private:
_transient NSObject<FetchDelegate> *delegate_;
_transient Database *database_;
+ std::set<std::string> fetches_;
public:
SourceStatus(NSObject<FetchDelegate> *delegate, Database *database) :
{
}
- void Set(bool fetch, pkgAcquire::ItemDesc &desc) {
- desc.Owner->ID = 0;
- [database_ setFetch:fetch forURI:desc.Owner->DescURI().c_str()];
+ void Set(bool fetch, const std::string &uri) {
+ if (fetch) {
+ if (!fetches_.insert(uri).second)
+ return;
+ } else {
+ if (fetches_.erase(uri) == 0)
+ return;
+ }
+
+ //printf("Set(%s, %s)\n", fetch ? "true" : "false", uri.c_str());
+ [database_ setFetch:fetch forURI:uri.c_str()];
+ }
+
+ _finline void Set(bool fetch, pkgAcquire::Item *item) {
+ /*unsigned long ID(fetch ? 1 : 0);
+ if (item->ID == ID)
+ return;
+ item->ID = ID;*/
+ Set(fetch, item->DescURI());
+ }
+
+ void Log(const char *tag, pkgAcquire::Item *item) {
+ //printf("%s(%s) S:%u Q:%u\n", tag, item->DescURI().c_str(), item->Status, item->QueueCounter);
}
virtual void Fetch(pkgAcquire::ItemDesc &desc) {
- Set(true, desc);
+ Log("Fetch", desc.Owner);
+ Set(true, desc.Owner);
}
virtual void Done(pkgAcquire::ItemDesc &desc) {
- Set(false, desc);
+ Log("Done", desc.Owner);
+ Set(false, desc.Owner);
}
virtual void Fail(pkgAcquire::ItemDesc &desc) {
- Set(false, desc);
+ Log("Fail", desc.Owner);
+ Set(false, desc.Owner);
}
virtual bool Pulse_(pkgAcquire *Owner) {
- for (pkgAcquire::ItemCIterator item = Owner->ItemsBegin(); item != Owner->ItemsEnd(); ++item)
- if ((*item)->ID != 0);
- else if ((*item)->Status == pkgAcquire::Item::StatIdle) {
- (*item)->ID = 1;
- [database_ setFetch:true forURI:(*item)->DescURI().c_str()];
- } else (*item)->ID = 0;
+ std::set<std::string> fetches;
+ for (pkgAcquire::ItemCIterator item(Owner->ItemsBegin()); item != Owner->ItemsEnd(); ++item) {
+ bool fetch;
+ if ((*item)->QueueCounter == 0)
+ fetch = false;
+ else switch ((*item)->Status) {
+ case pkgAcquire::Item::StatFetching:
+ fetches.insert((*item)->DescURI());
+ fetch = true;
+ break;
+
+ default:
+ fetch = false;
+ break;
+ }
+
+ Log(fetch ? "Pulse<true>" : "Pulse<false>", *item);
+ Set(fetch, *item);
+ }
+
+ std::vector<std::string> stops;
+ std::set_difference(fetches_.begin(), fetches_.end(), fetches.begin(), fetches.end(), std::back_insert_iterator<std::vector<std::string>>(stops));
+ for (std::vector<std::string>::const_iterator stop(stops.begin()); stop != stops.end(); ++stop) {
+ //printf("Stop(%s)\n", stop->c_str());
+ Set(false, *stop);
+ }
+
return ![delegate_ isSourceCancelled];
}