~nikwen/account-polld/directly-poll-with-new-account-data-fix

« back to all changes in this revision

Viewing changes to plugins/plugins.go

  • Committer: Sergio Schvezov
  • Date: 2014-07-09 00:38:13 UTC
  • Revision ID: sergio.schvezov@canonical.com-20140709003813-htloz24c4c19h7vw
Initial plugin interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 Copyright 2014 Canonical Ltd.
 
3
 Authors: Sergio Schvezov <sergio.schvezov@canonical.com>
 
4
 
 
5
 This program is free software: you can redistribute it and/or modify it
 
6
 under the terms of the GNU General Public License version 3, as published
 
7
 by the Free Software Foundation.
 
8
 
 
9
 This program is distributed in the hope that it will be useful, but
 
10
 WITHOUT ANY WARRANTY; without even the implied warranties of
 
11
 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
 
12
 PURPOSE.  See the GNU General Public License for more details.
 
13
 
 
14
 You should have received a copy of the GNU General Public License along
 
15
 with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
*/
 
17
 
 
18
package plugins
 
19
 
 
20
// Plugin is an interface which the plugins will adhere to for the poll
 
21
// daemon to interact with.
 
22
//
 
23
// Register is the first method to be called after creating a New[plugin],
 
24
// upon register the plugin will check if it is Authorized and Installed
 
25
// and send it over State.
 
26
//
 
27
// Poll interacts with the backend service with the means the plugin defines
 
28
// and  returns a list of Notifications to send to the Push service. If an
 
29
// error occurs and is returned the daemon can decide to throttle the service.
 
30
//
 
31
// GetType is for future use and helps the daemon determine the polling
 
32
// frequency.
 
33
type Plugin interface {
 
34
        Register() (ApplicationId, chan (State))
 
35
        Poll() (*[]Notification, error)
 
36
        //GetPriority() int
 
37
        //GetType() int
 
38
        //Notify()
 
39
}
 
40
 
 
41
// ApplicationId represents the application id to direct posts to.
 
42
// e.g.: com.ubuntu.diaspora_diaspora or com.ubuntu.diaspora_diaspora_1.0
 
43
//
 
44
// TODO define if APP_ID can be of short form
 
45
// TODO find documentation where short APP_ID is defined (aka versionless APP_ID).
 
46
type ApplicationId string
 
47
 
 
48
// Notification represents the data pass over to the Post Office
 
49
type Notification struct {
 
50
        Sound string `json:"sound"`
 
51
        Card  Card   `json:"card"`
 
52
}
 
53
 
 
54
type Card struct {
 
55
        Summary string `json:"summary"`
 
56
        Popup   bool   `json:"popup"`
 
57
        Persist bool   `json:"persist"`
 
58
}
 
59
 
 
60
// State represents a state change for a plugin. Installed is set to true when
 
61
// the package that is supposed to handle the notification is installed whilst
 
62
// Authorized being true means that at least one account is authorized to poll
 
63
type State struct {
 
64
        Installed, Authorized bool
 
65
}
 
66
 
 
67
// The constanst defined here determine the polling aggressivenes with the following criteria
 
68
// MAXIMUM: calls, health warning
 
69
// HIGH: SMS, chat message, new email
 
70
// DEFAULT: social media updates
 
71
// LOW: software updates, junk email
 
72
const (
 
73
        PRIORITY_MAXIMUM = 0
 
74
        PRIORITY_HIGH
 
75
        PRIORITY_DEFAULT
 
76
        PRIORITY_LOW
 
77
)
 
78
 
 
79
const (
 
80
        PLUGIN_EMAIL = 0
 
81
        PLUGIN_SOCIAL
 
82
)