proxy client: implement getLocal(), getLocalById()

This commit is contained in:
Adrien Béraud committed 2018-03-16 13:34:41 -04:00
1 parent 2f4acd26d6
commit 647de16f1c
3 files changed
+57 -7

No files matched your search

+2 -7
View File
@@ -227,13 +227,8 @@ public:
return types.getType(type_id);
}
std::vector<Sp<Value>> getLocal(const InfoHash&, Value::Filter) const {
return {};
}
Sp<Value> getLocalById(const InfoHash&, Value::Id) const {
return {};
}
std::vector<Sp<Value>> getLocal(const InfoHash& k, Value::Filter filter) const;
Sp<Value> getLocalById(const InfoHash& k, Value::Id id) const;
/**
* NOTE: The following methods will not be implemented because the
+16
View File
@@ -84,6 +84,22 @@ DhtProxyClient::~DhtProxyClient()
cancelAllListeners();
}
std::vector<Sp<Value>>
DhtProxyClient::getLocal(const InfoHash& k, Value::Filter filter) const {
auto s = listeners_.find(k);
if (s == listeners_.end())
return {};
return s->second.ops.get(filter);
}
Sp<Value>
DhtProxyClient::getLocalById(const InfoHash& k, Value::Id id) const {
auto s = listeners_.find(k);
if (s == listeners_.end())
return {};
return s->second.ops.get(id);
}
void
DhtProxyClient::cancelAllOperations()
{
+39
View File
@@ -139,6 +139,23 @@ public:
return listeners.empty();
}
std::vector<Sp<Value>> get(Value::Filter& filter) const {
std::vector<Sp<Value>> ret;
if (not filter)
ret.reserve(values.size());
for (const auto& v : values)
if (not filter or filter(*v.second.data))
ret.emplace_back(v.second.data);
return ret;
}
Sp<Value> get(Value::Id id) const {
auto v = values.find(id);
if (v == values.end())
return {};
return v->second.data;
}
size_t searchToken;
private:
std::map<size_t, LocalListener> listeners;
@@ -188,6 +205,28 @@ public:
return false;
}
std::vector<Sp<Value>> get(Value::Filter& filter) const {
if (ops.size() == 1)
return ops.begin()->second.get(filter);
std::map<Value::Id, Sp<Value>> c;
for (const auto& op : ops) {
for (const auto& v : op.second.get(filter))
c.emplace(v->id, v);
}
std::vector<Sp<Value>> ret;
ret.reserve(c.size());
for (auto& v : c)
ret.emplace_back(std::move(v.second));
return ret;
}
Sp<Value> get(Value::Id id) const {
for (const auto& op : ops)
if (auto v = op.second.get(id))
return v;
return {};
}
private:
std::map<Sp<Query>, OpCache> ops;
size_t nextToken_ {1};