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>
20
#ifndef RESULTFORWARDER_H_
21
#define RESULTFORWARDER_H_
23
#include<unity/scopes/SearchListenerBase.h>
24
#include<unity/scopes/SearchReplyProxyFwd.h>
25
#include<unity/scopes/ListenerBase.h>
26
#include<unity/scopes/CategorisedResult.h>
31
#include "notify-strategy.h"
33
class ResultForwarder : public unity::scopes::SearchListenerBase {
37
ResultForwarder(unity::scopes::SearchReplyProxy const& upstream,
38
std::function<bool(unity::scopes::CategorisedResult&)> const &result_filter = [](unity::scopes::CategorisedResult&) -> bool { return true; },
39
std::shared_ptr<NotifyStrategy> notify_strategy = std::make_shared<WaitForAnyResult>()) :
41
result_filter(result_filter),
42
notify_strategy_(notify_strategy),
44
assert(notify_strategy != nullptr);
46
virtual ~ResultForwarder() {}
48
virtual void push(unity::scopes::Category::SCPtr const& category) override;
49
virtual void push(unity::scopes::CategorisedResult result) override;
50
void add_observer(std::shared_ptr<ResultForwarder> result_forwarder);
52
virtual void finished(unity::scopes::CompletionDetails const& details) override;
55
void on_forwarder_ready(ResultForwarder *fw);
56
virtual void on_all_forwarders_ready();
57
unity::scopes::SearchReplyProxy upstream;
58
void notify_observers();
61
std::list<std::shared_ptr<ResultForwarder>> observers_;
62
std::list<ResultForwarder*> wait_for_;
63
std::function<bool(unity::scopes::CategorisedResult&)> result_filter;
64
std::shared_ptr<NotifyStrategy> notify_strategy_;