~timo-jyrinki/unity-scope-mediascanner/manual_import_rtm_0.2+14.10.20141009-0ubuntu1

« back to all changes in this revision

Viewing changes to src/utils/resultforwarder.h

  • Committer: Timo Jyrinki
  • Date: 2014-10-29 14:28:38 UTC
  • Revision ID: timo.jyrinki@canonical.com-20141029142838-uveiptpvvs5yz0pe
Manual import of 0.2+14.10.20141009-0ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2014 Canonical Ltd
3
 
 *
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.
7
 
 *
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.
12
 
 *
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/>.
15
 
 *
16
 
 * Authored by Jussi Pakkanen <jussi.pakkanen@canonical.com>
17
 
 *
18
 
 */
19
 
 
20
 
#ifndef RESULTFORWARDER_H_
21
 
#define RESULTFORWARDER_H_
22
 
 
23
 
#include<unity/scopes/SearchListenerBase.h>
24
 
#include<unity/scopes/SearchReplyProxyFwd.h>
25
 
#include<unity/scopes/ListenerBase.h>
26
 
#include<unity/scopes/CategorisedResult.h>
27
 
#include<list>
28
 
#include<memory>
29
 
#include<cassert>
30
 
#include <functional>
31
 
#include "notify-strategy.h"
32
 
 
33
 
class ResultForwarder : public unity::scopes::SearchListenerBase {
34
 
 
35
 
public:
36
 
 
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>()) :
40
 
        upstream(upstream),
41
 
        result_filter(result_filter),
42
 
        notify_strategy_(notify_strategy),
43
 
        ready_(false) {
44
 
            assert(notify_strategy != nullptr);
45
 
    }
46
 
    virtual ~ResultForwarder() {}
47
 
 
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);
51
 
 
52
 
    virtual void finished(unity::scopes::CompletionDetails const& details) override;
53
 
 
54
 
protected:
55
 
    void on_forwarder_ready(ResultForwarder *fw);
56
 
    virtual void on_all_forwarders_ready();
57
 
    unity::scopes::SearchReplyProxy upstream;
58
 
    void notify_observers();
59
 
 
60
 
private:
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_;
65
 
    bool ready_;
66
 
};
67
 
 
68
 
#endif