2
* Copyright (C) 2014 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by Jussi Pakkanen <jussi.pakkanen@canonical.com>
17
* Pawel Stolowski <pawel.stolowski@canonical.com>
21
#include "resultforwarder.h"
22
#include <unity/scopes/SearchReply.h>
24
using namespace unity::scopes;
26
void ResultForwarder::push(Category::SCPtr const& category) {
27
upstream->register_category(category);
30
void ResultForwarder::push(CategorisedResult result) {
32
if (result_filter(result))
34
upstream->push(result);
39
ready_ = notify_strategy_->is_ready(result);
47
void ResultForwarder::finished(unity::scopes::CompletionDetails const& /*details*/) {
55
void ResultForwarder::notify_observers()
57
for (auto o: observers_)
59
o->on_forwarder_ready(this);
64
void ResultForwarder::add_observer(std::shared_ptr<ResultForwarder> result_forwarder)
66
if (result_forwarder.get() != this)
68
observers_.push_back(result_forwarder);
69
result_forwarder->wait_for_.push_back(this);
73
void ResultForwarder::on_forwarder_ready(ResultForwarder *fw)
76
// remove the forwarder that notified us from the wait_for_ list;
77
wait_for_.remove_if([fw](ResultForwarder* r) -> bool { return r == fw; });
78
if (wait_for_.size() == 0)
80
on_all_forwarders_ready();
84
void ResultForwarder::on_all_forwarders_ready()
86
// base impl does nothing