~unity-api-team/unity-scopes-api/child-scopes-option

« back to all changes in this revision

Viewing changes to demo/scope-A.cpp

  • Committer: Michi Henning
  • Date: 2013-11-19 02:51:46 UTC
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: michi.henning@canonical.com-20131119025146-kglcalpphl4ozzk7
Fixed scoperegistry to use new scoperunner and to figure out which scopes to run from config files.
Still to do:
- deal with overrides and OEM scopes, particularly the grouping aspect.
- SignalThread needs to invoke a callback for clean shut-down on receipt of SIGINT.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013 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: Michi Henning <michi.henning@canonical.com>
17
 
 */
18
 
 
19
 
#include <scopes/ScopeBase.h>
20
 
#include <scopes/Reply.h>
21
 
#include <scopes/Category.h>
22
 
#include <scopes/ResultItem.h>
23
 
 
24
 
#include <iostream>
25
 
 
26
 
#define EXPORT __attribute__ ((visibility ("default")))
27
 
 
28
 
using namespace std;
29
 
using namespace unity::api::scopes;
30
 
 
31
 
// Example scope A: replies synchronously to a query. (Replies are returned before returning from the run() method.)
32
 
 
33
 
class MyQuery : public QueryBase
34
 
{
35
 
public:
36
 
    MyQuery(string const& query) :
37
 
        query_(query)
38
 
    {
39
 
    }
40
 
 
41
 
    ~MyQuery() noexcept
42
 
    {
43
 
    }
44
 
 
45
 
    virtual void cancelled() override
46
 
    {
47
 
    }
48
 
 
49
 
    virtual void run(ReplyProxy const& reply) override
50
 
    {
51
 
        auto cat = std::shared_ptr<Category>(new Category("cat1"));
52
 
        ResultItem res(cat);
53
 
        res.set_uri("uri");
54
 
        res.set_title("scope-A: result 1 for query \"" + query_ + "\"");
55
 
        res.set_icon("icon");
56
 
        res.set_dnd_uri("dnd_uri");
57
 
        reply->push(res);
58
 
        cout << "scope-A: query \"" << query_ << "\" complete" << endl;
59
 
    }
60
 
 
61
 
private:
62
 
    string query_;
63
 
};
64
 
 
65
 
class MyScope : public ScopeBase
66
 
{
67
 
public:
68
 
    virtual int start(string const&, RegistryProxy const&) override
69
 
    {
70
 
        return VERSION;
71
 
    }
72
 
 
73
 
    virtual void stop() override {}
74
 
    virtual void run() override {}
75
 
 
76
 
    virtual QueryBase::UPtr create_query(string const& q, VariantMap const&) override
77
 
    {
78
 
        QueryBase::UPtr query(new MyQuery(q));
79
 
        cout << "scope-A: created query: \"" << q << "\"" << endl;
80
 
        return query;
81
 
    }
82
 
};
83
 
 
84
 
extern "C"
85
 
{
86
 
 
87
 
    EXPORT
88
 
    unity::api::scopes::ScopeBase*
89
 
    // cppcheck-suppress unusedFunction
90
 
    UNITY_API_SCOPE_CREATE_FUNCTION()
91
 
    {
92
 
        return new MyScope;
93
 
    }
94
 
 
95
 
    EXPORT
96
 
    void
97
 
    // cppcheck-suppress unusedFunction
98
 
    UNITY_API_SCOPE_DESTROY_FUNCTION(unity::api::scopes::ScopeBase* scope_base)
99
 
    {
100
 
        delete scope_base;
101
 
    }
102
 
 
103
 
}